<rvanoostrum@ezgov.com> and Larry V. Streepy, Jr. <streepy@healthlanguage.com> on the ant-user mailing list: (1) don't even try to perform uptodate checks for IDL mode or when the -always(generate) option for IIOP mode has been specified (2) ignore -keepgenerated in IDL mode (we don't know what to keep) (3) use the correct target file names in IIOP mode. PR: 1625 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269263 13f79535-47bb-0310-9956-ffa450edef68master
@@ -65,6 +65,7 @@ import org.apache.tools.ant.util.*; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.rmi.Remote; | |||||
import java.util.Vector; | import java.util.Vector; | ||||
/** | /** | ||||
@@ -400,10 +401,16 @@ public class Rmic extends MatchingTask { | |||||
// Move the generated source file to the base directory | // Move the generated source file to the base directory | ||||
if (null != sourceBase) { | if (null != sourceBase) { | ||||
for (int j = 0; j < fileCount; j++) { | |||||
moveGeneratedFile(baseDir, sourceBase, | |||||
(String) compileList.elementAt(j), | |||||
adapter); | |||||
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); | |||||
} | |||||
} | } | ||||
} | } | ||||
compileList.removeAllElements(); | compileList.removeAllElements(); | ||||
@@ -446,8 +453,20 @@ public class Rmic extends MatchingTask { | |||||
*/ | */ | ||||
protected void scanDir(File baseDir, String files[], | protected void scanDir(File baseDir, String files[], | ||||
FileNameMapper mapper) { | FileNameMapper mapper) { | ||||
SourceFileScanner sfs = new SourceFileScanner(this); | |||||
String[] newFiles = sfs.restrict(files, baseDir, baseDir, mapper); | |||||
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++) { | for (int i = 0; i < newFiles.length; i++) { | ||||
String classname = newFiles[i].replace(File.separatorChar, '.'); | String classname = newFiles[i].replace(File.separatorChar, '.'); | ||||
classname = classname.substring(0, classname.lastIndexOf(".class")); | classname = classname.substring(0, classname.lastIndexOf(".class")); | ||||
@@ -461,8 +480,8 @@ public class Rmic extends MatchingTask { | |||||
public boolean isValidRmiRemote(String classname) { | public boolean isValidRmiRemote(String classname) { | ||||
try { | try { | ||||
Class testClass = loader.loadClass(classname); | Class testClass = loader.loadClass(classname); | ||||
// One cannot RMIC an interface | |||||
if (testClass.isInterface()) { | |||||
// One cannot RMIC an interface for "classic" RMI (JRMP) | |||||
if (testClass.isInterface() && !iiop && !idl) { | |||||
return false; | return false; | ||||
} | } | ||||
return isValidRmiRemote(testClass); | return isValidRmiRemote(testClass); | ||||
@@ -482,30 +501,35 @@ public class Rmic extends MatchingTask { | |||||
} | } | ||||
/** | /** | ||||
* Check to see if the class or (super)interfaces implement | |||||
* java.rmi.Remote. | |||||
* Returns the topmost interface that extends Remote for a given | |||||
* class - if one exists. | |||||
*/ | */ | ||||
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; | |||||
public Class getRemoteInterface(Class testClass) { | |||||
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 false; | |||||
return null; | |||||
} | |||||
/** | |||||
* Check to see if the class or (super)interfaces implement | |||||
* java.rmi.Remote. | |||||
*/ | |||||
private boolean isValidRmiRemote (Class testClass) { | |||||
return getRemoteInterface(testClass) != null; | |||||
} | } | ||||
/** | |||||
* Classloader for the user-specified classpath. | |||||
*/ | |||||
public ClassLoader getLoader() {return loader;} | |||||
} | } | ||||
@@ -60,6 +60,7 @@ import org.apache.tools.ant.types.*; | |||||
import org.apache.tools.ant.util.*; | import org.apache.tools.ant.util.*; | ||||
import java.io.File; | import java.io.File; | ||||
import java.util.Random; | |||||
import java.util.Vector; | import java.util.Vector; | ||||
/** | /** | ||||
@@ -320,6 +321,8 @@ public abstract class DefaultRmicAdapter implements RmicAdapter { | |||||
} | } | ||||
} | } | ||||
private final static Random rand = new Random(); | |||||
/** | /** | ||||
* Mapper that possibly returns two file names, *_Stub and *_Skel. | * Mapper that possibly returns two file names, *_Stub and *_Skel. | ||||
*/ | */ | ||||
@@ -353,19 +356,30 @@ public abstract class DefaultRmicAdapter implements RmicAdapter { | |||||
return null; | return null; | ||||
} | } | ||||
if (!attributes.getIiop()) { | |||||
/* | |||||
* fallback in case we have trouble loading the class or | |||||
* don't know how to handle it (there is no easy way to | |||||
* know what IDL mode would generate. | |||||
* | |||||
* This is supposed to make Ant always recompile the | |||||
* class, as a file of that name should not exist. | |||||
*/ | |||||
String[] target = new String[] {name+".tmp."+rand.nextLong()}; | |||||
if (!attributes.getIiop() && !attributes.getIdl()) { | |||||
// JRMP with simple naming convention | |||||
if ("1.2".equals(attributes.getStubVersion())) { | if ("1.2".equals(attributes.getStubVersion())) { | ||||
return new String[] { | |||||
target = new String[] { | |||||
base + getStubClassSuffix() + ".class" | base + getStubClassSuffix() + ".class" | ||||
}; | }; | ||||
} else { | } else { | ||||
return new String[] { | |||||
target = new String[] { | |||||
base + getStubClassSuffix() + ".class", | base + getStubClassSuffix() + ".class", | ||||
base + getSkelClassSuffix() + ".class", | base + getSkelClassSuffix() + ".class", | ||||
}; | }; | ||||
} | } | ||||
} else { | |||||
int lastSlash = base.lastIndexOf("/"); | |||||
} else if (!attributes.getIdl()) { | |||||
int lastSlash = base.lastIndexOf(File.separatorChar); | |||||
String dirname = ""; | String dirname = ""; | ||||
/* | /* | ||||
@@ -382,11 +396,55 @@ public abstract class DefaultRmicAdapter implements RmicAdapter { | |||||
String filename = base.substring(index); | String filename = base.substring(index); | ||||
return new String[] { | |||||
dirname + "_" + filename + getStubClassSuffix() + ".class", | |||||
dirname + "_" + filename + getTieClassSuffix() + ".class" | |||||
}; | |||||
try { | |||||
Class c = attributes.getLoader().loadClass(classname); | |||||
if (c.isInterface()) { | |||||
// only stub, no tie | |||||
target = new String[] { | |||||
dirname + "_" + filename + getStubClassSuffix() | |||||
+ ".class" | |||||
}; | |||||
} else { | |||||
/* | |||||
* stub is derived from implementation, | |||||
* tie from interface name. | |||||
*/ | |||||
Class interf = attributes.getRemoteInterface(c); | |||||
String iName = interf.getName(); | |||||
String iDir = ""; | |||||
int iIndex = -1; | |||||
int lastDot = iName.lastIndexOf("."); | |||||
if (lastDot == -1) { | |||||
// no package | |||||
iIndex = 0; | |||||
} else { | |||||
iIndex = lastDot + 1; | |||||
iDir = iName.substring(0, iIndex); | |||||
iDir = iDir.replace('.', File.separatorChar); | |||||
} | |||||
target = new String[] { | |||||
dirname + "_" + filename + getTieClassSuffix() | |||||
+ ".class", | |||||
iDir + "_" + iName.substring(iIndex) | |||||
+ getStubClassSuffix() + ".class" | |||||
}; | |||||
} | |||||
} catch (ClassNotFoundException e) { | |||||
attributes.log("Unable to verify class " + classname | |||||
+ ". It could not be found.", | |||||
Project.MSG_WARN); | |||||
} catch (NoClassDefFoundError e) { | |||||
attributes.log("Unable to verify class " + classname | |||||
+ ". It is not defined.", Project.MSG_WARN); | |||||
} catch (Throwable t) { | |||||
attributes.log("Unable to verify class " + classname | |||||
+ ". Loading caused Exception: " | |||||
+ t.getMessage(), Project.MSG_WARN); | |||||
} | |||||
} | } | ||||
return target; | |||||
} | } | ||||
} | } | ||||