Browse Source

Prevent adding sysproperties with a null key or a null value

PR: 21684


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274881 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 22 years ago
parent
commit
b6caf517ff
2 changed files with 66 additions and 4 deletions
  1. +3
    -0
      WHATSNEW
  2. +63
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java

+ 3
- 0
WHATSNEW View File

@@ -207,6 +207,9 @@ Fixed bugs:
* Do not overwrite the value (increment) attribute of PropertyFile nested Entry element. * Do not overwrite the value (increment) attribute of PropertyFile nested Entry element.
Bugzilla Report 21505. Bugzilla Report 21505.


* Prevent sysproperties with no key or no value from being added.
Bugzilla Report



Other changes: Other changes:
-------------- --------------


+ 63
- 4
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -179,6 +179,8 @@ public class JUnitTask extends Task {
private boolean showOutput = false; private boolean showOutput = false;
private File tmpDir; private File tmpDir;
private AntClassLoader classLoader = null; private AntClassLoader classLoader = null;

private static final int STRING_BUFFER_SIZE = 128;
/** /**
* If true, force ant to re-classload all classes for each JUnit TestCase * If true, force ant to re-classload all classes for each JUnit TestCase
* *
@@ -325,11 +327,19 @@ public class JUnitTask extends Task {
* Print summary enumeration values. * Print summary enumeration values.
*/ */
public static class SummaryAttribute extends EnumeratedAttribute { public static class SummaryAttribute extends EnumeratedAttribute {
/**
* list the possible values
* @return array of allowed values
*/
public String[] getValues() { public String[] getValues() {
return new String[] {"true", "yes", "false", "no", return new String[] {"true", "yes", "false", "no",
"on", "off", "withOutAndErr"}; "on", "off", "withOutAndErr"};
} }


/**
* gives the boolean equivalent of the authorized values
* @return boolean equivalent of the value
*/
public boolean asBoolean() { public boolean asBoolean() {
String value = getValue(); String value = getValue();
return "true".equals(value) return "true".equals(value)
@@ -409,8 +419,26 @@ public class JUnitTask extends Task {
* testcases when JVM forking is not enabled. * testcases when JVM forking is not enabled.
* *
* @since Ant 1.3 * @since Ant 1.3
* @deprecated since ant 1.6
* @param sysp environment variable to add
*/ */
public void addSysproperty(Environment.Variable sysp) { public void addSysproperty(Environment.Variable sysp) {

commandline.addSysproperty(sysp);
}

/**
* Adds a system property that tests can access.
* This might be useful to tranfer Ant properties to the
* testcases when JVM forking is not enabled.
* @param sysp new environment variable to add
* @since Ant 1.6
*/
public void addConfiguredSysproperty(Environment.Variable sysp) {
// get a build exception if there is a missing key or value
// see bugzilla report 21684
String testString = sysp.getContent();
getProject().log("sysproperty added : " + testString, Project.MSG_DEBUG);
commandline.addSysproperty(sysp); commandline.addSysproperty(sysp);
} }


@@ -421,6 +449,7 @@ public class JUnitTask extends Task {
* This might be useful to tranfer Ant properties to the * This might be useful to tranfer Ant properties to the
* testcases when JVM forking is not enabled. * testcases when JVM forking is not enabled.
* *
* @param sysp set of properties to be added
* @since Ant 1.6 * @since Ant 1.6
*/ */
public void addSyspropertyset(PropertySet sysp) { public void addSyspropertyset(PropertySet sysp) {
@@ -430,6 +459,7 @@ public class JUnitTask extends Task {
/** /**
* Adds path to classpath used for tests. * Adds path to classpath used for tests.
* *
* @return reference to the classpath in the embedded java command line
* @since Ant 1.2 * @since Ant 1.2
*/ */
public Path createClasspath() { public Path createClasspath() {
@@ -438,6 +468,7 @@ public class JUnitTask extends Task {


/** /**
* Adds a path to the bootclasspath. * Adds a path to the bootclasspath.
* @return reference to the bootclasspath in the embedded java command line
* @since Ant 1.6 * @since Ant 1.6
*/ */
public Path createBootclasspath() { public Path createBootclasspath() {
@@ -448,7 +479,7 @@ public class JUnitTask extends Task {
* Adds an environment variable; used when forking. * Adds an environment variable; used when forking.
* *
* <p>Will be ignored if we are not forking a new VM.</p> * <p>Will be ignored if we are not forking a new VM.</p>
*
* @param var environment variable to be added
* @since Ant 1.5 * @since Ant 1.5
*/ */
public void addEnv(Environment.Variable var) { public void addEnv(Environment.Variable var) {
@@ -460,6 +491,7 @@ public class JUnitTask extends Task {
* *
* <p>Will be ignored if we are not forking a new VM.</p> * <p>Will be ignored if we are not forking a new VM.</p>
* *
* @param newenv boolean indicating if setting a new environment is wished
* @since Ant 1.5 * @since Ant 1.5
*/ */
public void setNewenvironment(boolean newenv) { public void setNewenvironment(boolean newenv) {
@@ -494,6 +526,7 @@ public class JUnitTask extends Task {
/** /**
* Add a new formatter to all tests of this task. * Add a new formatter to all tests of this task.
* *
* @param fe formatter element
* @since Ant 1.2 * @since Ant 1.2
*/ */
public void addFormatter(FormatterElement fe) { public void addFormatter(FormatterElement fe) {
@@ -503,6 +536,7 @@ public class JUnitTask extends Task {
/** /**
* If true, include ant.jar, optional.jar and junit.jar in the forked VM. * If true, include ant.jar, optional.jar and junit.jar in the forked VM.
* *
* @param b include ant run time yes or no
* @since Ant 1.5 * @since Ant 1.5
*/ */
public void setIncludeantruntime(boolean b) { public void setIncludeantruntime(boolean b) {
@@ -519,6 +553,7 @@ public class JUnitTask extends Task {
* tests that are interactive and prompt the user to do * tests that are interactive and prompt the user to do
* something.</p> * something.</p>
* *
* @param showOutput if true, send output to Ant's logging system too
* @since Ant 1.5 * @since Ant 1.5
*/ */
public void setShowOutput(boolean showOutput) { public void setShowOutput(boolean showOutput) {
@@ -528,6 +563,7 @@ public class JUnitTask extends Task {
/** /**
* Creates a new JUnitRunner and enables fork of a new Java VM. * Creates a new JUnitRunner and enables fork of a new Java VM.
* *
* @throws Exception under ??? circumstances
* @since Ant 1.2 * @since Ant 1.2
*/ */
public JUnitTask() throws Exception { public JUnitTask() throws Exception {
@@ -538,6 +574,7 @@ public class JUnitTask extends Task {
/** /**
* Where Ant should place temporary files. * Where Ant should place temporary files.
* *
* @param tmpDir location where temporary files should go to
* @since Ant 1.6 * @since Ant 1.6
*/ */
public void setTempdir(File tmpDir) { public void setTempdir(File tmpDir) {
@@ -561,6 +598,7 @@ public class JUnitTask extends Task {
/** /**
* Runs the testcase. * Runs the testcase.
* *
* @throws BuildException in case of test failures or errors
* @since Ant 1.2 * @since Ant 1.2
*/ */
public void execute() throws BuildException { public void execute() throws BuildException {
@@ -575,6 +613,8 @@ public class JUnitTask extends Task {


/** /**
* Run the tests. * Run the tests.
* @param arg one JunitTest
* @throws BuildException in case of test failures or errors
*/ */
protected void execute(JUnitTest arg) throws BuildException { protected void execute(JUnitTest arg) throws BuildException {
JUnitTest test = (JUnitTest) arg.clone(); JUnitTest test = (JUnitTest) arg.clone();
@@ -632,6 +672,8 @@ public class JUnitTask extends Task {
* @param watchdog the watchdog in charge of cancelling the test if it * @param watchdog the watchdog in charge of cancelling the test if it
* exceeds a certain amount of time. Can be <tt>null</tt>, in this case * exceeds a certain amount of time. Can be <tt>null</tt>, in this case
* the test could probably hang forever. * the test could probably hang forever.
* @throws BuildException in case of error creating a temporary property file,
* or if the junit process can not be forked
*/ */
private int executeAsForked(JUnitTest test, ExecuteWatchdog watchdog) private int executeAsForked(JUnitTest test, ExecuteWatchdog watchdog)
throws BuildException { throws BuildException {
@@ -654,13 +696,14 @@ public class JUnitTask extends Task {
if (summary) { if (summary) {
log("Running " + test.getName(), Project.MSG_INFO); log("Running " + test.getName(), Project.MSG_INFO);
cmd.createArgument() cmd.createArgument()
.setValue("formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter");
.setValue("formatter"
+ "=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter");
} }


cmd.createArgument().setValue("showoutput=" cmd.createArgument().setValue("showoutput="
+ String.valueOf(showOutput)); + String.valueOf(showOutput));


StringBuffer formatterArg = new StringBuffer(128);
StringBuffer formatterArg = new StringBuffer(STRING_BUFFER_SIZE);
final FormatterElement[] feArray = mergeFormatters(test); final FormatterElement[] feArray = mergeFormatters(test);
for (int i = 0; i < feArray.length; i++) { for (int i = 0; i < feArray.length; i++) {
FormatterElement fe = feArray[i]; FormatterElement fe = feArray[i];
@@ -745,6 +788,7 @@ public class JUnitTask extends Task {
* Pass output sent to System.out to the TestRunner so it can * Pass output sent to System.out to the TestRunner so it can
* collect ot for the formatters. * collect ot for the formatters.
* *
* @param output output coming from System.out
* @since Ant 1.5 * @since Ant 1.5
*/ */
protected void handleOutput(String output) { protected void handleOutput(String output) {
@@ -777,6 +821,7 @@ public class JUnitTask extends Task {
* Pass output sent to System.out to the TestRunner so it can * Pass output sent to System.out to the TestRunner so it can
* collect ot for the formatters. * collect ot for the formatters.
* *
* @param output output coming from System.out
* @since Ant 1.5.2 * @since Ant 1.5.2
*/ */
protected void handleFlush(String output) { protected void handleFlush(String output) {
@@ -794,6 +839,7 @@ public class JUnitTask extends Task {
* Pass output sent to System.err to the TestRunner so it can * Pass output sent to System.err to the TestRunner so it can
* collect ot for the formatters. * collect ot for the formatters.
* *
* @param output output coming from System.err
* @since Ant 1.5 * @since Ant 1.5
*/ */
public void handleErrorOutput(String output) { public void handleErrorOutput(String output) {
@@ -812,6 +858,7 @@ public class JUnitTask extends Task {
* Pass output sent to System.err to the TestRunner so it can * Pass output sent to System.err to the TestRunner so it can
* collect ot for the formatters. * collect ot for the formatters.
* *
* @param output coming from System.err
* @since Ant 1.5.2 * @since Ant 1.5.2
*/ */
public void handleErrorFlush(String output) { public void handleErrorFlush(String output) {
@@ -831,6 +878,8 @@ public class JUnitTask extends Task {


/** /**
* Execute inside VM. * Execute inside VM.
* @param arg one JUnitTest
* @throws BuildException under unspecified circumstances
*/ */
private int executeInVM(JUnitTest arg) throws BuildException { private int executeInVM(JUnitTest arg) throws BuildException {
JUnitTest test = (JUnitTest) arg.clone(); JUnitTest test = (JUnitTest) arg.clone();
@@ -907,6 +956,7 @@ public class JUnitTask extends Task {
* @return <tt>null</tt> if there is a timeout value, otherwise the * @return <tt>null</tt> if there is a timeout value, otherwise the
* watchdog instance. * watchdog instance.
* *
* @throws BuildException under unspecified circumstances
* @since Ant 1.2 * @since Ant 1.2
*/ */
protected ExecuteWatchdog createWatchdog() throws BuildException { protected ExecuteWatchdog createWatchdog() throws BuildException {
@@ -919,6 +969,7 @@ public class JUnitTask extends Task {
/** /**
* Get the default output for a formatter. * Get the default output for a formatter.
* *
* @return default output stream for a formatter
* @since Ant 1.3 * @since Ant 1.3
*/ */
protected OutputStream getDefaultOutput() { protected OutputStream getDefaultOutput() {
@@ -929,6 +980,7 @@ public class JUnitTask extends Task {
* Merge all individual tests from the batchtest with all individual tests * Merge all individual tests from the batchtest with all individual tests
* and return an enumeration over all <tt>JUnitTest</tt>. * and return an enumeration over all <tt>JUnitTest</tt>.
* *
* @return enumeration over individual tests
* @since Ant 1.3 * @since Ant 1.3
*/ */
protected Enumeration getIndividualTests() { protected Enumeration getIndividualTests() {
@@ -943,6 +995,8 @@ public class JUnitTask extends Task {
} }


/** /**
* return an enumeration listing each test, then each batchtest
* @return enumeration
* @since Ant 1.3 * @since Ant 1.3
*/ */
protected Enumeration allTests() { protected Enumeration allTests() {
@@ -951,6 +1005,8 @@ public class JUnitTask extends Task {
} }


/** /**
* @param test junit test
* @return array of FormatterElement
* @since Ant 1.3 * @since Ant 1.3
*/ */
private FormatterElement[] mergeFormatters(JUnitTest test) { private FormatterElement[] mergeFormatters(JUnitTest test) {
@@ -964,7 +1020,9 @@ public class JUnitTask extends Task {
/** /**
* If the formatter sends output to a file, return that file. * If the formatter sends output to a file, return that file.
* null otherwise. * null otherwise.
*
* @param fe formatter element
* @param test one JUnit test
* @return file reference
* @since Ant 1.3 * @since Ant 1.3
*/ */
protected File getOutput(FormatterElement fe, JUnitTest test) { protected File getOutput(FormatterElement fe, JUnitTest test) {
@@ -984,6 +1042,7 @@ public class JUnitTask extends Task {
* <p>Doesn't work for archives in JDK 1.1 as the URL returned by * <p>Doesn't work for archives in JDK 1.1 as the URL returned by
* getResource doesn't contain the name of the archive.</p> * getResource doesn't contain the name of the archive.</p>
* *
* @param resource resource that one wants to lookup
* @since Ant 1.4 * @since Ant 1.4
*/ */
protected void addClasspathEntry(String resource) { protected void addClasspathEntry(String resource) {


Loading…
Cancel
Save