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 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 }