View Javadoc
1   package org.apache.maven.scm.provider.cvslib.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.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.add.AbstractAddCommand;
28  import org.apache.maven.scm.command.add.AddScmResult;
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   *
42   * @todo separate the CVSlib stuff from the cvs command line so it is clear what needs to be updated eventually
43   */
44  public abstract class AbstractCvsAddCommand
45      extends AbstractAddCommand
46      implements CvsCommand
47  {
48      /** {@inheritDoc} */
49      protected ScmResult executeAddCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
50                                             boolean binary )
51          throws ScmException
52      {
53          CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
54  
55          Commandline cl = CvsCommandUtils.getBaseCommand( "add", repository, fileSet );
56  
57          if ( binary )
58          {
59              cl.createArg().setValue( "-kb" );
60          }
61  
62          if ( message != null && message.length() > 0 )
63          {
64              cl.createArg().setValue( "-m" );
65  
66              cl.createArg().setValue( "\"" + message + "\"" );
67          }
68  
69  
70          List<ScmFile> addedFiles = new ArrayList<ScmFile>( fileSet.getFileList().size() );
71  
72          for ( File file : fileSet.getFileList() )
73          {
74              String path = file.getPath().replace( '\\', '/' );
75  
76              cl.createArg().setValue( path );
77  
78              addedFiles.add( new ScmFile( path, ScmFileStatus.ADDED ) );
79          }
80  
81          if ( getLogger().isInfoEnabled() )
82          {
83              getLogger().info( "Executing: " + cl );
84              getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
85          }
86  
87          return executeCvsCommand( cl, addedFiles );
88      }
89  
90      protected abstract AddScmResult executeCvsCommand( Commandline cl, List<ScmFile> addedFiles )
91          throws ScmException;
92  }