From f0282fd8b18b09bbd18ee4b82fed883f872a802a Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 18 Sep 2000 07:55:01 +0000 Subject: [PATCH] Various checks for required attributes and better error messages added. Submitted by: Nico Seessle git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268002 13f79535-47bb-0310-9956-ffa450edef68 --- docs/index.html | 150 +++++++++++------- src/main/org/apache/tools/ant/Project.java | 2 +- .../org/apache/tools/ant/taskdefs/Ant.java | 6 +- .../apache/tools/ant/taskdefs/Available.java | 8 + .../apache/tools/ant/taskdefs/Copydir.java | 6 +- .../apache/tools/ant/taskdefs/Copyfile.java | 6 +- .../apache/tools/ant/taskdefs/Deltree.java | 17 +- .../org/apache/tools/ant/taskdefs/Expand.java | 3 + .../org/apache/tools/ant/taskdefs/Filter.java | 4 + .../org/apache/tools/ant/taskdefs/GZip.java | 8 + .../org/apache/tools/ant/taskdefs/Get.java | 22 ++- .../org/apache/tools/ant/taskdefs/Mkdir.java | 21 ++- .../apache/tools/ant/taskdefs/Property.java | 2 +- .../org/apache/tools/ant/taskdefs/Rename.java | 8 + .../apache/tools/ant/taskdefs/Replace.java | 8 + .../org/apache/tools/ant/taskdefs/Tar.java | 7 +- 16 files changed, 197 insertions(+), 81 deletions(-) diff --git a/docs/index.html b/docs/index.html index e6697a6ed..3cbb80678 100644 --- a/docs/index.html +++ b/docs/index.html @@ -101,7 +101,7 @@ build Ant from the source code.

If you do not have a JAXP compliant XML parse installed, you may use the reference implementation available from Sun. It is available from http://java.sun.com/xml. - Once installed make sure the "jaxp.jar" and "parser.jar" files are in your classpath. + Once installed make sure the "jaxp.jar" and "parser.jar" files are in your classpath.

You will also need the JDK installed on your system, version 1.1 or later. @@ -155,12 +155,13 @@ least the following:

needed for your chosen JAXP compliant XML parser.

When you need JDK functionality (like a javac task, or a rmic task), then for JDK 1.1, the classes.zip -file of the JDK must be added to the classpath; for JDK 1.2, tools.jar +file of the JDK must be added to the classpath; for JDK 1.2 or JDK 1.3, tools.jar must be added. The scripts supplied with ant, in the bin directory, will add tools.jar automatically if the JAVA_HOME environment variable is set.

When you are executing platform specific applications (like the exec task, or the cvs task), the property ant.home -must be set to the directory containing a bin directory, which contains the antRun shell script necessary to run execs on Unix.

+must be set to the directory containing a bin directory, which contains the antRun +shell script necessary to run execs on Unix.


Running Ant

Running Ant is simple, when you installed it as described in the previous @@ -173,7 +174,10 @@ where <file> is the buildfile you want to use.

buildfile (see the property task). This can be done with the -D<property>=<value> option, where <property> is the name of the property and <value> -the value.

+the value. This can also be used (and is the only way since Java can not access them) +to have access to your environment variables, just pass -DMYVAR=%MYVAR% (Windows) or +-DMYVAR=$MYVAR (Unix) do Ant, you can access these variables inside your build-file +as ${MYVAR}.

Two more options are -quiet which instructs Ant to print less information on the console when running. The option -verbose on the other hand makes Ant print more information on the console.

@@ -303,7 +307,7 @@ always be executed.

href="#tstamp">tstamp tasks in a so called initialization target, on which all other targets depend. Make sure that target is always the first one in the depends list of the other targets. In this manual, most initialization targets -have the name "init".

+have the name "init".

The optional description attribute can be used to provide a one line description of this target that is printed by the -projecthelp commandline option.

A target has the following attributes:

@@ -314,7 +318,7 @@ have the name "init".

- + @@ -415,7 +419,7 @@ be of the form @token@ where token is the token name that is set in the filter task. This token syntax matches the syntax of other build systems that perform such filtering and remains sufficiently orthogonal to most programming and scripting languages, as well with documentation systems.

-

Note: in case a token with the format @token@ if found in a file but no +

Note: in case a token with the format @token@ is found in a file but no filter is associated with that token, no changes take place. So, no escaping method is present, but as long as you choose appropriate names for your tokens, this should not cause problems.

@@ -885,7 +889,7 @@ in the supplied directory (dir attribute) is used.

used.

The properties of the current project will be available in the new project. These properties will override the properties that are set in the new project. -(See also the properties task).  You can set properties +(See also the properties task). You can set properties in the new project from the old project by using nested property tags. This allows you to parameterize your subprojects.

Parameters:

@@ -897,13 +901,13 @@ allows you to parameterize your subprojects.

- + -     +     @@ -982,7 +986,7 @@ execution depending on system parameters.

      -     +           @@ -1092,7 +1096,7 @@ directly. More FileSets can be specified using nested UNIX system.

-    <chmod dir="${dist}/bin" perm="ugo+rx" includes="**/*.sh" />
+    <chmod dir="${dist}/bin" perm="ugo+rx" includes="**/*.sh" />
 

makes all ".sh" files below ${dist}/bin @@ -1391,7 +1395,8 @@ nested <include>, <exclude> and

- +
namethe name of the project.the name of the target. Yes
antfilethe buildfile to use.the buildfile to use. Defaults to "build.xml". No
dirthe directory to use as a basedir for the new Ant project - Defaults to the current directory.the directory to use as a basedir for the new Ant project. + Defaults to the current directory.No
valuethe value to set the property to. Defaults to "true".the value to set the property to. Defaults to "true".No
verboseShow name of each deleted file ("true"/"false"). Default is "false" when omitted.Show name of each deleted file ("true"/"false"). + Default is "false" when omitted. No
@@ -1479,7 +1484,7 @@ systems.

executable the command to execute without any command line - arguments. + arguments. dir @@ -1516,7 +1521,6 @@ systems.

<exec dir="${src}" executable="dir" os="windows" output="dir.txt" />

-

Parameters specified as nested elements

arg

Command line arguments should be specified as nested @@ -1558,7 +1562,7 @@ system command via nested <env> elements.

Examples
-<exec executable="emacs" >
+<exec executable="emacs" >
   <env key="DISPLAY" value=":1.0" />
 </exec>
 
@@ -1570,6 +1574,14 @@ system command via nested <env> elements.

adds ${basedir}/bin to the PATH of the system command.

+

Note: Although it may work for you to specify arguments using +a simple arg-element and seperate them by spaces it may fail if you switch to +a newer version of the JDK. JDK < 1.2 will pass these as separate arguments +to the program you are calling, JDK >= 1.2 will pass them as a single +argument and cause most calls to fail.

+

Note2: If you are using Ant on Windows and a new DOS-Window pops up +for every command which is excuted this may be a problem of the JDK you are using. +This problem may occur with all JDK's < 1.2.


ExecOn

Description

@@ -1589,7 +1601,7 @@ command. At least one nested <fileset> is required.

executable the command to execute without any command line - arguments. + arguments. Yes @@ -1710,7 +1722,6 @@ build.xml:4: Something wrong here.

Sets a token filter for this project. Token filters are used by all tasks that perform file copying operations through the Project commodity methods.

Note: the token string must not contain the separators chars (@).

-

Parameters

@@ -1815,7 +1826,7 @@ supports all attributes of <fileset> For Unix platforms, the default is remove. For DOS based systems (including Windows), the default is add.

- Note: Unless this property is specified as "asis", extra CR characters + Note: Unless this property is specified as "asis", extra CR characters which do not precede a LF will be removed.

@@ -1829,9 +1840,9 @@ supports all attributes of <fileset>
  • asis: leave tab and space characters alone
  • remove: convert tabs to spaces - Default for this parameter is "asis". + Default for this parameter is "asis".

    - Note: Unless this property is specified as "asis", extra spaces and + Note: Unless this property is specified as "asis", extra spaces and tabs after the last non-whitespace character on the line will be removed.

  • @@ -2467,7 +2478,8 @@ inclusion/exclusion of files works, and how to write patterns.

    - +
    No No
    targetGenerate class files for specific VM version, e.g. "1.1" or "1.2".Generate class files for specific VM version, e.g. + "1.1" or "1.2". No
    @@ -2528,6 +2540,10 @@ the propery src2. This can also be represented using nested element <exclude name="mypackage/p1/testpackage/**" /> </javac> +

    Note: If you are using Ant on Windows and a new DOS-Window pops up +for every use of an external compiler this may be a problem of the JDK you are using. +This problem may occur with all JDK's < 1.2.

    +

    Javadoc/Javadoc2

    Description

    @@ -3031,7 +3047,7 @@ necessary.

      <patch patchfile="module.1.0-1.1.patch" />

    applies the diff included in module.1.0-1.1.patch to the files in base directory guessing the filename(s) from the diff output. -

      <patch patchfile="module.1.0-1.1.patch" strip="1" />
    +
      <patch patchfile="module.1.0-1.1.patch" strip="1" />

    like above but one leading directory part will be removed. i.e. if the diff output looked like

    @@ -3155,7 +3171,7 @@ must use a nested <replacetoken> element.

    file file for which the token should be replaced. - Exactly one of the two. + Exactly one of the two. dir @@ -3282,14 +3298,14 @@ supports all attributes of <fileset> sourcebase - Pass the "-keepgenerated" flag to rmic and + Pass the "-keepgenerated" flag to rmic and move the generated source file to the base directory. No stubversion Specify the JDK version for the generated stub code. - Specify "1.1" to pass the "-v1.1" option to rmic. + Specify "1.1" to pass the "-v1.1" option to rmic. No @@ -3471,7 +3487,7 @@ supports all attributes of <fileset> extension desired file extension to be used for the targets. - If not specified, the default is "html". + If not specified, the default is "html". No @@ -3482,8 +3498,8 @@ supports all attributes of <fileset> processor name of the XSLT processor to use. Permissible -values are "xslp" for the XSL:P processor, "xalan" for the Apache XML Xalan -processor, or the name of an arbitrary XSLTLiaison class. +values are "xslp" for the XSL:P processor, "xalan" +for the Apache XML Xalan processor, or the name of an arbitrary XSLTLiaison class. Defaults to xslp or xalan (in that order), if one is found in your class path No @@ -3705,9 +3721,9 @@ initialization target.

    Unjar/Unwar/Unzip

    Description

    Unzips a zip-, war- or jarfile.

    -

    For JDK 1.1 "last modified time" field is set to current time instead of being +

    For JDK 1.1 "last modified time" field is set to current time instead of being carried from zipfile.

    -

    File permissions will not be restored on extracted files. +

    File permissions will not be restored on extracted files.

    Parameters

    @@ -3735,8 +3751,8 @@ carried from zipfile.

    Untar

    Description

    Untars a tarfile.

    -

    File permissions will not be restored on extracted files. -

    For JDK 1.1 "last modified time" field is set to current time instead of being +

    File permissions will not be restored on extracted files.

    +

    For JDK 1.1 "last modified time" field is set to current time instead of being carried from tarfile.

    Parameters

    @@ -4054,14 +4070,14 @@ supports all attributes of <fileset> - + - + @@ -4098,33 +4114,33 @@ supports all attributes of <fileset> + or not ("yes"/"no"). Default excludes are used when omitted.
    verboseset to "yes" if you want to see the output from - the cabarc tool. defaults to "no".set to "yes" if you want to see the output from + the cabarc tool. defaults to "no". No
    compressset to "no" to store files without compressing. - defaults to "yes".set to "no" to store files without compressing. + defaults to "yes". No
    defaultexcludes indicates whether default excludes should be used - or not ("yes"/"no"). Default excludes are used when omitted. No

    Examples

    -<cab cabfile="${dist}/manual.cab"
    -     basedir="htdocs/manual" 
    +<cab cabfile="${dist}/manual.cab"
    +     basedir="htdocs/manual" 
       />
     

    cabs all files in the htdocs/manual directory in a file called manual.cab in the ${dist} directory.

    -<cab cabfile="${dist}/manual.cab"
    -     basedir="htdocs/manual"
    -     excludes="mydocs/**, **/todo.html"
    +<cab cabfile="${dist}/manual.cab"
    +     basedir="htdocs/manual"
    +     excludes="mydocs/**, **/todo.html"
       />
     

    cabs all files in the htdocs/manual directory in a file called manual.cab in the ${dist} directory. Files in the directory mydocs, or files with the name todo.html are excluded.

    -<cab cabfile="${dist}/manual.cab"
    -     basedir="htdocs/manual"
    -     includes="api/**/*.html"
    -     excludes="**/todo.html"
    -     verbose="yes"
    +<cab cabfile="${dist}/manual.cab"
    +     basedir="htdocs/manual"
    +     includes="api/**/*.html"
    +     excludes="**/todo.html"
    +     verbose="yes"
       />
     

    cab all files in the htdocs/manual directory in a file called @@ -4289,7 +4305,7 @@ use the remotedir attribute as the base directory for the files on the FTP server, and the dir attribute as the local directory to put the files into. The file structure from the FTP site is preserved on the local machine.

    -  <ftp action="get"
    +  <ftp action="get"
            server="ftp.apache.org"
            userid="anonymous"
            password="me@myorg.com">
    @@ -4307,7 +4323,7 @@ select the files to delete from the remote FTP server.  Again, the
     filesets are relative to the remote directory, not a local directory.  In
     fact, the dir attribute of the fileset is ignored completely.
     
    -  <ftp action="del"
    +  <ftp action="del"
            server="ftp.apache.org"
            userid="anonymous"
            password="me@myorg.com" >
    @@ -4795,8 +4811,8 @@ BUILD SUCCESSFUL
     

    VssGet

    Description:

    Task to perform GET commands to Microsoft Visual Source Safe. -

    -The following attributes are interpretted: +

    If you specify two or more attributes from version, date and +label only one will be used in the order version, date, label.

    Parameters:

    @@ -4854,7 +4870,18 @@ The following attributes are interpretted:

    Note that only one of version, date or label should be specified

    Examples

    -

    None yet available

    +
    +<vssget localPath="C:\mysrc\myproject"
    +        recursive="true" 
    +        label="Release1"
    +        login="me,mypassword"
    +        vsspath="/source/aProject"
    +        writable="true"/>
    +
    +Does a get on the VSS-Project $/source/aproject using the username +me and the password mypassword. It will recursively get the files +which are labeled Release1 and write them to the local directory +C:\mysrc\myproject. The local files will be writable.

    Build Events

    @@ -4895,10 +4922,13 @@ output. name of the method must begin with "set", followed by the attribute name, with the first character in uppercase, and the rest in lowercase. The type of the attribute can be String, any - primitive type, Class, File (in which case the - value of the attribute is interpreted relative to the project's basedir) - or any other type that has a constructor with a single String - argument + primitive type (they are converted for you from their String-representation + in the build-file. If you specify a boolean your method will be passed the value + true if the value specified in the build-file is one of "true", + "yes" or "on"), Class, File + (in which case the value of the attribute is interpreted relative to the + project's basedir) or any other type that has a constructor with a single + String argument
  • If your task has enumerated attributes, you should consider using a subclass of org.apache.tools.ant.types.EnumeratedAttribute as argument to your setter method. See org.apache.tools.ant.taskdefs.FixCRLF for @@ -5007,8 +5037,8 @@ package. Then you can use it as if it were a built in task.

    href="http://jakarta.apache.org/jyve-faq/Turbine/screen/DisplayTopics/action/SetAll/project_id/2/faq_id/16">jakarta.apache.org. This FAQ is interactive, which means you can ask and answer questions online.

    -

    One of the questions poping up quite often is "Is there a DTD for -buildfiles?". Please refer to the FAQ for an answer.

    +

    One of the questions poping up quite often is "Is there a DTD for +buildfiles?". Please refer to the FAQ for an answer.


    Feedback

    To provide feedback on this software, please subscribe to the Ant User diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index 4c3233444..94506d491 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -307,7 +307,7 @@ public class Project { try { setBaseDir(new File(new File(baseD).getCanonicalPath())); } catch (IOException ioe) { - String msg = "Can't set basedir " + baseDir + " due to " + + String msg = "Can't set basedir " + baseD + " due to " + ioe.getMessage(); throw new BuildException(msg); } diff --git a/src/main/org/apache/tools/ant/taskdefs/Ant.java b/src/main/org/apache/tools/ant/taskdefs/Ant.java index a7a6b2b54..2634e5b52 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Ant.java +++ b/src/main/org/apache/tools/ant/taskdefs/Ant.java @@ -102,9 +102,11 @@ public class Ant extends Task { newP.setName(p.getName()); if (p.getValue() != null) { newP.setValue(p.getValue()); - } else if (p.getFile() != null) { + } + if (p.getFile() != null) { newP.setFile(p.getFile()); - } else if (p.getResource() != null) { + } + if (p.getResource() != null) { newP.setResource(p.getResource()); } properties.setElementAt(newP, i); diff --git a/src/main/org/apache/tools/ant/taskdefs/Available.java b/src/main/org/apache/tools/ant/taskdefs/Available.java index d2b53167f..d0e9132e1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Available.java +++ b/src/main/org/apache/tools/ant/taskdefs/Available.java @@ -115,6 +115,14 @@ public class Available extends Task { } public void execute() throws BuildException { + if (property == null) { + throw new BuildException("property attribute is required", location); + } + + if (classname == null && file == null && resource == null) { + throw new BuildException("At least one of (classname|file|resource) is required", location); + } + if (classpath != null) { this.loader = new AntClassLoader(project, classpath, false); } diff --git a/src/main/org/apache/tools/ant/taskdefs/Copydir.java b/src/main/org/apache/tools/ant/taskdefs/Copydir.java index 44eecf216..0b1cd8594 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Copydir.java +++ b/src/main/org/apache/tools/ant/taskdefs/Copydir.java @@ -96,7 +96,7 @@ public class Copydir extends MatchingTask { public void execute() throws BuildException { if (srcDir == null) { - throw new BuildException("srcdir attribute must be set!", + throw new BuildException("src attribute must be set!", location); } @@ -109,6 +109,10 @@ public class Copydir extends MatchingTask { throw new BuildException("The dest attribute must be set.", location); } + if (srcDir.equals(destDir)) { + log("Warning: src == dest"); + } + DirectoryScanner ds = super.getDirectoryScanner(srcDir); String[] files = ds.getIncludedFiles(); diff --git a/src/main/org/apache/tools/ant/taskdefs/Copyfile.java b/src/main/org/apache/tools/ant/taskdefs/Copyfile.java index 19e68e6db..11fb70254 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Copyfile.java +++ b/src/main/org/apache/tools/ant/taskdefs/Copyfile.java @@ -101,7 +101,11 @@ public class Copyfile extends Task { if (destFile == null) { throw new BuildException("The dest attribute must be present.", location); } - + + if (srcFile.equals(destFile)) { + log("Warning: src == dest"); + } + if (forceOverwrite || srcFile.lastModified() > destFile.lastModified()) { try { project.copyFile(srcFile, destFile, filtering, forceOverwrite); diff --git a/src/main/org/apache/tools/ant/taskdefs/Deltree.java b/src/main/org/apache/tools/ant/taskdefs/Deltree.java index 46700a934..10d77ebdd 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Deltree.java +++ b/src/main/org/apache/tools/ant/taskdefs/Deltree.java @@ -67,28 +67,35 @@ public class Deltree extends Task { private File dir; - public void setDir(String dirName) { - dir = project.resolveFile(dirName); + public void setDir(File dir) { + this.dir = dir; } public void execute() throws BuildException { - log("Deleting: " + dir.getAbsolutePath()); + if (dir == null) { + throw new BuildException("dir attribute must be set!", location); + } if (dir.exists()) { if (!dir.isDirectory()) { if (!dir.delete()) { - throw new BuildException("Unable to delete file " + dir.getAbsolutePath()); + throw new BuildException("Unable to delete directory " + + dir.getAbsolutePath(), + location); } return; // String msg = "Given dir: " + dir.getAbsolutePath() + // " is not a dir"; // throw new BuildException(msg); } + + log("Deleting: " + dir.getAbsolutePath()); + try { removeDir(dir); } catch (IOException ioe) { String msg = "Unable to delete " + dir.getAbsolutePath(); - throw new BuildException(msg); + throw new BuildException(msg, location); } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/Expand.java b/src/main/org/apache/tools/ant/taskdefs/Expand.java index e637c8550..a137db16b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Expand.java +++ b/src/main/org/apache/tools/ant/taskdefs/Expand.java @@ -87,6 +87,9 @@ public class Expand extends MatchingTask { if (source == null) { throw new BuildException("Source attribute must be specified"); } + if (dest == null) { + throw new BuildException("Dest attribute must be specified"); + } if (source.isDirectory()) { // get all the files in the descriptor directory diff --git a/src/main/org/apache/tools/ant/taskdefs/Filter.java b/src/main/org/apache/tools/ant/taskdefs/Filter.java index 0d66349bd..5d2042ba3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Filter.java +++ b/src/main/org/apache/tools/ant/taskdefs/Filter.java @@ -76,6 +76,10 @@ public class Filter extends Task { } public void execute() throws BuildException { + if (token == null || value == null) { + throw new BuildException("token and value are required", location); + } + project.addFilter(token, value); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/GZip.java b/src/main/org/apache/tools/ant/taskdefs/GZip.java index aa7cc14fc..bafad40ac 100644 --- a/src/main/org/apache/tools/ant/taskdefs/GZip.java +++ b/src/main/org/apache/tools/ant/taskdefs/GZip.java @@ -81,6 +81,14 @@ public class GZip extends Task { } public void execute() throws BuildException { + if (zipFile == null) { + throw new BuildException("zipfile attribute is required", location); + } + + if (source == null) { + throw new BuildException("src attribute is required", location); + } + log("Building gzip: " + zipFile.getAbsolutePath()); GZIPOutputStream zOut = null; diff --git a/src/main/org/apache/tools/ant/taskdefs/Get.java b/src/main/org/apache/tools/ant/taskdefs/Get.java index 5c3f3b5dc..f97a68c34 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Get.java +++ b/src/main/org/apache/tools/ant/taskdefs/Get.java @@ -80,11 +80,29 @@ public class Get extends Task { * @exception BuildException Thrown in unrecoverable error. */ public void execute() throws BuildException { - try { + if (source == null) { + throw new BuildException("src attribute is required", location); + } + + if (dest == null) { + throw new BuildException("dest attribute is required", location); + } + + if (dest.exists() && dest.isDirectory()) { + throw new BuildException("The specified destination is a directory", + location); + } + + if (dest.exists() && !dest.canWrite()) { + throw new BuildException("Can't write to " + dest.getAbsolutePath(), + location); + } + + try { log("Getting: " + source); - //set the timestamp to the file date. + //set the timestamp to the file date. long timestamp=0; boolean hasTimestamp=false; diff --git a/src/main/org/apache/tools/ant/taskdefs/Mkdir.java b/src/main/org/apache/tools/ant/taskdefs/Mkdir.java index 039b049eb..e34e4557d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Mkdir.java +++ b/src/main/org/apache/tools/ant/taskdefs/Mkdir.java @@ -66,22 +66,29 @@ import java.io.File; public class Mkdir extends Task { - private String dirName; + private File dir; public void execute() throws BuildException { - File dir = project.resolveFile(dirName); - if (!dir.exists()) { + if (dir == null) { + throw new BuildException("dir attribute is required", location); + } + + if (dir.isFile()) { + log("Warning: Specified directory is a file: " + dir.getAbsolutePath()); + } + + if (!dir.exists()) { boolean result = dir.mkdirs(); if (result == false) { - String msg = "Directory " + dirName + " creation was not " + + String msg = "Directory " + dir.getAbsolutePath() + " creation was not " + "succesful for an unknown reason"; - throw new BuildException(msg); + throw new BuildException(msg, location); } log("Created dir: " + dir.getAbsolutePath()); } } - public void setDir(String dirName) { - this.dirName = dirName; + public void setDir(File dir) { + this.dir = dir; } } diff --git a/src/main/org/apache/tools/ant/taskdefs/Property.java b/src/main/org/apache/tools/ant/taskdefs/Property.java index ad8139ad1..5a8170681 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Property.java +++ b/src/main/org/apache/tools/ant/taskdefs/Property.java @@ -124,7 +124,7 @@ public class Property extends Task { private void loadFile (File file) throws BuildException { Properties props = new Properties(); - log("Loading " + name, Project.MSG_VERBOSE); + log("Loading " + file.getAbsolutePath(), Project.MSG_VERBOSE); try { if (file.exists()) { props.load(new FileInputStream(file)); diff --git a/src/main/org/apache/tools/ant/taskdefs/Rename.java b/src/main/org/apache/tools/ant/taskdefs/Rename.java index 22ac4d5e9..3dd31838b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Rename.java +++ b/src/main/org/apache/tools/ant/taskdefs/Rename.java @@ -102,6 +102,14 @@ public class Rename extends Task { * thrown, if the rename operation fails. */ public void execute() throws BuildException { + if (dest == null) { + throw new BuildException("dest attribute is required", location); + } + + if (src == null) { + throw new BuildException("src attribute is required", location); + } + if (replace && dest.exists()) { if (!dest.delete()) { throw new BuildException("Unable to remove existing file " + diff --git a/src/main/org/apache/tools/ant/taskdefs/Replace.java b/src/main/org/apache/tools/ant/taskdefs/Replace.java index 736c969db..004baa286 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Replace.java +++ b/src/main/org/apache/tools/ant/taskdefs/Replace.java @@ -95,6 +95,10 @@ public class Replace extends MatchingTask { throw new BuildException("replace token must not be null", location); } + if (token.getText().equals("")) { + throw new BuildException("replace token must not be empty", location); + } + if (src == null && dir == null) { throw new BuildException("Either the file or the dir attribute must be specified", location); } @@ -124,6 +128,10 @@ public class Replace extends MatchingTask { * @param src the source file */ private void processFile(File src) throws BuildException { + if (!src.exists()) { + throw new BuildException("Replace: source file " + src.getPath() + " doesn't exist", location); + } + File temp = new File(src.getPath() + ".temp"); if (temp.exists()) { diff --git a/src/main/org/apache/tools/ant/taskdefs/Tar.java b/src/main/org/apache/tools/ant/taskdefs/Tar.java index 7fb213bb1..8d174b8ba 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Tar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Tar.java @@ -84,7 +84,10 @@ public class Tar extends MatchingTask { } public void execute() throws BuildException { - log("Building tar: "+ tarFile.getAbsolutePath()); + if (tarFile == null) { + throw new BuildException("tarfile attribute must be set!", + location); + } if (baseDir == null) { throw new BuildException("basedir attribute must be set!", @@ -94,6 +97,8 @@ public class Tar extends MatchingTask { throw new BuildException("basedir does not exist!", location); } + log("Building tar: "+ tarFile.getAbsolutePath()); + DirectoryScanner ds = super.getDirectoryScanner(baseDir); String[] files = ds.getIncludedFiles();