1 package org.apache.maven.scm.provider.starteam.command.edit;
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.edit.AbstractEditCommand;
26 import org.apache.maven.scm.command.edit.EditScmResult;
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 StarteamEditCommand
43 extends AbstractEditCommand
44 implements StarteamCommand
45 {
46
47
48
49
50
51 protected ScmResult executeEditCommand( ScmProviderRepository repo, ScmFileSet fileSet )
52 throws ScmException
53 {
54 if ( getLogger().isInfoEnabled() )
55 {
56 getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() );
57 }
58
59 StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
60
61 StarteamEditConsumer consumer = new StarteamEditConsumer( getLogger(), fileSet.getBasedir() );
62
63 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
64
65 List<File> editFiles = fileSet.getFileList();
66
67 if ( editFiles.size() == 0 )
68 {
69 Commandline cl = createCommandLine( repository, fileSet );
70
71 int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
72
73 if ( exitCode != 0 )
74 {
75 return new EditScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false );
76 }
77 }
78 else
79 {
80
81 for ( int i = 0; i < editFiles.size(); ++i )
82 {
83 ScmFileSet editFile = new ScmFileSet( fileSet.getBasedir(), (File) editFiles.get( i ) );
84 Commandline cl = createCommandLine( repository, editFile );
85
86 int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
87
88 if ( exitCode != 0 )
89 {
90 return new EditScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(),
91 false );
92 }
93 }
94 }
95
96 return new EditScmResult( null, consumer.getEditedFiles() );
97
98 }
99
100 public static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet dirOrFile )
101 {
102 List<String> args = new ArrayList<String>();
103 args.add( "-l" );
104
105 return StarteamCommandLineUtils.createStarteamCommandLine( "lck", args, dirOrFile, repo );
106 }
107 }