Fields Summary |
---|
public static final String | ERROR_RMIC_FAILEDrmic failed message |
private File | baseDir |
private String | classname |
private File | sourceBase |
private String | stubVersion |
private org.apache.tools.ant.types.Path | compileClasspath |
private org.apache.tools.ant.types.Path | extDirs |
private boolean | verify |
private boolean | filtering |
private boolean | iiop |
private String | iiopOpts |
private boolean | idl |
private String | idlOpts |
private boolean | debug |
private boolean | includeAntRuntime |
private boolean | includeJavaRuntime |
private Vector | compileList |
private ClassLoader | loader |
private org.apache.tools.ant.util.facade.FacadeTaskHelper | facade |
public static final String | ERROR_UNABLE_TO_VERIFY_CLASSunable to verify message |
public static final String | ERROR_NOT_FOUNDcould not be found message |
public static final String | ERROR_NOT_DEFINEDnot defined message |
public static final String | ERROR_LOADING_CAUSED_EXCEPTIONloaded error message |
public static final String | ERROR_NO_BASE_EXISTSbase not exists message |
public static final String | ERROR_NOT_A_DIRbase not a directory message |
public static final String | ERROR_BASE_NOT_SETbase attribute not set message |
private static final org.apache.tools.ant.util.FileUtils | FILE_UTILS |
Methods Summary |
---|
public org.apache.tools.ant.types.Path | createClasspath()Creates a nested classpath element.
if (compileClasspath == null) {
compileClasspath = new Path(getProject());
}
return compileClasspath.createPath();
|
public org.apache.tools.ant.taskdefs.Rmic$ImplementationSpecificArgument | createCompilerArg()Adds an implementation specific command line argument.
ImplementationSpecificArgument arg =
new ImplementationSpecificArgument();
facade.addImplementationArgument(arg);
return arg;
|
public org.apache.tools.ant.types.Path | createExtdirs()Maybe creates a nested extdirs element.
if (extDirs == null) {
extDirs = new Path(getProject());
}
return extDirs.createPath();
|
public void | execute()execute by creating an instance of an implementation
class and getting to do the work
if (baseDir == null) {
throw new BuildException(ERROR_BASE_NOT_SET, getLocation());
}
if (!baseDir.exists()) {
throw new BuildException(ERROR_NO_BASE_EXISTS + baseDir, getLocation());
}
if (!baseDir.isDirectory()) {
throw new BuildException(ERROR_NOT_A_DIR + baseDir, getLocation());
}
if (verify) {
log("Verify has been turned on.", Project.MSG_VERBOSE);
}
RmicAdapter adapter = RmicAdapterFactory.getRmic(getCompiler(), this);
// now we need to populate the compiler adapter
adapter.setRmic(this);
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());
}
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();
}
|
public java.io.File | getBase()Gets the base directory to output generated class.
return this.baseDir;
|
public java.lang.String | getClassname()Gets the class name to compile.
return classname;
|
public org.apache.tools.ant.types.Path | getClasspath()Gets the classpath.
return compileClasspath;
|
public java.util.Vector | getCompileList()
return compileList;
|
public java.lang.String | getCompiler()get the name of the current compiler
facade.setMagicValue(getProject().getProperty("build.rmic"));
return facade.getImplementation();
|
public java.lang.String[] | getCurrentCompilerArgs()Get the additional implementation specific command line arguments.
getCompiler();
return facade.getArgs();
|
public boolean | getDebug()Gets the debug flag.
return debug;
|
public org.apache.tools.ant.types.Path | getExtdirs()Gets the extension directories that will be used during the
compilation.
return extDirs;
|
public java.util.Vector | getFileList()Gets file list to compile.
return compileList;
|
public boolean | getFiltering()Gets whether token filtering is set
return filtering;
|
public boolean | getIdl()Gets IDL flags.
return idl;
|
public java.lang.String | getIdlopts()Gets additional arguments for idl compile.
return idlOpts;
|
public boolean | getIiop()Gets iiop flags.
return iiop;
|
public java.lang.String | getIiopopts()Gets additional arguments for iiop.
return iiopOpts;
|
public boolean | getIncludeantruntime()Gets whether or not the ant classpath is to be included in the
task's classpath.
return includeAntRuntime;
|
public boolean | getIncludejavaruntime()Gets whether or not the java runtime should be included in this
task's classpath.
return includeJavaRuntime;
|
public java.lang.ClassLoader | getLoader()Classloader for the user-specified classpath.
return loader;
|
public java.lang.Class | getRemoteInterface(java.lang.Class testClass)Returns the topmost interface that extends Remote for a given
class - if one exists.
if (Remote.class.isAssignableFrom(testClass)) {
Class [] interfaces = testClass.getInterfaces();
if (interfaces != null) {
for (int i = 0; i < interfaces.length; i++) {
if (Remote.class.isAssignableFrom(interfaces[i])) {
return interfaces[i];
}
}
}
}
return null;
|
public java.io.File | getSourceBase()Gets the source dirs to find the source java files.
return sourceBase;
|
public java.lang.String | getStubVersion()Gets the JDK version for the generated stub code.
return stubVersion;
|
public boolean | getVerify()Get verify flag.
return verify;
|
public boolean | isValidRmiRemote(java.lang.String classname)Load named class and test whether it can be rmic'ed
try {
Class testClass = loader.loadClass(classname);
// One cannot RMIC an interface for "classic" RMI (JRMP)
if (testClass.isInterface() && !iiop && !idl) {
return false;
}
return isValidRmiRemote(testClass);
} catch (ClassNotFoundException e) {
log(ERROR_UNABLE_TO_VERIFY_CLASS + classname
+ ERROR_NOT_FOUND, Project.MSG_WARN);
} catch (NoClassDefFoundError e) {
log(ERROR_UNABLE_TO_VERIFY_CLASS + classname
+ ERROR_NOT_DEFINED, Project.MSG_WARN);
} catch (Throwable t) {
log(ERROR_UNABLE_TO_VERIFY_CLASS + classname
+ ERROR_LOADING_CAUSED_EXCEPTION
+ t.getMessage(), Project.MSG_WARN);
}
// we only get here if an exception has been thrown
return false;
|
private boolean | isValidRmiRemote(java.lang.Class testClass)Check to see if the class or (super)interfaces implement
java.rmi.Remote.
return getRemoteInterface(testClass) != null;
|
private void | moveGeneratedFile(java.io.File baseDir, java.io.File sourceBaseFile, java.lang.String classname, org.apache.tools.ant.taskdefs.rmic.RmicAdapter adapter)Move the generated source file(s) to the base directory
String classFileName =
classname.replace('.", File.separatorChar) + ".class";
String[] generatedFiles =
adapter.getMapper().mapFileName(classFileName);
for (int i = 0; i < generatedFiles.length; i++) {
final String generatedFile = generatedFiles[i];
if (!generatedFile.endsWith(".class")) {
// don't know how to handle that - a IDL file doesn't
// have a corresponding Java source for example.
continue;
}
final int pos = generatedFile.length() - ".class".length();
String sourceFileName =
generatedFile.substring(0, pos) + ".java";
File oldFile = new File(baseDir, sourceFileName);
if (!oldFile.exists()) {
// no source file generated, nothing to move
continue;
}
File newFile = new File(sourceBaseFile, sourceFileName);
try {
if (filtering) {
FILE_UTILS.copyFile(oldFile, newFile,
new FilterSetCollection(getProject()
.getGlobalFilterSet()));
} else {
FILE_UTILS.copyFile(oldFile, newFile);
}
oldFile.delete();
} catch (IOException ioe) {
String msg = "Failed to copy " + oldFile + " to "
+ newFile + " due to " + ioe.getMessage();
throw new BuildException(msg, ioe, getLocation());
}
}
|
protected void | scanDir(java.io.File baseDir, java.lang.String[] files, org.apache.tools.ant.util.FileNameMapper mapper)Scans the directory looking for class files to be compiled.
The result is returned in the class variable compileList.
String[] newFiles = files;
if (idl) {
log("will leave uptodate test to rmic implementation in idl mode.",
Project.MSG_VERBOSE);
} else if (iiop
&& iiopOpts != null && iiopOpts.indexOf("-always") > -1) {
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);
}
for (int i = 0; i < newFiles.length; i++) {
String name = newFiles[i].replace(File.separatorChar, '.");
name = name.substring(0, name.lastIndexOf(".class"));
compileList.addElement(name);
}
|
public void | setBase(java.io.File base)Sets the location to store the compiled files; required
this.baseDir = base;
|
public void | setClassname(java.lang.String classname)Sets the class to run rmic against;
optional
this.classname = classname;
|
public void | setClasspath(org.apache.tools.ant.types.Path classpath)Set the classpath to be used for this compilation.
if (compileClasspath == null) {
compileClasspath = classpath;
} else {
compileClasspath.append(classpath);
}
|
public void | setClasspathRef(org.apache.tools.ant.types.Reference pathRef)Adds to the classpath a reference to
a <path> defined elsewhere.
createClasspath().setRefid(pathRef);
|
public void | setCompiler(java.lang.String compiler)Sets the compiler implementation to use; optional,
defaults to the value of the build.rmic property,
or failing that, default compiler for the current VM
if (compiler.length() > 0) {
facade.setImplementation(compiler);
}
|
public void | setDebug(boolean debug)Generate debug info (passes -g to rmic);
optional, defaults to false
this.debug = debug;
|
public void | setExtdirs(org.apache.tools.ant.types.Path extDirs)Sets the extension directories that will be used during the
compilation; optional.
if (this.extDirs == null) {
this.extDirs = extDirs;
} else {
this.extDirs.append(extDirs);
}
|
public void | setFiltering(boolean filter)Sets token filtering [optional], default=false
this.filtering = filter;
|
public void | setIdl(boolean idl)Indicates that IDL output should be
generated. This defaults to false
if not set.
this.idl = idl;
|
public void | setIdlopts(java.lang.String idlOpts)pass additional arguments for IDL compile
this.idlOpts = idlOpts;
|
public void | setIiop(boolean iiop)Indicates that IIOP compatible stubs should
be generated; optional, defaults to false
if not set.
this.iiop = iiop;
|
public void | setIiopopts(java.lang.String iiopOpts)Set additional arguments for iiop
this.iiopOpts = iiopOpts;
|
public void | setIncludeantruntime(boolean include)Sets whether or not to include ant's own classpath in this task's
classpath.
Optional; default is true .
includeAntRuntime = include;
|
public void | setIncludejavaruntime(boolean include)task's classpath.
Enables or disables including the default run-time
libraries from the executing VM; optional,
defaults to false
includeJavaRuntime = include;
|
public void | setSourceBase(java.io.File sourceBase)optional directory to save generated source files to.
this.sourceBase = sourceBase;
|
public void | setStubVersion(java.lang.String stubVersion)Specify the JDK version for the generated stub code.
Specify "1.1" to pass the "-v1.1" option to rmic. |
this.stubVersion = stubVersion;
public void | setVerify(boolean verify)Flag to enable verification so that the classes
found by the directory match are
checked to see if they implement java.rmi.Remote.
optional; This defaults to false if not set.
this.verify = verify;
|