Coverage Report - org.mule.tools.anttasks.FileChecker
 
Classes in this File Line Coverage Branch Coverage Complexity
FileChecker
0%
0/17
0%
0/16
7.5
 
 1  
 /*
 2  
 * $Id$
 3  
 * --------------------------------------------------------------------------------------
 4  
 * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
 5  
 *
 6  
 * The software in this package is published under the terms of the CPAL v1.0
 7  
 * license, a copy of which has been included with this distribution in the
 8  
 * LICENSE.txt file.
 9  
 */
 10  
 package org.mule.tools.anttasks;
 11  
 
 12  
 import org.apache.tools.ant.BuildException;
 13  
 import org.apache.tools.ant.Location;
 14  
 import org.apache.tools.ant.Task;
 15  
 
 16  
 import java.io.File;
 17  
 import java.text.MessageFormat;
 18  
 
 19  
 /**
 20  
 * Check file parameters to Ant tasks
 21  
 */
 22  
 public class FileChecker extends Task
 23  
 {
 24  
     private Location location;
 25  
 
 26  
     /**
 27  
 * Create a FileChecker
 28  
 */
 29  
     public FileChecker(Location location)
 30  0
     {
 31  0
         this.location = location;
 32  0
     }
 33  
 
 34  
     /**
 35  
 * Check that a specified file parameter is valid
 36  
 */
 37  
     public void checkFile(File file, String parameterName, boolean isDirectory, boolean needWrite) throws BuildException
 38  
     {
 39  0
         if (file == null)
 40  
         {
 41  0
             throw new BuildException(MessageFormat.format("No {0} specified", parameterName), getLocation());
 42  
         }
 43  0
         if (!file.exists())
 44  
         {
 45  0
             throw new BuildException(
 46  
                 MessageFormat.format("{0} \"{1}\" does not exist", parameterName, file),
 47  
                 getLocation());
 48  
         }
 49  0
         if (!file.canRead())
 50  
         {
 51  0
             throw new BuildException(
 52  
                 MessageFormat.format("{0} \"{1}\" is not readable", parameterName, file),
 53  
                 getLocation());
 54  
         }
 55  0
         if (needWrite && !file.canWrite())
 56  
         {
 57  0
             throw new BuildException(
 58  
                 MessageFormat.format("{0} \"{1}\" is not writable", parameterName, file),
 59  
                 getLocation());
 60  
         }
 61  0
         if (isDirectory)
 62  
         {
 63  0
             if (!file.isDirectory())
 64  
             {
 65  0
                 throw new BuildException(
 66  
                     MessageFormat.format("{0} \"{1}\" is not a directory", parameterName, file),
 67  
                     getLocation());
 68  
             }
 69  
         }
 70  
         else
 71  
         {
 72  0
             if (file.isDirectory())
 73  
             {
 74  0
                 throw new BuildException(
 75  
                     MessageFormat.format("{0} \"{1}\" is a directory", parameterName, file),
 76  
                     getLocation());
 77  
             }
 78  
         }
 79  0
     }
 80  
 }
 81