View Javadoc

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