ASF Bugzilla – Attachment 16183 Details for
Bug 20699
[PATCH] rmic and seaprate input/output directories
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Proposed patch to fix bug 20699, #3.
Bug20699c.patch (text/plain), 15.98 KB, created by
Mark A. Ziesemer
on 2005-08-24 22:46:47 UTC
(
hide
)
Description:
Proposed patch to fix bug 20699, #3.
Filename:
MIME Type:
Creator:
Mark A. Ziesemer
Created:
2005-08-24 22:46:47 UTC
Size:
15.98 KB
patch
obsolete
>diff -ur ant/docs/manual/CoreTasks/rmic.html ant-patch/docs/manual/CoreTasks/rmic.html >--- ant/docs/manual/CoreTasks/rmic.html 2005-04-29 13:58:13.000000000 -0500 >+++ ant-patch/docs/manual/CoreTasks/rmic.html 2005-08-24 15:36:38.888824900 -0500 >@@ -60,8 +60,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">*1</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> >@@ -173,6 +179,12 @@ > <td align="center" valign="top">No</td> > </tr> > <tr> >+ <td valign="top">sourcesOnClasspath</td> >+ <td valign="top">whether source folders are automatically included in the >+ compile classpath; defaults to <code>yes</code>.</td> >+ <td align="center" valign="top">No</td> >+ </tr> >+ <tr> > <td valign="top">extdirs</td> > <td valign="top">location of installed extensions.</td> > <td align="center" valign="top">No</td> >@@ -188,7 +200,25 @@ > <td align="center" valign="top">No</td> > </tr> > </table> >+ >+<p>*1:<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 execute-time error will occur.</li> >+</ul></p> >+ > <h3>Parameters specified as nested elements</h3> >+ >+<h4>fileset</h4> >+<p>The rmic task supports any number of nested <a >+href="../CoreTypes/fileset.html"><code><fileset></code></a> elements to specify >+the files to be rmic'd. Generated files will be saved to <code>destdir</code> if >+specified, or it will attempt to default to <code>base</code>. (<code>base</code> >+does not serve as a parent directory to any <code>fileset</code> elements.)</p> >+ > <h4>classpath and extdirs</h4> > <p><code>Rmic</code>'s <i>classpath</i> and <i>extdirs</i> attributes are <a > href="../using.html#path">PATH like structure</a> and can also be set via a nested >@@ -235,15 +265,30 @@ > </table> > > <h3>Examples</h3> >+ > <pre> <rmic classname="com.xyz.FooBar" base="${build}/classes"/></pre> > <p>runs the rmic compiler for the class <code>com.xyz.FooBar</code>. The > compiled files will be stored in the directory <code>${build}/classes</code>.</p> >+ > <pre> <rmic base="${build}/classes" includes="**/Remote*.class"/></pre> > <p>runs the rmic compiler for all classes with <code>.class</code> > files below <code>${build}/classes</code> whose classname starts with > <i>Remote</i>. The compiled files will be stored in the directory > <code>${build}/classes</code>.</p> > >+<pre> <rmic destdir="bin/Client" includeAntRuntime="false" verify="true"> >+ <fileset dir="bin/Server"> >+ <include name="**/*.class"/> >+ </fileset> >+ <classpath> >+ <pathelement path="bin/Common"/> >+ </classpath> >+ </rmic></pre> >+<p>runs the rmic compiler for all classes below <code>bin/Common</code> and are >+verified to extend java.rmi.remote. The generated files will be stored in the >+directory <code>bin/Client</code>. The classpath used by rmic will contain <code> >+bin/Common</code> and <code>bin/Server</code>. >+ > <hr> > <p align="center">Copyright © 2000-2005 The Apache Software Foundation. All rights > Reserved.</p> >diff -ur ant/src/main/org/apache/tools/ant/taskdefs/Rmic.java ant-patch/src/main/org/apache/tools/ant/taskdefs/Rmic.java >--- ant/src/main/org/apache/tools/ant/taskdefs/Rmic.java 2005-01-06 06:05:05.000000000 -0600 >+++ ant-patch/src/main/org/apache/tools/ant/taskdefs/Rmic.java 2005-08-24 15:38:35.478798100 -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; >@@ -84,6 +86,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; >@@ -99,6 +104,7 @@ > private boolean debug = false; > private boolean includeAntRuntime = true; > private boolean includeJavaRuntime = false; >+ private boolean sourcesOnClasspath = true; > > private Vector compileList = new Vector(); > >@@ -114,11 +120,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(); > >@@ -147,6 +153,42 @@ > } > > /** >+ * 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. >+ * @return the actual directory to output to (either destdir or basedir) >+ */ >+ public File getOutputDir() { >+ if (getDestdir() != null) { >+ return getDestdir(); >+ } >+ return getBase(); >+ } >+ >+ /** >+ * Adds a set of files to generate stubs for. >+ * @param set The FileSet to add. >+ */ >+ public void addFileset(FileSet set) { >+ filesets.addElement(set); >+ } >+ >+ /** > * Sets the class to run <code>rmic</code> against; > * optional > * @param classname the name of the class for rmic to create code for >@@ -405,6 +447,24 @@ > } > > /** >+ * Sets whether source folders are automatically included in the compile >+ * classpath; optional, defaults to true >+ * @param include true to include source folders >+ */ >+ public void setSourcesOnClasspath(boolean include) { >+ sourcesOnClasspath = include; >+ } >+ >+ /** >+ * Gets whether source folders are automatically included in the compile >+ * classpath >+ * @return 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 >@@ -496,19 +556,35 @@ > * if there's a problem with baseDir or RMIC > */ > public void execute() throws BuildException { >- if (baseDir == null) { >+ if (compileList.size() > 0) { >+ compileList.removeAllElements(); >+ } >+ >+ 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); > } > >+ 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 >@@ -517,56 +593,83 @@ > Path classpath = adapter.getClasspath(); > loader = getProject().createClassLoader(classpath); > >- try { >+ populateFilesToProcess(adapter.getMapper()); >+ >+ int fileCount = compileList.size(); >+ if (fileCount > 0) { >+ log("RMI Compiling " + fileCount >+ + " class" + (fileCount > 1 ? "es" : "") + " to " + outputDir, >+ Project.MSG_INFO); >+ >+ // finally, lets execute the compiler!! >+ if (!adapter.execute()) { >+ throw new BuildException(ERROR_RMIC_FAILED, getLocation()); >+ } >+ } >+ >+ /* >+ * Move the generated source file to the base directory. If >+ * base directory and sourcebase are the same, the generated >+ * sources are already in place. >+ */ >+ 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(outputDir, sourceBase, >+ (String) compileList.elementAt(j), >+ adapter); >+ } >+ } >+ } >+ } >+ >+ /** >+ * Adds any source folders to the compile classpath. >+ */ >+ 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); >+ } >+ } >+ } >+ >+ /** >+ * Sets the list of files to rmic, retrieved from all the filesets. >+ * @param mapper FileNameMapper used to resolve files. >+ */ >+ 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 = this.getDirectoryScanner(baseDir); >- String[] files = ds.getIncludedFiles(); >- scanDir(baseDir, files, adapter.getMapper()); >+ DirectoryScanner ds = fs.getDirectoryScanner(getProject()); >+ files = ds.getIncludedFiles(); > } else { > // otherwise perform a timestamp comparison - at least >- scanDir(baseDir, >- new String[] {classname.replace('.', >- File.separatorChar) >- + ".class"}, >- adapter.getMapper()); >+ files = new String[] {classname.replace('.', >+ File.separatorChar) + ".class"}; > } > >- int fileCount = compileList.size(); >- if (fileCount > 0) { >- log("RMI Compiling " + fileCount >- + " class" + (fileCount > 1 ? "es" : "") + " to " + baseDir, >- Project.MSG_INFO); >- >- // finally, lets execute the compiler!! >- if (!adapter.execute()) { >- throw new BuildException(ERROR_RMIC_FAILED, getLocation()); >- } >- } >- >- /* >- * Move the generated source file to the base directory. If >- * base directory and sourcebase are the same, the generated >- * sources are already in place. >- */ >- if (null != sourceBase && !baseDir.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), >- adapter); >- } >- } >- } >- } finally { >- compileList.removeAllElements(); >+ scanDir(fsBaseDir, files, mapper); > } > } > >@@ -642,7 +745,7 @@ > Project.MSG_VERBOSE); > } else { > SourceFileScanner sfs = new SourceFileScanner(this); >- newFiles = sfs.restrict(files, baseDir, baseDir, mapper); >+ newFiles = sfs.restrict(files, baseDir, getDestdir(), mapper); > } > > for (int i = 0; i < newFiles.length; i++) { >diff -ur ant/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java ant-patch/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java >--- ant/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java 2005-03-07 09:12:25.000000000 -0600 >+++ ant-patch/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java 2005-08-24 15:36:38.928883300 -0500 >@@ -130,9 +130,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 >@@ -179,7 +176,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");
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 20699
:
16086
|
16129
| 16183