|
Scala example source code file (Scalac.scala)
The Scala Scalac.scala source code/* __ *\ ** ________ ___ / / ___ Scala Ant Tasks ** ** / __/ __// _ | / / / _ | (c) 2005-2011, LAMP/EPFL ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ package scala.tools.ant import java.io.{File,PrintWriter,BufferedWriter,FileWriter} import org.apache.tools.ant.{ BuildException, Project, AntClassLoader } import org.apache.tools.ant.taskdefs.Java import org.apache.tools.ant.types.{Path, Reference} import org.apache.tools.ant.util.{FileUtils, GlobPatternMapper, SourceFileScanner} import scala.tools.nsc.{Global, Settings, CompilerCommand} import scala.tools.nsc.reporters.{Reporter, ConsoleReporter} /** <p> * An Ant task to compile with the new Scala compiler (NSC). * </p> * <p> * This task can take the following parameters as attributes: * </p> * <ul style="font-family:Courier;"> * <li>srcdir (mandatory), * <li>srcref, * <li>destdir, * <li>classpath, * <li>classpathref, * <li>sourcepath, * <li>sourcepathref, * <li>bootclasspath, * <li>bootclasspathref, * <li>extdirs, * <li>extdirsref, * <li>encoding, * <li>target, * <li>force, * <li>fork, * <li>logging, * <li>logphase, * <li>debuginfo, * <li>addparams, * <li>scalacdebugging, * <li>deprecation, * <li>optimise, * <li>unchecked, * <li>failonerror, * <li>scalacdebugging, * <li>assemname, * <li>assemrefs. * </ul> * <p> * It also takes the following parameters as nested elements: * </p> * <ul> * <li>src (for srcdir), * <li>classpath, * <li>sourcepath, * <li>bootclasspath, * <li>extdirs. * </ul> * * @author Gilles Dubochet, Stephane Micheloud */ class Scalac extends ScalaMatchingTask with ScalacShared { /** The unique Ant file utilities instance to use in this task. */ private val fileUtils = FileUtils.getFileUtils() /*============================================================================*\ ** Ant user-properties ** \*============================================================================*/ abstract class PermissibleValue { val values: List[String] def isPermissible(value: String): Boolean = (value == "") || values.exists(_.startsWith(value)) } /** Defines valid values for the logging property. */ object LoggingLevel extends PermissibleValue { val values = List("none", "verbose", "debug") } /** Defines valid values for properties that refer to compiler phases. */ object CompilerPhase extends PermissibleValue { val values = List("namer", "typer", "pickler", "uncurry", "tailcalls", "explicitouter", "erasure", "lambdalift", "flatten", "constructors", "mixin", "icode", "jvm", "terminal") } /** Defines valid values for the <code>target property. */ object Target extends PermissibleValue { val values = List("jvm-1.5", "msil") } /** Defines valid values for the <code>deprecation and * <code>unchecked properties. */ object Flag extends PermissibleValue { val values = List("yes", "no", "on", "off", "true", "false") def toBoolean(flag: String) = if (flag == "yes" || flag == "on" || flag == "true") Some(true) else if (flag == "no" || flag == "off" || flag == "false") Some(false) else None } /** The directories that contain source files to compile. */ protected var origin: Option[Path] = None /** The directory to put the compiled files in. */ protected var destination: Option[File] = None /** The class path to use for this compilation. */ protected var classpath: Option[Path] = None /** The source path to use for this compilation. */ protected var sourcepath: Option[Path] = None /** The boot class path to use for this compilation. */ protected var bootclasspath: Option[Path] = None /** The path to use when finding scalac - *only used for forking!* */ protected var compilerPath: Option[Path] = None /** The external extensions path to use for this compilation. */ protected var extdirs: Option[Path] = None /** The character encoding of the files to compile. */ protected var encoding: Option[String] = None // the targetted backend protected var backend: Option[String] = None /** Whether to force compilation of all files or not. */ protected var force: Boolean = false /** Whether to fork the execution of scalac */ protected var fork : Boolean = false /** If forking, these are the arguments to the JVM */ protected var jvmArgs : Option[String] = None /** How much logging output to print. Either none (default), * verbose or debug. */ protected var logging: Option[String] = None /** Which compilation phases should be logged during compilation. */ protected var logPhase: List[String] = Nil /** Instruct the compiler to generate debugging information */ protected var debugInfo: Option[String] = None /** Instruct the compiler to use additional parameters */ protected var addParams: String = "" /** Instruct the compiler to generate deprecation information. */ protected var deprecation: Option[Boolean] = None /** Instruct the compiler to run optimizations. */ protected var optimise: Option[Boolean] = None /** Instruct the compiler to generate unchecked information. */ protected var unchecked: Option[Boolean] = None /** Indicates whether compilation errors will fail the build; defaults to true. */ protected var failonerror: Boolean = true // Name of the output assembly (only relevant with -target:msil) protected var assemname: Option[String] = None // List of assemblies referenced by the program (only relevant with -target:msil) protected var assemrefs: Option[String] = None /** Prints out the files being compiled by the scalac ant task * (not only the number of files). */ protected var scalacDebugging: Boolean = false /** Helpers */ private def setOrAppend(old: Option[Path], arg: Path): Option[Path] = old match { case Some(x) => x append arg ; Some(x) case None => Some(arg) } private def pathAsList(p: Option[Path], name: String): List[File] = p match { case None => buildError("Member '" + name + "' is empty.") case Some(x) => x.list.toList map nameToFile } private def createNewPath(getter: () => Option[Path], setter: (Option[Path]) => Unit) = { if (getter().isEmpty) setter(Some(new Path(getProject()))) getter().get.createPath() } private def plural(xs: List[Any]) = if (xs.size > 1) "s" else "" private def plural(x: Int) = if (x > 1) "s" else "" /*============================================================================*\ ** Properties setters ** \*============================================================================*/ /** Sets the srcdir attribute. Used by Ant. * @param input The value of <code>origin. */ def setSrcdir(input: Path) { origin = setOrAppend(origin, input) } /** Sets the <code>origin as a nested src Ant parameter. * @return An origin path to be configured. */ def createSrc(): Path = createNewPath(origin _, p => origin = p) /** Sets the <code>origin as an external reference Ant parameter. * @param input A reference to an origin path. */ def setSrcref(input: Reference) = createSrc().setRefid(input) /** Sets the <code>destdir attribute. Used by Ant. * @param input The value of <code>destination. */ def setDestdir(input: File) { destination = Some(input) } /** Sets the <code>classpath attribute. Used by Ant. * @param input The value of <code>classpath. */ def setClasspath(input: Path) { classpath = setOrAppend(classpath, input) } /** Sets the <code>compilerPath attribute. Used by Ant. * @param input The value of <code>compilerPath. */ def setCompilerPath(input : Path) { compilerPath = setOrAppend(compilerPath, input) } def createCompilerPath: Path = createNewPath(compilerPath _, p => compilerPath = p) /** Sets the <code>compilerpathref attribute. Used by Ant. * @param input The value of <code>compilerpathref. */ def setCompilerPathRef(input: Reference) { createCompilerPath.setRefid(input) } /** Sets the <code>classpath as a nested classpath Ant parameter. * @return A class path to be configured. */ def createClasspath(): Path = createNewPath(classpath _, p => classpath = p) /** Sets the <code>classpath as an external reference Ant parameter. * @param input A reference to a class path. */ def setClasspathref(input: Reference) { createClasspath().setRefid(input) } /** Sets the <code>sourcepath attribute. Used by Ant. * @param input The value of <code>sourcepath. */ def setSourcepath(input: Path) { sourcepath = setOrAppend(sourcepath, input) } /** Sets the <code>sourcepath as a nested sourcepath Ant parameter. * @return A source path to be configured. */ def createSourcepath(): Path = createNewPath(sourcepath _, p => sourcepath = p) /** Sets the <code>sourcepath as an external reference Ant parameter. * @param input A reference to a source path. */ def setSourcepathref(input: Reference) { createSourcepath().setRefid(input) } /** Sets the boot classpath attribute. Used by Ant. * * @param input The value of <code>bootclasspath. */ def setBootclasspath(input: Path) { bootclasspath = setOrAppend(bootclasspath, input) } /** Sets the <code>bootclasspath as a nested sourcepath Ant * parameter. * @return A source path to be configured. */ def createBootclasspath(): Path = createNewPath(bootclasspath _, p => bootclasspath = p) /** Sets the <code>bootclasspath as an external reference Ant * parameter. * @param input A reference to a source path. */ def setBootclasspathref(input: Reference) = createBootclasspath().setRefid(input) /** Sets the external extensions path attribute. Used by Ant. * @param input The value of <code>extdirs. */ def setExtdirs(input: Path) = extdirs = setOrAppend(extdirs, input) /** Sets the <code>extdirs as a nested sourcepath Ant parameter. * @return An extensions path to be configured. */ def createExtdirs(): Path = createNewPath(extdirs _, p => extdirs = p) /** Sets the <code>extdirs as an external reference Ant parameter. * @param input A reference to an extensions path. */ def setExtdirsref(input: Reference) = createExtdirs().setRefid(input) /** Sets the <code>encoding attribute. Used by Ant. * @param input The value of <code>encoding. */ def setEncoding(input: String): Unit = encoding = Some(input) /** Sets the <code>target attribute. Used by Ant. * @param input The value for <code>target. */ def setTarget(input: String): Unit = if (Target.isPermissible(input)) backend = Some(input) else buildError("Unknown target '" + input + "'") /** Sets the <code>force attribute. Used by Ant. * @param input The value for <code>force. */ def setForce(input: Boolean) { force = input } /** Sets the <code>fork attribute. Used by Ant. * @param input The value for <code>fork. */ def setFork(input : Boolean) { fork = input } /** * Sets the <code>jvmargs attribute. Used by Ant. * @param input The value for <code>jvmargs */ def setJvmargs(input : String) { jvmArgs = Some(input) } /** Sets the logging level attribute. Used by Ant. * @param input The value for <code>logging. */ def setLogging(input: String) { if (LoggingLevel.isPermissible(input)) logging = Some(input) else buildError("Logging level '" + input + "' does not exist.") } /** Sets the <code>logphase attribute. Used by Ant. * @param input The value for <code>logPhase. */ def setLogPhase(input: String) { logPhase = input.split(",").toList.flatMap { s: String => val st = s.trim() if (CompilerPhase.isPermissible(st)) (if (input != "") List(st) else Nil) else { buildError("Phase " + st + " in log does not exist.") } } } /** Set the <code>debug info attribute. * @param input The value for <code>debug. */ def setDebuginfo(input: String) { debugInfo = Some(input) } /** Set the <code>addparams info attribute. * @param input The value for <code>addparams. */ def setAddparams(input: String) { addParams = input } /** Set the <code>deprecation info attribute. * @param input One of the flags <code>yes/no or Other Scala examples (source code examples)Here is a short list of links related to this Scala Scalac.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.