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