View Javadoc
1   package org.apache.maven.scm.provider.cvslib.command.mkdir;
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 java.io.File;
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.apache.maven.scm.CommandParameter;
27  import org.apache.maven.scm.CommandParameters;
28  import org.apache.maven.scm.ScmException;
29  import org.apache.maven.scm.ScmFile;
30  import org.apache.maven.scm.ScmFileSet;
31  import org.apache.maven.scm.ScmFileStatus;
32  import org.apache.maven.scm.ScmResult;
33  import org.apache.maven.scm.command.Command;
34  import org.apache.maven.scm.command.mkdir.AbstractMkdirCommand;
35  import org.apache.maven.scm.command.mkdir.MkdirScmResult;
36  import org.apache.maven.scm.provider.ScmProviderRepository;
37  
38  /**
39   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
40   *
41   */
42  public abstract class AbstractCvsMkdirCommand
43      extends AbstractMkdirCommand
44  {
45      /** {@inheritDoc} */
46      protected MkdirScmResult executeMkdirCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message,
47                                                    boolean createInLocal )
48          throws ScmException
49      {
50          CommandParameters parameters = new CommandParameters();
51  
52          parameters.setString( CommandParameter.MESSAGE, message == null ? "" : message );
53  
54          parameters.setString( CommandParameter.BINARY, "false" );
55  
56          // just invoke add command
57          Command cmd = getAddCommand();
58          cmd.setLogger( getLogger() );
59  
60          ScmResult addResult = cmd.execute( repository, fileSet, parameters );
61  
62          if ( !addResult.isSuccess() )
63          {
64              return new MkdirScmResult( addResult.getCommandLine().toString(), "The cvs command failed.",
65                                         addResult.getCommandOutput(), false );
66          }
67          
68          List<ScmFile> addedFiles = new ArrayList<ScmFile>();
69          
70          for (File file : fileSet.getFileList()) 
71          {
72              ScmFile scmFile = new ScmFile( file.getPath(), ScmFileStatus.ADDED );
73              addedFiles.add( scmFile );
74          }
75  
76          return new MkdirScmResult( addResult.getCommandLine().toString(), addedFiles );
77      }
78  
79      protected abstract Command getAddCommand();
80  }