1 package org.apache.maven.scm.provider.accurev.command.checkin;
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.Iterator;
24 import java.util.List;
25
26 import org.apache.maven.scm.CommandParameter;
27 import org.apache.maven.scm.CommandParameters;
28 import org.apache.maven.scm.ScmException;
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.checkin.CheckInScmResult;
33 import org.apache.maven.scm.log.ScmLogger;
34 import org.apache.maven.scm.provider.ScmProviderRepository;
35 import org.apache.maven.scm.provider.accurev.AccuRev;
36 import org.apache.maven.scm.provider.accurev.AccuRevException;
37 import org.apache.maven.scm.provider.accurev.AccuRevInfo;
38 import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository;
39 import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommand;
40
41
42
43
44 public class AccuRevCheckInCommand
45 extends AbstractAccuRevCommand
46 {
47
48 public AccuRevCheckInCommand( ScmLogger logger )
49 {
50 super( logger );
51 }
52
53 @Override
54 protected ScmResult executeAccurevCommand( AccuRevScmProviderRepository repository, ScmFileSet fileSet,
55 CommandParameters parameters )
56 throws ScmException, AccuRevException
57 {
58
59 AccuRev accuRev = repository.getAccuRev();
60
61 String message = parameters.getString( CommandParameter.MESSAGE );
62 List<File> promotedFiles = null;
63
64 File basedir = fileSet.getBasedir();
65 List<File> fileList = fileSet.getFileList();
66
67 if ( fileList.isEmpty() )
68 {
69
70
71
72 AccuRevInfo info = accuRev.info( basedir );
73
74 if ( repository.isWorkSpaceRoot( info ) )
75 {
76 promotedFiles = accuRev.promoteAll( basedir, message );
77 }
78 else
79 {
80 throw new ScmException( String.format( "Unsupported recursive checkin for %s. Not the workspace root",
81 basedir.getAbsolutePath() ) );
82 }
83 }
84 else
85 {
86 promotedFiles = accuRev.promote( basedir, fileList, message );
87 }
88
89
90 if ( promotedFiles != null )
91 {
92 Iterator<File> iter = promotedFiles.iterator();
93 while ( iter.hasNext() )
94 {
95 if ( new File( basedir, iter.next().getPath() ).isDirectory() )
96 {
97 iter.remove();
98 }
99 }
100
101 return new CheckInScmResult( accuRev.getCommandLines(), getScmFiles( promotedFiles,
102 ScmFileStatus.CHECKED_IN ) );
103 }
104 else
105 {
106 return new CheckInScmResult( accuRev.getCommandLines(), "AccuRev Error", accuRev.getErrorOutput(), false );
107 }
108 }
109
110 public CheckInScmResult checkIn( ScmProviderRepository repository, ScmFileSet fileSet,
111 CommandParameters parameters )
112 throws ScmException
113 {
114 return (CheckInScmResult) execute( repository, fileSet, parameters );
115 }
116
117 }