I've finally worked out the oddball build and class loading issue that only seems to happen on Windows XP (SP2) since Simon reports that the ant build works fine for him on Linux.

I can report success with "ant clean dist-build-2.1 test" on Sun Java versions:

1.5.0_03
1.5.0_02
1.4.2_08
1.3.1_14

In order achieve this; the new build.xml depends on Ant 1.6.

Version 1.2.2_017 hangs miserably for me though, as it did before.


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@179242 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2005-05-31 17:48:08 +00:00
parent 46fe76f81a
commit 43f7a149e0
5 changed files with 237 additions and 241 deletions

104
build.xml
View File

@ -55,14 +55,7 @@ limitations under the License.
</copy> </copy>
</target> </target>
<target name="compile" depends="static" description="Compile shareable components"> <target name="compile" depends="static" description="Compile shareable components">
<javac srcdir="${source.home}" <javac srcdir="${source.home}" destdir="${build.home}/classes" debug="${compile.debug}" deprecation="${compile.deprecation}" target="${compile.target}" source="${compile.source}" excludes="${compile.excludes}" optimize="${compile.optimize}">
destdir="${build.home}/classes"
debug="${compile.debug}"
deprecation="${compile.deprecation}"
target="${compile.target}"
source="${compile.source}"
excludes="${compile.excludes}"
optimize="${compile.optimize}">
<classpath refid="compile.classpath"/> <classpath refid="compile.classpath"/>
</javac> </javac>
<copy todir="${build.home}/classes" filtering="on"> <copy todir="${build.home}/classes" filtering="on">
@ -70,13 +63,7 @@ limitations under the License.
</copy> </copy>
</target> </target>
<target name="compile.tests" depends="compile" description="Compile unit test cases"> <target name="compile.tests" depends="compile" description="Compile unit test cases">
<javac srcdir="${test.home}" <javac srcdir="${test.home}" destdir="${build.home}/tests" debug="${compile.debug}" deprecation="off" target="${compile.target}" source="${compile.source}" optimize="${compile.optimize}">
destdir="${build.home}/tests"
debug="${compile.debug}"
deprecation="off"
target="${compile.target}"
source="${compile.source}"
optimize="${compile.optimize}">
<classpath refid="test.classpath"/> <classpath refid="test.classpath"/>
</javac> </javac>
<copy todir="${build.home}/tests" filtering="on"> <copy todir="${build.home}/tests" filtering="on">
@ -92,19 +79,7 @@ limitations under the License.
<mkdir dir="${dist.home}"/> <mkdir dir="${dist.home}"/>
<mkdir dir="${dist.home}/docs"/> <mkdir dir="${dist.home}/docs"/>
<mkdir dir="${dist.home}/docs/api"/> <mkdir dir="${dist.home}/docs/api"/>
<javadoc sourcepath="${source.home}" <javadoc sourcepath="${source.home}" destdir="${dist.home}/docs/api" overview="${source.home}/org/apache/commons/lang/overview.html" packagenames="org.apache.commons.*" excludepackagenames="${javadoc.excludepackagenames}" author="true" version="true" doctitle="&lt;h1&gt;${component.title}&lt;/h1&gt;" windowtitle="${component.title} (Version ${component.version})" bottom="Copyright &amp;copy; 2001-${copyright.end} - Apache Software Foundation" use="true" link="${jdk.javadoc}" source="${compile.source}">
destdir="${dist.home}/docs/api"
overview="${source.home}/org/apache/commons/lang/overview.html"
packagenames="org.apache.commons.*"
excludepackagenames="${javadoc.excludepackagenames}"
author="true"
version="true"
doctitle="&lt;h1&gt;${component.title}&lt;/h1&gt;"
windowtitle="${component.title} (Version ${component.version})"
bottom="Copyright &amp;copy; 2001-${copyright.end} - Apache Software Foundation"
use="true"
link="${jdk.javadoc}"
source="${compile.source}">
<classpath refid="compile.classpath"/> <classpath refid="compile.classpath"/>
</javadoc> </javadoc>
</target> </target>
@ -147,82 +122,57 @@ limitations under the License.
</copy> </copy>
</target> </target>
<!-- ========== Unit Test Targets ========================================= --> <!-- ========== Unit Test Targets ========================================= -->
<!-- removed test.text target from the depends list for the 2.1 release. It <!-- removed test.text target from the depends list for the 2.1 release. It
should be reinstated when the text package is included --> should be reinstated when the text package is included -->
<target name="test" depends=" <target name="test" depends="
compile.tests, compile.tests,
test.lang, test.lang,
test.builder, test.builder,
test.enum, test.enum,
test.enums,
test.exception, test.exception,
test.math, test.math,
test.mutable, test.mutable,
test.time" test.time" description="Run all unit test cases">
description="Run all unit test cases">
<echo message="Running tests ..."/> <echo message="Running tests ..."/>
</target> </target>
<target name="test.lang" depends="compile.tests"> <macrodef name="runTestCase">
<echo message="Running lang package tests ..."/> <attribute name="classname"/>
<java classname="${test.runner}" fork="${test.fork}" failonerror="${test.failonerror}"> <sequential>
<arg value="org.apache.commons.lang.LangTestSuite"/> <junit printsummary="true" showoutput="true" fork="${junit.fork}" haltonerror="${test.failonerror}">
<classpath refid="test.classpath"/> <classpath refid="test.classpath"/>
</java> <test name="@{classname}"/>
</junit>
</sequential>
</macrodef>
<target name="test.lang" depends="compile.tests">
<runTestCase classname="org.apache.commons.lang.LangTestSuite"/>
</target> </target>
<target name="test.builder" depends="compile.tests"> <target name="test.builder" depends="compile.tests">
<echo message="Running builder package tests ..."/> <runTestCase classname="org.apache.commons.lang.builder.BuilderTestSuite"/>
<java classname="${test.runner}" fork="${test.fork}" failonerror="${test.failonerror}">
<arg value="org.apache.commons.lang.builder.BuilderTestSuite"/>
<classpath refid="test.classpath"/>
</java>
</target> </target>
<target name="test.enum" depends="compile.tests"> <target name="test.enum" depends="compile.tests">
<echo message="Running enum package tests ..."/> <runTestCase classname="org.apache.commons.lang.enum.EnumTestSuite"/>
<java classname="${test.runner}" fork="${test.fork}" failonerror="${test.failonerror}"> </target>
<arg value="org.apache.commons.lang.enums.EnumTestSuite"/> <target name="test.enums" depends="compile.tests">
<arg value="org.apache.commons.lang.enum.EnumTestSuite"/> <runTestCase classname="org.apache.commons.lang.enums.EnumTestSuite"/>
<classpath refid="test.classpath"/>
</java>
</target> </target>
<target name="test.exception" depends="compile.tests"> <target name="test.exception" depends="compile.tests">
<echo message="Running exception package tests ..."/> <runTestCase classname="org.apache.commons.lang.exception.ExceptionTestSuite"/>
<java classname="${test.runner}" fork="${test.fork}" failonerror="${test.failonerror}">
<arg value="org.apache.commons.lang.exception.ExceptionTestSuite"/>
<classpath refid="test.classpath"/>
</java>
</target> </target>
<target name="test.math" depends="compile.tests"> <target name="test.math" depends="compile.tests">
<echo message="Running math package tests ..."/> <runTestCase classname="org.apache.commons.lang.math.MathTestSuite"/>
<java classname="${test.runner}" fork="${test.fork}" failonerror="${test.failonerror}">
<arg value="org.apache.commons.lang.math.MathTestSuite"/>
<classpath refid="test.classpath"/>
</java>
</target> </target>
<target name="test.mutable" depends="compile.tests"> <target name="test.mutable" depends="compile.tests">
<echo message="Running mutable package tests ..."/> <runTestCase classname="org.apache.commons.lang.mutable.MutableTestSuite"/>
<java classname="${test.runner}" fork="${test.fork}" failonerror="${test.failonerror}">
<arg value="org.apache.commons.lang.mutable.MutableTestSuite"/>
<classpath refid="test.classpath"/>
</java>
</target> </target>
<target name="test.text" depends="compile.tests"> <target name="test.text" depends="compile.tests">
<echo message="Running text package tests ..."/> <runTestCase classname="org.apache.commons.lang.text.TextTestSuite"/>
<java classname="${test.runner}" fork="${test.fork}" failonerror="${test.failonerror}">
<arg value="org.apache.commons.lang.text.TextTestSuite"/>
<classpath refid="test.classpath"/>
</java>
</target> </target>
<target name="test.time" depends="compile.tests"> <target name="test.time" depends="compile.tests">
<echo message="Running time package tests ..."/> <runTestCase classname="org.apache.commons.lang.time.TimeTestSuite"/>
<java classname="${test.runner}" fork="${test.fork}" failonerror="${test.failonerror}">
<arg value="org.apache.commons.lang.time.TimeTestSuite"/>
<classpath refid="test.classpath"/>
</java>
</target> </target>
<target name="test.util" depends="compile.tests"> <target name="test.util" depends="compile.tests">
<echo message="Running util package tests ..."/> <runTestCase classname="org.apache.commons.lang.util.UtilTestSuite"/>
<java classname="${test.runner}" fork="${test.fork}" failonerror="${test.failonerror}">
<arg value="org.apache.commons.lang.util.UtilTestSuite"/>
<classpath refid="test.classpath"/>
</java>
</target> </target>
</project> </project>

View File

@ -19,6 +19,9 @@
# The pathname of the "junit.jar" JAR file # The pathname of the "junit.jar" JAR file
junit.jar = ${junit.home}/junit-3.8.1.jar junit.jar = ${junit.home}/junit-3.8.1.jar
# Whether or not to fork tests
junit.fork = true
# The name of this component # The name of this component
component.name = commons-lang component.name = commons-lang
@ -52,9 +55,6 @@ source.home = src/java
# The base directory for unit test sources # The base directory for unit test sources
test.home = src/test test.home = src/test
# Whether or not to fork tests
test.fork = true
# Should Java compilations set the 'debug' compiler option? # Should Java compilations set the 'debug' compiler option?
compile.debug = true compile.debug = true

View File

@ -399,11 +399,18 @@ public void testPrimitivesToWrappers() {
* @return the resulting class loader * @return the resulting class loader
*/ */
public static ClassLoader newSystemClassLoader() throws SecurityException, IllegalArgumentException { public static ClassLoader newSystemClassLoader() throws SecurityException, IllegalArgumentException {
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
if (!(scl instanceof URLClassLoader)) { ClassLoader myClassLoader = ClassUtilsTest.class.getClassLoader();
if (!(myClassLoader instanceof URLClassLoader)) {
fail("Need a better test set up."); fail("Need a better test set up.");
} }
URLClassLoader urlScl = (URLClassLoader) scl; if (!(systemClassLoader instanceof URLClassLoader)) {
fail("Need a better test set up.");
}
if (!myClassLoader.equals(systemClassLoader)) {
fail("Need a better test set up?");
}
URLClassLoader urlScl = (URLClassLoader) myClassLoader;
return URLClassLoader.newInstance(urlScl.getURLs(), null); return URLClassLoader.newInstance(urlScl.getURLs(), null);
} }

View File

@ -13,10 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.lang.enum; package org.apache.commons.lang.enum;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -27,6 +30,7 @@
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.apache.commons.lang.ClassUtilsTest; import org.apache.commons.lang.ClassUtilsTest;
import org.apache.commons.lang.SerializationUtils; import org.apache.commons.lang.SerializationUtils;
@ -40,6 +44,8 @@
public final class EnumTest extends TestCase { public final class EnumTest extends TestCase {
private static final String ENUM_CLASS_NAME = "org.apache.commons.lang.enum.ColorEnum";
public EnumTest(String name) { public EnumTest(String name) {
super(name); super(name);
} }
@ -66,11 +72,13 @@ public void testCompareTo() {
try { try {
ColorEnum.RED.compareTo(null); ColorEnum.RED.compareTo(null);
fail(); fail();
} catch (NullPointerException ex) {} } catch (NullPointerException ex) {
}
try { try {
ColorEnum.RED.compareTo(new Object()); ColorEnum.RED.compareTo(new Object());
fail(); fail();
} catch (ClassCastException ex) {} } catch (ClassCastException ex) {
}
} }
public void testEquals() { public void testEquals() {
@ -104,8 +112,7 @@ public void testList() {
assertNotNull(list); assertNotNull(list);
assertEquals( list.size(), assertEquals(list.size(), ColorEnum.getEnumMap().keySet().size());
ColorEnum.getEnumMap().keySet().size());
Iterator it = list.iterator(); Iterator it = list.iterator();
assertSame(ColorEnum.RED, it.next()); assertSame(ColorEnum.RED, it.next());
@ -123,8 +130,7 @@ public void testMap() {
assertSame(ColorEnum.RED, map.get("Red")); assertSame(ColorEnum.RED, map.get("Red"));
assertSame(ColorEnum.GREEN, map.get("Green")); assertSame(ColorEnum.GREEN, map.get("Green"));
assertSame(ColorEnum.BLUE, map.get("Blue")); assertSame(ColorEnum.BLUE, map.get("Blue"));
assertEquals( map.keySet().size(), assertEquals(map.keySet().size(), ColorEnum.getEnumList().size());
ColorEnum.getEnumList().size());
} }
public void testGet() { public void testGet() {
@ -256,7 +262,7 @@ public void testOperationCalculation() {
assertEquals(-1, OperationEnum.MINUS.eval(1, 2)); assertEquals(-1, OperationEnum.MINUS.eval(1, 2));
} }
//----------------------------------------------------------------------- // -----------------------------------------------------------------------
public void testExtended1Get() { public void testExtended1Get() {
assertSame(Extended1Enum.ALPHA, Extended1Enum.getEnum("Alpha")); assertSame(Extended1Enum.ALPHA, Extended1Enum.getEnum("Alpha"));
assertSame(Extended1Enum.BETA, Extended1Enum.getEnum("Beta")); assertSame(Extended1Enum.BETA, Extended1Enum.getEnum("Beta"));
@ -381,7 +387,7 @@ public void testExtended3Map() {
assertSame(Extended3Enum.DELTA, map.get("Delta")); assertSame(Extended3Enum.DELTA, map.get("Delta"));
} }
//----------------------------------------------------------------------- // -----------------------------------------------------------------------
public void testNested() { public void testNested() {
List list = new ArrayList(Nest.ColorEnum.getEnumList()); List list = new ArrayList(Nest.ColorEnum.getEnumList());
assertEquals(3, list.size()); // all is well assertEquals(3, list.size()); // all is well
@ -481,7 +487,21 @@ Object getColorEnum(ClassLoader classLoader, String color) throws ClassNotFoundE
// set up: // set up:
assertNotNull(classLoader); assertNotNull(classLoader);
assertFalse(classLoader.equals(ColorEnum.class.getClassLoader())); assertFalse(classLoader.equals(ColorEnum.class.getClassLoader()));
Class otherColorEnumClass = classLoader.loadClass("org.apache.commons.lang.enum.ColorEnum"); Class otherColorEnumClass = null;
try {
otherColorEnumClass = classLoader.loadClass(ENUM_CLASS_NAME);
} catch (ClassNotFoundException e) {
// Dump some information to help debug class loader issues under different JREs, Ant, Eclipse.
System.err.println("Could not load " + ENUM_CLASS_NAME + " from the class loader " + classLoader);
URLClassLoader urlCl = (URLClassLoader) classLoader;
URL[] urls = urlCl.getURLs();
System.err.println("Class loader has " + urls.length + " URLs:");
for (int i = 0; i < urls.length; i++) {
System.err.println("URL[" + i + "] = " + urls[i]);
}
e.printStackTrace();
throw e;
}
assertNotNull(otherColorEnumClass); assertNotNull(otherColorEnumClass);
assertNotNull(otherColorEnumClass.getClassLoader()); assertNotNull(otherColorEnumClass.getClassLoader());
assertTrue(classLoader.equals(otherColorEnumClass.getClassLoader())); assertTrue(classLoader.equals(otherColorEnumClass.getClassLoader()));

View File

@ -17,6 +17,8 @@
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -29,6 +31,7 @@
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.apache.commons.lang.ClassUtilsTest; import org.apache.commons.lang.ClassUtilsTest;
import org.apache.commons.lang.SerializationUtils; import org.apache.commons.lang.SerializationUtils;
import org.apache.commons.lang.enum.ColorEnum;
/** /**
* Test cases for the {@link Enum} class. * Test cases for the {@link Enum} class.
@ -40,6 +43,8 @@
public final class EnumTest extends TestCase { public final class EnumTest extends TestCase {
private static final String ENUMS_CLASS_NAME = "org.apache.commons.lang.enums.ColorEnum";
public EnumTest(String name) { public EnumTest(String name) {
super(name); super(name);
} }
@ -481,7 +486,21 @@ Object getColorEnum(ClassLoader classLoader, String color) throws ClassNotFoundE
// set up: // set up:
assertNotNull(classLoader); assertNotNull(classLoader);
assertFalse(classLoader.equals(ColorEnum.class.getClassLoader())); assertFalse(classLoader.equals(ColorEnum.class.getClassLoader()));
Class otherColorEnumClass = classLoader.loadClass("org.apache.commons.lang.enums.ColorEnum"); Class otherColorEnumClass = null;
try {
otherColorEnumClass = classLoader.loadClass(ENUMS_CLASS_NAME);
} catch (ClassNotFoundException e) {
// Dump some information to help debug class loader issues under different JREs, Ant, Eclipse.
System.err.println("Could not load " + ENUMS_CLASS_NAME + " from the class loader " + classLoader);
URLClassLoader urlCl = (URLClassLoader) classLoader;
URL[] urls = urlCl.getURLs();
System.err.println("Class loader has " + urls.length + " URLs:");
for (int i = 0; i < urls.length; i++) {
System.err.println("URL[" + i + "] = " + urls[i]);
}
e.printStackTrace();
throw e;
}
assertNotNull(otherColorEnumClass); assertNotNull(otherColorEnumClass);
assertNotNull(otherColorEnumClass.getClassLoader()); assertNotNull(otherColorEnumClass.getClassLoader());
assertTrue(classLoader.equals(otherColorEnumClass.getClassLoader())); assertTrue(classLoader.equals(otherColorEnumClass.getClassLoader()));