Skip to content

Commit 0322a9b

Browse files
committed
address review
1 parent c8ae057 commit 0322a9b

File tree

3 files changed

+43
-91
lines changed

3 files changed

+43
-91
lines changed

library/src/scala/util/Properties.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import scala.annotation.tailrec
2020

2121
/** Loads `library.properties` from the jar. */
2222
object Properties extends PropertiesTrait {
23-
protected def propCategory = "library"
23+
protected def propCategory = "library3"
2424
protected def pickJarBasedOn: Class[Option[?]] = classOf[Option[?]]
2525

2626
/** Scala manifest attributes.
@@ -34,7 +34,6 @@ private[scala] trait PropertiesTrait {
3434

3535
/** The name of the properties file */
3636
protected val propFilename = "/" + propCategory + ".properties"
37-
protected val lib3Filename = "/library3.properties"
3837

3938
/** The loaded properties */
4039
protected lazy val scalaProps: java.util.Properties = {
@@ -43,12 +42,6 @@ private[scala] trait PropertiesTrait {
4342
if (stream ne null)
4443
quietlyDispose(props.load(stream), stream.close)
4544

46-
// If available in the same jar as the stdlib classes, overlay Scala 3
47-
// runtime properties contained in `library3.properties` (e.g., version.number).
48-
val lib3Stream = pickJarBasedOn.getResourceAsStream(lib3Filename)
49-
if (lib3Stream ne null)
50-
quietlyDispose(props.load(lib3Stream), lib3Stream.close)
51-
5245
props
5346
}
5447

project/Build.scala

Lines changed: 41 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,40 @@ object Build {
433433

434434
private lazy val currentYear: String = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR).toString
435435

436+
// Common generator for properties files
437+
lazy val generatePropertiesFile(contents: String, file: File) = Def.task {
438+
if (!(file.exists && IO.read(file) == contents)) {
439+
IO.write(file, contents)
440+
}
441+
Seq(file)
442+
}
443+
444+
// Generate compiler.properties consumed by sbt
445+
lazy val generateCompilerProperties: Def.Initialize[Task[Seq[File]]] = {
446+
import java.util._
447+
import java.text._
448+
val file = (Compile / resourceManaged).value / "compiler.properties"
449+
val dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss")
450+
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"))
451+
val contents = //2.11.11.v20170413-090219-8a413ba7cc
452+
s"""version.number=${version.value}
453+
|maven.version.number=${version.value}
454+
|git.hash=${VersionUtil.gitHash}
455+
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL
456+
""".stripMargin
457+
generatePropertiesFile(contents, file)
458+
}
459+
460+
// Generate library3.properties consumed by scala.util.Properties
461+
lazy val generateLibrary3Properties: Def.Initialize[Task[Seq[File]]] = generatePropertiesFile(
462+
contents = s"""version.number=${version.value}
463+
|maven.version.number=${version.value}
464+
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL and Lightbend, Inc. dba Akka
465+
|shell.banner=%n ________ ___ / / ___%n / __/ __// _ | / / / _ |%n __\\ \\/ /__/ __ |/ /__/ __ |%n /____/\\___/_/ |_/____/_/ | |%n |/ %s
466+
|""".stripMargin,
467+
file = (Compile / resourceManaged).value / "library3.properties"
468+
)
469+
436470
def scalacOptionsDocSettings(includeExternalMappings: Boolean = true) = {
437471
val extMap = Seq("-external-mappings:" +
438472
(if (includeExternalMappings) ".*scala/.*::scaladoc3::https://dotty.epfl.ch/api/," else "") +
@@ -700,25 +734,7 @@ object Build {
700734
scalacOptions += "-Wconf:cat=deprecation&origin=scala\\.collection\\.mutable\\.AnyRefMap.*:s",
701735

702736
// Generate compiler.properties, used by sbt
703-
(Compile / resourceGenerators) += Def.task {
704-
import java.util._
705-
import java.text._
706-
val file = (Compile / resourceManaged).value / "compiler.properties"
707-
val dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss")
708-
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"))
709-
val contents = //2.11.11.v20170413-090219-8a413ba7cc
710-
s"""version.number=${version.value}
711-
|maven.version.number=${version.value}
712-
|git.hash=${VersionUtil.gitHash}
713-
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL
714-
""".stripMargin
715-
716-
if (!(file.exists && IO.read(file) == contents)) {
717-
IO.write(file, contents)
718-
}
719-
720-
Seq(file)
721-
}.taskValue,
737+
(Compile / resourceGenerators) += generateCompilerProperties.taskValue,
722738

723739
// get libraries onboard
724740
libraryDependencies ++= Seq(
@@ -1916,19 +1932,8 @@ object Build {
19161932
customMimaReportBinaryIssues("MiMaFilters.Scala3Library"),
19171933
// Should we also patch .sjsir files
19181934
keepSJSIR := false,
1919-
Compile / resourceGenerators += Def.task {
1920-
val file = (Compile / resourceManaged).value / "library3.properties"
1921-
val contents =
1922-
s"""version.number=${version.value}
1923-
|maven.version.number=${version.value}
1924-
|""".stripMargin
1925-
1926-
if (!(file.exists && IO.read(file) == contents)) {
1927-
IO.write(file, contents)
1928-
}
1929-
1930-
Seq(file)
1931-
}.taskValue,
1935+
// Generate Scala 3 runtime properties overlay
1936+
Compile / resourceGenerators += generateLibrary3Properties.taskValue
19321937
)
19331938

19341939
/* Configuration of the org.scala-lang:scala3-library_3:*.**.**-nonbootstrapped project */
@@ -2054,19 +2059,8 @@ object Build {
20542059
customMimaReportBinaryIssues("MiMaFilters.Scala3Library"),
20552060
// Should we also patch .sjsir files
20562061
keepSJSIR := false,
2057-
Compile / resourceGenerators += Def.task {
2058-
val file = (Compile / resourceManaged).value / "library3.properties"
2059-
val contents =
2060-
s"""version.number=${version.value}
2061-
|maven.version.number=${version.value}
2062-
|""".stripMargin
2063-
2064-
if (!(file.exists && IO.read(file) == contents)) {
2065-
IO.write(file, contents)
2066-
}
2067-
2068-
Seq(file)
2069-
}.taskValue,
2062+
// Generate Scala 3 runtime properties overlay
2063+
Compile / resourceGenerators += generateLibrary3Properties.taskValue,
20702064
)
20712065

20722066
/* Configuration of the org.scala-lang:scala3-library_3:*.**.**-bootstrapped project */
@@ -2470,25 +2464,7 @@ object Build {
24702464
// Project specific target folder. sbt doesn't like having two projects using the same target folder
24712465
target := target.value / "scala3-compiler-nonbootstrapped",
24722466
// Generate compiler.properties, used by sbt
2473-
Compile / resourceGenerators += Def.task {
2474-
import java.util._
2475-
import java.text._
2476-
val file = (Compile / resourceManaged).value / "compiler.properties"
2477-
val dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss")
2478-
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"))
2479-
val contents = //2.11.11.v20170413-090219-8a413ba7cc
2480-
s"""version.number=${version.value}
2481-
|maven.version.number=${version.value}
2482-
|git.hash=${VersionUtil.gitHash}
2483-
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL
2484-
""".stripMargin
2485-
2486-
if (!(file.exists && IO.read(file) == contents)) {
2487-
IO.write(file, contents)
2488-
}
2489-
2490-
Seq(file)
2491-
}.taskValue,
2467+
Compile / resourceGenerators += generateCompilerProperties.taskValue,
24922468
// sbt adds all the projects to scala-tool config which breaks building the scalaInstance
24932469
// as a workaround, I build it manually by only adding the compiler
24942470
managedScalaInstance := false,
@@ -2638,25 +2614,7 @@ object Build {
26382614
// Project specific target folder. sbt doesn't like having two projects using the same target folder
26392615
target := target.value / "scala3-compiler-bootstrapped",
26402616
// Generate compiler.properties, used by sbt
2641-
Compile / resourceGenerators += Def.task {
2642-
import java.util._
2643-
import java.text._
2644-
val file = (Compile / resourceManaged).value / "compiler.properties"
2645-
val dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss")
2646-
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"))
2647-
val contents = //2.11.11.v20170413-090219-8a413ba7cc
2648-
s"""version.number=${version.value}
2649-
|maven.version.number=${version.value}
2650-
|git.hash=${VersionUtil.gitHash}
2651-
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL
2652-
""".stripMargin
2653-
2654-
if (!(file.exists && IO.read(file) == contents)) {
2655-
IO.write(file, contents)
2656-
}
2657-
2658-
Seq(file)
2659-
}.taskValue,
2617+
Compile / resourceGenerators += generateCompilerProperties.taskValue,
26602618
// Configure to use the non-bootstrapped compiler
26612619
managedScalaInstance := false,
26622620
scalaInstance := {

tests/run/properties-version-string.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// scalajs: --skip
12
object Test {
23
def main(args: Array[String]): Unit = {
34
val v = scala.util.Properties.versionNumberString

0 commit comments

Comments
 (0)