1 | |
package org.apache.maven.scm.provider.vss.commands.update; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
import org.apache.maven.scm.ScmException; |
24 | |
import org.apache.maven.scm.ScmFileSet; |
25 | |
import org.apache.maven.scm.ScmVersion; |
26 | |
import org.apache.maven.scm.command.changelog.ChangeLogCommand; |
27 | |
import org.apache.maven.scm.command.update.AbstractUpdateCommand; |
28 | |
import org.apache.maven.scm.command.update.UpdateScmResult; |
29 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
30 | |
import org.apache.maven.scm.provider.vss.commands.VssCommandLineUtils; |
31 | |
import org.apache.maven.scm.provider.vss.commands.VssConstants; |
32 | |
import org.apache.maven.scm.provider.vss.commands.changelog.VssHistoryCommand; |
33 | |
import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository; |
34 | |
import org.codehaus.plexus.util.cli.CommandLineUtils; |
35 | |
import org.codehaus.plexus.util.cli.Commandline; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 1 | public class VssUpdateCommand |
42 | |
extends AbstractUpdateCommand |
43 | |
{ |
44 | |
|
45 | |
|
46 | |
protected UpdateScmResult executeUpdateCommand( ScmProviderRepository repository, ScmFileSet fileSet, |
47 | |
ScmVersion version ) |
48 | |
throws ScmException |
49 | |
{ |
50 | 0 | if ( getLogger().isDebugEnabled() ) |
51 | |
{ |
52 | 0 | getLogger().debug( "executing update command..." ); |
53 | |
} |
54 | |
|
55 | 0 | VssScmProviderRepository repo = (VssScmProviderRepository) repository; |
56 | |
|
57 | 0 | Commandline cl = buildCmdLine( repo, fileSet, version ); |
58 | |
|
59 | 0 | VssUpdateConsumer consumer = new VssUpdateConsumer( repo, getLogger() ); |
60 | |
|
61 | |
|
62 | |
|
63 | 0 | CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); |
64 | |
|
65 | |
int exitCode; |
66 | |
|
67 | 0 | if ( getLogger().isDebugEnabled() ) |
68 | |
{ |
69 | 0 | getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() ); |
70 | |
} |
71 | |
|
72 | 0 | exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); |
73 | |
|
74 | 0 | if ( exitCode != 0 ) |
75 | |
{ |
76 | 0 | String error = stderr.getOutput(); |
77 | |
|
78 | 0 | if ( getLogger().isDebugEnabled() ) |
79 | |
{ |
80 | 0 | getLogger().debug( "VSS returns error: [" + error + "] return code: [" + exitCode + "]" ); |
81 | |
} |
82 | 0 | if ( error.indexOf( "A writable copy of" ) < 0 ) |
83 | |
{ |
84 | 0 | return new UpdateScmResult( cl.toString(), "The vss command failed.", error, false ); |
85 | |
} |
86 | |
|
87 | 0 | if ( getLogger().isWarnEnabled() ) |
88 | |
{ |
89 | 0 | getLogger().warn( error ); |
90 | |
} |
91 | |
} |
92 | |
|
93 | 0 | return new UpdateScmResult( cl.toString(), consumer.getUpdatedFiles() ); |
94 | |
} |
95 | |
|
96 | |
public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version ) |
97 | |
throws ScmException |
98 | |
{ |
99 | |
|
100 | 1 | Commandline command = new Commandline(); |
101 | |
|
102 | 1 | command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() ); |
103 | |
|
104 | |
try |
105 | |
{ |
106 | 1 | command.addSystemEnvironment(); |
107 | |
} |
108 | 0 | catch ( Exception e ) |
109 | |
{ |
110 | 0 | throw new ScmException( "Can't add system environment.", e ); |
111 | 1 | } |
112 | |
|
113 | 1 | command.addEnvironment( "SSDIR", repo.getVssdir() ); |
114 | |
|
115 | 1 | String ssDir = VssCommandLineUtils.getSsDir(); |
116 | |
|
117 | 1 | command.setExecutable( ssDir + VssConstants.SS_EXE ); |
118 | |
|
119 | 1 | command.createArg().setValue( VssConstants.COMMAND_GET ); |
120 | |
|
121 | 1 | command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() ); |
122 | |
|
123 | |
|
124 | 1 | if ( repo.getUserPassword() != null ) |
125 | |
{ |
126 | 1 | command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() ); |
127 | |
} |
128 | |
|
129 | |
|
130 | 1 | command.createArg().setValue( VssConstants.FLAG_RECURSION ); |
131 | |
|
132 | |
|
133 | 1 | command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF ); |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | 1 | command.createArg().setValue( VssConstants.FLAG_SKIP_WRITABLE ); |
140 | |
|
141 | 1 | if ( version != null ) |
142 | |
{ |
143 | 0 | command.createArg().setValue( VssConstants.FLAG_VERSION_LABEL + version ); |
144 | |
} |
145 | |
|
146 | 1 | return command; |
147 | |
} |
148 | |
|
149 | |
|
150 | |
protected ChangeLogCommand getChangeLogCommand() |
151 | |
{ |
152 | 0 | VssHistoryCommand command = new VssHistoryCommand(); |
153 | |
|
154 | 0 | command.setLogger( getLogger() ); |
155 | |
|
156 | 0 | return command; |
157 | |
} |
158 | |
|
159 | |
} |