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