Browse Source

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

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@805320 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
818ddcf183
8 changed files with 367 additions and 17 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +4
    -0
      WHATSNEW
  3. +5
    -0
      contributors.xml
  4. +22
    -1
      docs/manual/CoreTasks/rmic.html
  5. +166
    -2
      src/etc/testcases/taskdefs/rmic/rmic.xml
  6. +45
    -13
      src/main/org/apache/tools/ant/taskdefs/Rmic.java
  7. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java
  8. +123
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java

+ 1
- 0
CONTRIBUTORS View File

@@ -183,6 +183,7 @@ Mariusz Nowostawski
Mark Hecker
Mark Salter
Mark R. Diggory
Mark A. Ziesemer
Martijn Kruithof
Martin Landers
Martin Poeschl


+ 4
- 0
WHATSNEW View File

@@ -839,6 +839,10 @@ Other changes:
* 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
=============================================



+ 5
- 0
contributors.xml View File

@@ -756,6 +756,11 @@
<middle>R.</middle>
<last>Diggory</last>
</name>
<name>
<first>Mark</first>
<middle>A.</middle>
<last>Ziesemer</last>
</name>
<name>
<first>Martijn</first>
<last>Kruithof</last>


+ 22
- 1
docs/manual/CoreTasks/rmic.html View File

@@ -79,8 +79,14 @@ please consult miniRMI's documentation to learn how to use it.</p>
</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 @@ please consult miniRMI's documentation to learn how to use it.</p>
<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


+ 166
- 2
src/etc/testcases/taskdefs/rmic/rmic.xml View File

@@ -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>
<target name="testIIOPDest" depends="init">
<dest-rmic compiler="default" iiop="true"/>
<assertFileCreatedInDest file="_RemoteTimestamp_Stub.class"/>
<assertFileCreatedInDest file="_RemoteTimestampImpl_Tie.class"/>
</target>

</project>

+ 45
- 13
src/main/org/apache/tools/ant/taskdefs/Rmic.java View File

@@ -85,6 +85,7 @@ public class Rmic extends MatchingTask {
= "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 @@ public class Rmic extends MatchingTask {
/** 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();

@@ -140,11 +141,41 @@ public class Rmic extends MatchingTask {
this.baseDir = base;
}

/**
* 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 @@ public class Rmic extends MatchingTask {
* 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 @@ public class Rmic extends MatchingTask {
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 @@ public class Rmic extends MatchingTask {
* 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 @@ public class Rmic extends MatchingTask {
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, '.');


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java View File

@@ -200,7 +200,7 @@ public abstract class DefaultRmicAdapter implements RmicAdapter {
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");


+ 123
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java View File

@@ -58,12 +58,27 @@ public class RmicAdvancedTest extends BuildFileTest {
executeTarget("testDefault");
}

/**
* 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
*/
@@ -71,6 +86,13 @@ public class RmicAdvancedTest extends BuildFileTest {
executeTarget("testRmic");
}

/**
* test sun's rmic compiler
*/
public void testRmicDest() throws Exception {
executeTarget("testRmicDest");
}

/**
* test sun's rmic compiler strips
* out -J arguments when not forking
@@ -79,12 +101,28 @@ public class RmicAdvancedTest extends BuildFileTest {
executeTarget("testRmicJArg");
}

/**
* 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
@@ -114,6 +152,13 @@ public class RmicAdvancedTest extends BuildFileTest {
executeTarget("testForkingAntClasspath");
}

/**
* test the forking compiler
*/
public void testForkingAntClasspathDest() throws Exception {
executeTarget("testForkingAntClasspathDest");
}

/**
* test the forking compiler
*/
@@ -121,6 +166,13 @@ public class RmicAdvancedTest extends BuildFileTest {
executeTarget("testAntClasspath");
}

/**
* test the forking compiler
*/
public void testAntClasspathDest() throws Exception {
executeTarget("testAntClasspathDest");
}

/**
* A unit test for JUnit
*/
@@ -201,6 +253,14 @@ public class RmicAdvancedTest extends BuildFileTest {
executeTarget("testVersion11");
}

/**
* 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
*
@@ -210,6 +270,15 @@ public class RmicAdvancedTest extends BuildFileTest {
executeTarget("testVersion12");
}

/**
* test that version 1.2 stubs are good
*
* @throws Exception
*/
public void testVersion12Dest() throws Exception {
executeTarget("testVersion12Dest");
}

/**
* test that version compat stubs are good
*
@@ -219,6 +288,15 @@ public class RmicAdvancedTest extends BuildFileTest {
executeTarget("testVersionCompat");
}

/**
* test that version compat stubs are good
*
* @throws Exception
*/
public void testVersionCompatDest() throws Exception {
executeTarget("testVersionCompatDest");
}

/**
* test that passes -Xnew to sun's rmic.
*
@@ -228,6 +306,15 @@ public class RmicAdvancedTest extends BuildFileTest {
executeTarget("testXnew");
}

/**
* 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.
*
@@ -237,6 +324,15 @@ public class RmicAdvancedTest extends BuildFileTest {
executeTarget("testXnewForked");
}

/**
* 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.
*
@@ -246,6 +342,15 @@ public class RmicAdvancedTest extends BuildFileTest {
executeTarget("testXnewCompiler");
}

/**
* test that runs the new xnew compiler adapter.
*
* @throws Exception
*/
public void testXnewCompilerDest() throws Exception {
executeTarget("testXnewCompilerDest");
}

/**
* test that verifies that IDL compiles.
*
@@ -255,6 +360,15 @@ public class RmicAdvancedTest extends BuildFileTest {
executeTarget("testIDL");
}

/**
* test that verifies that IDL compiles.
*
* @throws Exception
*/
public void testIDLDest() throws Exception {
executeTarget("testIDLDest");
}

/**
* test that verifies that IIOP compiles.
*
@@ -264,6 +378,15 @@ public class RmicAdvancedTest extends BuildFileTest {
executeTarget("testIIOP");
}

/**
* 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


Loading…
Cancel
Save