1 package org.apache.maven.scm.provider.vss.commands.edit;
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.changelog.ChangeLogCommand;
26 import org.apache.maven.scm.command.edit.AbstractEditCommand;
27 import org.apache.maven.scm.command.edit.EditScmResult;
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.commands.changelog.VssHistoryCommand;
32 import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository;
33 import org.codehaus.plexus.util.cli.CommandLineUtils;
34 import org.codehaus.plexus.util.cli.Commandline;
35
36
37
38
39
40 public class VssEditCommand
41 extends AbstractEditCommand
42 {
43
44 protected ScmResult executeEditCommand( ScmProviderRepository repository, ScmFileSet fileSet )
45 throws ScmException
46 {
47 getLogger().debug( "executing checkout command..." );
48
49 VssScmProviderRepository repo = (VssScmProviderRepository) repository;
50
51 Commandline cl = buildCmdLine( repo, fileSet );
52
53 VssEditConsumer consumer = new VssEditConsumer( repo, getLogger() );
54
55
56 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
57
58 int exitCode;
59
60 getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
61
62 exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
63
64 if ( exitCode != 0 )
65 {
66 String error = stderr.getOutput();
67 getLogger().debug( "VSS returns error: [" + error + "] return code: [" + exitCode + "]" );
68 if ( error.indexOf( "A writable copy of" ) < 0 )
69 {
70 return new EditScmResult( cl.toString(), "The vss command failed.", error, false );
71 }
72
73 getLogger().warn( error );
74 }
75
76 return new EditScmResult( cl.toString(), consumer.getUpdatedFiles() );
77 }
78
79 public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet )
80 throws ScmException
81 {
82
83 Commandline command = new Commandline();
84
85 command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() );
86
87 try
88 {
89 command.addSystemEnvironment();
90 }
91 catch ( Exception e )
92 {
93 throw new ScmException( "Can't add system environment.", e );
94 }
95
96 command.addEnvironment( "SSDIR", repo.getVssdir() );
97
98 String ssDir = VssCommandLineUtils.getSsDir();
99
100 command.setExecutable( ssDir + VssConstants.SS_EXE );
101
102 command.createArgument().setValue( VssConstants.COMMAND_CHECKOUT );
103
104 command.createArgument().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() );
105
106
107 if ( repo.getUserPassword() != null )
108 {
109 command.createArgument().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
110 }
111
112
113 command.createArgument().setValue( VssConstants.FLAG_RECURSION );
114
115
116 command.createArgument().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );
117
118 return command;
119 }
120
121
122
123
124 protected ChangeLogCommand getChangeLogCommand()
125 {
126 VssHistoryCommand command = new VssHistoryCommand();
127
128 command.setLogger( getLogger() );
129
130 return command;
131 }
132
133 }