detect generated files properly) - doesn't quite work ATM. Add some extra warning and debugging info to Project. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269231 13f79535-47bb-0310-9956-ffa450edef68master
@@ -242,8 +242,10 @@ public class Project { | |||||
public void setProperty(String name, String value) { | public void setProperty(String name, String value) { | ||||
// command line properties take precedence | // command line properties take precedence | ||||
if (null != userProperties.get(name)) | |||||
if (null != userProperties.get(name)) { | |||||
log("Override ignored for user property " + name, MSG_VERBOSE); | |||||
return; | return; | ||||
} | |||||
log("Setting project property: " + name + " -> " + | log("Setting project property: " + name + " -> " + | ||||
value, MSG_DEBUG); | value, MSG_DEBUG); | ||||
properties.put(name, value); | properties.put(name, value); | ||||
@@ -1034,6 +1036,10 @@ public class Project { | |||||
} | } | ||||
public void addReference(String name, Object value) { | public void addReference(String name, Object value) { | ||||
if (null != references.get(name)) { | |||||
log("Overriding previous definition of reference to " + name, | |||||
MSG_WARN); | |||||
} | |||||
log("Adding reference: " + name + " -> " + value, MSG_DEBUG); | log("Adding reference: " + name + " -> " + value, MSG_DEBUG); | ||||
references.put(name,value); | references.put(name,value); | ||||
} | } | ||||
@@ -418,29 +418,23 @@ public class Rmic extends MatchingTask { | |||||
String classname, | String classname, | ||||
RmicAdapter adapter) | RmicAdapter adapter) | ||||
throws BuildException { | throws BuildException { | ||||
String stubFileName = classname.replace('.', File.separatorChar) | |||||
+ adapter.getStubClassSuffix()+".java"; | |||||
File oldStubFile = new File(baseDir, stubFileName); | |||||
File newStubFile = new File(sourceBaseFile, stubFileName); | |||||
try { | |||||
project.copyFile(oldStubFile, newStubFile, filtering); | |||||
oldStubFile.delete(); | |||||
} catch (IOException ioe) { | |||||
String msg = "Failed to copy " + oldStubFile + " to " + | |||||
newStubFile + " due to " + ioe.getMessage(); | |||||
throw new BuildException(msg, ioe, location); | |||||
} | |||||
if (!"1.2".equals(stubVersion)) { | |||||
String skelFileName = classname.replace('.', File.separatorChar) | |||||
+ adapter.getSkelClassSuffix()+".java"; | |||||
File oldSkelFile = new File(baseDir, skelFileName); | |||||
File newSkelFile = new File(sourceBaseFile, skelFileName); | |||||
String classFileName = | |||||
classname.replace('.', File.separatorChar) + ".class"; | |||||
String[] generatedFiles = | |||||
adapter.getMapper().mapFileName(classFileName); | |||||
for (int i=0; i<generatedFiles.length; i++) { | |||||
String sourceFileName = | |||||
classFileName.substring(0, classFileName.length()-6) + ".java"; | |||||
File oldFile = new File(baseDir, sourceFileName); | |||||
File newFile = new File(sourceBaseFile, sourceFileName); | |||||
try { | try { | ||||
project.copyFile(oldSkelFile, newSkelFile, filtering); | |||||
oldSkelFile.delete(); | |||||
project.copyFile(oldFile, newFile, filtering); | |||||
oldFile.delete(); | |||||
} catch (IOException ioe) { | } catch (IOException ioe) { | ||||
String msg = "Failed to copy " + oldSkelFile + " to " + | |||||
newSkelFile + " due to " + ioe.getMessage(); | |||||
String msg = "Failed to copy " + oldFile + " to " + | |||||
newFile + " due to " + ioe.getMessage(); | |||||
throw new BuildException(msg, ioe, location); | throw new BuildException(msg, ioe, location); | ||||
} | } | ||||
} | } | ||||
@@ -90,14 +90,18 @@ public abstract class DefaultRmicAdapter implements RmicAdapter { | |||||
return attributes; | return attributes; | ||||
} | } | ||||
public String getStubClassSuffix() { | |||||
protected String getStubClassSuffix() { | |||||
return "_Stub"; | return "_Stub"; | ||||
} | } | ||||
public String getSkelClassSuffix() { | |||||
protected String getSkelClassSuffix() { | |||||
return "_Skel"; | return "_Skel"; | ||||
} | } | ||||
protected String getTieClassSuffix() { | |||||
return "_Tie"; | |||||
} | |||||
/** | /** | ||||
* This implementation maps *.class to *getStubClassSuffix().class and - if | * This implementation maps *.class to *getStubClassSuffix().class and - if | ||||
* stubversion is not 1.2 - to *getSkelClassSuffix().class. | * stubversion is not 1.2 - to *getSkelClassSuffix().class. | ||||
@@ -321,21 +325,7 @@ public abstract class DefaultRmicAdapter implements RmicAdapter { | |||||
*/ | */ | ||||
private class RmicFileNameMapper implements FileNameMapper { | private class RmicFileNameMapper implements FileNameMapper { | ||||
private GlobPatternMapper stubMapper; | |||||
private GlobPatternMapper skelMapper; | |||||
RmicFileNameMapper() { | |||||
stubMapper = new GlobPatternMapper(); | |||||
stubMapper.setFrom("*.class"); | |||||
stubMapper.setTo("*"+getStubClassSuffix()+".class"); | |||||
// no _Skel file in stub version 1.2 | |||||
if (!"1.2".equals(attributes.getStubVersion())) { | |||||
skelMapper = new GlobPatternMapper(); | |||||
skelMapper.setFrom("*.class"); | |||||
skelMapper.setTo("*"+getSkelClassSuffix()+".class"); | |||||
} | |||||
} | |||||
RmicFileNameMapper() {} | |||||
/** | /** | ||||
* Empty implementation. | * Empty implementation. | ||||
@@ -347,28 +337,55 @@ public abstract class DefaultRmicAdapter implements RmicAdapter { | |||||
public void setTo(String s) {} | public void setTo(String s) {} | ||||
public String[] mapFileName(String name) { | public String[] mapFileName(String name) { | ||||
String[] stubName = stubMapper.mapFileName(name); | |||||
if (stubName == null | |||||
if (name == null | |||||
|| !name.endsWith(".class") | |||||
|| name.endsWith(getStubClassSuffix()+".class") | || name.endsWith(getStubClassSuffix()+".class") | ||||
|| name.endsWith(getSkelClassSuffix()+".class")) { | |||||
// Not a .class file | |||||
|| name.endsWith(getSkelClassSuffix()+".class") | |||||
|| name.endsWith(getTieClassSuffix()+".class")) { | |||||
// Not a .class file or the one we'd generate | |||||
return null; | return null; | ||||
} | } | ||||
String classname = name.replace(File.separatorChar, '.'); | |||||
classname = classname.substring(0, classname.indexOf(".class")); | |||||
String base = name.substring(0, name.indexOf(".class")); | |||||
String classname = base.replace(File.separatorChar, '.'); | |||||
if (attributes.getVerify() && | if (attributes.getVerify() && | ||||
!attributes.isValidRmiRemote(classname)) { | !attributes.isValidRmiRemote(classname)) { | ||||
return null; | return null; | ||||
} | } | ||||
if (skelMapper != null) { | |||||
if (!attributes.getIiop()) { | |||||
if ("1.2".equals(attributes.getStubVersion())) { | |||||
return new String[] { | |||||
base + getStubClassSuffix() + ".class" | |||||
}; | |||||
} else { | |||||
return new String[] { | |||||
base + getStubClassSuffix() + ".class", | |||||
base + getSkelClassSuffix() + ".class", | |||||
}; | |||||
} | |||||
} else { | |||||
int lastSlash = base.lastIndexOf("/"); | |||||
String dirname = ""; | |||||
/* | |||||
* I know, this is not necessary, but I prefer it explicit (SB) | |||||
*/ | |||||
int index = -1; | |||||
if (lastSlash == -1) { | |||||
// no package | |||||
index = 0; | |||||
} else { | |||||
index = lastSlash + 1; | |||||
dirname = base.substring(0, index); | |||||
} | |||||
String filename = base.substring(index); | |||||
return new String[] { | return new String[] { | ||||
stubName[0], | |||||
skelMapper.mapFileName(name)[0] | |||||
dirname + "_" + filename + getStubClassSuffix() + ".class", | |||||
dirname + "_" + filename + getTieClassSuffix() + ".class" | |||||
}; | }; | ||||
} else { | |||||
return stubName; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -93,18 +93,6 @@ public interface RmicAdapter { | |||||
*/ | */ | ||||
public FileNameMapper getMapper(); | public FileNameMapper getMapper(); | ||||
/** | |||||
* Difference between original class file name and the generated | |||||
* stub class. | |||||
*/ | |||||
public String getStubClassSuffix(); | |||||
/** | |||||
* Difference between original class file name and the generated | |||||
* skel class. | |||||
*/ | |||||
public String getSkelClassSuffix(); | |||||
/** | /** | ||||
* The CLASSPATH this rmic process will use. | * The CLASSPATH this rmic process will use. | ||||
*/ | */ | ||||
@@ -136,7 +136,7 @@ | |||||
<blockquote> | <blockquote> | ||||
<ul> | <ul> | ||||
<li><a href="#always-recompiles"> | <li><a href="#always-recompiles"> | ||||
Why does Ant always recompile all my Java files | |||||
Why does Ant always recompile all my Java files? | |||||
</a></li> | </a></li> | ||||
</ul> | </ul> | ||||
</blockquote> | </blockquote> | ||||
@@ -387,7 +387,7 @@ | |||||
<tr><td bgcolor="#828DA6"> | <tr><td bgcolor="#828DA6"> | ||||
<font color="#ffffff" face="arial,helvetica,sanserif"> | <font color="#ffffff" face="arial,helvetica,sanserif"> | ||||
<strong> | <strong> | ||||
Why does Ant always recompile all my Java files | |||||
Why does Ant always recompile all my Java files? | |||||
</strong> | </strong> | ||||
</font> | </font> | ||||
</td></tr> | </td></tr> | ||||
@@ -114,7 +114,7 @@ | |||||
<faqsection title="Using Ant"> | <faqsection title="Using Ant"> | ||||
<faq id="always-recompiles"> | <faq id="always-recompiles"> | ||||
<question>Why does Ant always recompile all my Java files</question> | |||||
<question>Why does Ant always recompile all my Java files?</question> | |||||
<answer> | <answer> | ||||
<p>In order to find out which files should be compiled, Ant | <p>In order to find out which files should be compiled, Ant | ||||