001package org.apache.maven.scm.provider.accurev.command.status; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.File; 023import java.util.ArrayList; 024import java.util.List; 025 026import org.apache.maven.scm.CommandParameters; 027import org.apache.maven.scm.ScmException; 028import org.apache.maven.scm.ScmFile; 029import org.apache.maven.scm.ScmFileSet; 030import org.apache.maven.scm.ScmFileStatus; 031import org.apache.maven.scm.ScmResult; 032import org.apache.maven.scm.command.status.StatusScmResult; 033import org.apache.maven.scm.log.ScmLogger; 034import org.apache.maven.scm.provider.ScmProviderRepository; 035import org.apache.maven.scm.provider.accurev.AccuRev; 036import org.apache.maven.scm.provider.accurev.AccuRevCapability; 037import org.apache.maven.scm.provider.accurev.AccuRevException; 038import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository; 039import org.apache.maven.scm.provider.accurev.AccuRevStat; 040import org.apache.maven.scm.provider.accurev.CategorisedElements; 041import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommand; 042 043/** 044 * 045 */ 046public class AccuRevStatusCommand 047 extends AbstractAccuRevCommand 048{ 049 050 public AccuRevStatusCommand( ScmLogger logger ) 051 { 052 super( logger ); 053 } 054 055 @Override 056 protected ScmResult executeAccurevCommand( AccuRevScmProviderRepository repository, ScmFileSet fileSet, 057 CommandParameters parameters ) 058 throws ScmException, AccuRevException 059 { 060 061 AccuRev accuRev = repository.getAccuRev(); 062 063 File basedir = fileSet.getBasedir(); 064 List<File> elements = fileSet.getFileList(); 065 066 List<File> defunctElements = accuRev.stat( basedir, elements, AccuRevStat.DEFUNCT ); 067 068 if ( defunctElements == null ) 069 { 070 return error( accuRev, "Failed retrieving defunct elements" ); 071 } 072 073 List<File> keptElements = accuRev.stat( basedir, elements, AccuRevStat.KEPT ); 074 075 // Defunct elements are also listed as kept (AccuRev 4.7.1), exclude those here. 076 if ( keptElements == null ) 077 { 078 return error( accuRev, "Failed retrieving kept elements" ); 079 } 080 081 List<File> modOrAddedElements = new ArrayList<File>(); 082 083 for ( File file : keptElements ) 084 { 085 if ( !defunctElements.contains( file ) ) 086 { 087 modOrAddedElements.add( file ); 088 } 089 } 090 091 List<File> modifiedElements = accuRev.stat( basedir, elements, AccuRevStat.MODIFIED ); 092 093 if ( modifiedElements == null ) 094 { 095 return error( accuRev, "Failed retrieving modified elements" ); 096 } 097 098 modOrAddedElements.addAll( modifiedElements ); 099 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}