1 | |
package org.apache.maven.scm.provider.perforce.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.perforce.PerforceScmProvider; |
29 | |
import org.apache.maven.scm.provider.perforce.command.PerforceCommand; |
30 | |
import org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository; |
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 | |
import java.util.List; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class PerforceRemoveCommand |
44 | |
extends AbstractRemoveCommand |
45 | |
implements PerforceCommand |
46 | |
{ |
47 | |
|
48 | |
|
49 | |
|
50 | |
protected ScmResult executeRemoveCommand( ScmProviderRepository repo, ScmFileSet files, String message ) |
51 | |
throws ScmException |
52 | |
{ |
53 | 0 | Commandline cl = createCommandLine( (PerforceScmProviderRepository) repo, files.getBasedir(), files ); |
54 | 0 | PerforceRemoveConsumer consumer = new PerforceRemoveConsumer(); |
55 | |
try |
56 | |
{ |
57 | 0 | CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer(); |
58 | 0 | int exitCode = CommandLineUtils.executeCommandLine( cl, consumer, err ); |
59 | |
|
60 | 0 | if ( exitCode != 0 ) |
61 | |
{ |
62 | 0 | String cmdLine = CommandLineUtils.toString( cl.getCommandline() ); |
63 | |
|
64 | 0 | StringBuilder msg = new StringBuilder( "Exit code: " + exitCode + " - " + err.getOutput() ); |
65 | 0 | msg.append( '\n' ); |
66 | 0 | msg.append( "Command line was:" + cmdLine ); |
67 | |
|
68 | 0 | throw new CommandLineException( msg.toString() ); |
69 | |
} |
70 | |
} |
71 | 0 | catch ( CommandLineException e ) |
72 | |
{ |
73 | 0 | throw new ScmException( "CommandLineException " + e.getMessage(), e ); |
74 | |
|
75 | 0 | } |
76 | |
|
77 | 0 | return new RemoveScmResult( cl.toString(), consumer.getRemovals() ); |
78 | |
} |
79 | |
|
80 | |
public static Commandline createCommandLine( PerforceScmProviderRepository repo, File workingDirectory, |
81 | |
ScmFileSet files ) |
82 | |
{ |
83 | 3 | Commandline command = PerforceScmProvider.createP4Command( repo, workingDirectory ); |
84 | 3 | command.createArg().setValue( "delete" ); |
85 | |
|
86 | 3 | List<File> fs = files.getFileList(); |
87 | 9 | for ( int i = 0; i < fs.size(); i++ ) |
88 | |
{ |
89 | 6 | File file = (File) fs.get( i ); |
90 | 6 | command.createArg().setValue( file.getName() ); |
91 | |
} |
92 | 3 | return command; |
93 | |
} |
94 | |
} |