diff -ur apache-ant-1.6.5/docs/manual/CoreTasks/rmic.html apache-ant-1.6.5-patch/docs/manual/CoreTasks/rmic.html --- apache-ant-1.6.5/docs/manual/CoreTasks/rmic.html 2005-06-02 15:19:46.000000000 -0500 +++ apache-ant-1.6.5-patch/docs/manual/CoreTasks/rmic.html 2005-08-20 00:14:57.612965000 -0500 @@ -53,8 +53,14 @@ base + the location to store the compiled files. + Also serves as the parent directory for any non-Fileset includes, etc. + (This functionality has remained unchanged.) + *1 + + + destdir the location to store the compiled files. - Yes classname @@ -163,6 +169,12 @@ No + sourcesOnClasspath + whether source folders are automatically included in the + compile classpath; defaults to yes. + No + + extdirs location of installed extensions. No @@ -178,7 +190,25 @@ No + +

*1:

+

Parameters specified as nested elements

+ +

fileset

+

The rmic task supports any number of nested <fileset> elements to specify +the files to be rmic'd. Generated files will be saved to destdir if +specified, or it will attempt to default to base. (base +does not serve as a parent directory to any fileset elements.)

+

classpath and extdirs

Rmic's classpath and extdirs attributes are PATH like structure and can also be set via a nested @@ -225,15 +255,29 @@

Examples

+
  <rmic classname="com.xyz.FooBar" base="${build}/classes"/>

runs the rmic compiler for the class com.xyz.FooBar. The compiled files will be stored in the directory ${build}/classes.

+
  <rmic base="${build}/classes" includes="**/Remote*.class"/>

runs the rmic compiler for all classes with .class files below ${build}/classes whose classname starts with Remote. The compiled files will be stored in the directory ${build}/classes.

+
  <rmic destdir="bin/Client" includeAntRuntime="false" verify="true">
+    <fileset dir="bin/Server">
+      <include name="**/*.class"/>
+    </fileset>
+    <classpath>
+      <pathelement path="bin/Common"/>
+    </classpath>
+  </rmic>
+

runs the rmic compiler for all classes below bin/Common and are +verified to extend java.rmi.remote. The generated files will be stored in the +directory bin/Client. The classpath used by rmic will contain +bin/Common and bin/Server.


Copyright © 2000-2004 The Apache Software Foundation. All rights Reserved.

diff -ur apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/Rmic.java apache-ant-1.6.5-patch/src/main/org/apache/tools/ant/taskdefs/Rmic.java --- apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/Rmic.java 2005-06-02 15:19:58.000000000 -0500 +++ apache-ant-1.6.5-patch/src/main/org/apache/tools/ant/taskdefs/Rmic.java 2005-08-20 00:07:50.303865800 -0500 @@ -20,12 +20,14 @@ import java.io.File; import java.io.IOException; import java.rmi.Remote; +import java.util.Iterator; import java.util.Vector; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.rmic.RmicAdapter; import org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory; +import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.FilterSetCollection; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; @@ -83,6 +85,9 @@ = "Rmic failed; see the compiler error output for details."; private File baseDir; + private File destDir; + private Vector filesets = new Vector(); + private String classname; private File sourceBase; private String stubVersion; @@ -98,6 +103,7 @@ private boolean debug = false; private boolean includeAntRuntime = true; private boolean includeJavaRuntime = false; + private boolean sourcesOnClasspath = true; private Vector compileList = new Vector(); @@ -137,6 +143,38 @@ } /** + * Sets the base directory to output the generated files. + * @param destdir the base directory to output the generated files. + */ + 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. + */ + public File getDestdir() { + return this.destDir; + } + + /** + * Gets the base directory to output the generated files, + * favoring destdir if set, otherwise defaulting to basedir. + */ + public File getOutputDir(){ + if (getDestdir() != null) return getDestdir(); + return getBase(); + } + + /** + * Adds a set of files to generate stubs for. + */ + public void addFileset(FileSet set) { + filesets.addElement(set); + } + + /** * Sets the class to run rmic against; * optional * @param classname the name of the class for rmic to create code for @@ -395,6 +433,24 @@ } /** + * Sets whether source folders are automatically included in the compile + * classpath; optional, defaults to false + * @param include true to include source folders + */ + public void setSourcesOnClasspath(boolean include) { + sourcesOnClasspath = include; + } + + /** + * Sets whether source folders are automatically included in the compile + * classpath + * @param true if source folders are automatically included + */ + public boolean getSourcesOnClasspath() { + return sourcesOnClasspath; + } + + /** * Sets the extension directories that will be used during the * compilation; optional. * @param extDirs the extension directories to be used @@ -484,17 +540,32 @@ * class and getting to do the work */ public void execute() throws BuildException { - if (baseDir == null) { - throw new BuildException("base attribute must be set!", getLocation()); - } - if (!baseDir.exists()) { - throw new BuildException("base does not exist!", getLocation()); + if(compileList.size() > 0){ + compileList.removeAllElements(); } + File outputDir = getOutputDir(); + if (outputDir == null) { + throw new BuildException("base or destdir attribute must be set!", getLocation()); + } + if (!outputDir.exists() || (baseDir != null && !baseDir.exists()) ) { + throw new BuildException("base or destdir location does not exist!", getLocation()); + } if (verify) { log("Verify has been turned on.", Project.MSG_VERBOSE); } + if (getBase() != null) { + FileSet implicitFs = getImplicitFileSet(); + implicitFs.setDir(getBase()); + filesets.add(implicitFs); + } + + // Must be performed before the loader's classpath is set so any + // classpaths can be used by isValidRmiRemote() (which occurs deep + // within populateFilesToProcess(...). + processSourcesOnClasspath(); + RmicAdapter adapter = RmicAdapterFactory.getRmic(getCompiler(), this); // now we need to populate the compiler adapter @@ -503,26 +574,12 @@ Path classpath = adapter.getClasspath(); loader = getProject().createClassLoader(classpath); - try { - // scan base dirs to build up compile lists only if a - // specific classname is not given - if (classname == null) { - DirectoryScanner ds = this.getDirectoryScanner(baseDir); - String[] files = ds.getIncludedFiles(); - scanDir(baseDir, files, adapter.getMapper()); - } else { - // otherwise perform a timestamp comparison - at least - scanDir(baseDir, - new String[] {classname.replace('.', - File.separatorChar) - + ".class"}, - adapter.getMapper()); - } + populateFilesToProcess(adapter.getMapper()); int fileCount = compileList.size(); if (fileCount > 0) { log("RMI Compiling " + fileCount - + " class" + (fileCount > 1 ? "es" : "") + " to " + baseDir, + + " class" + (fileCount > 1 ? "es" : "") + " to " + outputDir, Project.MSG_INFO); // finally, lets execute the compiler!! @@ -536,7 +593,7 @@ * 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, ", @@ -545,14 +602,48 @@ Project.MSG_WARN); } else { for (int j = 0; j < fileCount; j++) { - moveGeneratedFile(baseDir, sourceBase, + moveGeneratedFile(outputDir, sourceBase, (String) compileList.elementAt(j), adapter); } } } - } finally { - compileList.removeAllElements(); + } + + protected void processSourcesOnClasspath() { + // Moved from DefaultRmicAdapter, so that multiple + // locations can be added. + if(compileClasspath == null){ + compileClasspath = new Path(getProject()); + } + + if (getSourcesOnClasspath()) { + for (Iterator iter = filesets.iterator(); iter.hasNext();) { + FileSet fs = (FileSet) iter.next(); + File fsBaseDir = fs.getDir(getProject()); + compileClasspath.setLocation(fsBaseDir); + } + } + } + + protected void populateFilesToProcess (FileNameMapper mapper) { + for (Iterator iter = filesets.iterator(); iter.hasNext();) { + FileSet fs = (FileSet) iter.next(); + File fsBaseDir = fs.getDir(getProject()); + String[] files; + + // scan base dirs to build up compile lists only if a + // specific classname is not given + if (classname == null) { + DirectoryScanner ds = fs.getDirectoryScanner(getProject()); + files = ds.getIncludedFiles(); + } else { + // otherwise perform a timestamp comparison - at least + files = new String[] {classname.replace('.', + File.separatorChar) + ".class"}; + } + + scanDir(fsBaseDir, files, mapper); } } @@ -628,7 +719,7 @@ 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++) { diff -ur apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java apache-ant-1.6.5-patch/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java --- apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java 2005-06-02 15:20:06.000000000 -0500 +++ apache-ant-1.6.5-patch/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java 2005-08-20 00:08:01.585260200 -0500 @@ -96,9 +96,6 @@ */ protected Path getCompileClasspath() { Path classpath = new Path(attributes.getProject()); - // add dest dir to classpath so that previously compiled and - // untouched classes are on classpath - classpath.setLocation(attributes.getBase()); // Combine the build classpath with the system classpath, in an // order determined by the value of build.sysclasspath @@ -144,7 +141,7 @@ Path classpath = getCompileClasspath(); cmd.createArgument().setValue("-d"); - cmd.createArgument().setFile(attributes.getBase()); + cmd.createArgument().setFile(attributes.getOutputDir()); if (attributes.getExtdirs() != null) { if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) { @@ -293,7 +290,7 @@ if (!attributes.getIiop() && !attributes.getIdl()) { // JRMP with simple naming convention - if ("1.2".equals(attributes.getStubVersion())) { + if (isJRMP12Plus()) { target = new String[] { base + getStubClassSuffix() + ".class" }; @@ -371,5 +368,22 @@ } return target; } + + protected boolean isJRMP12Plus() { + // Find if the user specified a version. + if(attributes.getStubVersion() != null) { + if ("1.2".equals(attributes.getStubVersion())){ + return true; + }else{ + return false; + } + }else{ + // Set the default for the current JRE. + if (JavaEnvUtils.compareJavaVersion(JavaEnvUtils.JAVA_1_5) >= 0) { + return true; + } + } + return false; + } } } diff -ur apache-ant-1.6.5/src/main/org/apache/tools/ant/util/JavaEnvUtils.java apache-ant-1.6.5-patch/src/main/org/apache/tools/ant/util/JavaEnvUtils.java --- apache-ant-1.6.5/src/main/org/apache/tools/ant/util/JavaEnvUtils.java 2005-06-02 15:20:08.000000000 -0500 +++ apache-ant-1.6.5-patch/src/main/org/apache/tools/ant/util/JavaEnvUtils.java 2005-08-20 00:08:27.398090600 -0500 @@ -63,6 +63,9 @@ /** Version constant for Java 1.5 */ public static final String JAVA_1_5 = "1.5"; + protected static final String[] JAVA_VERSIONS = new String[] { + JAVA_1_0, JAVA_1_1, JAVA_1_2, JAVA_1_3, JAVA_1_4, JAVA_1_5}; + /** Whether this is the Kaffe VM */ private static boolean kaffeDetected; @@ -132,6 +135,32 @@ } /** + * Compares the current Java version to the passed in String - + * assumes the argument is one of the constants defined in this + * class. + * @param version the version to check against the current version. + * @return < 0 if older, 0 if same, > 0 if newer. + * (like Comparable.CompareTo(T)). + * @since Ant 1.7 // TODO: Verify this. + */ + public static int compareJavaVersion(String version) { + int curVer = getJavaVersionIdx(javaVersion); + int tstVer = getJavaVersionIdx(version); + return curVer - tstVer; + } + + protected static int getJavaVersionIdx(String version) { + int result = -1; + for (int i=0; i < JAVA_VERSIONS.length; i++) { + if (JAVA_VERSIONS[i].equals(version)){ + result = i; + break; + } + } + return result; + } + + /** * Checks whether the current Java VM is Kaffe. * @return true if the current Java VM is Kaffe. * @since Ant 1.6.3