1 package org.apache.maven.scm.provider.clearcase.command.remove;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.List;
24
25 import org.apache.maven.scm.ScmException;
26 import org.apache.maven.scm.ScmFileSet;
27 import org.apache.maven.scm.ScmResult;
28 import org.apache.maven.scm.command.remove.AbstractRemoveCommand;
29 import org.apache.maven.scm.command.status.StatusScmResult;
30 import org.apache.maven.scm.log.ScmLogger;
31 import org.apache.maven.scm.provider.ScmProviderRepository;
32 import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand;
33 import org.apache.maven.scm.provider.clearcase.command.edit.ClearCaseEditCommand;
34 import org.codehaus.plexus.util.cli.CommandLineException;
35 import org.codehaus.plexus.util.cli.CommandLineUtils;
36 import org.codehaus.plexus.util.cli.Commandline;
37
38
39
40
41
42
43 public class ClearCaseRemoveCommand
44 extends AbstractRemoveCommand
45 implements ClearCaseCommand
46 {
47
48 protected ScmResult executeRemoveCommand( ScmProviderRepository scmProviderRepository, ScmFileSet scmFileSet,
49 String string )
50 throws ScmException
51 {
52 if ( getLogger().isDebugEnabled() )
53 {
54 getLogger().debug( "executing remove command..." );
55 }
56 Commandline cl = createCommandLine( getLogger(), scmFileSet );
57
58 ClearCaseRemoveConsumer consumer = new ClearCaseRemoveConsumer( getLogger() );
59
60 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
61
62 int exitCode;
63 try
64 {
65
66 Commandline checkoutCurrentDirCommandLine =
67 ClearCaseEditCommand.createCheckoutCurrentDirCommandLine( scmFileSet );
68
69 if ( getLogger().isDebugEnabled() )
70 {
71 getLogger().debug(
72 "Executing: "
73 + checkoutCurrentDirCommandLine.getWorkingDirectory().getAbsolutePath()
74 + ">>" + checkoutCurrentDirCommandLine.toString() );
75 }
76 exitCode =
77 CommandLineUtils.executeCommandLine( checkoutCurrentDirCommandLine,
78 new CommandLineUtils.StringStreamConsumer(), stderr );
79
80 if ( exitCode == 0 )
81 {
82
83 if ( getLogger().isDebugEnabled() )
84 {
85 getLogger().debug(
86 "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>"
87 + cl.toString() );
88 }
89 exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
90
91 if ( exitCode == 0 )
92 {
93
94 Commandline checkinCurrentDirCommandLine =
95 ClearCaseEditCommand.createCheckinCurrentDirCommandLine( scmFileSet );
96 if ( getLogger().isDebugEnabled() )
97 {
98 getLogger().debug(
99 "Executing: "
100 + checkinCurrentDirCommandLine.getWorkingDirectory().getAbsolutePath()
101 + ">>" + checkinCurrentDirCommandLine.toString() );
102 }
103 exitCode = CommandLineUtils.executeCommandLine( checkinCurrentDirCommandLine,
104 new CommandLineUtils.StringStreamConsumer(),
105 stderr );
106 }
107 }
108 }
109 catch ( CommandLineException ex )
110 {
111 throw new ScmException( "Error while executing clearcase command.", ex );
112 }
113
114 if ( exitCode != 0 )
115 {
116 return new StatusScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
117 }
118
119 return new StatusScmResult( cl.toString(), consumer.getRemovedFiles() );
120 }
121
122
123
124
125
126 public static Commandline createCommandLine( ScmLogger logger, ScmFileSet scmFileSet )
127 {
128 Commandline command = new Commandline();
129
130 File workingDirectory = scmFileSet.getBasedir();
131
132 command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
133
134 command.setExecutable( "cleartool" );
135
136 command.createArg().setValue( "rmname" );
137
138 command.createArg().setValue( "-nc" );
139
140 List<File> files = scmFileSet.getFileList();
141 for ( File file : files )
142 {
143 if ( logger.isInfoEnabled() )
144 {
145 logger.info( "Deleting file: " + file.getAbsolutePath() );
146 }
147 command.createArg().setValue( file.getName() );
148 }
149
150 return command;
151 }
152 }