⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scalac.scala

📁 JAVA 语言的函数式编程扩展
💻 SCALA
📖 第 1 页 / 共 2 页
字号:
/*                     __                                               *\**     ________ ___   / /  ___     Scala Ant Tasks                      ****    / __/ __// _ | / /  / _ |    (c) 2005-2008, LAMP/EPFL             ****  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **** /____/\___/_/ |_/____/_/ | |                                         ****                          |/                                          **\*                                                                      */// $Id: Scalac.scala 14432 2008-03-21 20:04:29Z dubochet $package scala.tools.antimport java.io.Fileimport org.apache.tools.ant.{BuildException, Project}import org.apache.tools.ant.taskdefs.MatchingTaskimport org.apache.tools.ant.types.{Path, Reference}import org.apache.tools.ant.util.{FileUtils, GlobPatternMapper,                                  SourceFileScanner}import scala.tools.nsc.{Global, Settings}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> *    <li>srcref,</li> *    <li>destdir,</li> *    <li>classpath,</li> *    <li>classpathref,</li> *    <li>sourcepath,</li> *    <li>sourcepathref,</li> *    <li>bootclasspath,</li> *    <li>bootclasspathref,</li> *    <li>extdirs,</li> *    <li>extdirsref,</li> *    <li>encoding,</li> *    <li>target,</li> *    <li>force,</li> *    <li>logging,</li> *    <li>logphase,</li> *    <li>debuginfo,</li> *    <li>addparams,</li> *    <li>scalacdebugging,</li> *    <li>deprecation,</li> *    <li>optimise,</li> *    <li>unchecked,</li> *    <li>failonerror.</li> *  </ul> *  <p> *    It also takes the following parameters as nested elements: *  </p> *  <ul> *    <li>src (for srcdir),</li> *    <li>classpath,</li> *    <li>sourcepath,</li> *    <li>bootclasspath,</li> *    <li>extdirs.</li> * </ul> * * @author Gilles Dubochet, Stephane Micheloud */class Scalac extends MatchingTask {  /** The unique Ant file utilities instance to use in this task. */  private val fileUtils = FileUtils.newFileUtils()/*============================================================================*\**                             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",                      "transmatch", "explicitouter", "erasure", "lambdalift",                      "flatten", "constructors", "mixin", "icode", "jvm",                      "terminal")  }  /** Defines valid values for the <code>target</code> property. */  object Target extends PermissibleValue {    val values = List("jvm-1.5", "jvm-1.4", "msil", "cldc")  }  /** Defines valid values for the <code>deprecation</code> and   *  <code>unchecked</code> properties. */  object Flag extends PermissibleValue {    val values = List("yes", "no", "on", "off")  }  /** 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 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  /** 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  /** Whether the compiler is being debuged. Prints more information in case   *  in case of failure. */  protected var scalacDebugging: Boolean = false/*============================================================================*\**                             Properties setters                             **\*============================================================================*/  /** Sets the srcdir attribute. Used by Ant.   *  @param input The value of <code>origin</code>. */  def setSrcdir(input: Path) {    if (origin.isEmpty) origin = Some(input)    else origin.get.append(input)  }  /** Sets the <code>origin</code> as a nested src Ant parameter.   *  @return An origin path to be configured. */  def createSrc(): Path = {    if (origin.isEmpty) origin = Some(new Path(getProject()))    origin.get.createPath()  }  /** Sets the <code>origin</code> 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</code> attribute. Used by Ant.   *  @param input The value of <code>destination</code>. */  def setDestdir(input: File) { destination = Some(input) }  /** Sets the <code>classpath</code> attribute. Used by Ant.   *  @param input The value of <code>classpath</code>. */  def setClasspath(input: Path) {    if (classpath.isEmpty) classpath = Some(input)    else classpath.get.append(input)  }  /** Sets the <code>classpath</code> as a nested classpath Ant parameter.   *  @return A class path to be configured. */  def createClasspath(): Path = {    if (classpath.isEmpty) classpath = Some(new Path(getProject()))    classpath.get.createPath()  }  /** Sets the <code>classpath</code> 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</code> attribute. Used by Ant.   *  @param input The value of <code>sourcepath</code>. */  def setSourcepath(input: Path) {    if (sourcepath.isEmpty) sourcepath = Some(input)    else sourcepath.get.append(input)  }  /** Sets the <code>sourcepath</code> as a nested sourcepath Ant parameter.   *  @return A source path to be configured. */  def createSourcepath(): Path = {    if (sourcepath.isEmpty) sourcepath = Some(new Path(getProject()))    sourcepath.get.createPath()  }  /** Sets the <code>sourcepath</code> 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</code>. */  def setBootclasspath(input: Path) {    if (bootclasspath.isEmpty) bootclasspath = Some(input)    else bootclasspath.get.append(input)  }  /** Sets the <code>bootclasspath</code> as a nested sourcepath Ant   *  parameter.   *  @return A source path to be configured. */  def createBootclasspath(): Path = {    if (bootclasspath.isEmpty) bootclasspath = Some(new Path(getProject()))    bootclasspath.get.createPath()  }  /** Sets the <code>bootclasspath</code> 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</code>. */  def setExtdirs(input: Path) =    if (extdirs.isEmpty) extdirs = Some(input)    else extdirs.get.append(input)  /** Sets the <code>extdirs</code> as a nested sourcepath Ant parameter.   *  @return An extensions path to be configured. */  def createExtdirs(): Path = {    if (extdirs.isEmpty) extdirs = Some(new Path(getProject()))    extdirs.get.createPath()  }  /** Sets the <code>extdirs</code> 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</code> attribute. Used by Ant.   *  @param input The value of <code>encoding</code>. */  def setEncoding(input: String): Unit =    encoding = Some(input)  /** Sets the <code>target</code> attribute. Used by Ant.   *  @param input The value for <code>target</code>. */  def setTarget(input: String): Unit =    if (Target.isPermissible(input)) backend = Some(input)    else error("Unknown target '" + input + "'")  /** Sets the <code>force</code> attribute. Used by Ant.   *  @param input The value for <code>force</code>. */  def setForce(input: Boolean) { force = input }  /** Sets the logging level attribute. Used by Ant.   *  @param input The value for <code>logging</code>. */  def setLogging(input: String) {    if (LoggingLevel.isPermissible(input)) logging = Some(input)    else error("Logging level '" + input + "' does not exist.")  }  /** Sets the <code>logphase</code> attribute. Used by Ant.   *  @param input The value for <code>logPhase</code>. */  def setLogPhase(input: String) {    logPhase = List.fromArray(input.split(",")).flatMap { s: String =>      val st = s.trim()      if (CompilerPhase.isPermissible(st))        (if (input != "") List(st) else Nil)      else {        error("Phase " + st + " in log does not exist.")        Nil      }    }  }  /** Set the <code>debug</code> info attribute.   *  @param input The value for <code>debug</code>. */  def setDebuginfo(input: String) { debugInfo = Some(input) }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -