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 | 0 | 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 | 0 | if ( getLogger().isDebugEnabled() ) |
53 | |
{ |
54 | 0 | getLogger().debug( "executing remove command..." ); |
55 | |
} |
56 | 0 | Commandline cl = createCommandLine( getLogger(), scmFileSet ); |
57 | |
|
58 | 0 | ClearCaseRemoveConsumer consumer = new ClearCaseRemoveConsumer( getLogger() ); |
59 | |
|
60 | 0 | CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); |
61 | |
|
62 | |
int exitCode; |
63 | |
try |
64 | |
{ |
65 | |
|
66 | 0 | Commandline checkoutCurrentDirCommandLine = |
67 | |
ClearCaseEditCommand.createCheckoutCurrentDirCommandLine( scmFileSet ); |
68 | |
|
69 | 0 | if ( getLogger().isDebugEnabled() ) |
70 | |
{ |
71 | 0 | getLogger().debug( |
72 | |
"Executing: " |
73 | |
+ checkoutCurrentDirCommandLine.getWorkingDirectory().getAbsolutePath() |
74 | |
+ ">>" + checkoutCurrentDirCommandLine.toString() ); |
75 | |
} |
76 | 0 | exitCode = |
77 | |
CommandLineUtils.executeCommandLine( checkoutCurrentDirCommandLine, |
78 | |
new CommandLineUtils.StringStreamConsumer(), stderr ); |
79 | |
|
80 | 0 | if ( exitCode == 0 ) |
81 | |
{ |
82 | |
|
83 | 0 | if ( getLogger().isDebugEnabled() ) |
84 | |
{ |
85 | 0 | getLogger().debug( |
86 | |
"Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" |
87 | |
+ cl.toString() ); |
88 | |
} |
89 | 0 | exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr ); |
90 | |
|
91 | 0 | if ( exitCode == 0 ) |
92 | |
{ |
93 | |
|
94 | 0 | Commandline checkinCurrentDirCommandLine = |
95 | |
ClearCaseEditCommand.createCheckinCurrentDirCommandLine( scmFileSet ); |
96 | 0 | if ( getLogger().isDebugEnabled() ) |
97 | |
{ |
98 | 0 | getLogger().debug( |
99 | |
"Executing: " |
100 | |
+ checkinCurrentDirCommandLine.getWorkingDirectory().getAbsolutePath() |
101 | |
+ ">>" + checkinCurrentDirCommandLine.toString() ); |
102 | |
} |
103 | 0 | exitCode = CommandLineUtils.executeCommandLine( checkinCurrentDirCommandLine, |
104 | |
new CommandLineUtils.StringStreamConsumer(), |
105 | |
stderr ); |
106 | |
} |
107 | |
} |
108 | |
} |
109 | 0 | catch ( CommandLineException ex ) |
110 | |
{ |
111 | 0 | throw new ScmException( "Error while executing clearcase command.", ex ); |
112 | 0 | } |
113 | |
|
114 | 0 | if ( exitCode != 0 ) |
115 | |
{ |
116 | 0 | return new StatusScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false ); |
117 | |
} |
118 | |
|
119 | 0 | return new StatusScmResult( cl.toString(), consumer.getRemovedFiles() ); |
120 | |
} |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
public static Commandline createCommandLine( ScmLogger logger, ScmFileSet scmFileSet ) |
127 | |
{ |
128 | 1 | Commandline command = new Commandline(); |
129 | |
|
130 | 1 | File workingDirectory = scmFileSet.getBasedir(); |
131 | |
|
132 | 1 | command.setWorkingDirectory( workingDirectory.getAbsolutePath() ); |
133 | |
|
134 | 1 | command.setExecutable( "cleartool" ); |
135 | |
|
136 | 1 | command.createArg().setValue( "rmname" ); |
137 | |
|
138 | 1 | command.createArg().setValue( "-nc" ); |
139 | |
|
140 | 1 | List<File> files = scmFileSet.getFileList(); |
141 | 1 | for ( File file : files ) |
142 | |
{ |
143 | 1 | if ( logger.isInfoEnabled() ) |
144 | |
{ |
145 | 1 | logger.info( "Deleting file: " + file.getAbsolutePath() ); |
146 | |
} |
147 | 1 | command.createArg().setValue( file.getName() ); |
148 | |
} |
149 | |
|
150 | 1 | return command; |
151 | |
} |
152 | |
} |