1 package org.apache.maven.scm.provider.accurev.command.status;
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.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.status.StatusScmResult;
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.AccuRevCapability;
37 import org.apache.maven.scm.provider.accurev.AccuRevException;
38 import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository;
39 import org.apache.maven.scm.provider.accurev.AccuRevStat;
40 import org.apache.maven.scm.provider.accurev.CategorisedElements;
41 import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommand;
42
43
44
45
46 public class AccuRevStatusCommand
47 extends AbstractAccuRevCommand
48 {
49
50 public AccuRevStatusCommand( ScmLogger logger )
51 {
52 super( logger );
53 }
54
55 @Override
56 protected ScmResult executeAccurevCommand( AccuRevScmProviderRepository repository, ScmFileSet fileSet,
57 CommandParameters parameters )
58 throws ScmException, AccuRevException
59 {
60
61 AccuRev accuRev = repository.getAccuRev();
62
63 File basedir = fileSet.getBasedir();
64 List<File> elements = fileSet.getFileList();
65
66 List<File> defunctElements = accuRev.stat( basedir, elements, AccuRevStat.DEFUNCT );
67
68 if ( defunctElements == null )
69 {
70 return error( accuRev, "Failed retrieving defunct elements" );
71 }
72
73 List<File> keptElements = accuRev.stat( basedir, elements, AccuRevStat.KEPT );
74
75
76 if ( keptElements == null )
77 {
78 return error( accuRev, "Failed retrieving kept elements" );
79 }
80
81 List<File> modOrAddedElements = new ArrayList<File>();
82
83 for ( File file : keptElements )
84 {
85 if ( !defunctElements.contains( file ) )
86 {
87 modOrAddedElements.add( file );
88 }
89 }
90
91 List<File> modifiedElements = accuRev.stat( basedir, elements, AccuRevStat.MODIFIED );
92
93 if ( modifiedElements == null )
94 {
95 return error( accuRev, "Failed retrieving modified elements" );
96 }
97
98 modOrAddedElements.addAll( modifiedElements );
99
100 CategorisedElements catElems = accuRev.statBackingStream( basedir, modOrAddedElements );
101
102 if ( catElems == null )
103 {
104 return error( accuRev, "Failed stat backing stream to split modified and added elements" );
105 }
106
107 modifiedElements = catElems.getMemberElements();
108
109 List<File> addedElements;
110 if ( AccuRevCapability.STAT_ADDED_NOT_PROMOTED_BUG.isSupported( accuRev.getClientVersion() ) )
111 {
112 modOrAddedElements.removeAll( modifiedElements );
113 addedElements = modOrAddedElements;
114 }
115 else
116 {
117 addedElements = catElems.getNonMemberElements();
118 }
119
120 List<File> missingElements = accuRev.stat( basedir, elements, AccuRevStat.MISSING );
121
122 if ( missingElements == null )
123 {
124 return error( accuRev, "Failed retrieving missing elements" );
125 }
126
127 List<File> externalElements = accuRev.stat( basedir, elements, AccuRevStat.EXTERNAL );
128
129 if ( externalElements == null )
130 {
131 return error( accuRev, "Failed retrieving external elements" );
132 }
133
134 List<ScmFile> resultFiles = getScmFiles( defunctElements, ScmFileStatus.DELETED );
135 resultFiles.addAll( getScmFiles( modifiedElements, ScmFileStatus.MODIFIED ) );
136 resultFiles.addAll( getScmFiles( addedElements, ScmFileStatus.ADDED ) );
137 resultFiles.addAll( getScmFiles( missingElements, ScmFileStatus.MISSING ) );
138 resultFiles.addAll( getScmFiles( externalElements, ScmFileStatus.UNKNOWN ) );
139
140 return new StatusScmResult( accuRev.getCommandLines(), resultFiles );
141
142 }
143
144 private ScmResult error( AccuRev accuRev, String message )
145 {
146 return new StatusScmResult( accuRev.getCommandLines(), "AccuRev " + message, accuRev.getErrorOutput(), false );
147 }
148
149 public StatusScmResult status( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
150 throws ScmException
151 {
152 return (StatusScmResult) execute( repository, fileSet, parameters );
153 }
154
155 }