Browse Source

fix incorrect warning in the junit task when includeAntRuntime="no"

fixed by making the classloader used by checkForkedPath behave like a real forked classpath, thus completely isolated from the launching jvm
master
Nicolas Lalevée Stefan Bodewig 7 years ago
parent
commit
b38bf68f5c
4 changed files with 50 additions and 1 deletions
  1. +3
    -0
      WHATSNEW
  2. +15
    -0
      src/etc/testcases/taskdefs/optional/junit.xml
  3. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  4. +30
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java

+ 3
- 0
WHATSNEW View File

@@ -10,6 +10,9 @@ Fixed bugs:
is 'true'. is 'true'.
Bugzilla Report 60062 Bugzilla Report 60062


* The junit task when used with includeantruntime="no" was incorrectly
printing a warning about multiple versions of ant detected in path

Changes from Ant 1.9.10 TO Ant 1.9.11 Changes from Ant 1.9.10 TO Ant 1.9.11
===================================== =====================================




+ 15
- 0
src/etc/testcases/taskdefs/optional/junit.xml View File

@@ -358,4 +358,19 @@
</junit> </junit>
</target> </target>


<target name="testCheckForkedPath">
<property name="includeantruntime" value="yes" />
<!-- duplicate the Ant classes into a jar -->
<jar destfile="${output}/ant.jar" basedir="${antclasses}" />
<junit fork="yes" haltonerror="true" haltonfailure="true"
showoutput="${showoutput}" includeantruntime="${includeantruntime}">
<test name="org.example.junit.Output" />
<classpath>
<pathelement location="../../../../../build/testcases" />
<pathelement location="${junitjar}" />
<pathelement location="${output}/ant.jar" />
</classpath>
</junit>
</target>

</project> </project>

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

@@ -1395,7 +1395,8 @@ public class JUnitTask extends Task {
loader = loader =
AntClassLoader.newAntClassLoader(null, getProject(), AntClassLoader.newAntClassLoader(null, getProject(),
cmd.createClasspath(getProject()), cmd.createClasspath(getProject()),
true);
false);
loader.setIsolated(true);
final String projectResourceName = final String projectResourceName =
LoaderUtils.classNameToResource(Project.class.getName()); LoaderUtils.classNameToResource(Project.class.getName());
URL previous = null; URL previous = null;


+ 30
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java View File

@@ -577,6 +577,36 @@ public class JUnitTaskTest {
} }
} }


private void setupCheckDuplicateTest() {
final String projectResourceName =
LoaderUtils.classNameToResource(Project.class.getName());
final File antclasses = LoaderUtils.getResourceSource(
Project.class.getClassLoader(), projectResourceName);
final String testResourceName =
LoaderUtils.classNameToResource(junit.framework.Test.class.getName());
final File junitJar = LoaderUtils.getResourceSource(
Project.class.getClassLoader(), testResourceName);
buildRule.getProject().setProperty("antclasses", antclasses.getAbsolutePath());
buildRule.getProject().setProperty("junitjar", junitJar.getAbsolutePath());
}

@Test
public void testCheckDuplicateAntJar() throws Exception {
setupCheckDuplicateTest();
buildRule.executeTarget("testCheckForkedPath");
assertTrue("Expecting the warning about the duplicate ant jar",
buildRule.getLog().contains("WARNING: multiple versions of ant detected in path for junit"));
}

@Test
public void testCheckNonDuplicateAntJar() throws Exception {
setupCheckDuplicateTest();
buildRule.getProject().setProperty("includeantruntime", "no");
buildRule.executeTarget("testCheckForkedPath");
assertFalse("Unexpected warning about the duplicate ant jar",
buildRule.getLog().contains("WARNING: multiple versions of ant detected in path for junit"));
}

private void delete(File f) { private void delete(File f) {
if (f.isDirectory()) { if (f.isDirectory()) {
final File[] clds = f.listFiles(); final File[] clds = f.listFiles();


Loading…
Cancel
Save