Author: bodewig Date: Tue Aug 18 08:29:01 2009 New Revision: 805320 URL: http://svn.apache.org/viewvc?rev=805320&view=rev Log: add a destdir attribute to rmic so generated stubs or whatever can be put into a different place. PR 20699. Submitted by Mark A. Ziesemer
Modified: ant/core/trunk/CONTRIBUTORS ant/core/trunk/WHATSNEW ant/core/trunk/contributors.xml ant/core/trunk/docs/manual/CoreTasks/rmic.html ant/core/trunk/src/etc/testcases/taskdefs/rmic/rmic.xml ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Rmic.java ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java Modified: ant/core/trunk/CONTRIBUTORS URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=805320&r1=805319&r2=805320&view=diff ============================================================================== Binary files - no diff available. Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=805320&r1=805319&r2=805320&view=diff ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Tue Aug 18 08:29:01 2009 @@ -839,6 +839,10 @@ * A new islastmodified condition can check the last modified date of resources. + * <rmic> has a new destDir attribute that allows generated files to + be written to a different location than the original classes. + Bugzilla Report 20699. + Changes from Ant 1.7.0 TO Ant 1.7.1 ============================================= Modified: ant/core/trunk/contributors.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=805320&r1=805319&r2=805320&view=diff ============================================================================== --- ant/core/trunk/contributors.xml (original) +++ ant/core/trunk/contributors.xml Tue Aug 18 08:29:01 2009 @@ -757,6 +757,11 @@ <last>Diggory</last> </name> <name> + <first>Mark</first> + <middle>A.</middle> + <last>Ziesemer</last> + </name> + <name> <first>Martijn</first> <last>Kruithof</last> </name> Modified: ant/core/trunk/docs/manual/CoreTasks/rmic.html URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/rmic.html?rev=805320&r1=805319&r2=805320&view=diff ============================================================================== --- ant/core/trunk/docs/manual/CoreTasks/rmic.html (original) +++ ant/core/trunk/docs/manual/CoreTasks/rmic.html Tue Aug 18 08:29:01 2009 @@ -79,8 +79,14 @@ </tr> <tr> <td valign="top">base</td> + <td valign="top">the location to store the compiled files. + Also serves as the parent directory for any non-Fileset includes, etc. + (This functionality has remained unchanged.)</td> + <td valign="top" align="center" rowspan="2"><a href="#footnote-1">*1</a></td> + </tr> + <tr> + <td valign="top">destdir</td> <td valign="top">the location to store the compiled files.</td> - <td valign="top" align="center">Yes</td> </tr> <tr> <td valign="top">classname</td> @@ -219,6 +225,21 @@ <td align="center" valign="top">No</td> </tr> </table> + +<p><a name="footnote-1">*1</a>: +<ul> + <li>Maintaining compatibility, <code>base</code>, when specified by + itself, serves as both the parent directory for any source files + AND the output directory.</li> + <li><code>destdir</code> can be used to specify the output + directory, allowing for <code>base</code> to be used as the parent + directory for any source files.</li> + <li>At least one of either <code>base</code> or <code>destdir</code> + must be specified and exist, or a runtime error will + occur.</li> +</ul> +</p> + <h3>Parameters specified as nested elements</h3> <h4>classpath and extdirs</h4> <p><code>Rmic</code>'s <i>classpath</i> and <i>extdirs</i> attributes are <a Modified: ant/core/trunk/src/etc/testcases/taskdefs/rmic/rmic.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/rmic/rmic.xml?rev=805320&r1=805319&r2=805320&view=diff ============================================================================== --- ant/core/trunk/src/etc/testcases/taskdefs/rmic/rmic.xml (original) +++ ant/core/trunk/src/etc/testcases/taskdefs/rmic/rmic.xml Tue Aug 18 08:29:01 2009 @@ -19,15 +19,18 @@ <property name="rmic.dir" location="." /> <property name="src.dir" location="${rmic.dir}/src"/> - <property name="build.dir" location="${rmic.dir}/build"/> + <property name="build.dir" location="${java.io.tmpdir}/build"/> + <property name="dest.dir" location="${java.io.tmpdir}/dest"/> <target name="teardown"> <delete dir="${build.dir}"/> + <delete dir="${dest.dir}"/> </target> <!-- init builds the java source --> <target name="init" depends="probe-rmic"> <mkdir dir="${build.dir}"/> + <mkdir dir="${dest.dir}"/> <javac destdir="${build.dir}" @@ -50,6 +53,14 @@ /> </presetdef> + <presetdef name="dest-rmic"> + <rmic + base="${build.dir}" + destdir="${dest.dir}" + verify="true" + includes="**/*.class"/> + </presetdef> + <macrodef name="assertFileCreated"> <attribute name="file" /> <sequential> @@ -61,6 +72,17 @@ </sequential> </macrodef> + <macrodef name="assertFileCreatedInDest"> + <attribute name="file" /> + <sequential> + <fail>Not found : ${dest.dir}/@{file} + <condition> + <not><available file="${dest.dir}/@{file}"/></not> + </condition> + </fail> + </sequential> + </macrodef> + <macrodef name="assertFileAbsent"> <attribute name="file" /> <sequential> @@ -72,6 +94,16 @@ </sequential> </macrodef> + <macrodef name="assertFileAbsentInDest"> + <attribute name="file" /> + <sequential> + <fail>Expected to be missing : ${dest.dir}/@{file} + <condition> + <available file="${dest.dir}/@{file}"/> + </condition> + </fail> + </sequential> + </macrodef> <macrodef name="assertStubCompiled"> <sequential> @@ -79,18 +111,36 @@ </sequential> </macrodef> + <macrodef name="assertStubCompiledInDest"> + <sequential> + <assertFileCreatedInDest file="RemoteTimestampImpl_Stub.class" /> + </sequential> + </macrodef> + <macrodef name="assertSkelCompiled"> <sequential> <assertFileCreated file="RemoteTimestampImpl_Skel.class" /> </sequential> </macrodef> + <macrodef name="assertSkelCompiledInDest"> + <sequential> + <assertFileCreatedInDest file="RemoteTimestampImpl_Skel.class" /> + </sequential> + </macrodef> + <macrodef name="assertSkelAbsent"> <sequential> <assertFileAbsent file="RemoteTimestampImpl_Skel.class" /> </sequential> </macrodef> + <macrodef name="assertSkelAbsentInDest"> + <sequential> + <assertFileAbsentInDest file="RemoteTimestampImpl_Skel.class" /> + </sequential> + </macrodef> + <macrodef name="assertBaseCompiled"> <sequential> <assertStubCompiled /> @@ -98,6 +148,12 @@ </sequential> </macrodef> + <macrodef name="assertBaseCompiledInDest"> + <sequential> + <assertStubCompiledInDest /> + <assertSkelCompiledInDest /> + </sequential> + </macrodef> <macrodef name="assertAntStubCompiled"> <sequential> @@ -105,12 +161,24 @@ </sequential> </macrodef> + <macrodef name="assertAntStubCompiledInDest"> + <sequential> + <assertFileCreatedInDest file="AntTimestamp_Stub.class"/> + </sequential> + </macrodef> + <macrodef name="assertAntSkelCompiled"> <sequential> <assertFileCreated file="AntTimestamp_Skel.class"/> </sequential> </macrodef> + <macrodef name="assertAntSkelCompiledInDest"> + <sequential> + <assertFileCreatedInDest file="AntTimestamp_Skel.class"/> + </sequential> + </macrodef> + <macrodef name="assertAntCompiled"> <sequential> <assertAntStubCompiled /> @@ -118,6 +186,13 @@ </sequential> </macrodef> + <macrodef name="assertAntCompiledInDest"> + <sequential> + <assertAntStubCompiledInDest /> + <assertAntSkelCompiledInDest /> + </sequential> + </macrodef> + </target> <target name="probe-rmic"> @@ -143,32 +218,62 @@ <assertBaseCompiled/> </target> + <target name="testDefaultDest" depends="init"> + <dest-rmic compiler="default"/> + <assertBaseCompiledInDest/> + </target> + <target name="testEmpty" depends="init"> <base-rmic compiler=""/> <assertBaseCompiled/> </target> + <target name="testEmptyDest" depends="init"> + <dest-rmic compiler=""/> + <assertBaseCompiledInDest/> + </target> + <target name="testVersion11" depends="init"> <base-rmic compiler="default" stubversion="1.1" /> <assertBaseCompiled/> </target> + <target name="testVersion11Dest" depends="init"> + <dest-rmic compiler="default" stubversion="1.1" /> + <assertBaseCompiledInDest/> + </target> + <target name="testVersion12" depends="init"> <base-rmic compiler="default" stubversion="1.2" /> <assertStubCompiled/> <assertSkelAbsent/> </target> + <target name="testVersion12Dest" depends="init"> + <dest-rmic compiler="default" stubversion="1.2" /> + <assertStubCompiledInDest/> + <assertSkelAbsentInDest/> + </target> + <target name="testVersionCompat" depends="init"> <base-rmic compiler="default" stubversion="compat" /> <assertBaseCompiled/> </target> + <target name="testVersionCompatDest" depends="init"> + <dest-rmic compiler="default" stubversion="compat" /> + <assertBaseCompiledInDest/> + </target> + <target name="testRmic" if="rmic.present" depends="init"> <base-rmic compiler="sun"/> <assertBaseCompiled/> </target> + <target name="testRmicDest" if="rmic.present" depends="init"> + <dest-rmic compiler="sun"/> + <assertBaseCompiledInDest/> + </target> <target name="testRmicJArg" if="rmic.present" depends="init"> <base-rmic compiler="sun"> @@ -177,12 +282,26 @@ <assertBaseCompiled/> </target> + <target name="testRmicJArgDest" if="rmic.present" depends="init"> + <dest-rmic compiler="sun"> + <compilerarg value="-J-mx256m" /> + </dest-rmic> + <assertBaseCompiledInDest/> + </target> + <target name="testKaffe" if="kaffe.present" depends="init"> <base-rmic compiler="kaffe" /> <assertBaseCompiled/> </target> + + <target name="testKaffeDest" if="kaffe.present" depends="init"> + <dest-rmic + compiler="kaffe" + /> + <assertBaseCompiledInDest/> + </target> <!-- weblogic.rmic doesn't work without a global CLASSPATH <target name="testWlrmic" if="wlrmic.present" depends="init"> @@ -266,6 +385,13 @@ <assertAntCompiled/> </target> + <target name="testAntClasspathDest" depends="compileAntTimestamp"> + <dest-rmic + compiler="default" + /> + <assertAntCompiledInDest/> + </target> + <target name="testForkingAntClasspath" if="rmic.present" depends="compileAntTimestamp"> <base-rmic compiler="forking" @@ -273,6 +399,13 @@ <assertAntCompiled /> </target> + <target name="testForkingAntClasspathDest" if="rmic.present" depends="compileAntTimestamp"> + <dest-rmic + compiler="forking" + /> + <assertAntCompiledInDest /> + </target> + <target name="testDefaultBadClass" depends="init"> <rmic-bad-class compiler="default"/> </target> @@ -305,6 +438,13 @@ <assertBaseCompiled/> </target> + <target name="testXnewDest" if="rmic5.present" unless="rmic6.present" depends="init"> + <dest-rmic compiler="sun"> + <compilerarg value="-Xnew"/> + </dest-rmic> + <assertBaseCompiledInDest/> + </target> + <target name="testXnewForked" if="rmic5.present" depends="init"> <base-rmic compiler="forking"> <compilerarg value="-Xnew"/> @@ -312,21 +452,45 @@ <assertBaseCompiled/> </target> + <target name="testXnewForkedDest" if="rmic5.present" depends="init"> + <dest-rmic compiler="forking"> + <compilerarg value="-Xnew"/> + </dest-rmic> + <assertBaseCompiledInDest/> + </target> + <target name="testXnewCompiler" if="rmic5.present" depends="init"> <base-rmic compiler="xnew"> </base-rmic> <assertBaseCompiled/> </target> + <target name="testXnewCompilerDest" if="rmic5.present" depends="init"> + <dest-rmic compiler="xnew"> + </dest-rmic> + <assertBaseCompiledInDest/> + </target> + <target name="testIDL" depends="init"> <base-rmic compiler="default" idl="true"/> <assertFileCreated file="RemoteTimestamp.idl"/> </target> + <target name="testIDLDest" depends="init"> + <dest-rmic compiler="default" idl="true"/> + <assertFileCreatedInDest file="RemoteTimestamp.idl"/> + </target> + <target name="testIIOP" depends="init"> <base-rmic compiler="default" iiop="true"/> <assertFileCreated file="_RemoteTimestamp_Stub.class"/> <assertFileCreated file="_RemoteTimestampImpl_Tie.class"/> </target> -</project> \ No newline at end of file + <target name="testIIOPDest" depends="init"> + <dest-rmic compiler="default" iiop="true"/> + <assertFileCreatedInDest file="_RemoteTimestamp_Stub.class"/> + <assertFileCreatedInDest file="_RemoteTimestampImpl_Tie.class"/> + </target> + +</project> Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Rmic.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Rmic.java?rev=805320&r1=805319&r2=805320&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Rmic.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Rmic.java Tue Aug 18 08:29:01 2009 @@ -85,6 +85,7 @@ = "Rmic failed; see the compiler error output for details."; private File baseDir; + private File destDir; private String classname; private File sourceBase; private String stubVersion; @@ -115,11 +116,11 @@ /** loaded error message */ public static final String ERROR_LOADING_CAUSED_EXCEPTION = ". Loading caused Exception: "; /** base not exists message */ - public static final String ERROR_NO_BASE_EXISTS = "base does not exist: "; + public static final String ERROR_NO_BASE_EXISTS = "base or destdir does not exist: "; /** base not a directory message */ - public static final String ERROR_NOT_A_DIR = "base is not a directory:"; + public static final String ERROR_NOT_A_DIR = "base or destdir is not a directory:"; /** base attribute not set message */ - public static final String ERROR_BASE_NOT_SET = "base attribute must be set!"; + public static final String ERROR_BASE_NOT_SET = "base or destdir attribute must be set!"; private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); @@ -141,10 +142,40 @@ } /** + * Sets the base directory to output the generated files. + * @param destdir the base directory to output the generated files. + * @since Ant 1.8.0 + */ + public void setDestdir(File destdir) { + this.destDir = destdir; + } + + /** + * Gets the base directory to output the generated files. + * @return the base directory to output the generated files. + * @since Ant 1.8.0 + */ + public File getDestdir() { + return this.destDir; + } + + /** + * Gets the base directory to output the generated files, + * favoring destdir if set, otherwise defaulting to basedir. + * @return the actual directory to output to (either destdir or basedir) + * @since Ant 1.8.0 + */ + public File getOutputDir() { + if (getDestdir() != null) { + return getDestdir(); + } + return getBase(); + } + + /** * Gets the base directory to output generated class. * @return the location of the compiled files */ - public File getBase() { return this.baseDir; } @@ -526,14 +557,15 @@ * if there's a problem with baseDir or RMIC */ public void execute() throws BuildException { - if (baseDir == null) { + File outputDir = getOutputDir(); + if (outputDir == null) { throw new BuildException(ERROR_BASE_NOT_SET, getLocation()); } - if (!baseDir.exists()) { - throw new BuildException(ERROR_NO_BASE_EXISTS + baseDir, getLocation()); + if (!outputDir.exists()) { + throw new BuildException(ERROR_NO_BASE_EXISTS + outputDir, getLocation()); } - if (!baseDir.isDirectory()) { - throw new BuildException(ERROR_NOT_A_DIR + baseDir, getLocation()); + if (!outputDir.isDirectory()) { + throw new BuildException(ERROR_NOT_A_DIR + outputDir, getLocation()); } if (verify) { log("Verify has been turned on.", Project.MSG_VERBOSE); @@ -569,7 +601,7 @@ int fileCount = compileList.size(); if (fileCount > 0) { log("RMI Compiling " + fileCount + " class" + (fileCount > 1 ? "es" : "") + " to " - + baseDir, Project.MSG_INFO); + + outputDir, Project.MSG_INFO); // finally, lets execute the compiler!! if (!adapter.execute()) { throw new BuildException(ERROR_RMIC_FAILED, getLocation()); @@ -580,14 +612,14 @@ * base directory and sourcebase are the same, the generated * sources are already in place. */ - if (null != sourceBase && !baseDir.equals(sourceBase) + if (null != sourceBase && !outputDir.equals(sourceBase) && fileCount > 0) { if (idl) { log("Cannot determine sourcefiles in idl mode, ", Project.MSG_WARN); log("sourcebase attribute will be ignored.", Project.MSG_WARN); } else { for (int j = 0; j < fileCount; j++) { - moveGeneratedFile(baseDir, sourceBase, (String) compileList.elementAt(j), + moveGeneratedFile(outputDir, sourceBase, (String) compileList.elementAt(j), adapter); } } @@ -656,7 +688,7 @@ log("no uptodate test as -always option has been specified", Project.MSG_VERBOSE); } else { SourceFileScanner sfs = new SourceFileScanner(this); - newFiles = sfs.restrict(files, baseDir, baseDir, mapper); + newFiles = sfs.restrict(files, baseDir, getOutputDir(), mapper); } for (int i = 0; i < newFiles.length; i++) { String name = newFiles[i].replace(File.separatorChar, '.'); Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java?rev=805320&r1=805319&r2=805320&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java Tue Aug 18 08:29:01 2009 @@ -200,7 +200,7 @@ Path classpath = getCompileClasspath(); cmd.createArgument().setValue("-d"); - cmd.createArgument().setFile(attributes.getBase()); + cmd.createArgument().setFile(attributes.getOutputDir()); if (attributes.getExtdirs() != null) { cmd.createArgument().setValue("-extdirs"); Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java?rev=805320&r1=805319&r2=805320&view=diff ============================================================================== --- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java (original) +++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java Tue Aug 18 08:29:01 2009 @@ -59,11 +59,26 @@ } /** + * verify that "default" binds us to the default compiler + */ + public void testDefaultDest() throws Exception { + executeTarget("testDefaultDest"); + } + + /** * verify that "" binds us to the default compiler */ public void testEmpty() throws Exception { executeTarget("testEmpty"); } + + /** + * verify that "" binds us to the default compiler + */ + public void testEmptyDest() throws Exception { + executeTarget("testEmptyDest"); + } + /** * test sun's rmic compiler */ @@ -72,6 +87,13 @@ } /** + * test sun's rmic compiler + */ + public void testRmicDest() throws Exception { + executeTarget("testRmicDest"); + } + + /** * test sun's rmic compiler strips * out -J arguments when not forking */ @@ -80,11 +102,27 @@ } /** + * test sun's rmic compiler strips + * out -J arguments when not forking + */ + public void testRmicJArgDest() throws Exception { + executeTarget("testRmicJArgDest"); + } + + /** * A unit test for JUnit */ public void testKaffe() throws Exception { executeTarget("testKaffe"); } + + /** + * A unit test for JUnit + */ + public void testKaffeDest() throws Exception { + executeTarget("testKaffeDest"); + } + // WLrmic tests don't work /** * test weblogic @@ -117,11 +155,25 @@ /** * test the forking compiler */ + public void testForkingAntClasspathDest() throws Exception { + executeTarget("testForkingAntClasspathDest"); + } + + /** + * test the forking compiler + */ public void testAntClasspath() throws Exception { executeTarget("testAntClasspath"); } /** + * test the forking compiler + */ + public void testAntClasspathDest() throws Exception { + executeTarget("testAntClasspathDest"); + } + + /** * A unit test for JUnit */ public void testBadName() throws Exception { @@ -202,6 +254,14 @@ } /** + * test that version 1.1 stubs are good + * @throws Exception + */ + public void testVersion11Dest() throws Exception { + executeTarget("testVersion11Dest"); + } + + /** * test that version 1.2 stubs are good * * @throws Exception @@ -211,6 +271,15 @@ } /** + * test that version 1.2 stubs are good + * + * @throws Exception + */ + public void testVersion12Dest() throws Exception { + executeTarget("testVersion12Dest"); + } + + /** * test that version compat stubs are good * * @throws Exception @@ -220,6 +289,15 @@ } /** + * test that version compat stubs are good + * + * @throws Exception + */ + public void testVersionCompatDest() throws Exception { + executeTarget("testVersionCompatDest"); + } + + /** * test that passes -Xnew to sun's rmic. * * @throws Exception @@ -229,6 +307,15 @@ } /** + * test that passes -Xnew to sun's rmic. + * + * @throws Exception + */ + public void testXnewDest() throws Exception { + executeTarget("testXnewDest"); + } + + /** * test that passes -Xnew to sun's rmic running in a different VM. * * @throws Exception @@ -238,6 +325,15 @@ } /** + * test that passes -Xnew to sun's rmic running in a different VM. + * + * @throws Exception + */ + public void testXnewForkedDest() throws Exception { + executeTarget("testXnewForkedDest"); + } + + /** * test that runs the new xnew compiler adapter. * * @throws Exception @@ -247,6 +343,15 @@ } /** + * test that runs the new xnew compiler adapter. + * + * @throws Exception + */ + public void testXnewCompilerDest() throws Exception { + executeTarget("testXnewCompilerDest"); + } + + /** * test that verifies that IDL compiles. * * @throws Exception @@ -256,6 +361,15 @@ } /** + * test that verifies that IDL compiles. + * + * @throws Exception + */ + public void testIDLDest() throws Exception { + executeTarget("testIDLDest"); + } + + /** * test that verifies that IIOP compiles. * * @throws Exception @@ -265,6 +379,15 @@ } /** + * test that verifies that IIOP compiles. + * + * @throws Exception + */ + public void testIIOPDest() throws Exception { + executeTarget("testIIOPDest"); + } + + /** * this little bunny verifies that we can load stuff, and that * a failure to execute is turned into a fault */