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