Return-Path:
dir
becomes base
) as well as the nested
<include>
, <exclude>
and
<patternset>
elements.
It is possible to use different compilers. This can be selected with the +"build.rmic" property. There are two choices:
+generate debug info (passes -g to rmic). Defaults to false. | No | |
includeAntRuntime | +whether to include the Ant run-time libraries;
+ defaults to yes . |
+ No | +
includeJavaRuntime | +whether to include the default run-time
+ libraries from the executing VM; defaults to no . |
+ No | +
extdirs | +location of installed extensions. | +No | +
Rmic
's classpath attribute is a classpath and extdirs
+Rmic
's classpath and extdirs attributes are PATH like structure and can also be set via a nested
-classpath elements.
<rmic classname="com.xyz.FooBar" base="${build}/classes"/>
runs the rmic compiler for the class com.xyz.FooBar
. The
1.19 +209 -182 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Rmic.java
Index: Rmic.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Rmic.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Rmic.java 2001/02/04 13:08:51 1.18
+++ Rmic.java 2001/03/16 12:57:15 1.19
@@ -58,15 +58,14 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
-import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.taskdefs.rmic.*;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.util.*;
-import java.io.*;
-import java.util.StringTokenizer;
+import java.io.File;
+import java.io.IOException;
import java.util.Vector;
-import java.util.Date;
/**
* Task to compile RMI stubs and skeletons. This task can take the following
@@ -81,6 +80,9 @@
*
@@ -92,15 +94,20 @@
* @author ludovic.claude@websitewatchers.co.uk
* @author David Maclean david@cm.co.za
* @author Stefan Bodewig
+ * @author Takashi Okamoto tokamoto@rd.nttdata.co.jp
*/
public class Rmic extends MatchingTask {
+ private static final String FAIL_MSG
+ = "Rmic failed, messages should have been provided.";
+
private File baseDir;
private String classname;
private File sourceBase;
private String stubVersion;
private Path compileClasspath;
+ private Path extdirs;
private boolean verify = false;
private boolean filtering = false;
@@ -109,35 +116,70 @@
private boolean idl = false;
private String idlopts;
private boolean debug = false;
+ private boolean includeAntRuntime = true;
+ private boolean includeJavaRuntime = false;
private Vector compileList = new Vector();
private ClassLoader loader = null;
+ /** Sets the base directory to output generated class. */
public void setBase(File base) {
this.baseDir = base;
}
+ /** Gets the base directory to output generated class. */
+ public File getBase() {
+ return this.baseDir;
+ }
+
+ /** Sets the class name to compile. */
public void setClassname(String classname) {
this.classname = classname;
}
+ /** Gets the class name to compile. */
+ public String getClassname() {
+ return classname;
+ }
+
+ /** Sets the source dirs to find the source java files. */
public void setSourceBase(File sourceBase) {
this.sourceBase = sourceBase;
}
+ /** Gets the source dirs to find the source java files. */
+ public File getSourceBase() {
+ return sourceBase;
+ }
+
+ /** Sets the stub version. */
public void setStubVersion(String stubVersion) {
this.stubVersion = stubVersion;
}
+ public String getStubVersion() {
+ return stubVersion;
+ }
+
public void setFiltering(boolean filter) {
filtering = filter;
}
+ public boolean getFiltering() {
+ return filtering;
+ }
+
+ /** Sets the debug flag. */
public void setDebug(boolean debug) {
this.debug = debug;
}
+ /** Gets the debug flag. */
+ public boolean getDebug() {
+ return debug;
+ }
+
/**
* Set the classpath to be used for this compilation.
*/
@@ -167,6 +209,13 @@
}
/**
+ * Gets the classpath.
+ */
+ public Path getClasspath() {
+ return compileClasspath;
+ }
+
+ /**
* Indicates that the classes found by the directory match should be
* checked to see if they implement java.rmi.Remote.
* This defaults to false if not set. */
@@ -174,6 +223,11 @@
this.verify = verify;
}
+ /** Get verify flag. */
+ public boolean getVerify() {
+ return verify;
+ }
+
/**
* Indicates that IIOP compatible stubs should
* be generated. This defaults to false
@@ -183,6 +237,11 @@
this.iiop = iiop;
}
+ /** Gets iiop flags. */
+ public boolean getIiop() {
+ return iiop;
+ }
+
/**
* pass additional arguments for iiop
*/
@@ -190,6 +249,11 @@
this.iiopopts = iiopopts;
}
+ /** Gets additional arguments for iiop. */
+ public String getIiopopts() {
+ return iiopopts;
+ }
+
/**
* Indicates that IDL output should be
* generated. This defaults to false
@@ -199,6 +263,11 @@
this.idl = idl;
}
+ /* Gets IDL flags. */
+ public boolean getIdl() {
+ return idl;
+ }
+
/**
* pass additional arguments for idl compile
*/
@@ -206,6 +275,83 @@
this.idlopts = idlopts;
}
+ /**
+ * Gets additional arguments for idl compile.
+ */
+ public String getIdlopts() {
+ return idlopts;
+ }
+
+ /** Gets file list to compile. */
+ public Vector getFileList() {
+ return compileList;
+ }
+
+ /**
+ * Include ant's own classpath in this task's classpath?
+ */
+ public void setIncludeantruntime( boolean include ) {
+ includeAntRuntime = include;
+ }
+
+ /**
+ * Gets whether or not the ant classpath is to be included in the
+ * task's classpath.
+ */
+ public boolean getIncludeantruntime() {
+ return includeAntRuntime;
+ }
+
+ /**
+ * Sets whether or not to include the java runtime libraries to this
+ * task's classpath.
+ */
+ public void setIncludejavaruntime( boolean include ) {
+ includeJavaRuntime = include;
+ }
+
+ /**
+ * Gets whether or not the java runtime should be included in this
+ * task's classpath.
+ */
+ public boolean getIncludejavaruntime() {
+ return includeJavaRuntime;
+ }
+
+ /**
+ * Sets the extension directories that will be used during the
+ * compilation.
+ */
+ public void setExtdirs(Path extdirs) {
+ if (this.extdirs == null) {
+ this.extdirs = extdirs;
+ } else {
+ this.extdirs.append(extdirs);
+ }
+ }
+
+ /**
+ * Maybe creates a nested extdirs element.
+ */
+ public Path createExtdirs() {
+ if (extdirs == null) {
+ extdirs = new Path(project);
+ }
+ return extdirs.createPath();
+ }
+
+ /**
+ * Gets the extension directories that will be used during the
+ * compilation.
+ */
+ public Path getExtdirs() {
+ return extdirs;
+ }
+
+ public Vector getCompileList() {
+ return compileList;
+ }
+
public void execute() throws BuildException {
if (baseDir == null) {
throw new BuildException("base attribute must be set!", location);
@@ -217,20 +363,11 @@
if (verify) {
log("Verify has been turned on.", Project.MSG_INFO);
}
- if (iiop) {
- log("IIOP has been turned on.", Project.MSG_INFO);
- if( iiopopts != null ) {
- log("IIOP Options: " + iiopopts, Project.MSG_INFO );
- }
- }
- if (idl) {
- log("IDL has been turned on.", Project.MSG_INFO);
- if( idlopts != null ) {
- log("IDL Options: " + idlopts, Project.MSG_INFO );
- }
- }
- Path classpath = getCompileClasspath(baseDir);
+ String compiler = project.getProperty("build.rmic");
+ RmicAdapter adapter = RmicAdapterFactory.getRmic(compiler, this );
+
+ Path classpath = adapter.getClasspath();
loader = new AntClassLoader(project, classpath);
// scan base dirs to build up compile lists only if a
@@ -238,61 +375,27 @@
if (classname == null) {
DirectoryScanner ds = this.getDirectoryScanner(baseDir);
String[] files = ds.getIncludedFiles();
- scanDir(baseDir, files);
+ scanDir(baseDir, files, adapter.getMapper());
} else {
// otherwise perform a timestamp comparison - at least
scanDir(baseDir,
- new String[] {classname.replace('.', File.separatorChar) + ".class"});
+ new String[] {classname.replace('.', File.separatorChar) + ".class"},
+ adapter.getMapper());
}
- // XXX
- // need to provide an input stream that we read in from!
-
- OutputStream logstr = new LogOutputStream(this, Project.MSG_WARN);
- sun.rmi.rmic.Main compiler = new sun.rmi.rmic.Main(logstr, "rmic");
- Commandline cmd = new Commandline();
-
- cmd.createArgument().setValue("-d");
- cmd.createArgument().setFile(baseDir);
- cmd.createArgument().setValue("-classpath");
- cmd.createArgument().setPath(classpath);
- if (null != stubVersion) {
- if ("1.1".equals(stubVersion))
- cmd.createArgument().setValue("-v1.1");
- else if ("1.2".equals(stubVersion))
- cmd.createArgument().setValue("-v1.2");
- else
- cmd.createArgument().setValue("-vcompat");
- }
- if (null != sourceBase)
- cmd.createArgument().setValue("-keepgenerated");
-
- if( iiop ) {
- cmd.createArgument().setValue("-iiop");
- if( iiopopts != null )
- cmd.createArgument().setValue(iiopopts);
- }
-
- if( idl ) {
- cmd.createArgument().setValue("-idl");
- if( idlopts != null )
- cmd.createArgument().setValue(idlopts);
- }
- if( debug ) {
- cmd.createArgument().setValue("-g");
- }
-
int fileCount = compileList.size();
if (fileCount > 0) {
log("RMI Compiling " + fileCount +
" class"+ (fileCount > 1 ? "es" : "")+" to " + baseDir,
Project.MSG_INFO);
- for (int j = 0; j < fileCount; j++) {
- cmd.createArgument().setValue((String) compileList.elementAt(j));
+ // now we need to populate the compiler adapter
+ adapter.setRmic( this );
+
+ // finally, lets execute the compiler!!
+ if (!adapter.execute()) {
+ throw new BuildException(FAIL_MSG, location);
}
- log("Compilation args: " + cmd.toString(), Project.MSG_VERBOSE);
- compiler.compile(cmd.getArguments());
}
// Move the generated source file to the base directory
@@ -310,7 +413,7 @@
* @exception org.apache.tools.ant.BuildException When error copying/removing files.
*/
private void moveGeneratedFile (File baseDir, File sourceBaseFile, String classname)
- throws BuildException {
+ throws BuildException {
String stubFileName = classname.replace('.', File.separatorChar) + "_Stub.java";
File oldStubFile = new File(baseDir, stubFileName);
File newStubFile = new File(sourceBaseFile, stubFileName);
@@ -331,7 +434,7 @@
oldSkelFile.delete();
} catch (IOException ioe) {
String msg = "Failed to copy " + oldSkelFile + " to " +
- newSkelFile + " due to " + ioe.getMessage();
+ newSkelFile + " due to " + ioe.getMessage();
throw new BuildException(msg, ioe, location);
}
}
@@ -341,144 +444,68 @@
* Scans the directory looking for class files to be compiled.
* The result is returned in the class variable compileList.
*/
-
- protected void scanDir(File baseDir, String files[]) {
+ protected void scanDir(File baseDir, String files[],
+ FileNameMapper mapper) {
SourceFileScanner sfs = new SourceFileScanner(this);
- String[] newFiles = sfs.restrict(files, baseDir, baseDir,
- new RmicFileNameMapper());
+ String[] newFiles = sfs.restrict(files, baseDir, baseDir, mapper);
for (int i = 0; i < newFiles.length; i++) {
String classname = newFiles[i].replace(File.separatorChar, '.');
classname = classname.substring(0, classname.indexOf(".class"));
compileList.addElement(classname);
}
}
-
+
/**
- * Builds the compilation classpath.
+ * Load named class and test whether it can be rmic'ed
*/
-
- // XXX
- // we need a way to not use the current classpath.
-
- private Path getCompileClasspath(File baseFile) {
- // add dest dir to classpath so that previously compiled and
- // untouched classes are on classpath
- Path classpath = new Path(project, baseFile.getAbsolutePath());
-
- // Combine the build classpath with the system classpath, in an
- // order determined by the value of build.classpath
- if (compileClasspath == null) {
- classpath.addExisting(Path.systemClasspath);
- } else {
- classpath.addExisting(compileClasspath.concatSystemClasspath());
- }
-
- // in jdk 1.2, the system classes are not on the visible classpath.
- if (Project.getJavaVersion().startsWith("1.2")) {
- String bootcp = System.getProperty("sun.boot.class.path");
- if (bootcp != null) {
- classpath.addExisting(new Path(project, bootcp));
- }
- }
- return classpath;
+ public boolean isValidRmiRemote(String classname) {
+ try {
+ Class testClass = loader.loadClass(classname);
+ // One cannot RMIC an interface
+ if (testClass.isInterface()) {
+ return false;
+ }
+ return isValidRmiRemote(testClass);
+ } catch (ClassNotFoundException e) {
+ log("Unable to verify class " + classname +
+ ". It could not be found.", Project.MSG_WARN);
+ } catch (NoClassDefFoundError e) {
+ log("Unable to verify class " + classname +
+ ". It is not defined.", Project.MSG_WARN);
+ } catch (Throwable t) {
+ log("Unable to verify class " + classname +
+ ". Loading caused Exception: " +
+ t.getMessage(), Project.MSG_WARN);
+ }
+ // we only get here if an exception has been thrown
+ return false;
}
/**
- * Mapper that possibly returns two file names, *_Stub and *_Skel.
+ * Check to see if the class or (super)interfaces implement
+ * java.rmi.Remote.
*/
- private class RmicFileNameMapper implements FileNameMapper {
-
- private GlobPatternMapper stubMapper;
- private GlobPatternMapper skelMapper;
-
- RmicFileNameMapper() {
- stubMapper = new GlobPatternMapper();
- stubMapper.setFrom("*.class");
- stubMapper.setTo("*_Stub.class");
-
- // no _Skel file in stub version 1.2
- if (!"1.2".equals(stubVersion)) {
- skelMapper = new GlobPatternMapper();
- skelMapper.setFrom("*.class");
- skelMapper.setTo("*_Skel.class");
- }
- }
-
- /**
- * Empty implementation.
- */
- public void setFrom(String s) {}
- /**
- * Empty implementation.
- */
- public void setTo(String s) {}
-
- public String[] mapFileName(String name) {
- String[] stubName = stubMapper.mapFileName(name);
-
- if (stubName == null || name.endsWith("_Stub.class")
- || name.endsWith("_Skel.class")) {
- // Not a .class file
- return null;
- }
-
- String classname = name.replace(File.separatorChar, '.');
- classname = classname.substring(0, classname.indexOf(".class"));
- if (verify) {
- try {
- Class testClass = loader.loadClass(classname);
- // One cannot RMIC an interface
- if (testClass.isInterface() ||
- !isValidRmiRemote(testClass)) {
- return null;
- }
- } catch (ClassNotFoundException e) {
- log("Unable to verify class " + classname +
- ". It could not be found.", Project.MSG_WARN);
- } catch (NoClassDefFoundError e) {
- log("Unable to verify class " + classname +
- ". It is not defined.", Project.MSG_WARN);
- }
- }
-
- if (skelMapper != null) {
- return new String[] {
- stubName[0],
- skelMapper.mapFileName(name)[0]
- };
- } else {
- return stubName;
- }
+ private boolean isValidRmiRemote (Class testClass) {
+ Class rmiRemote = java.rmi.Remote.class;
+
+ if (rmiRemote.equals(testClass)) {
+ // This class is java.rmi.Remote
+ return true;
}
-
- /**
- * Check to see if the class or superclasses/interfaces implement
- * java.rmi.Remote.
- */
- private boolean isValidRmiRemote (Class testClass) {
- Class rmiRemote = java.rmi.Remote.class;
-
- if (rmiRemote.equals(testClass)) {
- // This class is java.rmi.Remote
- return true;
- }
- Class [] interfaces = testClass.getInterfaces();
- if (interfaces != null) {
- for (int i = 0; i < interfaces.length; i++) {
- if (rmiRemote.equals(interfaces[i])) {
- // This class directly implements java.rmi.Remote
- return true;
- }
- if (isValidRmiRemote(interfaces[i])) {
- return true;
- }
+ Class [] interfaces = testClass.getInterfaces();
+ if (interfaces != null) {
+ for (int i = 0; i < interfaces.length; i++) {
+ if (rmiRemote.equals(interfaces[i])) {
+ // This class directly implements java.rmi.Remote
+ return true;
}
+ if (isValidRmiRemote(interfaces[i])) {
+ return true;
+ }
}
- return false;
}
-
+ return false;
}
-
}
1.1 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java
Index: DefaultRmicAdapter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* A rmic adapter is an adapter that interprets the rmic's
* parameters in preperation to be passed off to the compiler this
* adapter represents. As all the necessary values are stored in the
* Rmic task itself, the only thing all adapters need is the rmic
* task, the execute command and a parameterless constructor (for
* reflection).
*
* @param rmicType either the name of the desired rmic, or the
* full classname of the rmic's adapter.
* @param task a task to log through.
* @throws BuildException if the rmic type could not be resolved into
* a rmic adapter.
*/
public static RmicAdapter getRmic( String rmicType, Task task )
throws BuildException {
if( rmicType == null){
/*
* When not specified rmicType, search SUN's rmic and
* Kaffe's rmic.
*/
try {
Class.forName("sun.rmi.rmic.Main");
rmicType = "sun";
} catch (ClassNotFoundException cnfe) {
try {
Class.forName("kaffe.rmi.rmic.RMIC");
Class.forName("kaffe.tools.compiler.Compiler");
rmicType = "kaffe";
} catch (ClassNotFoundException cnfk) {
throw new BuildException("Couldn\'t guess rmic implementation");
}
}
}
if ( rmicType.equalsIgnoreCase("sun") ) {
return new SunRmic();
} if ( rmicType.equalsIgnoreCase("kaffe") ) {
return new KaffeRmic();
}
return resolveClassName( rmicType );
}
/**
* Tries to resolve the given classname into a rmic adapter.
* Throws a fit if it can't.
*
* @param className The fully qualified classname to be created.
* @throws BuildException This is the fit that is thrown if className
* isn't an instance of RmicAdapter.
*/
private static RmicAdapter resolveClassName( String className )
throws BuildException {
try {
Class c = Class.forName( className );
Object o = c.newInstance();
return (RmicAdapter) o;
} catch ( ClassNotFoundException cnfe ) {
throw new BuildException( className + " can\'t be found.", cnfe );
} catch ( ClassCastException cce ) {
throw new BuildException(className + " isn\'t the classname of "
+ "a rmic adapter.", cce);
} catch ( Throwable t ) {
// for all other possibilities
throw new BuildException(className + " caused an interesting "
+ "exception.", t);
}
}
}
1.1 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/SunRmic.java
Index: SunRmic.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*