View Javadoc

1   package org.apache.maven.scm.provider.starteam.command.add;
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.add.AbstractAddCommand;
26  import org.apache.maven.scm.command.add.AddScmResult;
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.cli.CommandLineUtils;
32  import org.codehaus.plexus.util.cli.Commandline;
33  
34  import java.io.File;
35  import java.util.ArrayList;
36  import java.util.List;
37  
38  /**
39   * @author <a href="mailto:dantran@gmail.com">Dan T. Tran</a>
40   *
41   */
42  public class StarteamAddCommand
43      extends AbstractAddCommand
44      implements StarteamCommand
45  {
46      /** {@inheritDoc} */
47      protected ScmResult executeAddCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
48                                             boolean binary )
49          throws ScmException
50      {
51  
52          //work around until maven-scm-api allow this
53          String issue = System.getProperty( "maven.scm.issue" );
54  
55          if ( getLogger().isInfoEnabled() )
56          {
57              getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() );
58          }
59  
60          StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
61  
62          StarteamAddConsumer consumer = new StarteamAddConsumer( getLogger(), fileSet.getBasedir() );
63  
64          CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
65  
66          for ( File fileToBeAdded : fileSet.getFileList() )
67          {
68              ScmFileSet scmFile = new ScmFileSet( fileSet.getBasedir(), fileToBeAdded );
69  
70              Commandline cl = createCommandLine( repository, scmFile, issue );
71  
72              int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
73  
74              if ( exitCode != 0 )
75              {
76                  return new AddScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false );
77              }
78          }
79  
80          return new AddScmResult( null, consumer.getAddedFiles() );
81      }
82  
83      static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet scmFileSet, String issue )
84      {
85          List<String> args = new ArrayList<String>();
86  
87          if ( issue != null && issue.length() != 0 )
88          {
89              args.add( "-cr" );
90              args.add( issue );
91          }
92  
93          StarteamCommandLineUtils.addEOLOption( args );
94  
95          return StarteamCommandLineUtils.createStarteamCommandLine( "add", args, scmFileSet, repo );
96      }
97  }