Browse Source

Allow -sourcepath for <javac> to be set explicitly.

PR: 5268
Submitted by:	Alex Rosen <arosen@silverstream.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271351 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
271c73b91c
4 changed files with 73 additions and 11 deletions
  1. +2
    -0
      WHATSNEW
  2. +20
    -7
      docs/manual/CoreTasks/javac.html
  3. +34
    -0
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  4. +17
    -4
      src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java

+ 2
- 0
WHATSNEW View File

@@ -161,6 +161,8 @@ Other changes:
* <tstamp> now supports a new "prefix" attribute to prefix properties set.

* you can now specify the -sourcepath for <javac> explicitly.

Changes from Ant 1.4 to Ant 1.4.1
===========================================



+ 20
- 7
docs/manual/CoreTasks/javac.html View File

@@ -116,6 +116,11 @@ invoking the compiler.</p>
<td valign="top">the classpath to use.</td>
<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>&lt;src&gt;</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>
@@ -127,6 +132,12 @@ invoking the compiler.</p>
<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">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
@@ -255,14 +266,16 @@ supports all attributes of <code>&lt;fileset&gt;</code>
(<code>dir</code> becomes <code>srcdir</code>) as well as the nested
<code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
<code>&lt;patternset&gt;</code> elements.</p>
<h4><code>src</code>, <code>classpath</code>, <code>bootclasspath</code> and <code>extdirs</code></h4>
<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>bootclasspath</i> and <i>extdirs</i> attributes are <a
<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>&lt;src&gt</code>,
<code>&lt;classpath&gt</code>,
<code>&lt;bootclasspath&gt</code> and
<code>&lt;extdirs&gt</code> elements, respectively.</p>
<code>&lt;src&gt;</code>,
<code>&lt;classpath&gt;</code>,
<code>&lt;sourcepath&gt;</code>,
<code>&lt;bootclasspath&gt;</code> and
<code>&lt;extdirs&gt;</code> elements, respectively.</p>

<h4>compilerarg</h4>

@@ -425,7 +438,7 @@ build.compiler.warnings is &quot;true&quot; while all others are &quot;false&quo
</tr>
</table>
<hr>
<p align="center">Copyright &copy; 2001 Apache Software Foundation. All rights
<p align="center">Copyright &copy; 2001-2002 Apache Software Foundation. All rights
Reserved.</p>

</body>


+ 34
- 0
src/main/org/apache/tools/ant/taskdefs/Javac.java View File

@@ -111,6 +111,7 @@ public class Javac extends MatchingTask {
private Path src;
private File destDir;
private Path compileClasspath;
private Path compileSourcepath;
private String encoding;
private boolean debug = false;
private boolean optimize = false;
@@ -222,6 +223,39 @@ public class Javac extends MatchingTask {
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);
}

/**
* Set the classpath to be used for this compilation.
*/


+ 17
- 4
src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -97,6 +97,7 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
protected Path bootclasspath;
protected Path extdirs;
protected Path compileClasspath;
protected Path compileSourcepath;
protected Project project;
protected Location location;
protected boolean includeAntRuntime;
@@ -125,6 +126,7 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
extdirs = attributes.getExtdirs();
compileList = attributes.getFileList();
compileClasspath = attributes.getClasspath();
compileSourcepath = attributes.getSourcepath();
project = attributes.getProject();
location = attributes.getLocation();
includeAntRuntime = attributes.getIncludeantruntime();
@@ -184,6 +186,14 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
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,12 +247,15 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
cp.addExtdirs(extdirs);
}
cp.append(classpath);
cp.append(src);
cp.append(sourcepath);
cmd.createArgument().setPath(cp);
} else {
cmd.createArgument().setPath(classpath);
cmd.createArgument().setValue("-sourcepath");
cmd.createArgument().setPath(src);
// 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);


Loading…
Cancel
Save