summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2005-11-06 14:32:55 +0000
committermichelou <michelou@epfl.ch>2005-11-06 14:32:55 +0000
commit1634d380f684f605246ddf0eaddae67f7dc1baf8 (patch)
tree6659f736763a14e4f4b890b11f207cdd05e88a9e /sources
parent73fff1f47e73f418ec4a5f13acbd617aa0402e21 (diff)
downloadscala-1634d380f684f605246ddf0eaddae67f7dc1baf8.tar.gz
scala-1634d380f684f605246ddf0eaddae67f7dc1baf8.tar.bz2
scala-1634d380f684f605246ddf0eaddae67f7dc1baf8.zip
- corrected wrong bootclasspath on Windows (use...
- corrected wrong bootclasspath on Windows (use pathSeparator instead of - ":" !!). replaced leading tabs with blanks.
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/tools/scalac/ant/Scalac.java441
1 files changed, 225 insertions, 216 deletions
diff --git a/sources/scala/tools/scalac/ant/Scalac.java b/sources/scala/tools/scalac/ant/Scalac.java
index 2122de8a6a..ba0278deeb 100644
--- a/sources/scala/tools/scalac/ant/Scalac.java
+++ b/sources/scala/tools/scalac/ant/Scalac.java
@@ -1,4 +1,4 @@
-/* ____ ____ ____ ____ ______ *\
+/* ____ ____ ____ ____ ______ *\
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL **
** /_____/\____/\___/\____/____/ **
@@ -13,8 +13,8 @@ import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Vector;
-import org.apache.tools.ant.AntClassLoader;
+import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
@@ -114,11 +114,11 @@ public class Scalac extends MatchingTask {
* @param input The value of <code>origin</code>.
*/
public void setSrcdir(Path input) {
- if (origin == null) {
- origin = input;
- } else {
- origin.append(input);
- }
+ if (origin == null) {
+ origin = input;
+ } else {
+ origin.append(input);
+ }
}
/**
@@ -126,10 +126,10 @@ public class Scalac extends MatchingTask {
* @return An origin path to be configured.
*/
public Path createSrc() {
- if (origin == null) {
- origin = new Path(getProject());
- }
- return origin.createPath();
+ if (origin == null) {
+ origin = new Path(getProject());
+ }
+ return origin.createPath();
}
/**
@@ -137,7 +137,7 @@ public class Scalac extends MatchingTask {
* @param input A reference to an origin path.
*/
public void setSrcref(Reference input) {
- createSrc().setRefid(input);
+ createSrc().setRefid(input);
}
/**
@@ -145,7 +145,7 @@ public class Scalac extends MatchingTask {
* @param input The value of <code>destination</code>.
*/
public void setDestdir(File input) {
- destination = input;
+ destination = input;
}
/**
@@ -153,11 +153,11 @@ public class Scalac extends MatchingTask {
* @param input The value of <code>classpath</code>.
*/
public void setClasspath(Path input) {
- if (classpath == null) {
- classpath = input;
- } else {
- classpath.append(input);
- }
+ if (classpath == null) {
+ classpath = input;
+ } else {
+ classpath.append(input);
+ }
}
/**
@@ -165,10 +165,10 @@ public class Scalac extends MatchingTask {
* @return A class path to be configured.
*/
public Path createClasspath() {
- if (classpath == null) {
- classpath = new Path(getProject());
- }
- return classpath.createPath();
+ if (classpath == null) {
+ classpath = new Path(getProject());
+ }
+ return classpath.createPath();
}
/**
@@ -176,7 +176,7 @@ public class Scalac extends MatchingTask {
* @param input A reference to a class path.
*/
public void setClasspathref(Reference input) {
- createClasspath().setRefid(input);
+ createClasspath().setRefid(input);
}
/**
@@ -184,11 +184,11 @@ public class Scalac extends MatchingTask {
* @param input The value of <code>sourcepath</code>.
*/
public void setSourcepath(Path input) {
- if (sourcepath == null) {
- sourcepath = input;
- } else {
- sourcepath.append(input);
- }
+ if (sourcepath == null) {
+ sourcepath = input;
+ } else {
+ sourcepath.append(input);
+ }
}
/**
@@ -196,10 +196,10 @@ public class Scalac extends MatchingTask {
* @return A source path to be configured.
*/
public Path createSourcepath() {
- if (sourcepath == null) {
- sourcepath = new Path(getProject());
- }
- return sourcepath.createPath();
+ if (sourcepath == null) {
+ sourcepath = new Path(getProject());
+ }
+ return sourcepath.createPath();
}
/**
@@ -207,7 +207,7 @@ public class Scalac extends MatchingTask {
* @param input A reference to a source path.
*/
public void setSourcepathref(Reference input) {
- createSourcepath().setRefid(input);
+ createSourcepath().setRefid(input);
}
/**
@@ -215,11 +215,11 @@ public class Scalac extends MatchingTask {
* @param input The value of <code>bootclasspath</code>.
*/
public void setBootclasspath(Path input) {
- if (bootclasspath == null) {
- bootclasspath = input;
- } else {
- bootclasspath.append(input);
- }
+ if (bootclasspath == null) {
+ bootclasspath = input;
+ } else {
+ bootclasspath.append(input);
+ }
}
/**
@@ -227,10 +227,10 @@ public class Scalac extends MatchingTask {
* @return A source path to be configured.
*/
public Path createBootclasspath() {
- if (bootclasspath == null) {
- bootclasspath = new Path(getProject());
- }
- return bootclasspath.createPath();
+ if (bootclasspath == null) {
+ bootclasspath = new Path(getProject());
+ }
+ return bootclasspath.createPath();
}
/**
@@ -238,7 +238,7 @@ public class Scalac extends MatchingTask {
* @param input A reference to a source path.
*/
public void setBootclasspathref(Reference input) {
- createBootclasspath().setRefid(input);
+ createBootclasspath().setRefid(input);
}
/**
@@ -246,11 +246,11 @@ public class Scalac extends MatchingTask {
* @param input The value of <code>extpath</code>.
*/
public void setExtdirs(Path input) {
- if (extpath == null) {
- extpath = input;
- } else {
- extpath.append(input);
- }
+ if (extpath == null) {
+ extpath = input;
+ } else {
+ extpath.append(input);
+ }
}
/**
@@ -258,10 +258,10 @@ public class Scalac extends MatchingTask {
* @return A source path to be configured.
*/
public Path createExtdirs() {
- if (extpath == null) {
- extpath = new Path(getProject());
- }
- return extpath.createPath();
+ if (extpath == null) {
+ extpath = new Path(getProject());
+ }
+ return extpath.createPath();
}
/**
@@ -269,7 +269,7 @@ public class Scalac extends MatchingTask {
* @param input A reference to a source path.
*/
public void setExtdirsref(Reference input) {
- createExtdirs().setRefid(input);
+ createExtdirs().setRefid(input);
}
/**
@@ -277,7 +277,7 @@ public class Scalac extends MatchingTask {
* @param input The value of <code>encoding</code>.
*/
public void setEncoding(String input) {
- encoding = input;
+ encoding = input;
}
/**
@@ -285,7 +285,7 @@ public class Scalac extends MatchingTask {
* @param input The value for <code>verbose</code>.
*/
public void setVerbose(boolean input) {
- verbose = input;
+ verbose = input;
}
/**
@@ -293,7 +293,7 @@ public class Scalac extends MatchingTask {
* @param input The value for <code>debug</code>.
*/
public void setDebug(boolean input) {
- debug = input;
+ debug = input;
}
/**
@@ -301,7 +301,7 @@ public class Scalac extends MatchingTask {
* @param input The value for <code>usepredefs</code>.
*/
public void setUsepredefs(boolean input) {
- usepredefs = input;
+ usepredefs = input;
}
/**
@@ -309,7 +309,7 @@ public class Scalac extends MatchingTask {
* @param input The value for <code>useimport</code>.
*/
public void setUseimports(boolean input) {
- useimports = input;
+ useimports = input;
}
/**
@@ -317,7 +317,7 @@ public class Scalac extends MatchingTask {
* @param input The value for <code>force</code>.
*/
public void setForce(ForceMode input) {
- force = input.getValue();
+ force = input.getValue();
}
// ###################################################################
@@ -326,11 +326,13 @@ public class Scalac extends MatchingTask {
/**
* Generates a build error. Error location will be the current task in the ant file.
- * @param message The message of the error. This message should be end-user readable.
- * @throws org.apache.tools.ant.BuildException The build error exception. Will be thrown in all conditions.
+ *
+ * @param message The message of the error. This message should be end-user readable.
+ * @throws org.apache.tools.ant.BuildException The build error exception.
+ * Will be thrown in all conditions.
*/
private void error(String message) throws BuildException {
- throw new BuildException(message, getLocation());
+ throw new BuildException(message, getLocation());
}
/**
@@ -338,178 +340,185 @@ public class Scalac extends MatchingTask {
*/
public void execute() throws BuildException {
- // Tests if all mandatory attributes are set and valid.
- if (origin == null) error("Attribute 'srcdir' is not set.");
- if (origin.size() == 0) error("Attribute 'srcdir' is not set.");
- if (destination != null && !destination.isDirectory())
- error("Attribute 'destdir' does not refer to an existing directory.");
-
- Vector sourceFilesList = new Vector();
-
- // Scans source directories to build up a compile lists.
- // If force is false, only files were the .class file in destination is newer than
- // the .suffix file will be used.
- String[] originList = origin.list();
- for (int i = 0; i < originList.length; i++) {
- File originDir = getProject().resolveFile(originList[i]);
- if (!originDir.exists()) {
- log("Element '" + originDir.getPath() + "' in attribute 'srcdir' does not refer to an existing directory.", Project.MSG_WARN);
- break;
- }
- DirectoryScanner originDirScanner = this.getDirectoryScanner(originDir);
- String[] files = originDirScanner.getIncludedFiles();
-
- if (force.compareToIgnoreCase("always") == 0) {
- addFilesToSourceList(files, originDir, sourceFilesList);
- } else {
- GlobPatternMapper mapper = new GlobPatternMapper();
- mapper.setTo("*.class");
- mapper.setFrom("*.scala");
- SourceFileScanner scanner = new SourceFileScanner(this);
- String[] newFiles = scanner.restrict(files, originDir, destination, mapper);
- if (force.compareToIgnoreCase("changed") == 0 && (newFiles.length > 0)) {
- addFilesToSourceList(files, originDir, sourceFilesList);
- } else if (force.compareToIgnoreCase("never") == 0) {
- addFilesToSourceList(newFiles, originDir, sourceFilesList);
- }
- }
-
-
- }
-
- if (sourceFilesList.isEmpty()) {
- log("No files selected for compilation");
- } else {
- log("Compiling " + sourceFilesList.size() + " source file" + (sourceFilesList.size() == 1 ? "" : "s") + (destination != null ? " to " + destination.toString() : ""));
- }
-
- // Builds-up the compilation settings for Scalac with the existing Ant parameters.
- Reporter reporter = new ConsoleReporter();
- CompilerCommand command = new CompilerCommand(SCALA_PRODUCT, SCALA_VERSION, reporter, new CompilerPhases$class());
- if (destination != null) command.outpath.value = destination.getAbsolutePath();
- if (classpath != null) command.classpath.value = makeAbsolutePath(classpath, "classpath");
- if (sourcepath != null) {
- command.sourcepath.value = makeAbsolutePath(sourcepath, "sourcepath");
- } else {
- command.sourcepath.value = destination.getAbsolutePath();
- }
- // The bootclasspath needs to be treated specially.
- // When no bootclasspath is provided, the classpath of the current classloader is used:
- // This is where the scala classes should be.
- // Furthermore, the source files for the library must be available in the bootclasspath too.
- // Notice also how the bootclasspath must finish with a ":" for it to work.
- Path baseBootclasspath;
- if (bootclasspath != null) {
- baseBootclasspath = bootclasspath;
- } else {
- baseBootclasspath = getClassLoaderClasspath(this.getClass().getClassLoader());
- }
- command.bootclasspath.value = makeAbsolutePath(baseBootclasspath, "bootclasspath") + ":";
- if (!containsScala(command.bootclasspath.value)) {
- log("Bootclasspath does not contain a recognized Scala distribution. This might cause unexpected errors (Stack Overflow)", Project.MSG_WARN);
- }
- if (extpath != null) command.extdirs.value = makeAbsolutePath(extpath, "extpath");
- if (encoding != null) command.encoding.value = encoding;
- command.verbose.value = verbose;
- command.debug.value = debug;
- command.noimports.value = !useimports;
- command.nopredefs.value = !usepredefs;
- Timer timer = scalac.Global.getTimer(reporter);
-
- // Compiles the actual code
- Global$class compiler = new Global$class(command, timer, false);
-
- String[] stringArray = new String[sourceFilesList.size()];
- try {
- timer.start();
- CompilationUnit[] classes = compiler.compile((String[])sourceFilesList.toArray(stringArray), false);
- if (reporter.errors() > 0) {
- error("Compile failed with " + reporter.errors() + " error" + (reporter.errors() == 1 ? "" : "s") + "; see the compiler error output for details.");
- }
- compiler.dump(classes);
- } catch (AbortError exception) {
- if (debug) exception.printStackTrace();
- error("Compile failed because of an internal compiler error; see the error output for details.");
- } finally {
- timer.stop("Compile time");
- }
- if (reporter.warnings() > 0) {
- log("Compile suceeded with " + reporter.errors() + " warning" + (reporter.warnings() == 1 ? "" : "s") + "; see the compiler output for details.");
- }
-
+ // Tests if all mandatory attributes are set and valid.
+ if (origin == null) error("Attribute 'srcdir' is not set.");
+ if (origin.size() == 0) error("Attribute 'srcdir' is not set.");
+ if (destination != null && !destination.isDirectory())
+ error("Attribute 'destdir' does not refer to an existing directory.");
+
+ Vector sourceFilesList = new Vector();
+
+ // Scans source directories to build up a compile lists.
+ // If force is false, only files were the .class file in destination
+ // is newer than the .suffix file will be used.
+ String[] originList = origin.list();
+ for (int i = 0; i < originList.length; i++) {
+ File originDir = getProject().resolveFile(originList[i]);
+ if (!originDir.exists()) {
+ log("Element '" + originDir.getPath() + "' in attribute 'srcdir' does not refer to an existing directory.", Project.MSG_WARN);
+ break;
+ }
+ DirectoryScanner originDirScanner = this.getDirectoryScanner(originDir);
+ String[] files = originDirScanner.getIncludedFiles();
+
+ if (force.compareToIgnoreCase("always") == 0) {
+ addFilesToSourceList(files, originDir, sourceFilesList);
+ }
+ else {
+ GlobPatternMapper mapper = new GlobPatternMapper();
+ mapper.setTo("*.class");
+ mapper.setFrom("*.scala");
+ SourceFileScanner scanner = new SourceFileScanner(this);
+ String[] newFiles = scanner.restrict(files, originDir, destination, mapper);
+ if (force.compareToIgnoreCase("changed") == 0 && (newFiles.length > 0)) {
+ addFilesToSourceList(files, originDir, sourceFilesList);
+ }
+ else if (force.compareToIgnoreCase("never") == 0) {
+ addFilesToSourceList(newFiles, originDir, sourceFilesList);
+ }
+ }
+ }
+
+ if (sourceFilesList.isEmpty()) {
+ log("No files selected for compilation");
+ }
+ else {
+ log("Compiling " + sourceFilesList.size() + " source file" + (sourceFilesList.size() == 1 ? "" : "s") + (destination != null ? " to " + destination.toString() : ""));
+ }
+
+ // Builds-up the compilation settings for Scalac with the existing Ant parameters.
+ Reporter reporter = new ConsoleReporter();
+ CompilerCommand command = new CompilerCommand(SCALA_PRODUCT, SCALA_VERSION, reporter, new CompilerPhases$class());
+ if (destination != null) command.outpath.value = destination.getAbsolutePath();
+ if (classpath != null) command.classpath.value = makeAbsolutePath(classpath, "classpath");
+ if (sourcepath != null) {
+ command.sourcepath.value = makeAbsolutePath(sourcepath, "sourcepath");
+ }
+ else {
+ command.sourcepath.value = destination.getAbsolutePath();
+ }
+ // The bootclasspath needs to be treated specially.
+ // When no bootclasspath is provided, the classpath of the current classloader is used:
+ // This is where the scala classes should be.
+ // Furthermore, the source files for the library must be available in the bootclasspath too.
+ // Notice also how the bootclasspath must finish with a ":" for it to work.
+ Path baseBootclasspath;
+ if (bootclasspath != null) {
+ baseBootclasspath = bootclasspath;
+ }
+ else {
+ baseBootclasspath = getClassLoaderClasspath(this.getClass().getClassLoader());
+ }
+ command.bootclasspath.value =
+ makeAbsolutePath(baseBootclasspath, "bootclasspath") + File.pathSeparator;
+ if (!containsScala(command.bootclasspath.value)) {
+ log("Bootclasspath does not contain a recognized Scala distribution. This might cause unexpected errors (Stack Overflow)", Project.MSG_WARN);
+ }
+ if (extpath != null) command.extdirs.value = makeAbsolutePath(extpath, "extpath");
+ if (encoding != null) command.encoding.value = encoding;
+ command.verbose.value = verbose;
+ command.debug.value = debug;
+ command.noimports.value = !useimports;
+ command.nopredefs.value = !usepredefs;
+ Timer timer = scalac.Global.getTimer(reporter);
+
+ // Compiles the actual code
+ Global$class compiler = new Global$class(command, timer, false);
+
+ String[] stringArray = new String[sourceFilesList.size()];
+ try {
+ timer.start();
+ CompilationUnit[] classes = compiler.compile((String[])sourceFilesList.toArray(stringArray), false);
+ if (reporter.errors() > 0) {
+ error("Compile failed with " + reporter.errors() + " error" + (reporter.errors() == 1 ? "" : "s") + "; see the compiler error output for details.");
+ }
+ compiler.dump(classes);
+ }
+ catch (AbortError exception) {
+ if (debug) exception.printStackTrace();
+ error("Compile failed because of an internal compiler error; see the error output for details.");
+ }
+ finally {
+ timer.stop("Compile time");
+ }
+ if (reporter.warnings() > 0) {
+ log("Compile suceeded with " + reporter.errors() + " warning" + (reporter.warnings() == 1 ? "" : "s") + "; see the compiler output for details.");
+ }
}
private void addFilesToSourceList(String[] files, File originDir, Vector sourceFilesList) {
- for (int i = 0; i < files.length; i++) {
- String sourceFile = fileUtils.resolveFile(originDir, files[i]).toString();
- log(sourceFile, Project.MSG_VERBOSE);
- sourceFilesList.add(sourceFile);
- }
+ for (int i = 0; i < files.length; i++) {
+ String sourceFile = fileUtils.resolveFile(originDir, files[i]).toString();
+ log(sourceFile, Project.MSG_VERBOSE);
+ sourceFilesList.add(sourceFile);
+ }
}
private String makeAbsolutePath(Path path, String pathName) {
- String result = "";
- String[] pathList = path.list();
- for (int i = 0; i < pathList.length; i++) {
- File pathFile = new File(pathList[i]);
- if (pathFile.exists()) {
- result = result + ((result == "") ? "" : File.pathSeparator) + pathFile.getAbsolutePath();
- } else {
- log("Element '" + pathFile.toString() + "' in " + pathName + " does not exist.", Project.MSG_WARN);
- result = result + ((result == "") ? "" : File.pathSeparator) + pathFile.toString();
- }
- }
- return result;
+ String result = "";
+ String[] pathList = path.list();
+ for (int i = 0; i < pathList.length; i++) {
+ File pathFile = new File(pathList[i]);
+ if (pathFile.exists()) {
+ result = result + ((result == "") ? "" : File.pathSeparator) + pathFile.getAbsolutePath();
+ }
+ else {
+ log("Element '" + pathFile.toString() + "' in " + pathName + " does not exist.", Project.MSG_WARN);
+ result = result + ((result == "") ? "" : File.pathSeparator) + pathFile.toString();
+ }
+ }
+ return result;
}
private Path getClassLoaderClasspath(ClassLoader classLoader) throws BuildException {
- Path classLoaderClasspath = new Path(getProject());
- ClassLoader parentClassLoader = classLoader.getParent();
- String classloaderName = classLoader.getClass().getName();
- boolean isURLClassLoader = classloaderName.endsWith("URLClassLoader");
- boolean isAntClassLoader = classloaderName.endsWith("AntClassLoader2") || classloaderName.endsWith("AntClassLoader");
- if (isURLClassLoader) {
- URL[] urls = ((URLClassLoader) classLoader).getURLs();
- for (int i = 0; i < urls.length; i++) {
- classLoaderClasspath.append(new Path(getProject(), urls[i].toString()));
- }
- } else if (isAntClassLoader) {
- String[] paths = ((AntClassLoader) classLoader).getClasspath().split(File.pathSeparator);
- for (int i = 0; i < paths.length; i++) {
- classLoaderClasspath.append(new Path(getProject(), paths[i]));
- }
- }
- if (parentClassLoader != null && parentClassLoader != classLoader) {
- classLoaderClasspath.append(getClassLoaderClasspath(parentClassLoader));
- }
- return classLoaderClasspath;
+ Path classLoaderClasspath = new Path(getProject());
+ ClassLoader parentClassLoader = classLoader.getParent();
+ String classloaderName = classLoader.getClass().getName();
+ boolean isURLClassLoader = classloaderName.endsWith("URLClassLoader");
+ boolean isAntClassLoader = classloaderName.endsWith("AntClassLoader2") || classloaderName.endsWith("AntClassLoader");
+ if (isURLClassLoader) {
+ URL[] urls = ((URLClassLoader) classLoader).getURLs();
+ for (int i = 0; i < urls.length; i++) {
+ classLoaderClasspath.append(new Path(getProject(), urls[i].toString()));
+ }
+ }
+ else if (isAntClassLoader) {
+ String[] paths = ((AntClassLoader) classLoader).getClasspath().split(File.pathSeparator);
+ for (int i = 0; i < paths.length; i++) {
+ classLoaderClasspath.append(new Path(getProject(), paths[i]));
+ }
+ }
+ if (parentClassLoader != null && parentClassLoader != classLoader) {
+ classLoaderClasspath.append(getClassLoaderClasspath(parentClassLoader));
+ }
+ return classLoaderClasspath;
}
private boolean containsScala(String path) {
- boolean containsLibrary = false;
- boolean containsTools = false;
- String[] paths = path.split(File.pathSeparator);
- for (int i = 0; i < paths.length; i++) {
- if (paths[i].endsWith("scala.jar") || paths[i].endsWith("scala")) {
- containsLibrary = true;
- }
- if (paths[i].endsWith("tools.jar") || paths[i].endsWith("tools")) {
- containsTools = true;
- }
- }
- return containsLibrary && containsTools;
+ boolean containsLibrary = false;
+ boolean containsTools = false;
+ String[] paths = path.split(File.pathSeparator);
+ for (int i = 0; i < paths.length; i++) {
+ if (paths[i].endsWith("scala.jar") || paths[i].endsWith("scala")) {
+ containsLibrary = true;
+ }
+ if (paths[i].endsWith("tools.jar") || paths[i].endsWith("tools")) {
+ containsTools = true;
+ }
+ }
+ return containsLibrary && containsTools;
}
/**
* Enumerated attribute with the values "never", "always", "changed".
*/
public static class ForceMode extends EnumeratedAttribute {
- /**
- * @see EnumeratedAttribute#getValues
- */
- public String[] getValues() {
- return new String[] {"never", "always", "changed"};
- }
+ /**
+ * @see EnumeratedAttribute#getValues
+ */
+ public String[] getValues() {
+ return new String[] {"never", "always", "changed"};
+ }
}
}