View Javadoc
1   package org.apache.maven.scm.provider.cvslib.command.tag;
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  
25  import org.apache.maven.scm.ScmException;
26  import org.apache.maven.scm.ScmFileSet;
27  import org.apache.maven.scm.ScmResult;
28  import org.apache.maven.scm.ScmTagParameters;
29  import org.apache.maven.scm.command.tag.AbstractTagCommand;
30  import org.apache.maven.scm.command.tag.TagScmResult;
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.apache.maven.scm.provider.cvslib.util.CvsUtil;
36  import org.apache.maven.scm.providers.cvslib.settings.Settings;
37  import org.codehaus.plexus.util.cli.Commandline;
38  
39  /**
40   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse </a>
41   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
42   *
43   */
44  public abstract class AbstractCvsTagCommand
45      extends AbstractTagCommand
46      implements CvsCommand
47  {
48      
49      public ScmResult executeTagCommand( ScmProviderRepository repo, ScmFileSet fileSet, String tag, String message )
50          throws ScmException
51      {
52          return executeTagCommand( repo, fileSet, tag, new ScmTagParameters( message ) );
53      }
54  
55      /** {@inheritDoc} */
56      public ScmResult executeTagCommand( ScmProviderRepository repo, ScmFileSet fileSet, String tag,
57                                          ScmTagParameters scmTagParameters )
58          throws ScmException
59      {
60          CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
61  
62          Commandline cl = CvsCommandUtils.getBaseCommand( "tag", repository, fileSet, false );
63  
64          Settings settings = CvsUtil.getSettings();
65          if ( settings.isUseForceTag() )
66          {
67              cl.createArg().setValue( "-F" );
68          }
69  
70          cl.createArg().setValue( "-c" );
71  
72          cl.createArg().setValue( tag );
73  
74          if ( fileSet.getFileList() != null && !fileSet.getFileList().isEmpty() )
75          {
76              for ( Iterator<File> it = fileSet.getFileList().iterator(); it.hasNext(); )
77              {
78                  File fileName = it.next();
79                  cl.createArg().setValue( fileName.toString() );
80              }
81          }
82  
83          if ( getLogger().isInfoEnabled() )
84          {
85              getLogger().info( "Executing: " + cl );
86              getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
87          }
88  
89          return executeCvsCommand( cl );
90      }
91  
92      protected abstract TagScmResult executeCvsCommand( Commandline cl )
93          throws ScmException;
94  }