1 package org.apache.maven.scm.provider.starteam.command.add;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.ScmException;
23 import org.apache.maven.scm.ScmFileSet;
24 import org.apache.maven.scm.ScmResult;
25 import org.apache.maven.scm.command.add.AbstractAddCommand;
26 import org.apache.maven.scm.command.add.AddScmResult;
27 import org.apache.maven.scm.provider.ScmProviderRepository;
28 import org.apache.maven.scm.provider.starteam.command.StarteamCommand;
29 import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils;
30 import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
31 import org.codehaus.plexus.util.cli.CommandLineUtils;
32 import org.codehaus.plexus.util.cli.Commandline;
33
34 import java.io.File;
35 import java.util.ArrayList;
36 import java.util.List;
37
38
39
40
41
42 public class StarteamAddCommand
43 extends AbstractAddCommand
44 implements StarteamCommand
45 {
46
47 protected ScmResult executeAddCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
48 boolean binary )
49 throws ScmException
50 {
51
52
53 String issue = System.getProperty( "maven.scm.issue" );
54
55 if ( getLogger().isInfoEnabled() )
56 {
57 getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() );
58 }
59
60 StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
61
62 StarteamAddConsumer consumer = new StarteamAddConsumer( getLogger(), fileSet.getBasedir() );
63
64 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
65
66 for ( File fileToBeAdded : fileSet.getFileList() )
67 {
68 ScmFileSet scmFile = new ScmFileSet( fileSet.getBasedir(), fileToBeAdded );
69
70 Commandline cl = createCommandLine( repository, scmFile, issue );
71
72 int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
73
74 if ( exitCode != 0 )
75 {
76 return new AddScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false );
77 }
78 }
79
80 return new AddScmResult( null, consumer.getAddedFiles() );
81 }
82
83 static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet scmFileSet, String issue )
84 {
85 List<String> args = new ArrayList<String>();
86
87 if ( issue != null && issue.length() != 0 )
88 {
89 args.add( "-cr" );
90 args.add( issue );
91 }
92
93 StarteamCommandLineUtils.addEOLOption( args );
94
95 return StarteamCommandLineUtils.createStarteamCommandLine( "add", args, scmFileSet, repo );
96 }
97 }