From 836e29f56730f20450cc840c5ff74e2caff52645 Mon Sep 17 00:00:00 2001 From: michelou Date: Mon, 29 Jan 2007 16:53:19 +0000 Subject: [PATCH] moved version/copyright properties from source code to property file git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@9792 5e8d7ff9-d8ef-0310-90f0-a4852d11357a --- build.xml | 34 ++++++++++++- src/compiler/scala/tools/ant/Scalac.scala | 5 -- .../scala/tools/ant/templates/tool-unix.tmpl | 2 +- .../tools/ant/templates/tool-windows.tmpl | 6 +-- .../scala/tools/nsc/CompileClient.scala | 11 ++--- .../scala/tools/nsc/CompileServer.scala | 30 +++++------- .../scala/tools/nsc/CompileSocket.scala | 17 ++++--- src/compiler/scala/tools/nsc/Main.scala | 16 +++---- .../scala/tools/nsc/MainGenericRunner.scala | 13 +++-- src/compiler/scala/tools/nsc/Properties.scala | 48 +++++++++++++++++++ src/compiler/scala/tools/nsc/Settings.scala | 4 +- 11 files changed, 122 insertions(+), 64 deletions(-) create mode 100644 src/compiler/scala/tools/nsc/Properties.scala diff --git a/build.xml b/build.xml index 211d4b534..9f6577f99 100644 --- a/build.xml +++ b/build.xml @@ -29,7 +29,7 @@ PROPERTIES - + @@ -64,6 +64,7 @@ PROPERTIES + @@ -451,6 +462,16 @@ BUILD QUICK-TEST LAYER + + @@ -585,6 +606,17 @@ TEST + + + diff --git a/src/compiler/scala/tools/ant/Scalac.scala b/src/compiler/scala/tools/ant/Scalac.scala index 6b9fc7869..7e51be00d 100644 --- a/src/compiler/scala/tools/ant/Scalac.scala +++ b/src/compiler/scala/tools/ant/Scalac.scala @@ -9,8 +9,6 @@ package scala.tools.ant -import java.lang.System.getProperty - import java.io.File import java.net.{URL, URLClassLoader} import java.util.{ArrayList, Vector} @@ -71,9 +69,6 @@ import scala.tools.nsc.{Global, FatalError, Settings} */ class Scalac extends MatchingTask { - private val SCALA_PRODUCT: String = getProperty("scala.product", "scalac") - private val SCALA_VERSION: String = getProperty("scala.version", "Unknown version") - /** The unique Ant file utilities instance to use in this task. */ private val fileUtils = FileUtils.newFileUtils() diff --git a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl index 3e38b8970..8c7dbbd5c 100644 --- a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl +++ b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl @@ -70,4 +70,4 @@ if $cygwin; then BOOT_CLASSPATH=`cygpath --path --$format "$BOOT_CLASSPATH"` fi -${JAVACMD:=java} @javaflags@ -Xbootclasspath/a:"$BOOT_CLASSPATH" -cp "$EXTENSION_CLASSPATH" -Dscala.home="$SCALA_HOME" -Denv.classpath="$CLASSPATH" -Dscala.tool.name="@name@" -Dscala.tool.version="@version@" @properties@ @class@ @toolflags@ "$@@" +${JAVACMD:=java} @javaflags@ -Xbootclasspath/a:"$BOOT_CLASSPATH" -cp "$EXTENSION_CLASSPATH" -Dscala.home="$SCALA_HOME" -Denv.classpath="$CLASSPATH" @properties@ @class@ @toolflags@ "$@@" diff --git a/src/compiler/scala/tools/ant/templates/tool-windows.tmpl b/src/compiler/scala/tools/ant/templates/tool-windows.tmpl index 56e582b5e..11b9a3ae3 100644 --- a/src/compiler/scala/tools/ant/templates/tool-windows.tmpl +++ b/src/compiler/scala/tools/ant/templates/tool-windows.tmpl @@ -55,16 +55,12 @@ shift goto loop :exec -set _PROPS=-Dscala.home="%_SCALA_HOME%" -Denv.classpath="%CLASSPATH%" -Dscala.tool.name="@name@" -Dscala.tool.version="@version@" @properties@ +set _PROPS=-Dscala.home="%_SCALA_HOME%" -Denv.classpath="%CLASSPATH%" @properties@ rem echo %_JAVACMD% -Xbootclasspath/a:"%_BOOT_CLASSPATH%" @javaflags@ %_PROPS% -cp "%_EXTENSION_CLASSPATH%" @class@ @toolflags@ %_ARGS% %_JAVACMD% -Xbootclasspath/a:"%_BOOT_CLASSPATH%" @javaflags@ %_PROPS% -cp "%_EXTENSION_CLASSPATH%" @class@ @toolflags@ %_ARGS% goto end -:version -echo @name@ version @version@ -- @copyright@ -goto end - rem ########################################################################## rem # subroutines diff --git a/src/compiler/scala/tools/nsc/CompileClient.scala b/src/compiler/scala/tools/nsc/CompileClient.scala index e8496dc1e..bb24ad2d3 100644 --- a/src/compiler/scala/tools/nsc/CompileClient.scala +++ b/src/compiler/scala/tools/nsc/CompileClient.scala @@ -1,12 +1,11 @@ /* NSC -- new Scala compiler - * Copyright 2005-2006 LAMP/EPFL + * Copyright 2005-2007 LAMP/EPFL * @author Martin Odersky */ // $Id$ package scala.tools.nsc -import java.lang.System.getProperty import java.io.{BufferedReader, File, InputStreamReader, PrintWriter} import scala.compat.StringBuilder @@ -16,11 +15,9 @@ import scala.tools.util.StringOps * language Scala. */ object CompileClient { - val PRODUCT: String = getProperty("scala.tool.name", "scalac") - val VERSION: String = getProperty("scala.tool.version", "unknown version") - val COPYRIGHT: String = getProperty("scala.copyright", "(c) 2002-2007 LAMP/EPFL") - - val versionMsg = PRODUCT + " " + VERSION + " -- " + COPYRIGHT + val versionMsg = "Fast Scala Compiler " + + Properties.versionString + " -- " + + Properties.copyrightString var verbose = false var version = false diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala index 3a3b7744e..65ff49300 100644 --- a/src/compiler/scala/tools/nsc/CompileServer.scala +++ b/src/compiler/scala/tools/nsc/CompileServer.scala @@ -6,16 +6,14 @@ package scala.tools.nsc -import scala.tools.util.SocketServer -import scala.tools.nsc.util.FakePos //Position -import scala.tools.nsc.reporters.{Reporter, ConsoleReporter} -import scala.tools.nsc.doc.DocGenerator +import java.io.{BufferedOutputStream, File, FileOutputStream, PrintStream} +import java.lang.{Runtime, System, Thread} + import scala.concurrent.Process.spawn -import java.lang.System -import java.lang.Thread -import java.lang.Runtime -import java.io.File -import java.io.{PrintStream, BufferedOutputStream, FileOutputStream} +import scala.tools.nsc.doc.DocGenerator +import scala.tools.nsc.reporters.{Reporter, ConsoleReporter} +import scala.tools.nsc.util.FakePos //Position +import scala.tools.util.SocketServer /** The main class for NSC, a compiler for the programming * language Scala. @@ -25,13 +23,9 @@ import java.io.{PrintStream, BufferedOutputStream, FileOutputStream} */ object CompileServer extends SocketServer { - val PRODUCT: String = - System.getProperty("scala.tool.name", "scalac") - val VERSION: String = - System.getProperty("scala.tool.version", "unknown version") - val COPYRIGHT: String = - System.getProperty("scala.copyright", "(c) 2002-2007 LAMP/EPFL") - val versionMsg = PRODUCT + " " + VERSION + " -- " + COPYRIGHT + val versionMsg = "Fast Scala compiler " + + Properties.versionString + " -- " + + Properties.copyrightString val MaxCharge = 0.8 @@ -99,8 +93,8 @@ object CompileServer extends SocketServer { override def displayPrompt = {} } def error(msg: String): unit = - reporter.error(/*new Position*/ FakePos(PRODUCT), - msg + "\n " + PRODUCT + " -help gives more information") + reporter.error(/*new Position*/ FakePos("fsc"), + msg + "\n fsc -help gives more information") val command = new CompilerCommand(args, error, false) { override val cmdName = "fsc" settings.disable(settings.prompt) diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala index 2cefcc041..e0e257b8a 100644 --- a/src/compiler/scala/tools/nsc/CompileSocket.scala +++ b/src/compiler/scala/tools/nsc/CompileSocket.scala @@ -1,5 +1,5 @@ /* NSC -- new Scala compiler - * Copyright 2005-2006 LAMP/EPFL + * Copyright 2005-2007 LAMP/EPFL * @author Martin Odersky */ // $Id$ @@ -10,6 +10,7 @@ import java.lang.{Thread, System, Runtime} import java.lang.NumberFormatException import java.io.{File, IOException, PrintWriter, FileOutputStream} import java.io.{BufferedReader, FileReader} +import java.util.regex.Pattern import java.net._ object CompileSocket { @@ -19,19 +20,17 @@ object CompileSocket { */ private val dirName = "scalac-compile-server-port" - private val isWin = System.getProperty("os.name") startsWith "Windows" - private val cmdName = if (isWin) "scala.bat" else "scala" - /** The vm-part of the command to start a new scala compile server */ private val vmCommand = - System.getProperty("scala.home") match { - case null => cmdName + Properties.scalaHome match { + case null => + Properties.cmdName case dirname => - val trial = new File(new File(dirname, "bin"), cmdName) + val trial = new File(new File(dirname, "bin"), Properties.cmdName) if (trial.canRead) trial.getPath else - cmdName + Properties.cmdName } /** The class name of the scala compile server */ @@ -41,7 +40,7 @@ object CompileSocket { val errorRegex = ".*errors? found.*" /** A Pattern object for checking compiler output for errors */ - val errorPattern = java.util.regex.Pattern.compile(errorRegex) + val errorPattern = Pattern.compile(errorRegex) private def error(msg: String) = System.err.println(msg) diff --git a/src/compiler/scala/tools/nsc/Main.scala b/src/compiler/scala/tools/nsc/Main.scala index 0ff21f99b..81b0696a3 100644 --- a/src/compiler/scala/tools/nsc/Main.scala +++ b/src/compiler/scala/tools/nsc/Main.scala @@ -6,10 +6,9 @@ package scala.tools.nsc -import java.lang.System.getProperty -import scala.tools.nsc.util.FakePos //{Position} -import scala.tools.nsc.reporters.{Reporter, ConsoleReporter} import scala.tools.nsc.doc.DocGenerator +import scala.tools.nsc.reporters.{Reporter, ConsoleReporter} +import scala.tools.nsc.util.FakePos //{Position} /** The main class for NSC, a compiler for the programming @@ -17,17 +16,16 @@ import scala.tools.nsc.doc.DocGenerator */ object Main extends AnyRef with EvalLoop { - val PRODUCT: String = getProperty("scala.tool.name", "scalac") - val VERSION: String = getProperty("scala.tool.version", "unknown version") - val COPYRIGHT: String = getProperty("scala.copyright", "(c) 2002-2007 LAMP/EPFL") - val versionMsg = PRODUCT + " " + VERSION + " -- " + COPYRIGHT + val versionMsg = "Scala compiler " + + Properties.versionString + " -- " + + Properties.copyrightString val prompt = "\nnsc> " var reporter: ConsoleReporter = _ def error(msg: String): unit = - reporter.error(/*new Position */FakePos(PRODUCT), - msg + "\n " + PRODUCT + " -help gives more information") + reporter.error(/*new Position */FakePos("scalac"), + msg + "\n scalac -help gives more information") /* needed ?? */ def errors() = reporter.errors diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala index df753d020..36c3da2d6 100644 --- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala +++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala @@ -7,9 +7,8 @@ package scala.tools.nsc -import java.lang.System.getProperty -import java.lang.{ClassNotFoundException, NoSuchMethodException} import java.io.File +import java.lang.{ClassNotFoundException, NoSuchMethodException} import java.lang.reflect.InvocationTargetException /** An object that runs Scala code. It has three possible @@ -24,8 +23,8 @@ object MainGenericRunner { * @param classpath * @return ... */ - def addClasspathExtras(classpath: String): String = { - val scalaHome = getProperty("scala.home") + private def addClasspathExtras(classpath: String): String = { + val scalaHome = Properties.scalaHome val extraClassPath = if (scalaHome eq null) @@ -70,10 +69,10 @@ object MainGenericRunner { } if (settings.version.value) { - val version = getProperty("scala.tool.version", "unknown version") Console.println( - "Scala code runner version " + version + " -- " + - "(c) 2002-2007 LAMP/EPFL") + "Scala code runner " + + Properties.versionString + " -- " + + Properties.copyrightString) return } diff --git a/src/compiler/scala/tools/nsc/Properties.scala b/src/compiler/scala/tools/nsc/Properties.scala new file mode 100644 index 000000000..0ae9d9dc8 --- /dev/null +++ b/src/compiler/scala/tools/nsc/Properties.scala @@ -0,0 +1,48 @@ +/* NSC -- new Scala compiler + * Copyright 2006-2007 LAMP/EPFL + * @author Stephane Micheloud + */ + +// $Id: $ + +package scala.tools.nsc + +/** A utility to load the compiler properties from a Java properties file + * included in the jar. + */ +object Properties { + + /** The name of the properties file */ + private val propFilename = "/compiler.properties" + + /** The loaded properties */ + private val props = { + val props = new java.util.Properties + val stream = classOf[Global].getResourceAsStream(propFilename) + if (stream != null) + props.load(stream) + props + } + + /** The version number of the jar this was loaded from, or + * "(unknown)" if it cannot be determined. + */ + val versionString: String = { + val defaultString = "(unknown)" + "version " + props.getProperty("version.number") + } + + val copyrightString: String = { + val defaultString = "(c) 2002-2006 LAMP/EPFL" + props.getProperty("copyright.string", defaultString) + } + + val scalaHome: String = + System.getProperty("scala.home") + + val cmdName: String = { + val isWin = System.getProperty("os.name") startsWith "Windows" + if (isWin) "scala.bat" else "scala" + } + +} diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala index d5e5c98bd..cc9f9b21c 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -49,7 +49,7 @@ class Settings(error: String => unit) { else p2 private def guessedScalaBootClassPath = { - val scalaHome = System.getProperty("scala.home") + val scalaHome = Properties.scalaHome if (scalaHome ne null) { val guessJar = new File(new File(new File(scalaHome), "lib"), "scala-library.jar") if (guessJar.exists()) guessJar.getPath() @@ -61,7 +61,7 @@ class Settings(error: String => unit) { } private def guessedScalaExtDirs = { - val scalaHome = System.getProperty("scala.home") + val scalaHome = Properties.scalaHome if (scalaHome ne null) { val guess = new File(new File(scalaHome), "lib") if (guess.exists()) guess.getPath else null