summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-02-16 10:16:43 +0000
committerburaq <buraq@epfl.ch>2004-02-16 10:16:43 +0000
commite1f634c04cd8f33ecf3a1be2bea1fd6ee1a360b3 (patch)
treec24096c40737a1dbfc92e096ec01a6d7cc8bd917
parent07f96aac397e7eff4ed59884b968722b48895b1b (diff)
downloadscala-e1f634c04cd8f33ecf3a1be2bea1fd6ee1a360b3.tar.gz
scala-e1f634c04cd8f33ecf3a1be2bea1fd6ee1a360b3.tar.bz2
scala-e1f634c04cd8f33ecf3a1be2bea1fd6ee1a360b3.zip
fixes classpath problems, command line switch h...
fixes classpath problems, command line switch handling
-rw-r--r--sources/scala/tools/scala4ant/AntAdaptor.scala187
-rw-r--r--sources/scala/tools/scala4ant/AntTask.scala257
2 files changed, 234 insertions, 210 deletions
diff --git a/sources/scala/tools/scala4ant/AntAdaptor.scala b/sources/scala/tools/scala4ant/AntAdaptor.scala
index 56f9c58733..56938c2266 100644
--- a/sources/scala/tools/scala4ant/AntAdaptor.scala
+++ b/sources/scala/tools/scala4ant/AntAdaptor.scala
@@ -14,97 +14,146 @@ import java.io.IOException;
package scala.tools.scala4ant {
- /** a compiler adaptor for Scalac.
+ /** Scala compiler adaptor. adapted from (see below for additions to Scala license)
+ * jaco.framework.ant.AntCompilerAdaptor (c) Matthias Zenger, and
+ * org.apache.tools.ant.taskdefs.DefaultCompilerAdapter
+ * (c) the Apache Software Foundation
*
- * author: Burak Emir
- * adapted from package jaco.framework.ant.AntCompilerAdaptor
- * (part of Matthias Zenger's jaco framework)
- */
+ * @author Burak Emir
+ * @version 1.6
+ * $Id$
+ */
class AntAdaptor extends DefaultCompilerAdapter {
- var source:String = _;
- var mytarget:String = _;
-
final val PRODUCT = System.getProperty("scala.product", "scalac");
final val VERSION = System.getProperty("scala.version", "unknown version");
- def runCompiler(args:Array[String]) = {
- var result = true;
-
- // dirty work to get rid of debugging (-g) option, set in setupJavac...
-
- val nargs = new Array[ String ]( args.length - 1 );
- var j = 0;
- for( val i <- List.range( 0, args.length ) ) {
- if( !args( i ).startsWith("-g") ) {
- //System.err.print( args[ i ] +" ")
- nargs( j ) = args( i );
- j = j + 1;
- }
+ def runCompiler( args:Array[String] ) = {
+ var result = true;
+ val reporter = new Reporter();
+ val command = new CompilerCommand(PRODUCT,
+ VERSION,
+ reporter,
+ new CompilerPhases());
+ if( command.parse( args ) && command.files.list.size() > 0 ) {
+ val global = new Global(command);
+ try {
+ global.compile(command.files.toArray(), false);
+ } catch {
+ case e:Throwable => {
+ /* e.printStackTrace(); */
+ result = false;
+ throw new BuildException(e.getMessage());
+ }
}
-
- // compile
- val reporter = new Reporter();
- val command = new CompilerCommand(PRODUCT, VERSION, reporter, new CompilerPhases());
- if( command.parse(nargs) && command.files.list.size() > 0 ) {
- val global = new Global(command);
- try {
- global.compile(command.files.toArray(), false);
- } catch {
- case e:Throwable => {
- e.printStackTrace();
- result = false;
- throw new BuildException(e.getMessage());
- }
- }
- global.stop("total");
- global.reporter.printSummary();
- /*
- PizzaSettings js = new PizzaSettings();
- js.parse(args);
- return js.JavaContext().JavaCompiler().compile();
- */
- }
- result;
-
+ global.stop("total");
+ global.reporter.printSummary();
+ }
+ result;
}
- def compilerName() = "scalac";
+ def compilerName() = "scalac";
override def setJavac( attributes:Javac ) = {
super.setJavac( attributes );
- val myattribs = attributes.asInstanceOf[AntTask];
- source = myattribs.getSource();
- mytarget = myattribs.getTarget();
-
}
def execute() = {
- attributes.log("Using " + compilerName() + " as scala compiler", Project.MSG_VERBOSE);
+ attributes.log("Using " + compilerName() + " as scala compiler",
+ Project.MSG_VERBOSE);
runCompiler( setupScalacCommand().getArguments() );
}
def setupScalacCommand() = {
- val cmd = new Commandline();
- setupJavacCommandlineSwitches(cmd);
- //setupScalacCommandlineSwitches(cmd);
- logAndAddFilesToCompile(cmd);
- cmd
- }
+ val cmd = new Commandline();
- /*
- def setupScalacCommandlineSwitches( cmd:Commandline ) = {
- if (source != null) {
- cmd.createArgument().setValue("-source");
- cmd.createArgument().setValue(source);
- }
- if (target != null) {
- cmd.createArgument().setValue("-target");
- cmd.createArgument().setValue(target);
+ if( destDir != null ) {
+ cmd.createArgument().setValue("-d");
+ cmd.createArgument().setFile(destDir);
+ }
+
+ this.includeJavaRuntime = true;
+
+ if( compileClasspath != null ) {
+ cmd.createArgument().setValue("-classpath");
+ cmd.createArgument().setPath( getCompileClasspath() );
+ }
+
+ cmd.createArgument().setValue("-sourcepath");
+
+ cmd.createArgument().setPath(
+ if (compileSourcepath != null) {
+ compileSourcepath;
+ } else {
+ src;
}
- }
- */
+ );
+ if (bootclasspath != null && bootclasspath.size() > 0) {
+ cmd.createArgument().setValue("-bootclasspath");
+ cmd.createArgument().setPath(bootclasspath);
+ }
+
+ if (extdirs != null && extdirs.size() > 0) {
+ cmd.createArgument().setValue("-extdirs");
+ cmd.createArgument().setPath(extdirs);
+ }
+
+ logAndAddFilesToCompile(cmd);
+ cmd
+ }
}
}
+
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
+ * reserved.
+ * Copyright (c) 2000-2002 Matthias Zenger. All rights reserved.
+ * Copyright (c) 2003-2004 Burak Emir. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+*/
diff --git a/sources/scala/tools/scala4ant/AntTask.scala b/sources/scala/tools/scala4ant/AntTask.scala
index 569cdd85fc..b8c5dc08b2 100644
--- a/sources/scala/tools/scala4ant/AntTask.scala
+++ b/sources/scala/tools/scala4ant/AntTask.scala
@@ -5,166 +5,141 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Javac;
import org.apache.tools.ant.util._;
import java.io.File;
-import java.util._;
+/*import java.util._; */
-
-/** Scala AntTask.
- *
- * adapted from package jaco.framework.ant.AntCompilerTask
- * (part of Matthias Zenger's jaco framework)
- *
- * @todo deduce path to scala sources using path to tools.jar (brittle)
+/** Scala AntTask. adapted from (see below for additions to Scala license)
+ * jaco.framework.ant.AntCompilerTask (c) Matthias Zenger, and
+ * org.apache.tools.ant.taskdefs.Javac (c) the Apache Software Foundation
*
* @author Burak Emir
- * @version 1.5
+ * @version 1.6
* $Id$
*/
class AntTask extends Javac {
- private var suffixes = "scala";
- private var force = false;
- private var source:String = null;
- private var mytarget:String = null;
- private val fileUtils:FileUtils = FileUtils.newFileUtils();
-
- override def execute():unit = {
- try{
- Class.forName("ch.epfl.lamp.fjbg.JFieldOrMethod"); // simple check
-
- val project = getProject();
- //val old = project.getProperty("build.compiler");
- project.setProperty("build.compiler", "scala.tools.scala4ant.AntAdaptor$class");
- super.execute();
- //if (old == null)
- // project.setProperty("build.compiler", "modern");
- //else
- // project.setProperty("build.compiler", old);
- } catch {
- case e:ClassNotFoundException =>
- throw new BuildException("Cannot run scala4ant. It seems fjbg.jar is not in your CLASSPATH.");
- }
-
- }
-
- def setForce( fc:boolean ) = {
- force = fc;
- }
-
- def getForce() = {
- force;
- }
-
- override def setSource( source:String ) = {
- this.source = source;
- }
+ private val fileUtils:FileUtils = FileUtils.newFileUtils();
- override def getSource():java.lang.String = {
- source;
- }
+ var force : boolean = false;
- override def setTarget( target:String ) = {
- this.mytarget = target;
- }
+ override def execute():unit = try {
- override def getTarget():java.lang.String = {
- mytarget;
- }
+ Class.forName("ch.epfl.lamp.fjbg.JFieldOrMethod"); /* sanity check */
- def setSuffixes( s:String ) = {
- suffixes = s;
- }
+ getProject().setProperty("build.compiler",
+ "scala.tools.scala4ant.AntAdaptor$class");
+ super.execute();
- def getSuffixes() = {
- suffixes;
- }
+ } catch {
+ case e:ClassNotFoundException =>
+ throw new BuildException("Cannot run scala4ant. It seems fjbg.jar is not in your CLASSPATH.");
+ };
- def setScalaClasspath( s:String ) = {
- System.setProperty("scala.class.path",s);
- {}
- }
- def getScalaClasspath() = {
- System.getProperty("scala.class.path");
- }
- def setScalaBootClasspath( s:String ) = {
- System.setProperty("scala.boot.class.path",s);
- {}
- }
- def getScalaBootClasspath() = {
- System.getProperty("scala.boot.class.path");
- }
+ def setForce( b:boolean ) = this.force = b;
+ def getForce() = force;
- protected def parseSuffixes():Array[String] = {
- val st = new StringTokenizer(suffixes, " ,");
- val al = new ArrayList();
- while( st.hasMoreTokens() ) {
- al.add("." + st.nextToken());
- }
- al.toArray((new Array[String]( al.size() )).asInstanceOf[Array[java.lang.Object]]).asInstanceOf[Array[String]];
- }
+ override protected def scanDir(srcDir:File, destDir:File, files:Array[String] ):unit = {
+ if( force ) {
+ val newCompileList = new Array[File]( compileList.length + files.length );
+ System.arraycopy(compileList, 0, newCompileList, 0, compileList.length);
+ var j, i = 0;
- private def hasLegalSuffix( suffixes:Array[String], file:String ) = {
- var res = false;
- for ( val s <- new IterableArray( suffixes ).elements ) {
- res = res | file.endsWith( s );
- }
- res
- }
-
- override protected def scanDir( srcDir:File, destDir:File, files:Array[String] ):unit = {
- val sfx = parseSuffixes();
- if( force ) {
- val newCompileList = new Array[File]( compileList.length + files.length );
- System.arraycopy(compileList, 0, newCompileList, 0, compileList.length);
- var j, i = 0;
-
- def handleFile( theFile:String ):unit = { // this, because wile create anon-class -> access violation
- if( hasLegalSuffix(sfx, theFile )) {
- if( srcDir == null ) {
- newCompileList( compileList.length + j ) = new File( theFile );
- j = j + 1;
- } else {
- newCompileList( compileList.length + j ) =
- fileUtils.resolveFile( srcDir, theFile );
- j = j + 1
- }
- }
- }
-
- while( i < files.length ) {
- handleFile( files( i ) );
- i = i + 1;
- }
-
- if( j == files.length )
- compileList = newCompileList;
- else {
- compileList = new Array[File]( j );
- System.arraycopy(newCompileList, 0, compileList, 0, j);
- }
- } else {
-
- val m = new GlobPatternMapper();
-
- def handleNewFiles( newFiles:Array[File] ):unit = {
- if( newFiles.length > 0 ) {
- val newCompileList = new Array[ File ]( compileList.length +
- newFiles.length);
- System.arraycopy(compileList, 0, newCompileList, 0,
- compileList.length);
- System.arraycopy(newFiles, 0, newCompileList,
- compileList.length, newFiles.length);
- compileList = newCompileList;
- }
+ def handleFile( theFile:String ):unit = {
+ /* this, because wile create anon-class -> access violation */
+ if( theFile.endsWith( ".scala" )) {
+ if( srcDir == null ) {
+ newCompileList( compileList.length + j ) = new File( theFile );
+ j = j + 1;
+ } else {
+ newCompileList( compileList.length + j ) =
+ fileUtils.resolveFile( srcDir, theFile );
+ j = j + 1
}
+ }
+ }
- for (val i <- scala.List.range( 0, sfx.length )) {
- m.setFrom("*" + sfx( i ));
- m.setTo("*.class");
- val sfs = new SourceFileScanner(this);
- handleNewFiles( sfs.restrictAsFiles(files, srcDir, destDir, m) );
- }
+ while( i < files.length ) {
+ handleFile( files( i ) );
+ i = i + 1;
+ }
+ if( j == files.length )
+ compileList = newCompileList;
+ else {
+ compileList = new Array[File]( j );
+ System.arraycopy(newCompileList, 0, compileList, 0, j);
+ }
+ } else {
+
+ val m = new GlobPatternMapper();
+
+ def handleNewFiles( newFiles:Array[File] ):unit = {
+ if( newFiles.length > 0 ) {
+ val newCompileList = new Array[ File ]( compileList.length +
+ newFiles.length);
+ System.arraycopy(compileList, 0, newCompileList, 0,
+ compileList.length);
+ System.arraycopy(newFiles, 0, newCompileList,
+ compileList.length, newFiles.length);
+ compileList = newCompileList;
}
+ }
+ m.setFrom("*.scala");
+ m.setTo("*.class");
+ val sfs = new SourceFileScanner(this);
+ handleNewFiles( sfs.restrictAsFiles( files, srcDir, destDir, m ));
}
+ }
}
+
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
+ * reserved.
+ * Copyright (c) 2000-2002 Matthias Zenger. All rights reserved.
+ * Copyright (c) 2003-2004 Burak Emir. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+*/