previous state. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270487 13f79535-47bb-0310-9956-ffa450edef68master
@@ -72,7 +72,6 @@ import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.taskdefs.condition.Condition; | |||
import org.apache.tools.ant.taskdefs.MatchingTask; | |||
import org.apache.tools.ant.types.FileSet; | |||
import org.apache.tools.ant.types.SrcFile; | |||
/** | |||
* This task can be used to create checksums for files. | |||
@@ -130,8 +129,8 @@ public class Checksum extends MatchingTask implements Condition { | |||
/** | |||
* Sets the file for which the checksum is to be calculated. | |||
*/ | |||
public void setFile(SrcFile file) { | |||
this.file = file.getFile(); | |||
public void setFile(File file) { | |||
this.file = file; | |||
} | |||
/** | |||
@@ -220,6 +219,11 @@ public class Checksum extends MatchingTask implements Condition { | |||
"Specify at least one source - a file or a fileset."); | |||
} | |||
if (file != null && file.exists() && file.isDirectory()) { | |||
throw new BuildException( | |||
"Checksum cannot be generated for directories"); | |||
} | |||
if (property != null && fileext != null) { | |||
throw new BuildException( | |||
"Property and FileExt cannot co-exist."); | |||
@@ -57,10 +57,8 @@ package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.DirectoryScanner; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.types.DestDir; | |||
import org.apache.tools.ant.types.FileSet; | |||
import org.apache.tools.ant.types.PatternSet; | |||
import org.apache.tools.ant.types.SrcFile; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
@@ -106,10 +104,19 @@ public class Expand extends MatchingTask { | |||
"Dest attribute must be specified"); | |||
} | |||
if (dest.exists() && !dest.isDirectory()) { | |||
throw new BuildException("Dest must be a directory.", location); | |||
} | |||
FileUtils fileUtils = FileUtils.newFileUtils(); | |||
if (source != null) { | |||
expandFile(fileUtils, source, dest); | |||
if (source.isDirectory()) { | |||
throw new BuildException("Src must not be a directory." + | |||
" Use nested filesets instead.", location); | |||
} else { | |||
expandFile(fileUtils, source, dest); | |||
} | |||
} | |||
if (filesets.size() > 0) { | |||
for (int j=0; j < filesets.size(); j++) { | |||
@@ -246,49 +253,18 @@ public class Expand extends MatchingTask { | |||
* destination directory. | |||
* | |||
* @param d Path to the directory. | |||
* @deprecated setDest(File) is deprecated and is replaced with | |||
* setDest(DestDir) to let Ant's core perform validation | |||
*/ | |||
public void setDest(File d) { | |||
log("DEPRECATED - The setDest(File) method has been deprecated." | |||
+ " Use setDest(DestDir) instead."); | |||
DestDir dd = new DestDir(); | |||
dd.setFile(d); | |||
setDest(dd); | |||
} | |||
/** | |||
* Set the destination directory. File will be unzipped into the | |||
* destination directory. | |||
* | |||
* @param d Path to the directory. | |||
*/ | |||
public void setDest(DestDir d) { | |||
this.dest=d.getFile(); | |||
this.dest=d; | |||
} | |||
/** | |||
* Set the path to zip-file. | |||
* | |||
* @param s Path to zip-file. | |||
* @deprecated setSrc(File) is deprecated and is replaced with | |||
* setSrc(SrcFile) to let Ant's core perform validation | |||
*/ | |||
public void setSrc(File s) { | |||
log("DEPRECATED - The setSrc(File) method has been deprecated." | |||
+ " Use setSrc(SrcFile) instead."); | |||
SrcFile sf = new SrcFile(); | |||
sf.setFile(s); | |||
setSrc(sf); | |||
} | |||
/** | |||
* Set the path to zip-file. | |||
* | |||
* @param s Path to zip-file. | |||
*/ | |||
public void setSrc(SrcFile s) { | |||
this.source = s.getFile(); | |||
this.source = s; | |||
} | |||
/** | |||
@@ -58,7 +58,7 @@ import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.ProjectHelper; | |||
import org.apache.tools.ant.types.EnumeratedAttribute; | |||
import org.apache.tools.ant.types.SrcFile; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.InputStreamReader; | |||
@@ -67,7 +67,7 @@ import java.io.BufferedInputStream; | |||
/** | |||
* Load a file into a property | |||
* @since 1.5 | |||
* | |||
* @author Steve Loughran | |||
* @created 10 December 2001 | |||
*/ | |||
@@ -126,8 +126,8 @@ public class LoadFile extends Task { | |||
* | |||
* @param srcFile The new SrcFile value | |||
*/ | |||
public void setSrcFile(SrcFile srcFile) { | |||
this.srcFile = srcFile.getFile(); | |||
public void setSrcFile(File srcFile) { | |||
this.srcFile = srcFile; | |||
} | |||
@@ -182,7 +182,7 @@ public class LoadFile extends Task { | |||
project.setNewProperty(property, text); | |||
log("loaded "+buffer.length+" characters",Project.MSG_VERBOSE); | |||
log(property+" := "+text,Project.MSG_DEBUG); | |||
} catch (IOException ioe) { | |||
String message = "Unable to load file: " + ioe.toString(); | |||
if (failOnError) { | |||
@@ -203,4 +203,3 @@ public class LoadFile extends Task { | |||
//end class | |||
} | |||
@@ -54,11 +54,9 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import java.io.File; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.Task; | |||
import org.apache.tools.ant.types.DestDir; | |||
import org.apache.tools.ant.BuildException; | |||
import java.io.File; | |||
/** | |||
* Creates a given directory. | |||
@@ -75,6 +73,10 @@ public class Mkdir extends Task { | |||
throw new BuildException("dir attribute is required", location); | |||
} | |||
if (dir.isFile()) { | |||
throw new BuildException("Unable to create directory as a file already exists with that name: " + dir.getAbsolutePath()); | |||
} | |||
if (!dir.exists()) { | |||
boolean result = dir.mkdirs(); | |||
if (result == false) { | |||
@@ -86,19 +88,8 @@ public class Mkdir extends Task { | |||
} | |||
} | |||
/** | |||
* @deprecated setDir(File) is deprecated and is replaced with | |||
* setDir(DestDir) to let Ant's core perform validation | |||
*/ | |||
public void setDir(File dir) { | |||
log("DEPRECATED - The setDir(File) method has been deprecated." | |||
+ " Use setDir(DestDir) instead."); | |||
DestDir destDir = new DestDir(); | |||
destDir.setFile(dir); | |||
setDir(destDir); | |||
} | |||
public void setDir(DestDir destDir) { | |||
this.dir = destDir.getFile(); | |||
this.dir = dir; | |||
} | |||
} | |||
@@ -59,7 +59,6 @@ import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.AntClassLoader; | |||
import org.apache.tools.ant.ProjectHelper; | |||
import org.apache.tools.ant.types.DestFile; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.types.Reference; | |||
import java.io.File; | |||
@@ -118,20 +117,8 @@ public class Property extends Task { | |||
return value; | |||
} | |||
/** | |||
* @deprecated setFile(File) is deprecated and is replaced with | |||
* setFile(DestFile) to let Ant's core perform validation | |||
*/ | |||
public void setFile(File file) { | |||
log("DEPRECATED - The setFile(File) method has been deprecated." | |||
+ " Use setFile(DestFile) instead."); | |||
DestFile destFile = new DestFile(); | |||
destFile.setFile(file); | |||
setFile(destFile); | |||
} | |||
public void setFile(DestFile file) { | |||
this.file = file.getFile(); | |||
this.file = file; | |||
} | |||
public File getFile() { | |||
@@ -58,7 +58,6 @@ package org.apache.tools.ant.taskdefs; | |||
import java.io.File; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.Task; | |||
import org.apache.tools.ant.types.SrcFile; | |||
/** | |||
* Abstract Base class for unpack tasks. | |||
@@ -73,16 +72,14 @@ public abstract class Unpack extends Task { | |||
/** | |||
* @deprecated setSrc(String) is deprecated and is replaced with | |||
* setSrc(SrcFile) to make Ant's Introspection | |||
* setSrc(File) to make Ant's Introspection | |||
* mechanism do the work and also to encapsulate operations on | |||
* the type in its own class. | |||
*/ | |||
public void setSrc(String src) { | |||
log("DEPRECATED - The setSrc(String) method has been deprecated." | |||
+ " Use setSrc(SrcFile) instead."); | |||
SrcFile sf = new SrcFile(); | |||
sf.setFile(project.resolveFile(src)); | |||
setSrc(sf); | |||
+ " Use setSrc(File) instead."); | |||
setSrc(project.resolveFile(src)); | |||
} | |||
/** | |||
@@ -97,8 +94,8 @@ public abstract class Unpack extends Task { | |||
setDest(project.resolveFile(dest)); | |||
} | |||
public void setSrc(SrcFile srcFile) { | |||
source = srcFile.getFile(); | |||
public void setSrc(File src) { | |||
source = src; | |||
} | |||
public void setDest(File dest) { | |||
@@ -110,6 +107,14 @@ public abstract class Unpack extends Task { | |||
throw new BuildException("No Src specified", location); | |||
} | |||
if (!source.exists()) { | |||
throw new BuildException("Src doesn't exist", location); | |||
} | |||
if (source.isDirectory()) { | |||
throw new BuildException("Cannot expand a directory", location); | |||
} | |||
if (dest == null) { | |||
dest = new File(source.getParent()); | |||
} | |||
@@ -116,32 +116,25 @@ public class LoadFileTest extends BuildFileTest { | |||
public void testNoSourcefilefound() { | |||
expectBuildExceptionContaining("testNoSourcefilefound", | |||
"File not found", | |||
"does not exist"); | |||
"Unable to load file"); | |||
} | |||
/** | |||
* A unit test for JUnit | |||
*/ | |||
/* turned off as the move to SrcFile changed where the check | |||
* for existence went. | |||
* we need to think of an alternate way to generate a file which | |||
* cant be opened for reading | |||
*/ | |||
/* | |||
public void testFailOnError() | |||
public void testFailOnError() | |||
throws BuildException { | |||
executeTarget("testFailOnError"); | |||
if(project.getProperty("testFailOnError")!=null) { | |||
fail("property should not have been defined"); | |||
fail("property should not have been defined"); | |||
} | |||
} | |||
*/ | |||
/** | |||
* A unit test for JUnit | |||
*/ | |||
public void testLoadAFile() | |||
public void testLoadAFile() | |||
throws BuildException { | |||
executeTarget("testLoadAFile"); | |||
if(project.getProperty("testLoadAFile").indexOf("eh?")<0) { | |||
@@ -153,7 +146,7 @@ public class LoadFileTest extends BuildFileTest { | |||
/** | |||
* A unit test for JUnit | |||
*/ | |||
public void testLoadAFileEnc() | |||
public void testLoadAFileEnc() | |||
throws BuildException { | |||
executeTarget("testLoadAFileEnc"); | |||
if(project.getProperty("testLoadAFileEnc")==null) { | |||
@@ -164,3 +157,4 @@ public class LoadFileTest extends BuildFileTest { | |||
} | |||