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.List;
24  
25  import org.apache.maven.scm.CommandParameter;
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.ScmVersion;
33  import org.apache.maven.scm.log.ScmLogger;
34  import org.apache.maven.scm.provider.accurev.AccuRevException;
35  import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository;
36  import org.apache.maven.scm.provider.accurev.AccuRevVersion;
37  
38  public abstract class AbstractAccuRevExtractSourceCommand
39      extends AbstractAccuRevCommand
40  {
41  
42      public AbstractAccuRevExtractSourceCommand( ScmLogger logger )
43      {
44          super( logger );
45      }
46  
47      @Override
48      protected ScmResult executeAccurevCommand( AccuRevScmProviderRepository repository, ScmFileSet fileSet,
49                                                 CommandParameters parameters )
50          throws ScmException, AccuRevException
51      {
52  
53          ScmVersion scmVersion = parameters.getScmVersion( CommandParameter.SCM_VERSION, null );
54  
55  
56          File basedir = fileSet.getBasedir();
57          String outputDirectory = parameters.getString( CommandParameter.OUTPUT_DIRECTORY, null );
58          if ( outputDirectory != null )
59          {
60              basedir = new File( outputDirectory );
61          }
62  
63          if ( !basedir.exists() )
64          {
65              basedir.mkdirs();
66          }
67  
68          if ( !basedir.isDirectory() || basedir.list().length != 0 )
69          {
70              throw new ScmException( "Checkout directory " + basedir.getAbsolutePath() + " not empty" );
71          }
72  
73          AccuRevVersion accuRevVersion = repository.getAccuRevVersion( scmVersion );
74          
75          List<File> checkedOutFiles = extractSource( repository, basedir, accuRevVersion );
76          List<ScmFile> scmFiles =
77              checkedOutFiles == null ? null : getScmFiles( checkedOutFiles, ScmFileStatus.CHECKED_OUT );
78  
79          return getScmResult( repository, scmFiles, scmVersion );
80  
81      }
82  
83      protected abstract ScmResult getScmResult( AccuRevScmProviderRepository repository, List<ScmFile> scmFiles, ScmVersion scmVersion );
84  
85      protected abstract List<File> extractSource( AccuRevScmProviderRepository repository, File basedir,
86                                                   AccuRevVersion version )
87          throws AccuRevException;
88  }