Coverage Report - org.apache.maven.wagon.FileTestUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
FileTestUtils
0 %
0/29
0 %
0/4
1,8
 
 1  
 package org.apache.maven.wagon;
 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.codehaus.plexus.util.FileUtils;
 23  
 
 24  
 import java.io.File;
 25  
 import java.io.FileWriter;
 26  
 import java.io.IOException;
 27  
 import java.io.Writer;
 28  
 
 29  
 /**
 30  
  * @author <a href="michal@apache.org>Michal Maczka</a>
 31  
  * @version $Id: FileTestUtils.java 1133758 2011-06-09 09:53:31Z struberg $
 32  
  */
 33  0
 public class FileTestUtils
 34  
 {
 35  
 
 36  
     public static final File createUniqueFile( final String dirname, final String name )
 37  
         throws IOException
 38  
     {
 39  
 
 40  0
         final File dir = createDir( dirname );
 41  
 
 42  0
         final File retValue = new File( dir, name );
 43  
 
 44  0
         return retValue;
 45  
 
 46  
     }
 47  
 
 48  
 
 49  
     public static final File createUniqueDir( final String name )
 50  
         throws IOException
 51  
     {
 52  
 
 53  0
         String filename = name + System.currentTimeMillis();
 54  
 
 55  0
         return createDir( filename );
 56  
 
 57  
     }
 58  
 
 59  
 
 60  
     public static final File createDir( final String name )
 61  
         throws IOException
 62  
     {
 63  
 
 64  0
         final File baseDirectory = getTestOutputDir();
 65  
 
 66  0
         final File retValue = new File( baseDirectory, name );
 67  
        
 68  0
         if ( retValue.exists() )
 69  
         {
 70  0
             FileUtils.cleanDirectory( retValue );
 71  0
             return retValue;
 72  
         }
 73  
         
 74  0
         retValue.mkdirs();
 75  
 
 76  0
         if ( !retValue.exists() )
 77  
         {
 78  0
             throw new IOException( "Unable to create the directory for testdata " + retValue.getPath() );
 79  
         }
 80  
 
 81  0
         return retValue;
 82  
     }
 83  
 
 84  
     public static final File getTestOutputDir()
 85  
     {
 86  0
         final String tempDir = System.getProperty( "java.io.tmpdir" );
 87  
 
 88  0
         final String baseDir = System.getProperty( "basedir", tempDir );
 89  
 
 90  0
         final File base = new File( baseDir ).getAbsoluteFile();
 91  
 
 92  0
         final String pathname = base + File.separator + "target" + File.separator + "test-output";
 93  
 
 94  0
         final File retValue = new File( pathname );
 95  
 
 96  0
         retValue.mkdirs();
 97  
 
 98  0
         return retValue;
 99  
     }
 100  
 
 101  
     public static File generateFile( String file, String content )
 102  
         throws IOException
 103  
     {
 104  0
         File f = new File( file );
 105  
 
 106  0
         f.getParentFile().mkdirs();
 107  
 
 108  0
         Writer writer = new FileWriter( f );
 109  
 
 110  
         try
 111  
         {
 112  0
             writer.write( content );
 113  
         }
 114  
         finally
 115  
         {
 116  0
             writer.close();
 117  0
         }
 118  
 
 119  0
         return f;
 120  
     }
 121  
 }