summaryrefslogtreecommitdiff
path: root/project
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-02-03 22:06:42 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-02-04 09:19:19 +1000
commitda46355a90442636ee7634c31a69eae8e8b9cd42 (patch)
treeeec9abbf057e3c5fd4566df6628f9693835cc536 /project
parent74e53cb4930fc3e02222d8be0f065ce8aaa71230 (diff)
parentcc6fea6d30609b8879db1ecdbc288e4cdaa5b8d4 (diff)
downloadscala-da46355a90442636ee7634c31a69eae8e8b9cd42.tar.gz
scala-da46355a90442636ee7634c31a69eae8e8b9cd42.tar.bz2
scala-da46355a90442636ee7634c31a69eae8e8b9cd42.zip
Merge commit 'cc6fea6' into merge/2.11.x-to-2.12.x-20160203
Conflicts: build.sbt scripts/jobs/integrate/bootstrap
Diffstat (limited to 'project')
-rw-r--r--project/JarJar.scala4
-rw-r--r--project/ScalaTool.scala21
-rw-r--r--project/ScriptCommands.scala19
-rw-r--r--project/VersionUtil.scala99
4 files changed, 95 insertions, 48 deletions
diff --git a/project/JarJar.scala b/project/JarJar.scala
index 2eec0e9033..918060c9ee 100644
--- a/project/JarJar.scala
+++ b/project/JarJar.scala
@@ -35,12 +35,12 @@ object JarJar {
}
case class JarEntryInput(jarFile: JarFile, entry: JarEntry) extends Entry {
- def name = entry.getName
+ def name = entry.getName.replace('\\', '/')
def time = entry.getTime
def data = sbt.IO.readBytes(jarFile.getInputStream(entry))
}
case class FileInput(base: File, file: File) extends Entry {
- def name = file.relativeTo(base).get.getPath
+ def name = file.relativeTo(base).get.getPath.replace('\\', '/')
def time = file.lastModified
def data = sbt.IO.readBytes(file)
}
diff --git a/project/ScalaTool.scala b/project/ScalaTool.scala
index 559b215c18..e9531f229e 100644
--- a/project/ScalaTool.scala
+++ b/project/ScalaTool.scala
@@ -1,4 +1,5 @@
import sbt._
+import org.apache.commons.lang3.SystemUtils
import org.apache.commons.lang3.StringUtils.replaceEach
/**
@@ -15,8 +16,15 @@ case class ScalaTool(mainClass: String,
// demarcation of any script variables (e.g. `${SCALA_HOME}` or
// `%SCALA_HOME%`) can be specified in a platform independent way (e.g.
// `@SCALA_HOME@`) and automatically translated for you.
- def patchedToolScript(template: String, platform: String) = {
+ def patchedToolScript(template: String, forWindows: Boolean) = {
val varRegex = """@(\w+)@""" // the group should be able to capture each of the keys of the map below
+ val platformClasspath =
+ if(forWindows) classpath.mkString(";").replace('/', '\\').replaceAll(varRegex, "%$1%")
+ else if(SystemUtils.IS_OS_WINDOWS) {
+ // When building on Windows, use a Windows classpath in the shell script (for MSYS/Cygwin).
+ // This is only used for "quick", which uses absolute paths, so it is not portable anyway.
+ classpath.mkString(";").replace("\\", "\\\\").replaceAll(varRegex, """\${$1}""")
+ } else classpath.mkString(":").replace('\\', '/').replaceAll(varRegex, """\${$1}""")
val variables = Map(
("@@" -> "@"), // for backwards compatibility
@@ -24,10 +32,7 @@ case class ScalaTool(mainClass: String,
("@properties@" -> (properties map { case (k, v) => s"""-D$k="$v""""} mkString " ")),
("@javaflags@" -> javaOpts),
("@toolflags@" -> toolFlags),
- ("@classpath@" -> (platform match {
- case "unix" => classpath.mkString(":").replace('\\', '/').replaceAll(varRegex, """\${$1}""")
- case "windows" => classpath.mkString(";").replace('/', '\\').replaceAll(varRegex, "%$1%")
- }))
+ ("@classpath@" -> platformClasspath)
)
val (from, to) = variables.unzip
@@ -35,10 +40,12 @@ case class ScalaTool(mainClass: String,
}
def writeScript(file: String, platform: String, rootDir: File, outDir: File): File = {
+ val forWindows = platform match { case "windows" => true case _ => false }
val templatePath = s"scala/tools/ant/templates/tool-$platform.tmpl"
- val suffix = platform match { case "windows" => ".bat" case _ => "" }
+ val suffix = if(forWindows) ".bat" else ""
val scriptFile = outDir / s"$file$suffix"
- IO.write(scriptFile, patchedToolScript(IO.read(rootDir / templatePath), platform))
+ val patched = patchedToolScript(IO.read(rootDir / templatePath).replace("\r", ""), forWindows)
+ IO.write(scriptFile, if(forWindows) patched.replace("\n", "\r\n") else patched)
scriptFile
}
}
diff --git a/project/ScriptCommands.scala b/project/ScriptCommands.scala
new file mode 100644
index 0000000000..537990d985
--- /dev/null
+++ b/project/ScriptCommands.scala
@@ -0,0 +1,19 @@
+import sbt._
+import Keys._
+import complete.DefaultParsers._
+
+/** Custom commands for use by the Jenkins scripts. This keeps the surface area and call syntax small. */
+object ScriptCommands {
+ def all = Seq(setupPublishCore)
+
+ /** Set up the environment for `validate/publish-core`. The argument is the Artifactory snapshot repository URL. */
+ def setupPublishCore = Command.single("setupPublishCore") { case (state, url) =>
+ Project.extract(state).append(Seq(
+ VersionUtil.baseVersionSuffix in Global := "SHA-SNAPSHOT",
+ // Append build.timestamp to Artifactory URL to get consistent build numbers (see https://github.com/sbt/sbt/issues/2088):
+ publishTo in Global := Some("scala-pr" at url.replaceAll("/$", "") + ";build.timestamp=" + System.currentTimeMillis),
+ publishArtifact in (Compile, packageDoc) in ThisBuild := false,
+ scalacOptions in Compile in ThisBuild += "-optimise"
+ ), state)
+ }
+}
diff --git a/project/VersionUtil.scala b/project/VersionUtil.scala
index 71de772b08..f237c35c68 100644
--- a/project/VersionUtil.scala
+++ b/project/VersionUtil.scala
@@ -5,21 +5,29 @@ import java.io.FileInputStream
import scala.collection.JavaConverters._
object VersionUtil {
+ lazy val baseVersion = settingKey[String]("The base version number from which all others are derived")
+ lazy val baseVersionSuffix = settingKey[String]("Identifies the kind of version to build")
lazy val copyrightString = settingKey[String]("Copyright string.")
lazy val versionProperties = settingKey[Versions]("Version properties.")
lazy val generateVersionPropertiesFile = taskKey[File]("Generating version properties file.")
+ lazy val generateBuildCharacterPropertiesFile = taskKey[File]("Generating buildcharacter.properties file.")
- lazy val versionPropertiesSettings = Seq[Setting[_]](
- versionProperties := versionPropertiesImpl.value
+ lazy val globalVersionSettings = Seq[Setting[_]](
+ // Set the version properties globally (they are the same for all projects)
+ versionProperties in Global := versionPropertiesImpl.value,
+ version in Global := versionProperties.value.mavenVersion
)
lazy val generatePropertiesFileSettings = Seq[Setting[_]](
copyrightString := "Copyright 2002-2015, LAMP/EPFL",
resourceGenerators in Compile += generateVersionPropertiesFile.map(file => Seq(file)).taskValue,
- versionProperties := versionPropertiesImpl.value,
generateVersionPropertiesFile := generateVersionPropertiesFileImpl.value
)
+ lazy val generateBuildCharacterFileSettings = Seq[Setting[_]](
+ generateBuildCharacterPropertiesFile := generateBuildCharacterPropertiesFileImpl.value
+ )
+
case class Versions(canonicalVersion: String, mavenVersion: String, osgiVersion: String, commitSha: String, commitDate: String, isRelease: Boolean) {
val githubTree =
if(isRelease) "v" + mavenVersion
@@ -28,30 +36,36 @@ object VersionUtil {
override def toString = s"Canonical: $canonicalVersion, Maven: $mavenVersion, OSGi: $osgiVersion, github: $githubTree"
- def toProperties: Properties = {
- val props = new Properties
- props.put("version.number", canonicalVersion)
- props.put("maven.version.number", mavenVersion)
- props.put("osgi.version.number", osgiVersion)
- props
- }
+ def toMap: Map[String, String] = Map(
+ "version.number" -> canonicalVersion,
+ "maven.version.number" -> mavenVersion,
+ "osgi.version.number" -> osgiVersion
+ )
}
- lazy val versionPropertiesImpl: Def.Initialize[Versions] = Def.setting {
- /** Regexp that splits version number split into two parts: version and suffix.
- * Examples of how the split is performed:
- *
- * "2.11.5": ("2.11.5", null)
- * "2.11.5-acda7a": ("2.11.5", "-acda7a")
- * "2.11.5-SNAPSHOT": ("2.11.5", "-SNAPSHOT") */
- val versionSplitted = """([\w+\.]+)(-[\w+\.]+)??""".r
-
- val versionSplitted(ver, suffixOrNull) = version.value
-
- val osgiSuffix = suffixOrNull match {
- case null => "-VFINAL"
- case "-SNAPSHOT" => ""
- case suffixStr => suffixStr
+ /** Compute the canonical, Maven and OSGi version number from `baseVersion` and `baseVersionSuffix`.
+ * Examples of the generated versions:
+ *
+ * ("2.11.8", "SNAPSHOT" ) -> ("2.11.8-20151215-133023-7559aed3c5", "2.11.8-SNAPSHOT", "2.11.8.v20151215-133023-7559aed3c5")
+ * ("2.11.8", "SHA-SNAPSHOT") -> ("2.11.8-20151215-133023-7559aed3c5", "2.11.8-7559aed3c5-SNAPSHOT", "2.11.8.v20151215-133023-7559aed3c5")
+ * ("2.11.8", "" ) -> ("2.11.8", "2.11.8", "2.11.8.v20151215-133023-VFINAL-7559aed3c5")
+ * ("2.11.8", "M3" ) -> ("2.11.8-M3", "2.11.8-M3", "2.11.8.v20151215-133023-M3-7559aed3c5")
+ * ("2.11.8", "RC4" ) -> ("2.11.8-RC4", "2.11.8-RC4", "2.11.8.v20151215-133023-RC4-7559aed3c5")
+ * ("2.11.8-RC4", "SPLIT" ) -> ("2.11.8-RC4", "2.11.8-RC4", "2.11.8.v20151215-133023-RC4-7559aed3c5")
+ *
+ * A `baseVersionSuffix` of "SNAPSHOT" is the default, which is used for local snapshot builds. The PR validation
+ * job uses "SHA-SNAPSHOT". An empty suffix is used for releases. All other suffix values are treated as RC /
+ * milestone builds. The special suffix value "SPLIT" is used to split the real suffix off from `baseVersion`
+ * instead and then apply the usual logic. */
+ private lazy val versionPropertiesImpl: Def.Initialize[Versions] = Def.setting {
+
+ val (base, suffix) = {
+ val (b, s) = (baseVersion.value, baseVersionSuffix.value)
+ if(s == "SPLIT") {
+ val split = """([\w+\.]+)(-[\w+\.]+)??""".r
+ val split(b2, sOrNull) = b
+ (b2, Option(sOrNull).map(_.drop(1)).getOrElse(""))
+ } else (b, s)
}
def executeTool(tool: String) = {
@@ -62,24 +76,31 @@ object VersionUtil {
Process(cmd).lines.head
}
- val commitDate = executeTool("get-scala-commit-date")
- val commitSha = executeTool("get-scala-commit-sha")
+ val date = executeTool("get-scala-commit-date")
+ val sha = executeTool("get-scala-commit-sha").substring(0, 7) // The script produces 10 digits at the moment
- Versions(
- canonicalVersion = s"$ver-$commitDate-$commitSha",
- mavenVersion = s"${version.value}",
- osgiVersion = s"$ver.v$commitDate$osgiSuffix-$commitSha",
- commitSha = commitSha,
- commitDate = commitDate,
- isRelease = !osgiSuffix.isEmpty
- )
+ val (canonicalV, mavenV, osgiV, release) = suffix match {
+ case "SNAPSHOT" => (s"$base-$date-$sha", s"$base-SNAPSHOT", s"$base.v$date-$sha", false)
+ case "SHA-SNAPSHOT" => (s"$base-$date-$sha", s"$base-$sha-SNAPSHOT", s"$base.v$date-$sha", false)
+ case "" => (s"$base", s"$base", s"$base.v$date-VFINAL-$sha", true)
+ case suffix => (s"$base-$suffix", s"$base-$suffix", s"$base.v$date-$suffix-$sha", true)
+ }
+
+ Versions(canonicalV, mavenV, osgiV, sha, date, release)
}
- lazy val generateVersionPropertiesFileImpl: Def.Initialize[Task[File]] = Def.task {
- val props = versionProperties.value.toProperties
- val propFile = (resourceManaged in Compile).value / s"${thisProject.value.id}.properties"
- props.put("copyright.string", copyrightString.value)
+ private lazy val generateVersionPropertiesFileImpl: Def.Initialize[Task[File]] = Def.task {
+ writeProps(versionProperties.value.toMap + ("copyright.string" -> copyrightString.value),
+ (resourceManaged in Compile).value / s"${thisProject.value.id}.properties")
+ }
+
+ private lazy val generateBuildCharacterPropertiesFileImpl: Def.Initialize[Task[File]] = Def.task {
+ writeProps(versionProperties.value.toMap, (baseDirectory in ThisBuild).value / "buildcharacter.properties")
+ }
+ private def writeProps(m: Map[String, String], propFile: File): File = {
+ val props = new Properties
+ m.foreach { case (k, v) => props.put(k, v) }
// unfortunately, this will write properties in arbitrary order
// this makes it harder to test for stability of generated artifacts
// consider using https://github.com/etiennestuder/java-ordered-properties