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 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 if ( getLogger().isDebugEnabled() )
51 {
52 getLogger().debug( "executing update command..." );
53 }
54
55 VssScmProviderRepository repo = (VssScmProviderRepository) repository;
56
57 Commandline cl = buildCmdLine( repo, fileSet, version );
58
59 VssUpdateConsumer consumer = new VssUpdateConsumer( repo, getLogger() );
60
61
62
63 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
64
65 int exitCode;
66
67 if ( getLogger().isDebugEnabled() )
68 {
69 getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
70 }
71
72 exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
73
74 if ( exitCode != 0 )
75 {
76 String error = stderr.getOutput();
77
78 if ( getLogger().isDebugEnabled() )
79 {
80 getLogger().debug( "VSS returns error: [" + error + "] return code: [" + exitCode + "]" );
81 }
82 if ( error.indexOf( "A writable copy of" ) < 0 )
83 {
84 return new UpdateScmResult( cl.toString(), "The vss command failed.", error, false );
85 }
86
87 if ( getLogger().isWarnEnabled() )
88 {
89 getLogger().warn( error );
90 }
91 }
92
93 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 Commandline command = new Commandline();
101
102 command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() );
103
104 try
105 {
106 command.addSystemEnvironment();
107 }
108 catch ( Exception e )
109 {
110 throw new ScmException( "Can't add system environment.", e );
111 }
112
113 command.addEnvironment( "SSDIR", repo.getVssdir() );
114
115 String ssDir = VssCommandLineUtils.getSsDir();
116
117 command.setExecutable( ssDir + VssConstants.SS_EXE );
118
119 command.createArg().setValue( VssConstants.COMMAND_GET );
120
121 command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() );
122
123
124 if ( repo.getUserPassword() != null )
125 {
126 command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
127 }
128
129
130 command.createArg().setValue( VssConstants.FLAG_RECURSION );
131
132
133 command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );
134
135
136
137
138
139 command.createArg().setValue( VssConstants.FLAG_SKIP_WRITABLE );
140
141 if ( version != null )
142 {
143 command.createArg().setValue( VssConstants.FLAG_VERSION_LABEL + version );
144 }
145
146 return command;
147 }
148
149
150 protected ChangeLogCommand getChangeLogCommand()
151 {
152 VssHistoryCommand command = new VssHistoryCommand();
153
154 command.setLogger( getLogger() );
155
156 return command;
157 }
158
159 }