Skip to content

Commit 1a6e03d

Browse files
spangaermkurz
authored andcommitted
Test various combinations JDT writing mode
1 parent ea3a3b2 commit 1a6e03d

File tree

14 files changed

+194
-0
lines changed

14 files changed

+194
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!.settings
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
2+
org.eclipse.jdt.core.compiler.source=1.8
3+
org.eclipse.jdt.core.compiler.compliance=1.8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
2+
org.eclipse.jdt.core.compiler.source=11
3+
org.eclipse.jdt.core.compiler.compliance=11
4+
dummy.key=abc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
2+
org.eclipse.jdt.core.compiler.source=11
3+
org.eclipse.jdt.core.compiler.compliance=11
4+
dummy.key=abc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
2+
org.eclipse.jdt.core.compiler.source=11
3+
org.eclipse.jdt.core.compiler.compliance=11
4+
dummy.key=abc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
2+
org.eclipse.jdt.core.compiler.source=17
3+
org.eclipse.jdt.core.compiler.compliance=17
4+
dummy.key=abc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
2+
org.eclipse.jdt.core.compiler.source=11
3+
org.eclipse.jdt.core.compiler.compliance=11
4+
dummy.key=abc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
2+
org.eclipse.jdt.core.compiler.source=11
3+
org.eclipse.jdt.core.compiler.compliance=11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
2+
org.eclipse.jdt.core.compiler.source=11
3+
org.eclipse.jdt.core.compiler.compliance=11
4+
dummy.key=abc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dummy.key=abc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dummy.key=abc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
val pluginVersion = System.getProperty("plugin.version")
3+
if(pluginVersion == null)
4+
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
5+
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
6+
else addSbtPlugin("com.github.sbt" % "sbt-eclipse" % pluginVersion)
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# timestamp marker file
2+
$ touch marker
3+
4+
$ exists f/.settings/org.eclipse.jdt.core.prefs
5+
6+
> eclipse
7+
8+
> check
9+
10+
$ exists a/.settings/org.eclipse.core.resources.prefs
11+
-$ exists a/.settings/org.eclipse.jdt.core.prefs
12+
13+
$ exists b/.settings/org.eclipse.jdt.core.prefs
14+
$ newer b/.settings/org.eclipse.jdt.core.prefs marker
15+
16+
$ exists c/.settings/org.eclipse.jdt.core.prefs
17+
$ newer marker c/.settings/org.eclipse.jdt.core.prefs
18+
19+
$ exists d/.settings/org.eclipse.jdt.core.prefs
20+
$ newer d/.settings/org.eclipse.jdt.core.prefs marker
21+
22+
$ exists e/.settings/org.eclipse.jdt.core.prefs
23+
$ newer e/.settings/org.eclipse.jdt.core.prefs marker
24+
25+
$ exists f/.settings/org.eclipse.core.resources.prefs
26+
-$ exists f/.settings/org.eclipse.jdt.core.prefs
27+
28+
$ exists g/.settings/org.eclipse.jdt.core.prefs
29+
$ newer marker g/.settings/org.eclipse.jdt.core.prefs
30+
31+
# test overwrite mode via command arg
32+
$ touch marker
33+
> eclipse jdt-mode=Overwrite
34+
# no runtime defined for a
35+
-$ exists a/.settings/org.eclipse.jdt.core.prefs
36+
$ newer b/.settings/org.eclipse.jdt.core.prefs marker
37+
$ newer c/.settings/org.eclipse.jdt.core.prefs marker
38+
$ newer d/.settings/org.eclipse.jdt.core.prefs marker
39+
$ newer e/.settings/org.eclipse.jdt.core.prefs marker
40+
-$ exists f/.settings/org.eclipse.jdt.core.prefs
41+
$ newer g/.settings/org.eclipse.jdt.core.prefs marker
42+
43+
# test ignore mode via command arg
44+
$ touch marker
45+
> eclipse jdt-mode=Ignore
46+
-$ exists a/.settings/org.eclipse.jdt.core.prefs
47+
$ newer marker b/.settings/org.eclipse.jdt.core.prefs
48+
$ newer marker c/.settings/org.eclipse.jdt.core.prefs
49+
$ newer marker d/.settings/org.eclipse.jdt.core.prefs
50+
$ newer marker e/.settings/org.eclipse.jdt.core.prefs
51+
-$ exists f/.settings/org.eclipse.jdt.core.prefs
52+
$ newer marker g/.settings/org.eclipse.jdt.core.prefs
53+
54+
# test remove mode via command arg
55+
> eclipse jdt-mode=Remove
56+
-$ exists a/.settings/org.eclipse.jdt.core.prefs
57+
-$ exists b/.settings/org.eclipse.jdt.core.prefs
58+
-$ exists c/.settings/org.eclipse.jdt.core.prefs
59+
-$ exists d/.settings/org.eclipse.jdt.core.prefs
60+
-$ exists e/.settings/org.eclipse.jdt.core.prefs
61+
-$ exists f/.settings/org.eclipse.jdt.core.prefs
62+
-$ exists g/.settings/org.eclipse.jdt.core.prefs

0 commit comments

Comments
 (0)