1 | |
package org.apache.maven.scm.provider.perforce.command.unedit; |
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.unedit.AbstractUnEditCommand; |
26 | |
import org.apache.maven.scm.command.unedit.UnEditScmResult; |
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 PerforceUnEditCommand |
44 | |
extends AbstractUnEditCommand |
45 | |
implements PerforceCommand |
46 | |
{ |
47 | |
|
48 | |
|
49 | |
protected ScmResult executeUnEditCommand( ScmProviderRepository repo, ScmFileSet files ) |
50 | |
throws ScmException |
51 | |
{ |
52 | 0 | Commandline cl = createCommandLine( (PerforceScmProviderRepository) repo, files.getBasedir(), files ); |
53 | 0 | PerforceUnEditConsumer consumer = new PerforceUnEditConsumer(); |
54 | |
try |
55 | |
{ |
56 | 0 | CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer(); |
57 | 0 | int exitCode = CommandLineUtils.executeCommandLine( cl, consumer, err ); |
58 | |
|
59 | 0 | if ( exitCode != 0 ) |
60 | |
{ |
61 | 0 | String cmdLine = CommandLineUtils.toString( cl.getCommandline() ); |
62 | |
|
63 | 0 | StringBuilder msg = new StringBuilder( "Exit code: " + exitCode + " - " + err.getOutput() ); |
64 | 0 | msg.append( '\n' ); |
65 | 0 | msg.append( "Command line was:" + cmdLine ); |
66 | |
|
67 | 0 | throw new CommandLineException( msg.toString() ); |
68 | |
} |
69 | |
} |
70 | 0 | catch ( CommandLineException e ) |
71 | |
{ |
72 | 0 | if ( getLogger().isErrorEnabled() ) |
73 | |
{ |
74 | 0 | getLogger().error( "CommandLineException " + e.getMessage(), e ); |
75 | |
} |
76 | 0 | } |
77 | |
|
78 | 0 | if ( consumer.isSuccess() ) |
79 | |
{ |
80 | 0 | return new UnEditScmResult( cl.toString(), consumer.getEdits() ); |
81 | |
} |
82 | |
|
83 | 0 | return new UnEditScmResult( cl.toString(), "Unable to revert", consumer.getOutput(), consumer.isSuccess() ); |
84 | |
} |
85 | |
|
86 | |
public static Commandline createCommandLine( PerforceScmProviderRepository repo, File workingDirectory, |
87 | |
ScmFileSet files ) |
88 | |
{ |
89 | 1 | Commandline command = PerforceScmProvider.createP4Command( repo, workingDirectory ); |
90 | |
|
91 | 1 | command.createArg().setValue( "revert" ); |
92 | |
|
93 | 1 | List<File> fs = files.getFileList(); |
94 | 1 | for ( File file : fs ) |
95 | |
{ |
96 | 2 | command.createArg().setValue( file.getName() ); |
97 | |
} |
98 | 1 | return command; |
99 | |
} |
100 | |
} |