This patch allows you to explicitly set the compiler's -sourcepath argument.
Currently, the <javac> task uses the srcdir as the sourcepath, which is a
good default most of the time, but not always right. This has caused
problems for us, and it's also bug #5268, and it's also suggested by Conor
at the end of this message
http://marc.theaimsgroup.com/?l=ant-dev&m=86951893308055&w=2. Doc patches
included. If the sourcepath is not set explicitly, it falls back to the old
behavior, both for backwards compatibility, and because it's ususally a good
default value, as I mentioned.
Alex
? jakarta-ant/sourcepath.patch.txt
Index: jakarta-ant/docs/manual/CoreTasks/javac.html
===================================================================
RCS file: /home/cvspublic/jakarta-ant/docs/manual/CoreTasks/javac.html,v
retrieving revision 1.21
diff -c -r1.21 javac.html
*** jakarta-ant/docs/manual/CoreTasks/javac.html 26 Dec 2001 20:35:14
-0000 1.21
--- jakarta-ant/docs/manual/CoreTasks/javac.html 3 Jan 2002 19:10:24
-0000
***************
*** 117,122 ****
--- 117,127 ----
<td align="center" valign="top">No</td>
</tr>
<tr>
+ <td valign="top">sourcepath</td>
+ <td valign="top">the sourcepath to use; defaults to the value of the
srcdir attribute (or <code><src></code> elements).</td>
+ <td align="center" valign="top">No</td>
+ </tr>
+ <tr>
<td valign="top">bootclasspath</td>
<td valign="top">location of bootstrap class files.</td>
<td align="center" valign="top">No</td>
***************
*** 128,133 ****
--- 133,144 ----
<td align="center" valign="top">No</td>
</tr>
<tr>
+ <td valign="top">sourcepathref</td>
+ <td valign="top">the sourcepath to use, given as a
+ <a href="../using.html#references">reference</a> to a PATH defined
elsewhere.</td>
+ <td align="center" valign="top">No</td>
+ </tr>
+ <tr>
<td valign="top">bootclasspathref</td>
<td valign="top">location of bootstrap class files, given as a
<a href="../using.html#references">reference</a> to a PATH defined
elsewhere.</td>
***************
*** 255,268 ****
(<code>dir</code> becomes <code>srcdir</code>) as well as the nested
<code><include></code>, <code><exclude></code> and
<code><patternset></code> elements.</p>
! <h4><code>src</code>, <code>classpath</code>, <code>bootclasspath</code> and
<code>extdirs</code></h4>
<p><code>Javac</code>'s <i>srcdir</i>, <i>classpath</i>,
! <i>bootclasspath</i> and <i>extdirs</i> attributes are <a
href="../using.html#path">path-like structures</a> and can also be set via
nested
! <code><src></code>,
! <code><classpath></code>,
! <code><bootclasspath></code> and
! <code><extdirs></code> elements, respectively.</p>
<h4>compilerarg</h4>
--- 266,281 ----
(<code>dir</code> becomes <code>srcdir</code>) as well as the nested
<code><include></code>, <code><exclude></code> and
<code><patternset></code> elements.</p>
! <h4><code>src</code>, <code>classpath</code>, <code>sourcepath</code>,
! <code>bootclasspath</code> and <code>extdirs</code></h4>
<p><code>Javac</code>'s <i>srcdir</i>, <i>classpath</i>,
! <i>sourcepath</i>, <i>bootclasspath</i> and <i>extdirs</i> attributes are <a
href="../using.html#path">path-like structures</a> and can also be set via
nested
! <code><src></code>,
! <code><classpath></code>,
! <code><sourcepath></code>,
! <code><bootclasspath></code> and
! <code><extdirs></code> elements, respectively.</p>
<h4>compilerarg</h4>
Index: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java,v
retrieving revision 1.78
diff -c -r1.78 Javac.java
*** jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java 7 Dec
2001 20:45:38 -0000 1.78
--- jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java 3 Jan
2002 19:10:43 -0000
***************
*** 111,116 ****
--- 111,117 ----
private Path src;
private File destDir;
private Path compileClasspath;
+ private Path compileSourcepath;
private String encoding;
private boolean debug = false;
private boolean optimize = false;
***************
*** 220,225 ****
--- 221,259 ----
*/
public File getDestdir() {
return destDir;
+ }
+
+ /**
+ * Set the sourcepath to be used for this compilation.
+ */
+ public void setSourcepath(Path sourcepath) {
+ if (compileSourcepath == null) {
+ compileSourcepath = sourcepath;
+ } else {
+ compileSourcepath.append(sourcepath);
+ }
+ }
+
+ /** Gets the sourcepath to be used for this compilation. */
+ public Path getSourcepath() {
+ return compileSourcepath;
+ }
+
+ /**
+ * Maybe creates a nested sourcepath element.
+ */
+ public Path createSourcepath() {
+ if (compileSourcepath == null) {
+ compileSourcepath = new Path(project);
+ }
+ return compileSourcepath.createPath();
+ }
+
+ /**
+ * Adds a reference to a CLASSPATH defined elsewhere.
+ */
+ public void setSourcepathRef(Reference r) {
+ createSourcepath().setRefid(r);
}
/**
Index:
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java,v
retrieving revision 1.18
diff -c -r1.18 DefaultCompilerAdapter.java
***
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
21 Nov 2001 23:09:39 -0000 1.18
---
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
3 Jan 2002 19:10:43 -0000
***************
*** 97,102 ****
--- 97,103 ----
protected Path bootclasspath;
protected Path extdirs;
protected Path compileClasspath;
+ protected Path compileSourcepath;
protected Project project;
protected Location location;
protected boolean includeAntRuntime;
***************
*** 125,130 ****
--- 126,132 ----
extdirs = attributes.getExtdirs();
compileList = attributes.getFileList();
compileClasspath = attributes.getClasspath();
+ compileSourcepath = attributes.getSourcepath();
project = attributes.getProject();
location = attributes.getLocation();
includeAntRuntime = attributes.getIncludeantruntime();
***************
*** 184,189 ****
--- 186,199 ----
protected Commandline setupJavacCommandlineSwitches(Commandline cmd,
boolean
useDebugLevel) {
Path classpath = getCompileClasspath();
+ // For -sourcepath, use the "sourcepath" value if present.
+ // Otherwise default to the "srcdir" value.
+ Path sourcepath = null;
+ if (compileSourcepath != null) {
+ sourcepath = compileSourcepath;
+ } else {
+ sourcepath = src;
+ }
// we cannot be using Java 1.0 when forking, so we only have to
// distinguish between Java 1.1, and Java 1.2 and higher, as Java 1.1
***************
*** 237,248 ****
cp.addExtdirs(extdirs);
}
cp.append(classpath);
! cp.append(src);
cmd.createArgument().setPath(cp);
} else {
cmd.createArgument().setPath(classpath);
! cmd.createArgument().setValue("-sourcepath");
! cmd.createArgument().setPath(src);
if (target != null) {
cmd.createArgument().setValue("-target");
cmd.createArgument().setValue(target);
--- 247,261 ----
cp.addExtdirs(extdirs);
}
cp.append(classpath);
! cp.append(sourcepath);
cmd.createArgument().setPath(cp);
} else {
cmd.createArgument().setPath(classpath);
! // If the buildfile specifies sourcepath="", then don't output
any sourcepath.
! if (sourcepath.size() > 0) {
! cmd.createArgument().setValue("-sourcepath");
! cmd.createArgument().setPath(sourcepath);
! }
if (target != null) {
cmd.createArgument().setValue("-target");
cmd.createArgument().setValue(target);
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>