1 package org.apache.maven.scm.provider.vss.commands.checkout;
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.ScmVersion;
25 import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand;
26 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
27 import org.apache.maven.scm.provider.ScmProviderRepository;
28 import org.apache.maven.scm.provider.vss.commands.VssCommandLineUtils;
29 import org.apache.maven.scm.provider.vss.commands.VssConstants;
30 import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository;
31 import org.codehaus.plexus.util.cli.CommandLineUtils;
32 import org.codehaus.plexus.util.cli.Commandline;
33
34
35
36
37
38 public class VssCheckOutCommand
39 extends AbstractCheckOutCommand
40 {
41
42
43 protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repository, ScmFileSet fileSet,
44 ScmVersion version, boolean recursive )
45 throws ScmException
46 {
47 if ( getLogger().isDebugEnabled() )
48 {
49 getLogger().debug( "executing checkout command..." );
50 }
51
52 VssScmProviderRepository repo = (VssScmProviderRepository) repository;
53
54 Commandline cl = buildCmdLine( repo, fileSet, version );
55
56 VssCheckOutConsumer consumer = new VssCheckOutConsumer( repo, getLogger() );
57
58
59 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
60
61 int exitCode;
62
63 if ( getLogger().isDebugEnabled() )
64 {
65 getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
66 }
67
68 exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
69
70 if ( exitCode != 0 )
71 {
72 String error = stderr.getOutput();
73
74 if ( getLogger().isDebugEnabled() )
75 {
76 getLogger().debug( "VSS returns error: [" + error + "] return code: [" + exitCode + "]" );
77 }
78 if ( error.indexOf( "A writable copy of" ) < 0 )
79 {
80 return new CheckOutScmResult( cl.toString(), "The vss command failed.", error, false );
81 }
82
83 if ( getLogger().isWarnEnabled() )
84 {
85 getLogger().warn( error );
86 }
87 }
88
89 return new CheckOutScmResult( cl.toString(), consumer.getUpdatedFiles() );
90 }
91
92 public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version )
93 throws ScmException
94 {
95
96 Commandline command = new Commandline();
97
98 command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() );
99
100 try
101 {
102 command.addSystemEnvironment();
103 }
104 catch ( Exception e )
105 {
106 throw new ScmException( "Can't add system environment.", e );
107 }
108
109 command.addEnvironment( "SSDIR", repo.getVssdir() );
110
111 String ssDir = VssCommandLineUtils.getSsDir();
112
113 command.setExecutable( ssDir + VssConstants.SS_EXE );
114
115 command.createArg().setValue( VssConstants.COMMAND_GET );
116
117 command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() );
118
119
120 if ( repo.getUserPassword() != null )
121 {
122 command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
123 }
124
125
126 command.createArg().setValue( VssConstants.FLAG_RECURSION );
127
128
129 command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );
130
131
132 command.createArg().setValue( VssConstants.FLAG_REPLACE_WRITABLE );
133
134 if ( version != null )
135 {
136 command.createArg().setValue( VssConstants.FLAG_VERSION_LABEL + '"' + version + '"' );
137 }
138
139 return command;
140 }
141 }