Browse Source

JDK 1.1 doesn't seem to grok spaces in the keys of a properties file,

no matter which version of escapes I have tried.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272554 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
73c26feb56
4 changed files with 63 additions and 13 deletions
  1. +7
    -0
      src/etc/testcases/taskdefs/input.properties
  2. +26
    -0
      src/etc/testcases/taskdefs/input.xml
  3. +4
    -3
      src/main/org/apache/tools/ant/input/PropertyFileInputHandler.java
  4. +26
    -10
      src/testcases/org/apache/tools/ant/taskdefs/InputTest.java

+ 7
- 0
src/etc/testcases/taskdefs/input.properties View File

@@ -2,3 +2,10 @@ Press\ Return\ key\ to\ continue...=test
All\ data\ is\ going\ to\ be\ deleted\ from\ DB\ continue?=test
All\ data\ is\ going\ to\ be\ deleted\ from\ db\ continue\ (y/n)?=y
Please\ enter\ db-username\:=scott
#
# JDK 1.1 doesn't seem to handle blanks in the property key
#
Press_Return_key_to_continue...=test
All_data_is_going_to_be_deleted_from_DB_continue?=test
All_data_is_going_to_be_deleted_from_db_continue_(y/n)?=y
Please_enter_db_username=scott

+ 26
- 0
src/etc/testcases/taskdefs/input.xml View File

@@ -28,4 +28,30 @@
/>
</target>

<target name="test1.1">
<input>Press_Return_key_to_continue...</input>
</target>

<target name="test2.1">
<input message="Press_Return_key_to_continue..." />
</target>

<target name="test3.1">
<input message="All_data_is_going_to_be_deleted_from_DB_continue?"
validargs="y,n"
/>
</target>

<target name="test5.1">
<input message="All_data_is_going_to_be_deleted_from_db_continue_(y/n)?"
validargs="y,n"
/>
</target>

<target name="test6.1">
<input message="Please_enter_db_username"
addproperty="db.user"
/>
</target>

</project>

+ 4
- 3
src/main/org/apache/tools/ant/input/PropertyFileInputHandler.java View File

@@ -90,15 +90,16 @@ public class PropertyFileInputHandler implements InputHandler {
*/
public void handleInput(InputRequest request) throws BuildException {
readProps();
Object o = props.get(request.getPrompt());
if (o == null) {
throw new BuildException("Unable to find input for "
+ request.getPrompt());
throw new BuildException("Unable to find input for \'"
+ request.getPrompt()+"\'");
}
request.setInput(o.toString());
if (!request.isInputValid()) {
throw new BuildException("Found invalid input " + o
+ " for " + request.getPrompt());
+ " for \'" + request.getPrompt() + "\'");
}
}



+ 26
- 10
src/testcases/org/apache/tools/ant/taskdefs/InputTest.java View File

@@ -56,6 +56,7 @@ package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.input.PropertyFileInputHandler;
import org.apache.tools.ant.util.JavaEnvUtils;

/**
* @author Ulrich Schmidt <usch@usch.net>
@@ -63,40 +64,55 @@ import org.apache.tools.ant.input.PropertyFileInputHandler;
*/
public class InputTest extends BuildFileTest {

private String targetPostfix = "";

public InputTest(String name) {
super(name);
if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
targetPostfix = ".1";
}
}

public void setUp() {
configureProject("src/etc/testcases/taskdefs/input.xml");
System.getProperties()
.put(PropertyFileInputHandler.FILE_NAME_KEY,
"src/etc/testcases/taskdefs/input.properties");
configureProject("src/etc/testcases/taskdefs/input.xml");
getProject().resolveFile("input.properties")
.getAbsolutePath());
getProject().setInputHandler(new PropertyFileInputHandler());
}

public void test1() {
executeTarget("test1");
executeTarget("test1" + targetPostfix);
}

public void test2() {
executeTarget("test1");
executeTarget("test2" + targetPostfix);
}

public void test3() {
expectSpecificBuildException("test3", "invalid input",
"Found invalid input test for All data is"
+ " going to be deleted from DB"
+ " continue?");
expectSpecificBuildException("test3" + targetPostfix, "invalid input",
"Found invalid input test for \'"
+ getKey("All data is"
+ " going to be deleted from DB"
+ " continue?")
+ "\'");
}

public void test5() {
executeTarget("test5");
executeTarget("test5" + targetPostfix);
}

public void test6() {
executeTarget("test6");
executeTarget("test6" + targetPostfix);
assertEquals("scott", project.getProperty("db.user"));
}

private String getKey(String key) {
if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
key = key.replace(' ', '_');
}
return key;
}

}

Loading…
Cancel
Save