Browse Source

Validate system properties before running a Java command, PR 34725

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278221 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 20 years ago
parent
commit
da4edf3f9b
3 changed files with 14 additions and 3 deletions
  1. +2
    -0
      src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
  2. +1
    -0
      src/main/org/apache/tools/ant/types/CommandlineJava.java
  3. +11
    -3
      src/main/org/apache/tools/ant/types/Environment.java

+ 2
- 0
src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java View File

@@ -179,6 +179,8 @@ public class ExecuteJava implements Runnable, TimeoutObserver {
throw new BuildException("Could not find " + classname + "."
+ " Make sure you have it in your"
+ " classpath");
} catch (BuildException e) {
throw e;
} catch (SecurityException e) {
throw e;
} catch (ThreadDeath e) {


+ 1
- 0
src/main/org/apache/tools/ant/types/CommandlineJava.java View File

@@ -141,6 +141,7 @@ public class CommandlineJava implements Cloneable {
p.putAll(mergePropertySets());
for (Enumeration e = variables.elements(); e.hasMoreElements();) {
Environment.Variable v = (Environment.Variable) e.nextElement();
v.validate();
p.put(v.getKey(), v.getValue());
}
System.setProperties(p);


+ 11
- 3
src/main/org/apache/tools/ant/types/Environment.java View File

@@ -109,13 +109,21 @@ public class Environment {
* @throws BuildException if key or value are unassigned
*/
public String getContent() throws BuildException {
validate();
StringBuffer sb = new StringBuffer(key.trim());
sb.append("=").append(value.trim());
return sb.toString();
}

/**
* checks whether all required attributes have been specified.
* @throws BuildException if key or value are unassigned
*/
public void validate() {
if (key == null || value == null) {
throw new BuildException("key and value must be specified "
+ "for environment variables.");
}
StringBuffer sb = new StringBuffer(key.trim());
sb.append("=").append(value.trim());
return sb.toString();
}
}



Loading…
Cancel
Save