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