Coverage Report - org.apache.maven.scm.provider.local.command.list.LocalListCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
LocalListCommand
0 %
0/38
0 %
0/24
10,5
 
 1  
 package org.apache.maven.scm.provider.local.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 org.apache.maven.scm.ScmException;
 23  
 import org.apache.maven.scm.ScmFile;
 24  
 import org.apache.maven.scm.ScmFileSet;
 25  
 import org.apache.maven.scm.ScmFileStatus;
 26  
 import org.apache.maven.scm.ScmVersion;
 27  
 import org.apache.maven.scm.command.list.AbstractListCommand;
 28  
 import org.apache.maven.scm.command.list.ListScmResult;
 29  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 30  
 import org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository;
 31  
 import org.codehaus.plexus.util.StringUtils;
 32  
 
 33  
 import java.io.File;
 34  
 import java.util.ArrayList;
 35  
 import java.util.Iterator;
 36  
 import java.util.List;
 37  
 
 38  
 /**
 39  
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
 40  
  * @version $Id: LocalListCommand.java 1055646 2011-01-05 21:22:58Z olamy $
 41  
  */
 42  0
 public class LocalListCommand
 43  
     extends AbstractListCommand
 44  
 {
 45  
     /** {@inheritDoc} */
 46  
     protected ListScmResult executeListCommand( ScmProviderRepository repo, ScmFileSet fileSet, boolean recursive,
 47  
                                                 ScmVersion version )
 48  
         throws ScmException
 49  
     {
 50  0
         if ( version != null )
 51  
         {
 52  0
             throw new ScmException( "The local scm doesn't support tags." );
 53  
         }
 54  
 
 55  0
         LocalScmProviderRepository repository = (LocalScmProviderRepository) repo;
 56  
 
 57  0
         File root = new File( repository.getRoot() );
 58  
 
 59  0
         String module = repository.getModule();
 60  
 
 61  0
         File source = new File( root, module );
 62  
 
 63  0
         if ( !root.exists() )
 64  
         {
 65  0
             throw new ScmException( "The base directory doesn't exist (" + root.getAbsolutePath() + ")." );
 66  
         }
 67  
 
 68  0
         if ( !source.exists() )
 69  
         {
 70  0
             throw new ScmException( "The module directory doesn't exist (" + source.getAbsolutePath() + ")." );
 71  
         }
 72  
 
 73  0
         if ( getLogger().isInfoEnabled() )
 74  
         {
 75  0
             getLogger().info( "Listing files of '" + source.getAbsolutePath() + "'." );
 76  
         }
 77  
 
 78  
         try
 79  
         {
 80  0
             if ( fileSet.getFileList() == null || fileSet.getFileList().isEmpty() )
 81  
             {
 82  0
                 return new LocalListScmResult( null, getFiles( source, source, recursive ) );
 83  
             }
 84  
             else
 85  
             {
 86  0
                 List<ScmFile> files = new ArrayList<ScmFile>();
 87  0
                 Iterator<File> it = fileSet.getFileList().iterator();
 88  
 
 89  0
                 while ( it.hasNext() )
 90  
                 {
 91  0
                     File file = (File) it.next();
 92  
 
 93  0
                     files.addAll( getFiles( source, new File( source, file.getPath() ), recursive ) );
 94  0
                 }
 95  
 
 96  0
                 return new LocalListScmResult( null, files );
 97  
             }
 98  
         }
 99  0
         catch ( Exception e )
 100  
         {
 101  0
             return new ListScmResult( null, "The svn command failed.", e.getMessage(), false );
 102  
         }
 103  
     }
 104  
 
 105  
     private List<ScmFile> getFiles( File source, File directory, boolean recursive )
 106  
         throws Exception
 107  
     {
 108  0
         if ( !directory.exists() )
 109  
         {
 110  0
             throw new Exception( "Directory '" + directory.getAbsolutePath() + "' doesn't exist." );
 111  
         }
 112  
 
 113  0
         List<ScmFile> files = new ArrayList<ScmFile>();
 114  
 
 115  0
         File[] filesArray = directory.listFiles();
 116  
 
 117  0
         if ( filesArray != null )
 118  
         {
 119  0
             for ( int i = 0; i < filesArray.length; i++ )
 120  
             {
 121  0
                 File f = filesArray[i];
 122  
 
 123  0
                 String path = f.getAbsolutePath().substring( source.getAbsolutePath().length() );
 124  0
                 path = StringUtils.replace( path, "\\", "/" );
 125  0
                 path = StringUtils.replace( path, "/./", "/" );
 126  
 
 127  0
                 files.add( new ScmFile( path, ScmFileStatus.CHECKED_IN ) );
 128  
 
 129  0
                 if ( f.isDirectory() && recursive )
 130  
                 {
 131  0
                     files.addAll( getFiles( source, f, recursive ) );
 132  
                 }
 133  
             }
 134  
         }
 135  
 
 136  0
         return files;
 137  
     }
 138  
 }