001 package org.apache.maven.scm.provider.cvslib.command.add; 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 022 import org.apache.maven.scm.ScmException; 023 import org.apache.maven.scm.ScmFile; 024 import org.apache.maven.scm.ScmFileSet; 025 import org.apache.maven.scm.ScmFileStatus; 026 import org.apache.maven.scm.ScmResult; 027 import org.apache.maven.scm.command.add.AbstractAddCommand; 028 import org.apache.maven.scm.command.add.AddScmResult; 029 import org.apache.maven.scm.provider.ScmProviderRepository; 030 import org.apache.maven.scm.provider.cvslib.command.CvsCommand; 031 import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils; 032 import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository; 033 import org.codehaus.plexus.util.cli.Commandline; 034 035 import java.io.File; 036 import java.util.ArrayList; 037 import java.util.List; 038 039 /** 040 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 041 * @version $Id: AbstractCvsAddCommand.java 1054126 2010-12-31 15:18:11Z olamy $ 042 * @todo separate the CVSlib stuff from the cvs command line so it is clear what needs to be updated eventually 043 */ 044 public abstract class AbstractCvsAddCommand 045 extends AbstractAddCommand 046 implements CvsCommand 047 { 048 /** {@inheritDoc} */ 049 protected ScmResult executeAddCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message, 050 boolean binary ) 051 throws ScmException 052 { 053 CvsScmProviderRepository repository = (CvsScmProviderRepository) repo; 054 055 Commandline cl = CvsCommandUtils.getBaseCommand( "add", repository, fileSet ); 056 057 if ( binary ) 058 { 059 cl.createArg().setValue( "-kb" ); 060 } 061 062 if ( message != null && message.length() > 0 ) 063 { 064 cl.createArg().setValue( "-m" ); 065 066 cl.createArg().setValue( "\"" + message + "\"" ); 067 } 068 069 070 List<ScmFile> addedFiles = new ArrayList<ScmFile>( fileSet.getFileList().size() ); 071 072 for ( File file : fileSet.getFileList() ) 073 { 074 String path = file.getPath().replace( '\\', '/' ); 075 076 cl.createArg().setValue( path ); 077 078 addedFiles.add( new ScmFile( path, ScmFileStatus.ADDED ) ); 079 } 080 081 if ( getLogger().isInfoEnabled() ) 082 { 083 getLogger().info( "Executing: " + cl ); 084 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); 085 } 086 087 return executeCvsCommand( cl, addedFiles ); 088 } 089 090 protected abstract AddScmResult executeCvsCommand( Commandline cl, List<ScmFile> addedFiles ) 091 throws ScmException; 092 }