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