View Javadoc
1   package org.apache.maven.scm.provider.cvslib.command.update;
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.Iterator;
24  import java.util.List;
25  
26  import org.apache.maven.scm.ScmException;
27  import org.apache.maven.scm.ScmFileSet;
28  import org.apache.maven.scm.ScmVersion;
29  import org.apache.maven.scm.command.update.AbstractUpdateCommand;
30  import org.apache.maven.scm.command.update.UpdateScmResult;
31  import org.apache.maven.scm.provider.ScmProviderRepository;
32  import org.apache.maven.scm.provider.cvslib.command.CvsCommand;
33  import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils;
34  import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
35  import org.codehaus.plexus.util.StringUtils;
36  import org.codehaus.plexus.util.cli.Commandline;
37  
38  /**
39   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse </a>
40   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
41   * @author Olivier Lamy
42   *
43   */
44  public abstract class AbstractCvsUpdateCommand
45      extends AbstractUpdateCommand
46      implements CvsCommand
47  {
48      /** {@inheritDoc} */
49      public UpdateScmResult executeUpdateCommand( ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version )
50          throws ScmException
51      {
52          CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
53  
54          Commandline cl = CvsCommandUtils.getBaseCommand( "update", repository, fileSet, false );
55  
56          cl.createArg().setValue( "-d" );
57  
58          if ( version != null && StringUtils.isNotEmpty( version.getName() ) )
59          {
60              cl.createArg().setValue( "-r" + version.getName() );
61          }
62          
63          List<File> files = fileSet.getFileList();
64          if ( !files.isEmpty() )
65          {
66              Iterator<File> fileIterator = files.iterator();
67              while ( fileIterator.hasNext() )
68              {
69                  cl.createArg().setValue( ( (File) fileIterator.next() ).getPath() );
70              }
71          }
72  
73          if ( getLogger().isInfoEnabled() )
74          {
75              getLogger().info( "Executing: " + cl );
76              getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
77          }
78  
79          return executeCvsCommand( cl );
80      }
81  
82      protected abstract UpdateScmResult executeCvsCommand( Commandline cl )
83          throws ScmException;
84  }