1 | |
package org.apache.maven.scm.provider.perforce.command.update; |
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.CommandParameter; |
23 | |
import org.apache.maven.scm.CommandParameters; |
24 | |
import org.apache.maven.scm.ScmException; |
25 | |
import org.apache.maven.scm.ScmFileSet; |
26 | |
import org.apache.maven.scm.ScmVersion; |
27 | |
import org.apache.maven.scm.command.changelog.ChangeLogCommand; |
28 | |
import org.apache.maven.scm.command.checkout.CheckOutScmResult; |
29 | |
import org.apache.maven.scm.command.update.AbstractUpdateCommand; |
30 | |
import org.apache.maven.scm.command.update.UpdateScmResult; |
31 | |
import org.apache.maven.scm.command.update.UpdateScmResultWithRevision; |
32 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
33 | |
import org.apache.maven.scm.provider.perforce.PerforceScmProvider; |
34 | |
import org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository; |
35 | |
import org.apache.maven.scm.provider.perforce.command.PerforceCommand; |
36 | |
import org.apache.maven.scm.provider.perforce.command.changelog.PerforceChangeLogCommand; |
37 | |
import org.apache.maven.scm.provider.perforce.command.checkout.PerforceCheckOutCommand; |
38 | |
|
39 | |
import org.codehaus.plexus.util.cli.CommandLineException; |
40 | |
import org.codehaus.plexus.util.cli.CommandLineUtils; |
41 | |
import org.codehaus.plexus.util.cli.Commandline; |
42 | |
|
43 | |
import java.io.File; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | 0 | public class PerforceUpdateCommand |
50 | |
extends AbstractUpdateCommand |
51 | |
implements PerforceCommand |
52 | |
{ |
53 | |
|
54 | |
protected UpdateScmResult executeUpdateCommand( ScmProviderRepository repo, ScmFileSet files, |
55 | |
ScmVersion scmVersion ) |
56 | |
throws ScmException |
57 | |
{ |
58 | |
|
59 | |
|
60 | |
|
61 | 0 | PerforceCheckOutCommand command = new PerforceCheckOutCommand(); |
62 | 0 | command.setLogger( getLogger() ); |
63 | 0 | CommandParameters params = new CommandParameters(); |
64 | 0 | params.setScmVersion( CommandParameter.SCM_VERSION, scmVersion ); |
65 | |
|
66 | 0 | CheckOutScmResult cosr = (CheckOutScmResult) command.execute( repo, files, params ); |
67 | 0 | if ( !cosr.isSuccess() ) |
68 | |
{ |
69 | 0 | return new UpdateScmResult( cosr.getCommandLine(), cosr.getProviderMessage(), cosr.getCommandOutput(), |
70 | |
false ); |
71 | |
} |
72 | |
|
73 | 0 | PerforceScmProviderRepository p4repo = (PerforceScmProviderRepository) repo; |
74 | 0 | String clientspec = PerforceScmProvider.getClientspecName( getLogger(), p4repo, files.getBasedir() ); |
75 | 0 | Commandline cl = createCommandLine( p4repo, files.getBasedir(), clientspec ); |
76 | |
|
77 | |
@SuppressWarnings( "unused" ) |
78 | 0 | String location = PerforceScmProvider.getRepoPath( getLogger(), p4repo, files.getBasedir() ); |
79 | 0 | PerforceHaveConsumer consumer = |
80 | |
new PerforceHaveConsumer( getLogger() ); |
81 | |
|
82 | |
try |
83 | |
{ |
84 | 0 | if ( getLogger().isDebugEnabled() ) |
85 | |
{ |
86 | 0 | getLogger().debug( PerforceScmProvider.clean( "Executing " + cl.toString() ) ); |
87 | |
} |
88 | |
|
89 | 0 | CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer(); |
90 | 0 | int exitCode = CommandLineUtils.executeCommandLine( cl, consumer, err ); |
91 | |
|
92 | 0 | if ( exitCode != 0 ) |
93 | |
{ |
94 | 0 | String cmdLine = CommandLineUtils.toString( cl.getCommandline() ); |
95 | |
|
96 | 0 | StringBuilder msg = new StringBuilder( "Exit code: " + exitCode + " - " + err.getOutput() ); |
97 | 0 | msg.append( '\n' ); |
98 | 0 | msg.append( "Command line was:" + cmdLine ); |
99 | |
|
100 | 0 | throw new CommandLineException( msg.toString() ); |
101 | |
} |
102 | |
} |
103 | 0 | catch ( CommandLineException e ) |
104 | |
{ |
105 | 0 | if ( getLogger().isErrorEnabled() ) |
106 | |
{ |
107 | 0 | getLogger().error( "CommandLineException " + e.getMessage(), e ); |
108 | |
} |
109 | 0 | } |
110 | |
|
111 | 0 | return new UpdateScmResultWithRevision( cosr.getCommandLine(), cosr.getCheckedOutFiles(), |
112 | |
String.valueOf( consumer.getHave() ) ); |
113 | |
} |
114 | |
|
115 | |
|
116 | |
protected ChangeLogCommand getChangeLogCommand() |
117 | |
{ |
118 | 0 | PerforceChangeLogCommand command = new PerforceChangeLogCommand(); |
119 | 0 | command.setLogger( getLogger() ); |
120 | 0 | return command; |
121 | |
} |
122 | |
|
123 | |
public static Commandline createCommandLine( PerforceScmProviderRepository repo, File workingDirectory, |
124 | |
String clientspec ) |
125 | |
{ |
126 | 0 | Commandline command = PerforceScmProvider.createP4Command( repo, workingDirectory ); |
127 | |
|
128 | 0 | if ( clientspec != null ) |
129 | |
{ |
130 | 0 | command.createArg().setValue( "-c" ); |
131 | 0 | command.createArg().setValue( clientspec ); |
132 | |
} |
133 | 0 | command.createArg().setValue( "changes" ); |
134 | 0 | command.createArg().setValue( "-m1" ); |
135 | 0 | command.createArg().setValue( "-ssubmitted" ); |
136 | 0 | command.createArg().setValue( "//" + clientspec + "/...#have" ); |
137 | |
|
138 | 0 | return command; |
139 | |
} |
140 | |
} |