From 098290b6de9ed04f19bb0676c976e545fc0f4488 Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Thu, 16 Oct 2003 17:04:01 +0000 Subject: [PATCH] add an optional attribute to import note this is differnet from a failonerror attribute in that it only checks for the existance of the imported file, other errors in the imported file would cause the build to fail git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275513 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/CoreTasks/import.html | 9 +++++++ .../apache/tools/ant/taskdefs/ImportTask.java | 25 +++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/docs/manual/CoreTasks/import.html b/docs/manual/CoreTasks/import.html index 63170692e..fadd7fc1e 100644 --- a/docs/manual/CoreTasks/import.html +++ b/docs/manual/CoreTasks/import.html @@ -83,6 +83,15 @@ imported files.
Yes + + optional
+ + + if true, do not issue stop the build if the file does not exist, + default is false.
+ + No +


diff --git a/src/main/org/apache/tools/ant/taskdefs/ImportTask.java b/src/main/org/apache/tools/ant/taskdefs/ImportTask.java index d569e5538..119a9069a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ImportTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ImportTask.java @@ -64,8 +64,6 @@ import java.io.IOException; import java.util.Vector; /** - * EXPERIMENTAL: This task is experimental and may be under continual - * change till Ant1.6 ships; it may even be omitted from the product. *

* Task to import another build file into the current project. *

@@ -96,7 +94,18 @@ import java.util.Vector; */ public class ImportTask extends Task { private String file; + private boolean optional; + /** + * sets the optional attribute + * + * @param optional if true ignore files that are not present, + * default is false + */ + public void setOptional(boolean optional) { + this.optional = true; + } + /** * the name of the file to import. How relative paths are resolved is still * in flux: use absolute paths for safety. @@ -151,9 +160,15 @@ public class ImportTask extends Task { } if (!importedFile.exists()) { - throw new BuildException( - "Cannot find " + file + " imported from " - + buildFile.getAbsolutePath()); + String message = + "Cannot find " + file + " imported from " + + buildFile.getAbsolutePath(); + if (optional) { + getProject().log(message, Project.MSG_VERBOSE); + return; + } else { + throw new BuildException(message); + } } importedFile = new File(getPath(importedFile));