Browse Source

Better handling of tasks that are wrapped in TaskAdapters - unwrap

InvocationTargetExceptions when they happen

PR: 5830

To test it I've enabled all tests for <condition>.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271429 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
851bf0c5ed
4 changed files with 30 additions and 43 deletions
  1. +9
    -1
      src/main/org/apache/tools/ant/TaskAdapter.java
  2. +6
    -2
      src/main/org/apache/tools/ant/taskdefs/ConditionTask.java
  3. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/condition/FilesMatch.java
  4. +14
    -39
      src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java

+ 9
- 1
src/main/org/apache/tools/ant/TaskAdapter.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -131,6 +131,14 @@ public class TaskAdapter extends Task {
} }
executeM.invoke(proxy, null); executeM.invoke(proxy, null);
return; return;
} catch (java.lang.reflect.InvocationTargetException ie) {
log("Error in " + proxy.getClass(), Project.MSG_ERR);
Throwable t = ie.getTargetException();
if (t instanceof BuildException) {
throw ((BuildException) t);
} else {
throw new BuildException(t);
}
} catch( Exception ex ) { } catch( Exception ex ) {
log("Error in " + proxy.getClass(), Project.MSG_ERR); log("Error in " + proxy.getClass(), Project.MSG_ERR);
throw new BuildException( ex ); throw new BuildException( ex );


+ 6
- 2
src/main/org/apache/tools/ant/taskdefs/ConditionTask.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -73,7 +73,7 @@ import org.apache.tools.ant.taskdefs.condition.ConditionBase;
*/ */
public class ConditionTask extends ConditionBase { public class ConditionTask extends ConditionBase {


private String property;
private String property = null;
private String value = "true"; private String value = "true";


/** /**
@@ -102,6 +102,10 @@ public class ConditionTask extends ConditionBase {
if (countConditions() < 1) { if (countConditions() < 1) {
throw new BuildException("You must nest a condition into <condition>"); throw new BuildException("You must nest a condition into <condition>");
} }
if (property == null) {
throw new BuildException("The property attribute is required.");
}
Condition c = (Condition) getConditions().nextElement(); Condition c = (Condition) getConditions().nextElement();
if (c.eval()) { if (c.eval()) {
getProject().setNewProperty(property, value); getProject().setNewProperty(property, value);


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/condition/FilesMatch.java View File

@@ -110,7 +110,7 @@ public class FilesMatch implements Condition {


//validate //validate
if (file1 == null || file2 == null) { if (file1 == null || file2 == null) {
throw new BuildException("both file1 and file2 are required in fileequals");
throw new BuildException("both file1 and file2 are required in filesmatch");
} }


//#now match the files //#now match the files


+ 14
- 39
src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java View File

@@ -93,24 +93,16 @@ public class ConditionTest extends BuildFileTest {
expectPropertySet("basic","basic"); expectPropertySet("basic","basic");
} }


/**
* @todo have this reject the current error
*/
public void testConditionIncomplete() { public void testConditionIncomplete() {
try {
executeTarget("condition-incomplete");
} catch(Exception e) {
}
expectSpecificBuildException("condition-incomplete",
"property attribute has been omitted",
"The property attribute is required.");
} }
/**
* @todo have this reject the current error
*/
public void testConditionEmpty() { public void testConditionEmpty() {
try {
executeTarget("condition-empty");
} catch(Exception e) {
}
expectSpecificBuildException("condition-empty",
"no conditions",
"You must nest a condition into <condition>");
} }


public void testShortcut() { public void testShortcut() {
@@ -133,14 +125,10 @@ public class ConditionTest extends BuildFileTest {
expectPropertyUnset("negationfalse","negationfalse"); expectPropertyUnset("negationfalse","negationfalse");
} }
/**
* @todo have this reject the current error
*/
public void testNegationIncomplete() { public void testNegationIncomplete() {
try {
executeTarget("negationincomplete");
} catch(Exception e) {
}
expectSpecificBuildException("negationincomplete",
"no conditions in <not>",
"You must nest a condition into <not>");
} }
public void testAnd() { public void testAnd() {
@@ -180,33 +168,20 @@ public class ConditionTest extends BuildFileTest {
} }
/**
* @todo have this reject the current error
*/
public void testFilesmatchIncomplete() { public void testFilesmatchIncomplete() {
try {
executeTarget("filesmatch-incomplete");
} catch(Exception e) {
}
}
expectSpecificBuildException("filesmatch-incomplete",
"Missing file2 attribute",
"both file1 and file2 are required in filesmatch");
}
public void testFilesmatchOddsizes() { public void testFilesmatchOddsizes() {
expectPropertyUnset("filesmatch-oddsizes","filesmatch-oddsizes"); expectPropertyUnset("filesmatch-oddsizes","filesmatch-oddsizes");
} }
/**
* @todo have this reject the current error
*/
public void testFilesmatchExistence() { public void testFilesmatchExistence() {
try {
executeTarget("filesmatch-existence");
} catch(Exception e) {
}
expectPropertyUnset("filesmatch-existence", "filesmatch-existence");
} }


/**
* @todo have this reject the current error
*/
public void testFilesmatchDifferent() { public void testFilesmatchDifferent() {
expectPropertyUnset("filesmatch-different","filesmatch-different"); expectPropertyUnset("filesmatch-different","filesmatch-different");
} }


Loading…
Cancel
Save