From 85f05e8b8d719e03559e6b07e480b6c0812dfd56 Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Thu, 5 Aug 2004 17:13:43 +0000 Subject: [PATCH] more tests; 'default' compiler and "" has a well defined behaviour. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276757 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/CoreTasks/rmic.html | 8 +- src/etc/testcases/taskdefs/rmic/rmic.xml | 102 +++++++++++++++++- .../taskdefs/rmic/src/AntTimestamp.java | 29 +++++ .../org/apache/tools/ant/taskdefs/Rmic.java | 17 +-- .../ant/taskdefs/rmic/ForkingSunRmic.java | 6 ++ .../tools/ant/taskdefs/rmic/KaffeRmic.java | 18 ++-- .../ant/taskdefs/rmic/RmicAdapterFactory.java | 18 +++- .../tools/ant/taskdefs/rmic/SunRmic.java | 5 + .../tools/ant/taskdefs/rmic/WLRmic.java | 5 + .../tools/ant/taskdefs/RmicAdvancedTest.java | 98 ++++++++++++++++- 10 files changed, 281 insertions(+), 25 deletions(-) create mode 100644 src/etc/testcases/taskdefs/rmic/src/AntTimestamp.java diff --git a/docs/manual/CoreTasks/rmic.html b/docs/manual/CoreTasks/rmic.html index 32f67efae..4c837a612 100644 --- a/docs/manual/CoreTasks/rmic.html +++ b/docs/manual/CoreTasks/rmic.html @@ -32,12 +32,18 @@ supports all attributes of <fileset> <patternset> elements.

It is possible to use different compilers. This can be selected with the "build.rmic" property or the compiler -attribute. There are three choices:

+attribute. +Here are the choices:

The miniRMI diff --git a/src/etc/testcases/taskdefs/rmic/rmic.xml b/src/etc/testcases/taskdefs/rmic/rmic.xml index 42bb33416..0c981ce9f 100644 --- a/src/etc/testcases/taskdefs/rmic/rmic.xml +++ b/src/etc/testcases/taskdefs/rmic/rmic.xml @@ -15,7 +15,8 @@ + srcdir="${src.dir}" + includes="Remote*.java"> @@ -24,6 +25,38 @@ verify="true" includes="**/*.class"/> + + + + + + + + + + + Not found : ${file.to.find} + + + + + + + + + + + + + + + + + @@ -31,15 +64,27 @@ - + + + + + + + + + + + - + + + @@ -52,6 +97,7 @@ + @@ -86,4 +132,54 @@ includes="**/*.class"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/etc/testcases/taskdefs/rmic/src/AntTimestamp.java b/src/etc/testcases/taskdefs/rmic/src/AntTimestamp.java new file mode 100644 index 000000000..ccdb0809e --- /dev/null +++ b/src/etc/testcases/taskdefs/rmic/src/AntTimestamp.java @@ -0,0 +1,29 @@ +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.util.Calendar; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.util.DateUtils; + + +/** + * This class imports a dependency on the Ant runtime classes, + * so tests that classpath setup include them + */ +public class AntTimestamp implements RemoteTimestamp { + + + /** + * return the phase of the moon. + * Note the completely different semantics of the other implementation, + * which goes to show why signature is an inadeuqate way of verifying + * how well an interface is implemented. + * + * @return + * @throws RemoteException + */ + public long when() throws RemoteException { + Calendar cal=Calendar.getInstance(); + return DateUtils.getPhaseOfMoon(cal); + } +} diff --git a/src/main/org/apache/tools/ant/taskdefs/Rmic.java b/src/main/org/apache/tools/ant/taskdefs/Rmic.java index 447e35e24..969d5f599 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Rmic.java +++ b/src/main/org/apache/tools/ant/taskdefs/Rmic.java @@ -80,7 +80,7 @@ import org.apache.tools.ant.util.facade.FacadeTaskHelper; public class Rmic extends MatchingTask { - private static final String FAIL_MSG + public static final String ERROR_RMIC_FAILED = "Rmic failed; see the compiler error output for details."; private File baseDir; @@ -116,8 +116,7 @@ public class Rmic extends MatchingTask { public static final String ERROR_BASE_NOT_SET = "base attribute must be set!"; public Rmic() { - String facadeName=KaffeRmic.isAvailable()?"kaffe":"sun"; - facade = new FacadeTaskHelper(facadeName); + facade = new FacadeTaskHelper(RmicAdapterFactory.DEFAULT_COMPILER); } /** @@ -398,7 +397,9 @@ public class Rmic extends MatchingTask { * @since Ant 1.5 */ public void setCompiler(String compiler) { - facade.setImplementation(compiler); + if(compiler.length()>0) { + facade.setImplementation(compiler); + } } /** @@ -481,7 +482,7 @@ public class Rmic extends MatchingTask { // finally, lets execute the compiler!! if (!adapter.execute()) { - throw new BuildException(FAIL_MSG, getLocation()); + throw new BuildException(ERROR_RMIC_FAILED, getLocation()); } } @@ -583,9 +584,9 @@ public class Rmic extends MatchingTask { } for (int i = 0; i < newFiles.length; i++) { - String classname = newFiles[i].replace(File.separatorChar, '.'); - classname = classname.substring(0, classname.lastIndexOf(".class")); - compileList.addElement(classname); + String name = newFiles[i].replace(File.separatorChar, '.'); + name = name.substring(0, name.lastIndexOf(".class")); + compileList.addElement(name); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/rmic/ForkingSunRmic.java b/src/main/org/apache/tools/ant/taskdefs/rmic/ForkingSunRmic.java index 19cb695ec..6f90e1f5f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/rmic/ForkingSunRmic.java +++ b/src/main/org/apache/tools/ant/taskdefs/rmic/ForkingSunRmic.java @@ -41,6 +41,11 @@ import java.io.IOException; */ public class ForkingSunRmic extends DefaultRmicAdapter { + /** + * the name of this adapter for users to select + */ + public static final String COMPILER_NAME = "forking"; + /** * exec by creating a new command * @return @@ -63,6 +68,7 @@ public class ForkingSunRmic extends DefaultRmicAdapter { exe.setAntRun(project); exe.setWorkingDirectory(project.getBaseDir()); exe.setCommandline(args); + exe.execute(); return exe.getExitValue()==0; } catch (IOException exception) { diff --git a/src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java b/src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java index fad6a19e9..f4f28f6e4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java +++ b/src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java @@ -21,7 +21,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; -import org.apache.tools.ant.util.facade.FacadeTaskHelper; import org.apache.tools.ant.types.Commandline; /** @@ -31,6 +30,11 @@ import org.apache.tools.ant.types.Commandline; */ public class KaffeRmic extends DefaultRmicAdapter { public static final String RMIC_CLASSNAME = "kaffe.rmi.rmic.RMIC"; + /** + * the name of this adapter for users to select + */ + public static final String COMPILER_NAME = "kaffe"; + public boolean execute() throws BuildException { getRmic().log("Using Kaffe rmic", Project.MSG_VERBOSE); @@ -51,19 +55,19 @@ public class KaffeRmic extends DefaultRmicAdapter { + "set the environment variable " + "JAVA_HOME or CLASSPATH.", getRmic().getLocation()); + } catch (BuildException ex) { + //rethrow + throw ex; } catch (Exception ex) { - if (ex instanceof BuildException) { - throw (BuildException) ex; - } else { - throw new BuildException("Error starting Kaffe rmic: ", + //wrap + throw new BuildException("Error starting Kaffe rmic: ", ex, getRmic().getLocation()); - } } } /** * test for kaffe being on the system - * @return + * @return true if kaffe is on the current classpath */ public static boolean isAvailable() { try { diff --git a/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapterFactory.java b/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapterFactory.java index 73b6d129b..4e4e27e8c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapterFactory.java +++ b/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapterFactory.java @@ -29,6 +29,7 @@ import org.apache.tools.ant.Task; public class RmicAdapterFactory { public static final String ERROR_UNKNOWN_COMPILER = "Cannot find the compiler or class: "; public static final String ERROR_NOT_RMIC_ADAPTER = "Not an rmic adapter: "; + public static final String DEFAULT_COMPILER = "default"; /** This is a singleton -- can't create instances!! */ private RmicAdapterFactory() { @@ -55,13 +56,22 @@ public class RmicAdapterFactory { */ public static RmicAdapter getRmic(String rmicType, Task task) throws BuildException { - if (rmicType.equalsIgnoreCase("sun")) { + + //handle default specially. + if(DEFAULT_COMPILER.equalsIgnoreCase(rmicType) || rmicType.length()==0) { + String adapter = KaffeRmic.isAvailable() ? + KaffeRmic.COMPILER_NAME + :SunRmic.COMPILER_NAME; + return getRmic(adapter,task); + } + + if (SunRmic.COMPILER_NAME.equalsIgnoreCase(rmicType)) { return new SunRmic(); - } else if (rmicType.equalsIgnoreCase("kaffe")) { + } else if (KaffeRmic.COMPILER_NAME.equalsIgnoreCase(rmicType)) { return new KaffeRmic(); - } else if (rmicType.equalsIgnoreCase("weblogic")) { + } else if (WLRmic.COMPILER_NAME.equalsIgnoreCase(rmicType)) { return new WLRmic(); - } else if (rmicType.equalsIgnoreCase("forking")) { + } else if (ForkingSunRmic.COMPILER_NAME.equalsIgnoreCase(rmicType)) { return new ForkingSunRmic(); } return resolveClassName(rmicType); diff --git a/src/main/org/apache/tools/ant/taskdefs/rmic/SunRmic.java b/src/main/org/apache/tools/ant/taskdefs/rmic/SunRmic.java index 1ed994672..cc6d4a16f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/rmic/SunRmic.java +++ b/src/main/org/apache/tools/ant/taskdefs/rmic/SunRmic.java @@ -38,6 +38,11 @@ public class SunRmic extends DefaultRmicAdapter { */ public static final String RMIC_CLASSNAME = "sun.rmi.rmic.Main"; + /** + * the name of this adapter for users to select + */ + public static final String COMPILER_NAME = "sun"; + /** * name of the executable */ diff --git a/src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java b/src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java index e3f1fc661..3c80c493a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java +++ b/src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java @@ -30,6 +30,11 @@ import org.apache.tools.ant.types.Commandline; */ public class WLRmic extends DefaultRmicAdapter { public static final String WLRMIC_CLASSNAME = "weblogic.rmic"; + /** + * the name of this adapter for users to select + */ + public static final String COMPILER_NAME = "weblogic"; + public static final String ERROR_NO_WLRMIC_ON_CLASSPATH = "Cannot use WebLogic rmic, as it is not " + "available. A common solution is to " + "set the environment variable " diff --git a/src/testcases/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java b/src/testcases/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java index 6ed130f3c..7a368f917 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java @@ -19,7 +19,9 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.BuildFileTest; +import org.apache.tools.ant.BuildException; import org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory; +import org.apache.tools.ant.taskdefs.rmic.DefaultRmicAdapter; /** * Date: 04-Aug-2004 @@ -47,6 +49,19 @@ public class RmicAdvancedTest extends BuildFileTest { executeTarget("teardown"); } + /** + * verify that "default" binds us to the default compiler + */ + public void testDefault() throws Exception { + executeTarget("testDefault"); + } + + /** + * verify that "" binds us to the default compiler + */ + public void testEmpty() throws Exception { + executeTarget("testEmpty"); + } /** * A unit test for JUnit */ @@ -68,12 +83,26 @@ public class RmicAdvancedTest extends BuildFileTest { } /** - * A unit test for JUnit + * test the forking compiler */ - public void testForking() throws Exception { + public void NotestForking() throws Exception { executeTarget("testForking"); } + /** + * test the forking compiler + */ + public void NotestForkingAntClasspath() throws Exception { + executeTarget("testForkingAntClasspath"); + } + + /** + * test the forking compiler + */ + public void testAntClasspath() throws Exception { + executeTarget("testAntClasspath"); + } + /** * A unit test for JUnit */ @@ -91,5 +120,70 @@ public class RmicAdvancedTest extends BuildFileTest { "class not an RMIC adapter", RmicAdapterFactory.ERROR_NOT_RMIC_ADAPTER); } + + + /** + * A unit test for JUnit + */ + public void testDefaultBadClass() throws Exception { + expectBuildExceptionContaining("testDefaultBadClass", + "expected the class to fail", + Rmic.ERROR_RMIC_FAILED); + //dont look for much text here as it is vendor and version dependent + assertLogContaining("unimplemented.class"); + } + + + /** + * A unit test for JUnit + */ + public void testMagicProperty() throws Exception { + expectBuildExceptionContaining("testMagicProperty", + "magic property not working", + RmicAdapterFactory.ERROR_UNKNOWN_COMPILER); + } + + /** + * A unit test for JUnit + */ + public void testMagicPropertyOverridesEmptyString() throws Exception { + expectBuildExceptionContaining("testMagicPropertyOverridesEmptyString", + "magic property not working", + RmicAdapterFactory.ERROR_UNKNOWN_COMPILER); + } + + + /** + * test the forking compiler + */ + public void testMagicPropertyIsEmptyString() throws Exception { + executeTarget("testMagicPropertyIsEmptyString"); + } + + + public void NotestFailingAdapter() throws Exception { + expectBuildExceptionContaining("testFailingAdapter", + "expected failures to propagate", + Rmic.ERROR_RMIC_FAILED); + } + + + /** + * this little bunny verifies that we can load stuff, and that + * a failure to execute is turned into a fault + */ + public static class FailingRmicAdapter extends DefaultRmicAdapter { + public static final String LOG_MESSAGE = "hello from FailingRmicAdapter"; + + /** + * Executes the task. + * + * @return false -always + */ + public boolean execute() throws BuildException { + getRmic().log(LOG_MESSAGE); + return false; + } + } }