View Javadoc
1   package org.apache.maven.scm.provider.starteam.command.remove;
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.remove.AbstractRemoveCommand;
26  import org.apache.maven.scm.command.remove.RemoveScmResult;
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.command.checkin.StarteamCheckInConsumer;
31  import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
32  import org.codehaus.plexus.util.cli.CommandLineUtils;
33  import org.codehaus.plexus.util.cli.Commandline;
34  
35  import java.io.File;
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 StarteamRemoveCommand
44      extends AbstractRemoveCommand
45      implements StarteamCommand
46  {
47      /** {@inheritDoc} */
48      protected ScmResult executeRemoveCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message )
49          throws ScmException
50      {
51          if ( getLogger().isInfoEnabled() )
52          {
53              getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() );
54          }
55  
56          StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
57  
58          StarteamCheckInConsumer consumer = new StarteamCheckInConsumer( getLogger(), fileSet.getBasedir() );
59  
60          CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
61  
62          List<File> remvoveFiles = fileSet.getFileList();
63  
64          if ( remvoveFiles.size() == 0 )
65          {
66              Commandline cl = createCommandLine( repository, fileSet );
67  
68              int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
69  
70              if ( exitCode != 0 )
71              {
72                  return new RemoveScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false );
73              }
74          }
75          else
76          {
77              //update only interested files already on the local disk
78              for ( int i = 0; i < remvoveFiles.size(); ++i )
79              {
80                  File fileToBeRemoved = (File) remvoveFiles.get( i );
81                  ScmFileSet scmFileSet = new ScmFileSet( fileSet.getBasedir(), fileToBeRemoved );
82                  Commandline cl = createCommandLine( repository, scmFileSet );
83  
84                  int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
85  
86                  if ( exitCode != 0 )
87                  {
88                      return new RemoveScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(),
89                                                  false );
90                  }
91              }
92          }
93  
94          return new RemoveScmResult( null, consumer.getCheckedInFiles() );
95  
96      }
97  
98      public static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet dirOrFile )
99      {
100         return StarteamCommandLineUtils.createStarteamCommandLine( "remove", null, dirOrFile, repo );
101     }
102 }