Skip to content

Commit 646ffe6

Browse files
authored
Merge pull request #468 from mkurz/sbt2
sbt 2 cross build
2 parents ef40979 + 01ade30 commit 646ffe6

15 files changed

Lines changed: 191 additions & 87 deletions

File tree

‎.github/workflows/build-test.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ jobs:
1717
name: Tests
1818
uses: playframework/.github/.github/workflows/cmd.yml@v4
1919
with:
20-
java: 21, 17, 11, 8
21-
scala: 2.12.21
20+
java: 25, 17, 11, 8
21+
scala: 2.12.x, 3.x
22+
exclude: '[{"java": "8", "scala": "3.x"}, {"java": "11", "scala": "3.x"}]'
2223
cmd: |
2324
sbt ++$MATRIX_SCALA test scripted
2425

‎build.sbt‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1-
lazy val root = (project in file("."))
1+
lazy val scala212 = "2.12.21"
2+
lazy val scala3 = "3.8.3"
3+
4+
ThisBuild / crossScalaVersions := Seq(scala212, scala3)
5+
6+
lazy val root = project.in(file("."))
27
.enablePlugins(SbtPlugin)
38
.settings(
49
Seq(
510
organization := "com.github.sbt",
611
name := "sbt-eclipse",
7-
scalacOptions ++= Seq("-unchecked", "-deprecation", "-target:jvm-1.8"),
8-
scalaVersion := "2.12.21",
12+
crossScalaVersions := Seq(scala212, scala3),
13+
scalacOptions ++= {
14+
CrossVersion.partialVersion(scalaVersion.value) match {
15+
case Some((2, _)) => Seq("-unchecked", "-deprecation", "-Xsource:3", "-release:8")
16+
case _ => Seq("-unchecked", "-deprecation")
17+
}
18+
},
19+
scalaVersion := scala212,
20+
ThisBuild / (pluginCrossBuild / sbtVersion) := {
21+
scalaBinaryVersion.value match {
22+
case "2.12" => "1.12.9"
23+
case _ => "2.0.0-RC11"
24+
}
25+
},
926
// Customise sbt-dynver's behaviour to make it work with tags which aren't v-prefixed
1027
ThisBuild / dynverVTagPrefix := false,
1128
// Sanity-check: assert that version comes from a tag (e.g. not a too-shallow clone)

‎project/build.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.12.6
1+
sbt.version=1.12.9
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.typesafe.sbteclipse.core
2+
3+
import sbt.{Configuration, Def, Keys, Setting, Task}
4+
import xsbti.compile.CompileAnalysis
5+
6+
private object CompileTaskCompat {
7+
def compileSetting(scope: Configuration, task: Def.Initialize[Task[CompileAnalysis]]): Setting[?] =
8+
(scope / Keys.compile) := task.value
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.typesafe.sbteclipse.core
2+
3+
import sbt._
4+
import sbt.{Configuration, Def, Keys, Setting, Task}
5+
import xsbti.compile.CompileAnalysis
6+
7+
private object CompileTaskCompat {
8+
def compileSetting(scope: Configuration, task: Def.Initialize[Task[CompileAnalysis]]): Setting[?] =
9+
(scope / Keys.compile) := Def.uncached(task).value
10+
}

‎src/main/scala/com/typesafe/sbteclipse/core/Eclipse.scala‎

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package com.typesafe.sbteclipse.core
2020

21+
import sbt._
2122
import EclipsePlugin.{
2223
EclipseClasspathEntry,
2324
EclipseTransformerFactory,
@@ -39,7 +40,6 @@ import sbt.{
3940
Configurations,
4041
EvaluateTask,
4142
File,
42-
Inc,
4343
Incomplete,
4444
Keys,
4545
ModuleID,
@@ -52,8 +52,7 @@ import sbt.{
5252
State,
5353
TaskKey,
5454
ThisBuild,
55-
UpdateReport,
56-
Value
55+
UpdateReport
5756
}
5857
import sbt.fileToRichFile
5958
import sbt.internal.BuildStructure
@@ -100,7 +99,9 @@ private object Eclipse extends EclipseSDTConfig {
10099
import EclipseExecutionEnvironment._
101100
import EclipseOpts._
102101
import sbt.complete.DefaultParsers._
103-
val (head :: tail) = valueSeq map (_.toString)
102+
val parsedValues = valueSeq.toList.map(_.toString)
103+
val head = parsedValues.head
104+
val tail = parsedValues.tail
104105
val executionEnvironments = tail.foldLeft(head: Parser[String])(_ | _)
105106
(Space ~> ExecutionEnvironment ~ ("=" ~> executionEnvironments)) map { case (k, v) => k -> withName(v) }
106107
}
@@ -109,7 +110,9 @@ private object Eclipse extends EclipseSDTConfig {
109110
import EclipseJDTMode._
110111
import EclipseOpts._
111112
import sbt.complete.DefaultParsers._
112-
val (head :: tail) = valueSeq map (_.toString)
113+
val parsedValues = valueSeq.toList.map(_.toString)
114+
val head = parsedValues.head
115+
val tail = parsedValues.tail
113116
val jdtModes = tail.foldLeft(head: Parser[String])(_ | _)
114117
(Space ~> JDTMode ~ ("=" ~> jdtModes)) map { case (k, v) => k -> withName(v) }
115118
}
@@ -160,7 +163,7 @@ private object Eclipse extends EclipseSDTConfig {
160163
builderAndNatures(projectFlavor(ref, state)),
161164
state))
162165
}
163-
effects.toList.sequence[Validation, IO[String]].map((list: List[IO[String]]) => list.toStream.sequence.map(_.toList))
166+
effects.toList.sequence[Validation, IO[String]].map((list: List[IO[String]]) => list.sequence.map(_.toList))
164167
}
165168

166169
def removeExtendedConfigurations(configurations: Seq[Configuration]): Seq[Configuration] = {
@@ -230,8 +233,8 @@ private object Eclipse extends EclipseSDTConfig {
230233
projectDependencies,
231234
jreContainer,
232235
state)
233-
_ <- saveXml(baseDirectory / ".project", new RuleTransformer(projectTransformers: _*)(projectXml(name, builderAndNatures, linkedSrcDirectories)))
234-
_ <- saveXml(baseDirectory / ".classpath", new RuleTransformer(classpathTransformers: _*)(cp))
236+
_ <- saveXml(baseDirectory / ".project", new RuleTransformer(projectTransformers*)(projectXml(name, builderAndNatures, linkedSrcDirectories)))
237+
_ <- saveXml(baseDirectory / ".classpath", new RuleTransformer(classpathTransformers*)(cp))
235238
_ <- saveProperties(baseDirectory / ".settings" / "org.eclipse.core.resources.prefs", Seq(("encoding/<project>" -> "UTF-8")))
236239
_ <- saveProperties(baseDirectory / ".settings" / "org.scala-ide.sdt.core.prefs", scalacOptions ++: compileOrder.map { order => Seq(("compileorder" -> order)) }.getOrElse(Nil))
237240
_ <- handleJDTSettings(jdtMode, baseDirectory, jreContainer)
@@ -330,10 +333,10 @@ private object Eclipse extends EclipseSDTConfig {
330333
dir
331334
}
332335
val entries = srcEntries ++ linkEntries ++
333-
(projectDependencies map EclipseClasspathEntry.Project) ++
336+
(projectDependencies map EclipseClasspathEntry.Project.apply) ++
334337
(externalDependencies map libEntry(buildDirectory, baseDirectory, relativizeLibs, state)) ++
335-
(Seq(jreContainer) map EclipseClasspathEntry.Con) ++
336-
(Seq(classDirectory) map EclipseClasspathEntry.Output)
338+
(Seq(jreContainer) map EclipseClasspathEntry.Con.apply) ++
339+
(Seq(classDirectory) map EclipseClasspathEntry.Output.apply)
337340
<classpath>{ entries map (_.toXml) }</classpath>
338341
}
339342
}
@@ -389,7 +392,7 @@ private object Eclipse extends EclipseSDTConfig {
389392
if (buildDirectory === baseDirectory) Some(".") else sbt.IO.relativize(buildDirectory, baseDirectory)
390393
val relativizedFile = sbt.IO.relativize(buildDirectory, file)
391394
val relativized = (relativizedBase |@| relativizedFile)((base, file) =>
392-
s"${base split FileSepPattern map (part => if (part != ".") ".." else part) mkString FileSep}${FileSep}${file}")
395+
s"${base.split(FileSepPattern).map(part => if (part != ".") ".." else part).mkString(FileSep)}${FileSep}${file}")
393396
if (relativizeLibs) relativized getOrElse file.getAbsolutePath else file.getAbsolutePath
394397
}
395398
EclipseClasspathEntry.Lib(path(lib.binary), lib.source map path, lib.javadoc map path)
@@ -484,7 +487,8 @@ private object Eclipse extends EclipseSDTConfig {
484487
dirs(ValueSet(), Keys.unmanagedSourceDirectories),
485488
dirs(ValueSet(), Keys.unmanagedResourceDirectories),
486489
dirs(ValueSet(ManagedSrc), Keys.managedSourceDirectories),
487-
dirs(ValueSet(ManagedResources), Keys.managedResourceDirectories)) reduceLeft (_ +++ _)
490+
dirs(ValueSet(ManagedResources), Keys.managedResourceDirectories)
491+
).sequence.map(_.flatten)
488492
}
489493

490494
def scalacOptions(ref: ProjectRef, state: State): Validation[Seq[(String, String)]] = {
@@ -511,7 +515,7 @@ private object Eclipse extends EclipseSDTConfig {
511515
def moduleReports(key: TaskKey[UpdateReport]) =
512516
evalTask(key) map { updateReport =>
513517
for {
514-
configurationReport <- (updateReport configuration configuration).toSeq
518+
configurationReport <- updateReport.configuration(configuration).toSeq
515519
moduleReports <- configurationReport.modules
516520
} yield moduleReports
517521
}
@@ -528,14 +532,24 @@ private object Eclipse extends EclipseSDTConfig {
528532
def moduleFileToArtifactFile(binaries: Map[ModuleID, File], sources: Map[ModuleID, File], javadocs: Map[ModuleID, File]) =
529533
for ((moduleId, binaryFile) <- binaries)
530534
yield binaryFile -> Lib(binaryFile)(sources get moduleId)(javadocs get moduleId)
531-
def libs(files: Seq[Attributed[File]], moduleFiles: Map[File, Lib]): Seq[Lib] = {
532-
var result: Seq[Lib] = files.files map { file => moduleFiles.get(file).getOrElse(Lib(file)(None)(None)) }
535+
def classpathFile(a: Attributed[?], conv: xsbti.FileConverter): File =
536+
a.data match {
537+
case file: File => file
538+
case ref: xsbti.VirtualFileRef => conv.toPath(ref).toFile
539+
}
540+
541+
def libs(files: Seq[Attributed[?]], conv: xsbti.FileConverter, moduleFiles: Map[File, Lib]): Seq[Lib] = {
542+
var result: Seq[Lib] = files.map { a =>
543+
val file = classpathFile(a, conv)
544+
moduleFiles.get(file).getOrElse(Lib(file)(None)(None))
545+
}
533546
if (createSrc(ref, state)(configuration).contains(EclipseCreateSrc.ManagedClasses)) {
534547
result = result ++ managedClassDirectories(ref, state)(configuration).filter(_.exists).map(Lib(_)(None)(None))
535548
}
536549
result
537550
}
538551
val externalDependencyClasspath: Validation[sbt.Keys.Classpath] = evalTask(Keys.externalDependencyClasspath)
552+
val fileConverter = settingValidation((ref / Keys.fileConverter), state)
539553
val moduleFiles: Validation[Map[File, Lib]] = {
540554
lazy val classifierModuleReports = moduleReports(Keys.updateClassifiers)
541555

@@ -551,14 +565,14 @@ private object Eclipse extends EclipseSDTConfig {
551565

552566
sources |+| javadoc match {
553567
case Some(_) => {
554-
val binaryModuleToFile = moduleToFile(moduleReports(Keys.update))
568+
val binaryModuleToFile = moduleToFile(moduleReports(Keys.update), (_, _) => true)
555569

556570
(binaryModuleToFile |@| classifierModuleToFile(sources) |@| classifierModuleToFile(javadoc))(moduleFileToArtifactFile)
557571
}
558572
case None => Map[File, Lib]().success
559573
}
560574
}
561-
val externalDependencies = (externalDependencyClasspath |@| moduleFiles)(libs)
575+
val externalDependencies = (externalDependencyClasspath |@| fileConverter |@| moduleFiles)(libs)
562576
state.log.debug(
563577
s"External dependencies for configuration '${configuration}' and withSource '${withSource}' and withJavadoc '${withJavadoc}': ${externalDependencies}")
564578
externalDependencies
@@ -731,8 +745,8 @@ private object Eclipse extends EclipseSDTConfig {
731745
new File(normalizeName(file.getAbsolutePath))
732746

733747
def normalizeName(filename: String): String = {
734-
if (filename contains "..") {
735-
val parts = (filename split "[\\/]+").toList
748+
if (filename.contains("..")) {
749+
val parts = (filename.split("[\\/]+")).toList
736750
def fix(parts: List[String], result: String): String = parts match {
737751
case Nil => result
738752
case a :: ".." :: rest => fix(rest, result)
@@ -751,7 +765,11 @@ private object Eclipse extends EclipseSDTConfig {
751765

752766
def boolOpt(key: String): Parser[(String, Boolean)] = {
753767
import sbt.complete.DefaultParsers._
754-
(Space ~> key ~ ("=" ~> ("true" | "false"))) map { case (k, v) => k -> v.toBoolean }
768+
val parserValues = List("true", "false").map(s => s: Parser[String])
769+
val head = parserValues.head
770+
val tail = parserValues.tail
771+
val bools = tail.foldLeft(head)(_ | _)
772+
(Space ~> key ~ ("=" ~> bools)) map { case (k, v) => k -> v.toBoolean }
755773
}
756774

757775
/**
@@ -773,8 +791,11 @@ private object Eclipse extends EclipseSDTConfig {
773791
def evaluateTask[A](key: TaskKey[A], ref: ProjectRef, state: State): Validation[A] = {
774792
val taskConfig = EvaluateTask.extractedTaskConfig(Project.extract(state), structure(state), state)
775793
EvaluateTask(structure(state), key, state, ref, taskConfig) match {
776-
case Some((_, Value(a))) => a.success
777-
case Some((_, Inc(inc))) => s"Error evaluating task '${key.key}': ${Incomplete.show(inc.tpe)}".failureNel
794+
case Some((_, result)) =>
795+
result.toEither.fold(
796+
inc => s"Error evaluating task '${key.key}': ${Incomplete.show(inc.tpe)}".failureNel,
797+
_.success
798+
)
778799
case None => s"Undefined task '${key.key}' for '${ref.project}'!".failureNel
779800
}
780801
}

0 commit comments

Comments
 (0)