View Javadoc

1   package org.apache.maven.scm.provider.vss.commands.checkout;
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.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   * @author <a href="mailto:triek@thrx.de">Thorsten Riek</a>
36   * @version $Id: VssCheckOutCommand.java 02.06.2006 00:05:51
37   */
38  public class VssCheckOutCommand
39      extends AbstractCheckOutCommand
40  {
41  
42      protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repository, ScmFileSet fileSet,
43                                                          ScmVersion version )
44          throws ScmException
45      {
46          getLogger().debug( "executing checkout command..." );
47  
48          VssScmProviderRepository repo = (VssScmProviderRepository) repository;
49  
50          Commandline cl = buildCmdLine( repo, fileSet, version );
51  
52          VssCheckOutConsumer consumer = new VssCheckOutConsumer( repo, getLogger() );
53  
54          //      TODO handle deleted files from VSS
55          CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
56  
57          int exitCode;
58  
59          getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
60  
61          exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
62  
63          if ( exitCode != 0 )
64          {
65              String error = stderr.getOutput();
66              getLogger().debug( "VSS returns error: [" + error + "] return code: [" + exitCode + "]" );
67              if ( error.indexOf( "A writable copy of" ) < 0 )
68              {
69                  return new CheckOutScmResult( cl.toString(), "The vss command failed.", error, false );
70              }
71              // print out the writable copy for manual handling
72              getLogger().warn( error );
73          }
74  
75          return new CheckOutScmResult( cl.toString(), consumer.getUpdatedFiles() );
76      }
77  
78      public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version )
79          throws ScmException
80      {
81  
82          Commandline command = new Commandline();
83  
84          command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() );
85  
86          try
87          {
88              command.addSystemEnvironment();
89          }
90          catch ( Exception e )
91          {
92              throw new ScmException( "Can't add system environment.", e );
93          }
94  
95          command.addEnvironment( "SSDIR", repo.getVssdir() );
96  
97          String ssDir = VssCommandLineUtils.getSsDir();
98  
99          command.setExecutable( ssDir + VssConstants.SS_EXE );
100 
101         command.createArgument().setValue( VssConstants.COMMAND_GET );
102 
103         command.createArgument().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() );
104 
105         //User identification to get access to vss repository
106         if ( repo.getUserPassword() != null )
107         {
108             command.createArgument().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
109         }
110 
111         //Display the history of an entire project list
112         command.createArgument().setValue( VssConstants.FLAG_RECURSION );
113 
114         //Ignore: Do not ask for input under any circumstances.
115         command.createArgument().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );
116 
117         //Ignore: Do not touch local writable files.
118         command.createArgument().setValue( VssConstants.FLAG_REPLACE_WRITABLE );
119 
120         // TODO: Get Labled Version
121         // command.createArgument().setValue( VssConstants.FLAG_VERSION_LABEL );
122 
123         return command;
124     }
125 }