View Javadoc

1   package org.apache.maven.scm.provider.cvslib.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.ScmFile;
24  import org.apache.maven.scm.ScmFileSet;
25  import org.apache.maven.scm.ScmFileStatus;
26  import org.apache.maven.scm.ScmResult;
27  import org.apache.maven.scm.command.remove.AbstractRemoveCommand;
28  import org.apache.maven.scm.command.remove.RemoveScmResult;
29  import org.apache.maven.scm.provider.ScmProviderRepository;
30  import org.apache.maven.scm.provider.cvslib.command.CvsCommand;
31  import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils;
32  import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
33  import org.codehaus.plexus.util.cli.Commandline;
34  
35  import java.io.File;
36  import java.util.ArrayList;
37  import java.util.List;
38  
39  /**
40   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
41   * @author Olivier Lamy
42   *
43   * @todo separate the CVSlib stuff from the cvs command line so it is clear what needs to be updated eventually
44   */
45  public abstract class AbstractCvsRemoveCommand
46      extends AbstractRemoveCommand
47      implements CvsCommand
48  {
49      /** {@inheritDoc} */
50      protected ScmResult executeRemoveCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message )
51          throws ScmException
52      {
53          CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
54  
55          Commandline cl = CvsCommandUtils.getBaseCommand( "remove", repository, fileSet );
56  
57          cl.createArg().setValue( "-f" );
58  
59          cl.createArg().setValue( "-l" );
60  
61          List<File> files = fileSet.getFileList();
62  
63          List<ScmFile> removedFiles = new ArrayList<ScmFile>();
64  
65          for ( File file : files )
66          {
67              String path = file.getPath().replace( '\\', '/' );
68  
69              cl.createArg().setValue( path );
70  
71              removedFiles.add( new ScmFile( path, ScmFileStatus.DELETED ) );
72          }
73  
74          if ( getLogger().isInfoEnabled() )
75          {
76              getLogger().info( "Executing: " + cl );
77              getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
78          }
79  
80          return executeCvsCommand( cl, removedFiles );
81      }
82  
83      protected abstract RemoveScmResult executeCvsCommand( Commandline cl, List<ScmFile> removedFiles )
84          throws ScmException;
85  }