From d516870b6a5d7189ddb0fe311e45aef8bd676c1f Mon Sep 17 00:00:00 2001 From: "Jesse N. Glick" Date: Mon, 5 Mar 2012 23:05:21 +0000 Subject: [PATCH] Random failures in AntClassLoaderTest traceable to different jobs overwriting the same test.jar. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1297271 13f79535-47bb-0310-9956-ffa450edef68 --- src/etc/testcases/core/antclassloader.xml | 7 ++++--- .../apache/tools/ant/AntClassLoaderTest.java | 20 +++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/etc/testcases/core/antclassloader.xml b/src/etc/testcases/core/antclassloader.xml index 541f70152..b6f278edd 100644 --- a/src/etc/testcases/core/antclassloader.xml +++ b/src/etc/testcases/core/antclassloader.xml @@ -61,15 +61,16 @@ package org.example; public class Foo {} ]]> - + destdir="${tmp.dir.nonascii}" source="1.4"/> + + + storepass="apacheant" jar="${test.jar}"/> diff --git a/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java b/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java index 2465eea1a..32503ac21 100644 --- a/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java +++ b/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java @@ -20,7 +20,9 @@ package org.apache.tools.ant; import java.io.File; import java.io.PrintStream; +import java.net.URL; import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util.FileUtils; /** * Test case for ant class loader @@ -107,8 +109,7 @@ public class AntClassLoaderTest extends BuildFileTest { public void testGetPackage() throws Exception { executeTarget("prepareGetPackageTest"); Path myPath = new Path(getProject()); - myPath.setLocation(new File(getProject().getProperty("tmp.dir") - + "/test.jar")); + myPath.setLocation(new File(getProject().getProperty("test.jar"))); getProject().setUserProperty("build.sysclasspath","ignore"); loader = getProject().createClassLoader(myPath); assertNotNull("should find class", loader.findClass("org.example.Foo")); @@ -119,21 +120,20 @@ public class AntClassLoaderTest extends BuildFileTest { public void testCodeSource() throws Exception { executeTarget("prepareGetPackageTest"); Path myPath = new Path(getProject()); - myPath.setLocation(new File(getProject().getProperty("tmp.dir") - + "/test.jar")); + File testJar = new File(getProject().getProperty("test.jar")); + myPath.setLocation(testJar); getProject().setUserProperty("build.sysclasspath","ignore"); loader = getProject().createClassLoader(myPath); Class foo = loader.findClass("org.example.Foo"); - String codeSourceLocation = - foo.getProtectionDomain().getCodeSource().getLocation().toString(); - assertTrue(codeSourceLocation + " should point to test.jar", - codeSourceLocation.endsWith("test.jar")); + URL codeSourceLocation = + foo.getProtectionDomain().getCodeSource().getLocation(); + assertEquals(codeSourceLocation + " should point to test.jar", + FileUtils.getFileUtils().getFileURL(testJar), codeSourceLocation); } public void testSignedJar() throws Exception { executeTarget("signTestJar"); - File jar = new File(getProject().getProperty("tmp.dir") - + "/test.jar"); + File jar = new File(getProject().getProperty("test.jar")); Path myPath = new Path(getProject()); myPath.setLocation(jar);