@@ -50,6 +50,12 @@ public class LoadResource extends Task {
*/
*/
private boolean failOnError = true;
private boolean failOnError = true;
/**
* suppress error message if it goes pear-shaped, sets failOnError=false
*/
private boolean quiet = false;
/**
/**
* Encoding to use for filenames, defaults to the platform's default
* Encoding to use for filenames, defaults to the platform's default
* encoding.
* encoding.
@@ -100,7 +106,18 @@ public class LoadResource extends Task {
public final void setFailonerror(final boolean fail) {
public final void setFailonerror(final boolean fail) {
failOnError = fail;
failOnError = fail;
}
}
/**
* If true, suppress the load error report and set the
* the failonerror value to true.
* @param quiet The new Quiet value
*/
public void setQuiet(final boolean quiet) {
this.quiet = quiet;
if (quiet) {
this.failOnError = false;
}
}
/**
/**
* read in a source file to a property
* read in a source file to a property
@@ -116,12 +133,16 @@ public class LoadResource extends Task {
if (property == null) {
if (property == null) {
throw new BuildException("output property not defined");
throw new BuildException("output property not defined");
}
}
if (quiet && failOnError) {
throw new BuildException("quiet and failonerror cannot both be "
+ "set to true");
}
if (!src.isExists()) {
if (!src.isExists()) {
String message = src + " doesn't exist";
String message = src + " doesn't exist";
if (failOnError) {
if (failOnError) {
throw new BuildException(message);
throw new BuildException(message);
} else {
} else {
log(message, Project.MSG_ERR);
log(message, quiet ? Project.MSG_WARN : Project.MSG_ERR);
return;
return;
}
}
}
}
@@ -175,13 +196,14 @@ public class LoadResource extends Task {
if (failOnError) {
if (failOnError) {
throw new BuildException(message, ioe, getLocation());
throw new BuildException(message, ioe, getLocation());
} else {
} else {
log(message, Project.MSG_ERR);
log(message, quiet ? Project.MSG_VERBOSE : Project.MSG_ERR);
}
}
} catch (final BuildException be) {
} catch (final BuildException be) {
if (failOnError) {
if (failOnError) {
throw be;
throw be;
} else {
} else {
log(be.getMessage(), Project.MSG_ERR);
log(be.getMessage(),
quiet ? Project.MSG_VERBOSE : Project.MSG_ERR);
}
}
} finally {
} finally {
FileUtils.close(is);
FileUtils.close(is);