001package org.apache.maven.scm.provider.cvslib.command.list; 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.Iterator; 024 025import org.apache.maven.scm.ScmException; 026import org.apache.maven.scm.ScmFileSet; 027import org.apache.maven.scm.ScmVersion; 028import org.apache.maven.scm.command.list.AbstractListCommand; 029import org.apache.maven.scm.command.list.ListScmResult; 030import org.apache.maven.scm.provider.ScmProviderRepository; 031import org.apache.maven.scm.provider.cvslib.command.CvsCommand; 032import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils; 033import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository; 034import org.codehaus.plexus.util.StringUtils; 035import org.codehaus.plexus.util.cli.Commandline; 036 037/** 038 * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a> 039 * 040 */ 041public abstract class AbstractCvsListCommand 042 extends AbstractListCommand 043 implements CvsCommand 044{ 045 /** {@inheritDoc} */ 046 protected ListScmResult executeListCommand( ScmProviderRepository repo, ScmFileSet fileSet, boolean recursive, 047 ScmVersion version ) 048 throws ScmException 049 { 050 CvsScmProviderRepository repository = (CvsScmProviderRepository) repo; 051 052 Commandline cl = CvsCommandUtils.getBaseCommand( "rls", repository, fileSet, "-n" ); 053 054 if ( version != null && !StringUtils.isEmpty( version.getName() ) ) 055 { 056 cl.createArg().setValue( "-r" ); 057 cl.createArg().setValue( version.getName() ); 058 } 059 060 cl.createArg().setValue( "-d" ); 061 cl.createArg().setValue( "-e" ); // szakusov: to fix "Unknown file status" problem 062 063 if ( recursive ) 064 { 065 cl.createArg().setValue( "-R" ); 066 } 067 068 for ( Iterator<File> it = fileSet.getFileList().iterator(); it.hasNext(); ) 069 { 070 File target = (File) it.next(); 071 String path = target.getPath(); 072 if ( path.startsWith( "\\" ) ) 073 { 074 path = path.substring( 1 ); 075 } 076 cl.createArg().setValue( path ); 077 } 078 079 if ( getLogger().isInfoEnabled() ) 080 { 081 getLogger().info( "Executing: " + cl ); 082 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); 083 } 084 085 return executeCvsCommand( cl ); 086 } 087 088 protected abstract ListScmResult executeCvsCommand( Commandline cl ) 089 throws ScmException; 090}