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 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.status.StatusScmResult;
27 import org.apache.maven.scm.log.ScmLogger;
28 import org.apache.maven.scm.provider.ScmProviderRepository;
29 import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand;
30 import org.apache.maven.scm.provider.clearcase.command.edit.ClearCaseEditCommand;
31 import org.codehaus.plexus.util.cli.CommandLineException;
32 import org.codehaus.plexus.util.cli.CommandLineUtils;
33 import org.codehaus.plexus.util.cli.Commandline;
34
35 import java.io.File;
36
37
38
39
40 public class ClearCaseRemoveCommand
41 extends AbstractRemoveCommand
42 implements ClearCaseCommand
43 {
44 protected ScmResult executeRemoveCommand( ScmProviderRepository scmProviderRepository, ScmFileSet scmFileSet,
45 String string )
46 throws ScmException
47 {
48 getLogger().debug( "executing remove command..." );
49 Commandline cl = createCommandLine( getLogger(), scmFileSet );
50
51 ClearCaseRemoveConsumer consumer = new ClearCaseRemoveConsumer( getLogger() );
52
53 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
54
55 int exitCode;
56 try
57 {
58
59 Commandline checkoutCurrentDirCommandLine =
60 ClearCaseEditCommand.createCheckoutCurrentDirCommandLine( scmFileSet );
61 getLogger().debug( "Executing: " + checkoutCurrentDirCommandLine.getWorkingDirectory().getAbsolutePath() +
62 ">>" + checkoutCurrentDirCommandLine.toString() );
63 exitCode = CommandLineUtils.executeCommandLine( checkoutCurrentDirCommandLine,
64 new CommandLineUtils.StringStreamConsumer(), stderr );
65
66 if ( exitCode == 0 )
67 {
68
69 getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
70 exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
71
72 if ( exitCode == 0 )
73 {
74
75 Commandline checkinCurrentDirCommandLine =
76 ClearCaseEditCommand.createCheckinCurrentDirCommandLine( scmFileSet );
77 getLogger().debug( "Executing: " +
78 checkinCurrentDirCommandLine.getWorkingDirectory().getAbsolutePath() + ">>" +
79 checkinCurrentDirCommandLine.toString() );
80 exitCode = CommandLineUtils.executeCommandLine( checkinCurrentDirCommandLine,
81 new CommandLineUtils.StringStreamConsumer(),
82 stderr );
83 }
84 }
85 }
86 catch ( CommandLineException ex )
87 {
88 throw new ScmException( "Error while executing clearcase command.", ex );
89 }
90
91 if ( exitCode != 0 )
92 {
93 return new StatusScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
94 }
95
96 return new StatusScmResult( cl.toString(), consumer.getRemovedFiles() );
97 }
98
99
100
101
102
103 public static Commandline createCommandLine( ScmLogger logger, ScmFileSet scmFileSet )
104 {
105 Commandline command = new Commandline();
106
107 File workingDirectory = scmFileSet.getBasedir();
108
109 command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
110
111 command.setExecutable( "cleartool" );
112
113 command.createArgument().setValue( "rmname" );
114
115 command.createArgument().setValue( "-nc" );
116
117 File[] files = scmFileSet.getFiles();
118 for ( int i = 0; i < files.length; i++ )
119 {
120 File file = files[i];
121 logger.info( "Deleting file: " + file.getAbsolutePath() );
122 command.createArgument().setValue( file.getName() );
123 }
124
125 return command;
126 }
127 }