Browse Source

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
master
Peter Reilly 21 years ago
parent
commit
098290b6de
2 changed files with 29 additions and 5 deletions
  1. +9
    -0
      docs/manual/CoreTasks/import.html
  2. +20
    -5
      src/main/org/apache/tools/ant/taskdefs/ImportTask.java

+ 9
- 0
docs/manual/CoreTasks/import.html View File

@@ -83,6 +83,15 @@ imported files.<br>
</td>
<td valign="top" align="center">Yes</td>
</tr>
<tr>
<td valign="top">optional<br>
</td>
<td valign="top">
if true, do not issue stop the build if the file does not exist,
default is false.<br>
</td>
<td valign="top" align="center">No</td>
</tr>
</tbody>
</table>
<h3><br>


+ 20
- 5
src/main/org/apache/tools/ant/taskdefs/ImportTask.java View File

@@ -64,8 +64,6 @@ import java.io.IOException;
import java.util.Vector;

/**
* <i>EXPERIMENTAL:</i> This task is experimental and may be under continual
* change till Ant1.6 ships; it may even be omitted from the product.
* <p>
* Task to import another build file into the current project.
* <p>
@@ -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));


Loading…
Cancel
Save