View Javadoc

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