View Javadoc

1   package org.apache.maven.scm.provider.starteam.command.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.starteam.command.StarteamCommand;
29  import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils;
30  import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
31  import org.codehaus.plexus.util.StringUtils;
32  import org.codehaus.plexus.util.cli.CommandLineUtils;
33  import org.codehaus.plexus.util.cli.Commandline;
34  
35  import java.util.ArrayList;
36  import java.util.List;
37  
38  /**
39   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
40   * @author <a href="mailto:dantran@gmail.com">Dan T. Tran</a>
41   * @author Olivier Lamy
42   *
43   */
44  public class StarteamCheckOutCommand
45      extends AbstractCheckOutCommand
46      implements StarteamCommand
47  {
48      // ----------------------------------------------------------------------
49      // AbstractCheckOutCommand Implementation
50      // ----------------------------------------------------------------------
51  
52      /** {@inheritDoc} */
53      protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repo, ScmFileSet fileSet,
54                                                          ScmVersion version, boolean recursive )
55          throws ScmException
56      {
57          if ( fileSet.getFileList().size() != 0 )
58          {
59              throw new ScmException( "This provider doesn't support checking out subsets of a directory" );
60          }
61  
62          if ( getLogger().isInfoEnabled() )
63          {
64              getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() );
65          }
66  
67          StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
68  
69          StarteamCheckOutConsumer consumer = new StarteamCheckOutConsumer( getLogger(), fileSet.getBasedir() );
70  
71          CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
72  
73          Commandline cl = createCommandLine( repository, fileSet, version );
74  
75          int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
76  
77          if ( exitCode != 0 )
78          {
79              return new CheckOutScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false );
80          }
81  
82          return new CheckOutScmResult( cl.toString(), consumer.getCheckedOutFiles() );
83      }
84  
85      // ----------------------------------------------------------------------
86      //
87      // ----------------------------------------------------------------------
88  
89      public static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet baseDir,
90                                                   ScmVersion version )
91      {
92          List<String> args = new ArrayList<String>();
93  
94          if ( version != null && StringUtils.isNotEmpty( version.getName() ) )
95          {
96              args.add( "-vl" );
97              args.add( version.getName() );
98          }
99  
100         StarteamCommandLineUtils.addEOLOption( args );
101 
102         return StarteamCommandLineUtils.createStarteamCommandLine( "co", args, baseDir, repo );
103     }
104 }