1 package org.apache.maven.scm.provider.starteam.command.remove;
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.remove.AbstractRemoveCommand;
26 import org.apache.maven.scm.command.remove.RemoveScmResult;
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.command.checkin.StarteamCheckInConsumer;
31 import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
32 import org.codehaus.plexus.util.cli.CommandLineUtils;
33 import org.codehaus.plexus.util.cli.Commandline;
34
35 import java.io.File;
36 import java.util.List;
37
38
39
40
41
42
43 public class StarteamRemoveCommand
44 extends AbstractRemoveCommand
45 implements StarteamCommand
46 {
47
48 protected ScmResult executeRemoveCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message )
49 throws ScmException
50 {
51 if ( getLogger().isInfoEnabled() )
52 {
53 getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() );
54 }
55
56 StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
57
58 StarteamCheckInConsumer consumer = new StarteamCheckInConsumer( getLogger(), fileSet.getBasedir() );
59
60 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
61
62 List<File> remvoveFiles = fileSet.getFileList();
63
64 if ( remvoveFiles.size() == 0 )
65 {
66 Commandline cl = createCommandLine( repository, fileSet );
67
68 int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
69
70 if ( exitCode != 0 )
71 {
72 return new RemoveScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false );
73 }
74 }
75 else
76 {
77
78 for ( int i = 0; i < remvoveFiles.size(); ++i )
79 {
80 File fileToBeRemoved = (File) remvoveFiles.get( i );
81 ScmFileSet scmFileSet = new ScmFileSet( fileSet.getBasedir(), fileToBeRemoved );
82 Commandline cl = createCommandLine( repository, scmFileSet );
83
84 int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
85
86 if ( exitCode != 0 )
87 {
88 return new RemoveScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(),
89 false );
90 }
91 }
92 }
93
94 return new RemoveScmResult( null, consumer.getCheckedInFiles() );
95
96 }
97
98 public static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet dirOrFile )
99 {
100 return StarteamCommandLineUtils.createStarteamCommandLine( "remove", null, dirOrFile, repo );
101 }
102 }