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