Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make version compatibility tasks workable #1517

Merged
merged 3 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _ext/eclipse-wtp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ sourceSets {
* All test classes need to run separately since they all instatiate different setups of the
* Eclipse framework.
*/
test {
tasks.withType(Test).configureEach {
//Skip default tests, which would run every test case.
exclude '**'
}
Expand Down
4 changes: 3 additions & 1 deletion _ext/gradle/java-setup.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ dependencies {
testImplementation project(':testlib')
}

test { useJUnitPlatform() }
tasks.withType(Test).configureEach {
useJUnitPlatform()
}
2 changes: 1 addition & 1 deletion gradle/special-tests.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def special = [
]

boolean isCiServer = System.getenv().containsKey("CI")
tasks.named('test') {
tasks.withType(Test).configureEach {
// See com.diffplug.spotless.tag package for available JUnit 5 @Tag annotations
useJUnitPlatform {
excludeTags special as String[]
Expand Down
2 changes: 1 addition & 1 deletion lib-extra/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {
spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes)

apply from: rootProject.file('gradle/special-tests.gradle')
tasks.named('test') {
tasks.withType(Test).configureEach {
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) {
// needed for EclipseCdtFormatterStepTest
jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED'
Expand Down
22 changes: 22 additions & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ versionCompatibility {
}
}

tasks.named("check").configure {
dependsOn(tasks.named("testCompatibilityAdapters"))
dependsOn(tasks.named("testCompatibility"))
}
Comment on lines +45 to +48
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


dependencies {
compileOnly 'org.slf4j:slf4j-api:2.0.0'
// zero runtime reqs is a hard requirements for spotless-lib
Expand Down Expand Up @@ -114,6 +119,23 @@ dependencies {
spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes)

apply from: rootProject.file('gradle/special-tests.gradle')
tasks.withType(Test).configureEach {
def jdkVersion = JavaVersion.current().majorVersion.toInteger()
def args = []
if (jdkVersion >= 16) {
// https://docs.gradle.org/7.5/userguide/upgrading_version_7.html#removes_implicit_add_opens_for_test_workers
args += [
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.base/java.util=ALL-UNNAMED",
]
}
if (jdkVersion >= 18) {
// https://openjdk.org/jeps/411
args += "-Djava.security.manager=allow"
}
jvmArgs(args)
}
Comment on lines +122 to +137
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run ./gradlew :lib:testCompatKtLint0Dot48Dot0

> Task :lib:testCompatKtLint0Dot48Dot0 FAILED

com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0AdapterTest

  Test testEditorConfigCanDisable(Path) PASSED
  Test testDefaults(Path) FAILED

  java.lang.ExceptionInInitializerError
      at com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0AdapterTest.testDefaults(KtLintCompat0Dot48Dot0AdapterTest.java:43)
  Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private transient java.lang.Object java.lang.Throwable.backtrace accessible: module java.base does not "opens java.lang" to unnamed module @689349f1
      at com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0AdapterTest.testDefaults(KtLintCompat0Dot48Dot0AdapterTest.java:43)


FAILURE: Executed 2 tests in 1s (1 failed)


jar {
for (glue in NEEDS_GLUE) {
from sourceSets.getByName(glue).output.classesDirs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -33,27 +34,29 @@ public class KtLintCompat0Dot48Dot0AdapterTest {
public void testDefaults(@TempDir Path path) throws IOException {
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
String text = loadAndWriteText(path, "empty_class_body.kt");
final Path filePath = Paths.get(path.toString(), "empty_class_body.kt");

Map<String, String> userData = new HashMap<>();

Map<String, Object> editorConfigOverrideMap = new HashMap<>();

String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, path, false, false, null, userData, editorConfigOverrideMap);
String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap);
assertEquals("class empty_class_body\n", formatted);
}

@Test
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
String text = loadAndWriteText(path, "fails_no_semicolons.kt");
final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt");

Map<String, String> userData = new HashMap<>();

Map<String, Object> editorConfigOverrideMap = new HashMap<>();
editorConfigOverrideMap.put("indent_style", "tab");
editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled");

String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, path, false, false, null, userData, editorConfigOverrideMap);
String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap);
assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted);
}

Expand Down
2 changes: 1 addition & 1 deletion plugin-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
}

apply from: rootProject.file('gradle/special-tests.gradle')
tasks.named('test') {
tasks.withType(Test).configureEach {
testLogging.showStandardStreams = true
}

Expand Down
2 changes: 1 addition & 1 deletion testlib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {
spotbugs { reportLevel = 'high' } // low|medium|high (low = sensitive to even minor mistakes)

apply from: rootProject.file('gradle/special-tests.gradle')
tasks.named('test') {
tasks.withType(Test).configureEach {
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) {
// for Antlr4FormatterStepTest and KtLintStepTest
def args = [
Expand Down