|
| 1 | + |
| 2 | +val check = TaskKey[Unit]("check") := { |
| 3 | + import java.util.Properties |
| 4 | + import java.io.FileInputStream |
| 5 | + import scala.collection.JavaConverters._ |
| 6 | + |
| 7 | + val s: TaskStreams = streams.value |
| 8 | + val expectedFile = baseDirectory.value / "expected" |
| 9 | + val resultFile = baseDirectory.value / ".settings" / "org.eclipse.jdt.core.prefs" |
| 10 | + |
| 11 | + if (expectedFile.exists()) { |
| 12 | + val expectedIn = new FileInputStream(expectedFile) |
| 13 | + val expected = |
| 14 | + try { |
| 15 | + val prop = new Properties() |
| 16 | + prop.load(expectedIn) |
| 17 | + prop.asScala.toMap |
| 18 | + } finally { |
| 19 | + expectedIn.close() |
| 20 | + } |
| 21 | + |
| 22 | + val resultIn = new FileInputStream(resultFile) |
| 23 | + val result = |
| 24 | + try { |
| 25 | + val prop = new Properties() |
| 26 | + prop.load(resultIn) |
| 27 | + prop.asScala.toMap |
| 28 | + } finally { |
| 29 | + resultIn.close() |
| 30 | + } |
| 31 | + |
| 32 | + if (expected == result) |
| 33 | + s.log.info(s"correct data: ${resultFile}") |
| 34 | + else |
| 35 | + sys.error("Expected settings to be '%s', but was '%s'!".format(expected, result)) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +// ensure org.eclipse.core.resources.prefs will always be generated |
| 40 | +ThisBuild / scalacOptions ++= Seq("-encoding", "utf-8") |
| 41 | + |
| 42 | +// check that no JDT file is generated (default ignore, no runtime defined) |
| 43 | +lazy val projectA = (project in file("a")) |
| 44 | + .settings( |
| 45 | + check |
| 46 | + ) |
| 47 | + |
| 48 | +// check that a new and correct JDT file is generated |
| 49 | +lazy val projectB = (project in file("b")) |
| 50 | + .settings( |
| 51 | + EclipseKeys.executionEnvironment := Some(EclipseExecutionEnvironment.JavaSE18), |
| 52 | + EclipseKeys.jdtMode := EclipseJDTMode.Update, |
| 53 | + check |
| 54 | + ) |
| 55 | + |
| 56 | +// check that a correct JDT file is is not updated |
| 57 | +lazy val projectC = (project in file("c")) |
| 58 | + .settings( |
| 59 | + EclipseKeys.executionEnvironment := Some(EclipseExecutionEnvironment.JavaSE11), |
| 60 | + EclipseKeys.jdtMode := EclipseJDTMode.Update, |
| 61 | + check |
| 62 | + ) |
| 63 | + |
| 64 | +// check that an outdated JDT file is selectively updated |
| 65 | +lazy val projectD = (project in file("d")) |
| 66 | + .settings( |
| 67 | + EclipseKeys.executionEnvironment := Some(EclipseExecutionEnvironment.JavaSE_17), |
| 68 | + EclipseKeys.jdtMode := EclipseJDTMode.Update, |
| 69 | + check |
| 70 | + ) |
| 71 | + |
| 72 | +// check that a JDT file is overwritten |
| 73 | +lazy val projectE = (project in file("e")) |
| 74 | + .settings( |
| 75 | + EclipseKeys.executionEnvironment := Some(EclipseExecutionEnvironment.JavaSE11), |
| 76 | + EclipseKeys.jdtMode := EclipseJDTMode.Overwrite, |
| 77 | + check |
| 78 | + ) |
| 79 | + |
| 80 | +// check that an JDT file is removed |
| 81 | +lazy val projectF = (project in file("f")) |
| 82 | + .settings( |
| 83 | + EclipseKeys.jdtMode := EclipseJDTMode.Remove, |
| 84 | + check |
| 85 | + ) |
| 86 | + |
| 87 | +// check that an JDT file is default ignored, but written on command |
| 88 | +lazy val projectG = (project in file("g")) |
| 89 | + .settings( |
| 90 | + EclipseKeys.executionEnvironment := Some(EclipseExecutionEnvironment.JavaSE18), |
| 91 | + check |
| 92 | + ) |
0 commit comments