Coverage Report - org.apache.maven.scm.provider.git.GitScmTestUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
GitScmTestUtils
0 %
0/38
0 %
0/14
2,6
 
 1  
 package org.apache.maven.scm.provider.git;
 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 junit.framework.Assert;
 23  
 import org.codehaus.plexus.PlexusTestCase;
 24  
 import org.codehaus.plexus.util.FileUtils;
 25  
 import org.codehaus.plexus.util.Os;
 26  
 import org.codehaus.plexus.util.StringUtils;
 27  
 import org.codehaus.plexus.util.cli.CommandLineException;
 28  
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 29  
 import org.codehaus.plexus.util.cli.Commandline;
 30  
 
 31  
 import java.io.File;
 32  
 import java.io.IOException;
 33  
 
 34  
 /**
 35  
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
 36  
  * @version $Id: GitScmTestUtils.java 823147 2009-10-08 12:39:23Z struberg $
 37  
  */
 38  
 public final class GitScmTestUtils
 39  
 {
 40  
     private GitScmTestUtils()
 41  0
     {
 42  0
     }
 43  
 
 44  
     public static void initRepo( File repository, File workingDirectory, File assertionDirectory )
 45  
         throws IOException
 46  
     {
 47  0
         initRepo( "src/test/repository/", repository, workingDirectory );
 48  
 
 49  0
         FileUtils.deleteDirectory( assertionDirectory );
 50  
 
 51  0
         Assert.assertTrue( assertionDirectory.mkdirs() );
 52  0
     }
 53  
 
 54  
     public static void initRepo( String source, File repository, File workingDirectory )
 55  
         throws IOException
 56  
     {
 57  
         // Copy the repository to target
 58  0
         File src = PlexusTestCase.getTestFile( source );
 59  
 
 60  0
         FileUtils.deleteDirectory( repository );
 61  
 
 62  0
         Assert.assertTrue( repository.mkdirs() );
 63  
 
 64  0
         FileUtils.copyDirectoryStructure( src, repository );
 65  
 
 66  
         // now let's get rid of all .svn directories in the copied folder
 67  0
         deleteAllDirectories( repository, ".svn" );
 68  
 
 69  0
         FileUtils.deleteDirectory( workingDirectory );
 70  
 
 71  0
         Assert.assertTrue( workingDirectory.mkdirs() );
 72  0
     }
 73  
 
 74  
     public static String getScmUrl( File repositoryRootFile, String provider )
 75  
         throws CommandLineException
 76  
     {
 77  0
         String repositoryRoot = repositoryRootFile.getAbsolutePath();
 78  
 
 79  
         // TODO: it'd be great to build this into CommandLineUtils somehow
 80  
         // TODO: some way without a custom cygwin sys property?
 81  0
         if ( "true".equals( System.getProperty( "cygwin" ) ) )
 82  
         {
 83  0
             Commandline cl = new Commandline();
 84  
 
 85  0
             cl.setExecutable( "cygpath" );
 86  
 
 87  0
             cl.createArg().setValue( "--unix" );
 88  
 
 89  0
             cl.createArg().setValue( repositoryRoot );
 90  
 
 91  0
             CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
 92  
 
 93  0
             int exitValue = CommandLineUtils.executeCommandLine( cl, stdout, null );
 94  
 
 95  0
             if ( exitValue != 0 )
 96  
             {
 97  0
                 throw new CommandLineException( "Unable to convert cygwin path, exit code = " + exitValue );
 98  
             }
 99  
 
 100  0
             repositoryRoot = stdout.getOutput().trim();
 101  0
         }
 102  0
         else if ( Os.isFamily( "windows" ) )
 103  
         {
 104  0
             repositoryRoot = "/" + StringUtils.replace( repositoryRoot, "\\", "/" );
 105  
         }
 106  
 
 107  0
         return "scm:" + provider + ":file://" + repositoryRoot;
 108  
     }
 109  
     
 110  
     
 111  
     public static void deleteAllDirectories( File startDirectory, String pattern ) 
 112  
     throws IOException
 113  
     {
 114  0
         if ( startDirectory.isDirectory() ) 
 115  
         {
 116  0
             File[] childs = startDirectory.listFiles();
 117  0
             for ( int i = 0; i < childs.length; i++ )
 118  
             {
 119  0
                 File child = childs[ i ];
 120  0
                 if ( child.isDirectory() )
 121  
                 {
 122  0
                     if ( child.getName().equals( pattern ) )
 123  
                     {
 124  0
                         FileUtils.deleteDirectory( child );
 125  
                     }
 126  
                     else
 127  
                     {
 128  0
                         deleteAllDirectories( child, pattern );
 129  
                     }
 130  
                 }
 131  
             }
 132  
         }
 133  0
     }
 134  
 
 135  
 }