View Javadoc
1   package org.apache.maven.scm.provider.accurev.command;
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.CommandParameters;
27  import org.apache.maven.scm.ScmException;
28  import org.apache.maven.scm.ScmFile;
29  import org.apache.maven.scm.ScmFileSet;
30  import org.apache.maven.scm.ScmFileStatus;
31  import org.apache.maven.scm.ScmResult;
32  import org.apache.maven.scm.command.AbstractCommand;
33  import org.apache.maven.scm.log.ScmLogger;
34  import org.apache.maven.scm.provider.ScmProviderRepository;
35  import org.apache.maven.scm.provider.accurev.AccuRevException;
36  import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository;
37  
38  /**
39   * 
40   */
41  public abstract class AbstractAccuRevCommand
42      extends AbstractCommand
43  {
44  
45      public AbstractAccuRevCommand( ScmLogger logger )
46      {
47          super();
48          setLogger( logger );
49      }
50  
51      protected abstract ScmResult executeAccurevCommand( AccuRevScmProviderRepository repository, ScmFileSet fileSet,
52                                                          CommandParameters parameters )
53          throws ScmException, AccuRevException;
54  
55      protected final ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
56                                                CommandParameters parameters )
57          throws ScmException
58      {
59  
60          if ( !( repository instanceof AccuRevScmProviderRepository ) )
61          {
62              throw new ScmException( "Not an AccuRev repository " + repository );
63          }
64  
65          AccuRevScmProviderRepository accuRevRepository = (AccuRevScmProviderRepository) repository;
66          accuRevRepository.getAccuRev().reset();
67          try
68          {
69              return executeAccurevCommand( accuRevRepository, fileSet, parameters );
70          }
71          catch ( AccuRevException e )
72          {
73              throw new ScmException( "Error invoking AccuRev command", e );
74          }
75      }
76  
77      protected static List<ScmFile> getScmFiles( final List<File> files, ScmFileStatus status )
78      {
79          ArrayList<ScmFile> resultFiles = new ArrayList<ScmFile>( files.size() );
80          for ( File addedFile : files )
81          {
82              // TODO paths are relative to the workspace dir, should be made relative to project path.
83              resultFiles.add( new ScmFile( addedFile.getPath(), status ) );
84          }
85          return resultFiles;
86      }
87  
88  }