View Javadoc

1   package org.apache.maven.scm.provider.vss.commands.edit;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * @author <a href="mailto:triek@thrx.de">Thorsten Riek</a>
38   * @version $Id: VssCheckOutCommand.java 02.06.2006 00:05:51
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          //      TODO handle deleted files from VSS
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              // print out the writable copy for manual handling
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         //User identification to get access to vss repository
107         if ( repo.getUserPassword() != null )
108         {
109             command.createArgument().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
110         }
111 
112         //Display the history of an entire project list
113         command.createArgument().setValue( VssConstants.FLAG_RECURSION );
114 
115         //Ignore: Do not ask for input under any circumstances.
116         command.createArgument().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );
117 
118         return command;
119     }
120 
121     /**
122      * @see org.apache.maven.scm.command.checkout.AbstractCheckOutCommand#getChangeLogCommand()
123      */
124     protected ChangeLogCommand getChangeLogCommand()
125     {
126         VssHistoryCommand command = new VssHistoryCommand();
127 
128         command.setLogger( getLogger() );
129 
130         return command;
131     }
132 
133 }