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      /** {@inheritDoc} */
43      protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repository, ScmFileSet fileSet,
44                                                          ScmVersion version, boolean recursive )
45          throws ScmException
46      {
47          if ( getLogger().isDebugEnabled() )
48          {
49              getLogger().debug( "executing checkout command..." );
50          }
51  
52          VssScmProviderRepository repo = (VssScmProviderRepository) repository;
53  
54          Commandline cl = buildCmdLine( repo, fileSet, version );
55  
56          VssCheckOutConsumer consumer = new VssCheckOutConsumer( repo, getLogger() );
57  
58          //      TODO handle deleted files from VSS
59          CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
60  
61          int exitCode;
62  
63          if ( getLogger().isDebugEnabled() )
64          {
65              getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
66          }
67  
68          exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
69  
70          if ( exitCode != 0 )
71          {
72              String error = stderr.getOutput();
73  
74              if ( getLogger().isDebugEnabled() )
75              {
76                  getLogger().debug( "VSS returns error: [" + error + "] return code: [" + exitCode + "]" );
77              }
78              if ( error.indexOf( "A writable copy of" ) < 0 )
79              {
80                  return new CheckOutScmResult( cl.toString(), "The vss command failed.", error, false );
81              }
82              // print out the writable copy for manual handling
83              if ( getLogger().isWarnEnabled() )
84              {
85                  getLogger().warn( error );
86              }
87          }
88  
89          return new CheckOutScmResult( cl.toString(), consumer.getUpdatedFiles() );
90      }
91  
92      public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version )
93          throws ScmException
94      {
95  
96          Commandline command = new Commandline();
97  
98          command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() );
99  
100         try
101         {
102             command.addSystemEnvironment();
103         }
104         catch ( Exception e )
105         {
106             throw new ScmException( "Can't add system environment.", e );
107         }
108 
109         command.addEnvironment( "SSDIR", repo.getVssdir() );
110 
111         String ssDir = VssCommandLineUtils.getSsDir();
112 
113         command.setExecutable( ssDir + VssConstants.SS_EXE );
114 
115         command.createArg().setValue( VssConstants.COMMAND_GET );
116 
117         command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() );
118 
119         //User identification to get access to vss repository
120         if ( repo.getUserPassword() != null )
121         {
122             command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
123         }
124 
125         //Display the history of an entire project list
126         command.createArg().setValue( VssConstants.FLAG_RECURSION );
127 
128         //Ignore: Do not ask for input under any circumstances.
129         command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );
130 
131         //Ignore: Do not touch local writable files.
132         command.createArg().setValue( VssConstants.FLAG_REPLACE_WRITABLE );
133 
134         if ( version != null )
135         {
136             command.createArg().setValue( VssConstants.FLAG_VERSION_LABEL + '"' + version + '"' );
137         }
138 
139         return command;
140     }
141 }