1 | |
package org.apache.maven.scm.provider.vss.commands.add; |
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.ScmResult; |
25 | |
import org.apache.maven.scm.command.add.AbstractAddCommand; |
26 | |
import org.apache.maven.scm.command.add.AddScmResult; |
27 | |
import org.apache.maven.scm.command.changelog.ChangeLogScmResult; |
28 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
29 | |
import org.apache.maven.scm.provider.vss.commands.VssCommandLineUtils; |
30 | |
import org.apache.maven.scm.provider.vss.commands.VssConstants; |
31 | |
import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository; |
32 | |
import org.codehaus.plexus.util.cli.CommandLineUtils; |
33 | |
import org.codehaus.plexus.util.cli.Commandline; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 2 | public class VssAddCommand |
40 | |
extends AbstractAddCommand |
41 | |
{ |
42 | |
|
43 | |
protected ScmResult executeAddCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message, |
44 | |
boolean binary ) |
45 | |
throws ScmException |
46 | |
{ |
47 | 0 | VssScmProviderRepository repo = (VssScmProviderRepository) repository; |
48 | |
|
49 | 0 | if ( fileSet.getFileList().isEmpty() ) |
50 | |
{ |
51 | 0 | throw new ScmException( "You must provide at least one file/directory to add" ); |
52 | |
} |
53 | |
|
54 | 0 | Commandline cl = buildCmdLine( repo, fileSet ); |
55 | |
|
56 | 0 | VssAddConsumer consumer = new VssAddConsumer( getLogger() ); |
57 | |
|
58 | 0 | CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); |
59 | |
|
60 | 0 | if ( getLogger().isInfoEnabled() ) |
61 | |
{ |
62 | 0 | getLogger().info( "Executing: " + cl ); |
63 | 0 | getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); |
64 | |
} |
65 | |
|
66 | 0 | int exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); |
67 | |
|
68 | 0 | if ( exitCode != 0 ) |
69 | |
{ |
70 | 0 | return new ChangeLogScmResult( cl.toString(), "The vss command failed.", stderr.getOutput(), false ); |
71 | |
} |
72 | |
|
73 | 0 | return new AddScmResult( cl.toString(), consumer.getAddedFiles() ); |
74 | |
} |
75 | |
|
76 | |
public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet ) |
77 | |
throws ScmException |
78 | |
{ |
79 | 1 | Commandline command = new Commandline(); |
80 | |
|
81 | 1 | command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() ); |
82 | |
|
83 | |
try |
84 | |
{ |
85 | 1 | command.addSystemEnvironment(); |
86 | |
} |
87 | 0 | catch ( Exception e ) |
88 | |
{ |
89 | 0 | throw new ScmException( "Can't add system environment.", e ); |
90 | 1 | } |
91 | |
|
92 | 1 | command.addEnvironment( "SSDIR", repo.getVssdir() ); |
93 | |
|
94 | 1 | String ssDir = VssCommandLineUtils.getSsDir(); |
95 | |
|
96 | 1 | command.setExecutable( ssDir + VssConstants.SS_EXE ); |
97 | |
|
98 | 1 | command.createArg().setValue( VssConstants.COMMAND_ADD ); |
99 | |
|
100 | 1 | VssCommandLineUtils.addFiles( command, fileSet ); |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | 1 | if ( repo.getUserPassword() != null ) |
106 | |
{ |
107 | 1 | command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() ); |
108 | |
} |
109 | |
|
110 | |
|
111 | 1 | command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF ); |
112 | |
|
113 | 1 | return command; |
114 | |
} |
115 | |
|
116 | |
public Commandline buildSetCurrentProjectCmdLine( VssScmProviderRepository repo ) |
117 | |
throws ScmException |
118 | |
{ |
119 | 1 | Commandline command = new Commandline(); |
120 | |
|
121 | |
try |
122 | |
{ |
123 | 1 | command.addSystemEnvironment(); |
124 | |
} |
125 | 0 | catch ( Exception e ) |
126 | |
{ |
127 | 0 | throw new ScmException( "Can't add system environment.", e ); |
128 | 1 | } |
129 | |
|
130 | 1 | command.addEnvironment( "SSDIR", repo.getVssdir() ); |
131 | |
|
132 | 1 | String ssDir = VssCommandLineUtils.getSsDir(); |
133 | |
|
134 | 1 | command.setExecutable( ssDir + VssConstants.SS_EXE ); |
135 | |
|
136 | 1 | command.createArg().setValue( VssConstants.COMMAND_CP ); |
137 | |
|
138 | 1 | command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() ); |
139 | |
|
140 | |
|
141 | 1 | if ( repo.getUserPassword() != null ) |
142 | |
{ |
143 | 1 | command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() ); |
144 | |
} |
145 | |
|
146 | |
|
147 | 1 | command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF ); |
148 | |
|
149 | 1 | return command; |
150 | |
} |
151 | |
|
152 | |
} |