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