001package org.apache.maven.scm.provider.cvslib.command.remove; 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 org.apache.maven.scm.ScmException; 023import org.apache.maven.scm.ScmFile; 024import org.apache.maven.scm.ScmFileSet; 025import org.apache.maven.scm.ScmFileStatus; 026import org.apache.maven.scm.ScmResult; 027import org.apache.maven.scm.command.remove.AbstractRemoveCommand; 028import org.apache.maven.scm.command.remove.RemoveScmResult; 029import org.apache.maven.scm.provider.ScmProviderRepository; 030import org.apache.maven.scm.provider.cvslib.command.CvsCommand; 031import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils; 032import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository; 033import org.codehaus.plexus.util.cli.Commandline; 034 035import java.io.File; 036import java.util.ArrayList; 037import java.util.List; 038 039/** 040 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 041 * @author Olivier Lamy 042 * 043 * @todo separate the CVSlib stuff from the cvs command line so it is clear what needs to be updated eventually 044 */ 045public abstract class AbstractCvsRemoveCommand 046 extends AbstractRemoveCommand 047 implements CvsCommand 048{ 049 /** {@inheritDoc} */ 050 protected ScmResult executeRemoveCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message ) 051 throws ScmException 052 { 053 CvsScmProviderRepository repository = (CvsScmProviderRepository) repo; 054 055 Commandline cl = CvsCommandUtils.getBaseCommand( "remove", repository, fileSet ); 056 057 cl.createArg().setValue( "-f" ); 058 059 cl.createArg().setValue( "-l" ); 060 061 List<File> files = fileSet.getFileList(); 062 063 List<ScmFile> removedFiles = new ArrayList<ScmFile>(); 064 065 for ( File file : files ) 066 { 067 String path = file.getPath().replace( '\\', '/' ); 068 069 cl.createArg().setValue( path ); 070 071 removedFiles.add( new ScmFile( path, ScmFileStatus.DELETED ) ); 072 } 073 074 if ( getLogger().isInfoEnabled() ) 075 { 076 getLogger().info( "Executing: " + cl ); 077 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); 078 } 079 080 return executeCvsCommand( cl, removedFiles ); 081 } 082 083 protected abstract RemoveScmResult executeCvsCommand( Commandline cl, List<ScmFile> removedFiles ) 084 throws ScmException; 085}