View Javadoc

1   package org.apache.maven.scm.provider.cvslib.command.list;
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.ScmVersion;
28  import org.apache.maven.scm.command.list.AbstractListCommand;
29  import org.apache.maven.scm.command.list.ListScmResult;
30  import org.apache.maven.scm.provider.ScmProviderRepository;
31  import org.apache.maven.scm.provider.cvslib.command.CvsCommand;
32  import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils;
33  import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
34  import org.codehaus.plexus.util.StringUtils;
35  import org.codehaus.plexus.util.cli.Commandline;
36  
37  /**
38   * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
39   *
40   */
41  public abstract class AbstractCvsListCommand
42      extends AbstractListCommand
43      implements CvsCommand
44  {
45      /** {@inheritDoc} */
46      protected ListScmResult executeListCommand( ScmProviderRepository repo, ScmFileSet fileSet, boolean recursive,
47                                                  ScmVersion version )
48          throws ScmException
49      {
50          CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
51  
52          Commandline cl = CvsCommandUtils.getBaseCommand( "rls", repository, fileSet, "-n" );
53  
54          if ( version != null && !StringUtils.isEmpty( version.getName() ) )
55          {
56              cl.createArg().setValue( "-r" );
57              cl.createArg().setValue( version.getName() );
58          }
59  
60          cl.createArg().setValue( "-d" );
61          cl.createArg().setValue( "-e" ); // szakusov: to fix "Unknown file status" problem
62  
63          if ( recursive )
64          {
65              cl.createArg().setValue( "-R" );
66          }
67  
68          for ( Iterator<File> it = fileSet.getFileList().iterator(); it.hasNext(); )
69          {
70              File target = (File) it.next();
71              String path = target.getPath();
72              if ( path.startsWith( "\\" ) )
73              {
74                  path = path.substring( 1 );
75              }
76              cl.createArg().setValue( path );
77          }
78  
79          if ( getLogger().isInfoEnabled() )
80          {
81              getLogger().info( "Executing: " + cl );
82              getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
83          }
84  
85          return executeCvsCommand( cl );
86      }
87  
88      protected abstract ListScmResult executeCvsCommand( Commandline cl )
89          throws ScmException;
90  }