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 7 years ago
parent
commit
1026236154
4 changed files with 52 additions and 3 deletions
  1. +3
    -0
      WHATSNEW
  2. +15
    -0
      src/etc/testcases/taskdefs/optional/junit.xml
  3. +4
    -3
      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'.
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.10.2 TO Ant 1.10.3
=====================================



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

@@ -354,4 +354,19 @@
</junit>
</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>

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

@@ -1368,9 +1368,10 @@ public class JUnitTask extends Task {
return;
}
try (AntClassLoader loader =
AntClassLoader.newAntClassLoader(null, getProject(),
cmd.createClasspath(getProject()),
true)) {
AntClassLoader.newAntClassLoader(null, getProject(),
cmd.createClasspath(getProject()),
false)) {
loader.setIsolated(true);
final String projectResourceName =
LoaderUtils.classNameToResource(Project.class.getName());
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) {
if (f.isDirectory()) {
final File[] clds = f.listFiles();


Loading…
Cancel
Save