View Javadoc
1   package org.apache.maven.scm.provider.starteam.command.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.edit.AbstractEditCommand;
26  import org.apache.maven.scm.command.edit.EditScmResult;
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 StarteamEditCommand
43      extends AbstractEditCommand
44      implements StarteamCommand
45  {
46      // ----------------------------------------------------------------------
47      // AbstractEditCommand Implementation
48      // ----------------------------------------------------------------------
49  
50      /** {@inheritDoc} */
51      protected ScmResult executeEditCommand( ScmProviderRepository repo, ScmFileSet fileSet )
52          throws ScmException
53      {
54          if ( getLogger().isInfoEnabled() )
55          {
56              getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() );
57          }
58  
59          StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
60  
61          StarteamEditConsumer consumer = new StarteamEditConsumer( getLogger(), fileSet.getBasedir() );
62  
63          CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
64  
65          List<File> editFiles = fileSet.getFileList();
66  
67          if ( editFiles.size() == 0 )
68          {
69              Commandline cl = createCommandLine( repository, fileSet );
70  
71              int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
72  
73              if ( exitCode != 0 )
74              {
75                  return new EditScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false );
76              }
77          }
78          else
79          {
80              //edit only interested files already on the local disk
81              for ( int i = 0; i < editFiles.size(); ++i )
82              {
83                  ScmFileSet editFile = new ScmFileSet( fileSet.getBasedir(), (File) editFiles.get( i ) );
84                  Commandline cl = createCommandLine( repository, editFile );
85  
86                  int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
87  
88                  if ( exitCode != 0 )
89                  {
90                      return new EditScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(),
91                                                false );
92                  }
93              }
94          }
95  
96          return new EditScmResult( null, consumer.getEditedFiles() );
97  
98      }
99  
100     public static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet dirOrFile )
101     {
102         List<String> args = new ArrayList<String>();
103         args.add( "-l" );
104 
105         return StarteamCommandLineUtils.createStarteamCommandLine( "lck", args, dirOrFile, repo );
106     }
107 }