From 271c73b91cf469886bc023adde1bd592600518b3 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 14 Feb 2002 17:34:19 +0000 Subject: [PATCH] Allow -sourcepath for to be set explicitly. PR: 5268 Submitted by: Alex Rosen git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271351 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 2 ++ docs/manual/CoreTasks/javac.html | 27 +++++++++++---- .../org/apache/tools/ant/taskdefs/Javac.java | 34 +++++++++++++++++++ .../compilers/DefaultCompilerAdapter.java | 21 +++++++++--- 4 files changed, 73 insertions(+), 11 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 024ff3226..8e8d9d0b6 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -161,6 +161,8 @@ Other changes: * now supports a new "prefix" attribute to prefix properties set. +* you can now specify the -sourcepath for explicitly. + Changes from Ant 1.4 to Ant 1.4.1 =========================================== diff --git a/docs/manual/CoreTasks/javac.html b/docs/manual/CoreTasks/javac.html index 8701e4b75..4655d6fcc 100644 --- a/docs/manual/CoreTasks/javac.html +++ b/docs/manual/CoreTasks/javac.html @@ -116,6 +116,11 @@ invoking the compiler.

the classpath to use. No + + sourcepath + the sourcepath to use; defaults to the value of the srcdir attribute (or <src> elements). + No + bootclasspath location of bootstrap class files. @@ -127,6 +132,12 @@ invoking the compiler.

reference to a PATH defined elsewhere. No + + sourcepathref + the sourcepath to use, given as a + reference to a PATH defined elsewhere. + No + bootclasspathref location of bootstrap class files, given as a @@ -255,14 +266,16 @@ supports all attributes of <fileset> (dir becomes srcdir) as well as the nested <include>, <exclude> and <patternset> elements.

-

src, classpath, bootclasspath and extdirs

+

src, classpath, sourcepath, +bootclasspath and extdirs

Javac's srcdir, classpath, -bootclasspath and extdirs attributes are sourcepath, bootclasspath and extdirs attributes are path-like structures and can also be set via nested -<src>, -<classpath>, -<bootclasspath> and -<extdirs> elements, respectively.

+<src>, +<classpath>, +<sourcepath>, +<bootclasspath> and +<extdirs> elements, respectively.

compilerarg

@@ -425,7 +438,7 @@ build.compiler.warnings is "true" while all others are "false&quo
-

Copyright © 2001 Apache Software Foundation. All rights +

Copyright © 2001-2002 Apache Software Foundation. All rights Reserved.

diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java index cfeba0f4f..f7a67669a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javac.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java @@ -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. */ diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java index 825b4175f..3d28fe2e8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java @@ -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);