Skip to content

Commit

Permalink
Update Ktlint to 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tbroyer committed Oct 24, 2024
1 parent 3b32d64 commit 89aae31
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 245 deletions.
15 changes: 8 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ testing {

val testJavaToolchain = project.findProperty("test.java-toolchain")
testJavaToolchain?.also {
val metadata = project.javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(testJavaToolchain.toString()))
}.get().metadata
val launcher =
project.javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(testJavaToolchain.toString()))
}
val metadata = launcher.get().metadata
systemProperty("test.java-version", metadata.languageVersion.asInt())
systemProperty("test.java-home", metadata.installationPath.asFile.canonicalPath)
}
Expand Down Expand Up @@ -165,15 +167,14 @@ publishing {

spotless {
kotlinGradle {
ktlint("0.49.1")
ktlint("1.3.1")
}
kotlin {
ktlint("0.49.1")
ktlint("1.3.1")
}
}

fun cmd(vararg cmdarray: String) =
Runtime.getRuntime().exec(cmdarray, null, rootDir)
fun cmd(vararg cmdarray: String) = Runtime.getRuntime().exec(cmdarray, null, rootDir)

val Process.text: String
get() = inputStream.bufferedReader().readText()
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import java.io.File
import java.util.Properties

abstract class AbstractPluginIntegrationTest {

@TempDir
lateinit var testProjectDir: File
lateinit var settingsFile: File
Expand All @@ -21,16 +20,18 @@ abstract class AbstractPluginIntegrationTest {
store(it, null)
}
}
settingsFile = testProjectDir.resolve("settings.gradle.kts").apply {
createNewFile()
}
buildFile = testProjectDir.resolve("build.gradle.kts").apply {
writeText(
"""
import net.ltgt.gradle.errorprone.*
settingsFile =
testProjectDir.resolve("settings.gradle.kts").apply {
createNewFile()
}
buildFile =
testProjectDir.resolve("build.gradle.kts").apply {
writeText(
"""
import net.ltgt.gradle.errorprone.*
""".trimIndent(),
)
}
""".trimIndent(),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.junit.jupiter.api.Test
import java.io.File

class ErrorPronePluginIntegrationTest : AbstractPluginIntegrationTest() {

@BeforeEach
fun setup() {
buildFile.appendText(
Expand Down Expand Up @@ -236,8 +235,8 @@ class ErrorPronePluginIntegrationTest : AbstractPluginIntegrationTest() {
"com.google.errorprone.bugpatterns.BugChecker",
).writeText(
"""
com.google.errorprone.sample.CPSChecker
com.google.errorprone.sample.EffectivelyFinalChecker
com.google.errorprone.sample.CPSChecker
com.google.errorprone.sample.EffectivelyFinalChecker
""".trimIndent(),
)

Expand Down
63 changes: 31 additions & 32 deletions src/integrationTest/kotlin/net/ltgt/gradle/errorprone/Fixtures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ fun File.writeSuccessSource() {
createNewFile()
writeText(
"""
package test;
package test;
public class Success {
// See http://errorprone.info/bugpattern/ArrayEquals
@SuppressWarnings("ArrayEquals")
public boolean arrayEquals(int[] a, int[] b) {
return a.equals(b);
}
public class Success {
// See http://errorprone.info/bugpattern/ArrayEquals
@SuppressWarnings("ArrayEquals")
public boolean arrayEquals(int[] a, int[] b) {
return a.equals(b);
}
}
""".trimIndent(),
)
}
Expand All @@ -41,50 +41,49 @@ fun File.writeFailureSource() {
createNewFile()
writeText(
"""
package test;
package test;
public class Failure {
// See http://errorprone.info/bugpattern/ArrayEquals
public boolean arrayEquals(int[] a, int[] b) {
return a.equals(b);
}
public class Failure {
// See http://errorprone.info/bugpattern/ArrayEquals
public boolean arrayEquals(int[] a, int[] b) {
return a.equals(b);
}
}
""".trimIndent(),
)
}
}

fun File.buildWithArgs(vararg tasks: String): BuildResult {
return prepareBuild(*tasks)
fun File.buildWithArgs(vararg tasks: String): BuildResult =
prepareBuild(*tasks)
.build()
}

fun File.buildWithArgsAndFail(vararg tasks: String): BuildResult {
return prepareBuild(*tasks)
fun File.buildWithArgsAndFail(vararg tasks: String): BuildResult =
prepareBuild(*tasks)
.buildAndFail()
}

fun File.prepareBuild(vararg tasks: String): GradleRunner {
return GradleRunner.create()
fun File.prepareBuild(vararg tasks: String): GradleRunner =
GradleRunner
.create()
.withGradleVersion(testGradleVersion.version)
.withProjectDir(this)
.withPluginClasspath()
.withArguments(*tasks)
.forwardOutput()
}

// Based on https://docs.gradle.org/current/userguide/compatibility.html#java_runtime
val COMPATIBLE_GRADLE_VERSIONS = mapOf(
val COMPATIBLE_GRADLE_VERSIONS =
mapOf(
JavaVersion.VERSION_16 to GradleVersion.version("7.0"),
JavaVersion.VERSION_17 to GradleVersion.version("7.3"),
JavaVersion.VERSION_18 to GradleVersion.version("7.5"),
JavaVersion.VERSION_19 to GradleVersion.version("7.6"),
JavaVersion.VERSION_20 to GradleVersion.version("8.3"),
JavaVersion.VERSION_21 to GradleVersion.version("8.5"),
JavaVersion.VERSION_22 to GradleVersion.version("8.8"),
JavaVersion.VERSION_23 to GradleVersion.version("8.10"),
)

JavaVersion.VERSION_16 to GradleVersion.version("7.0"),
JavaVersion.VERSION_17 to GradleVersion.version("7.3"),
JavaVersion.VERSION_18 to GradleVersion.version("7.5"),
JavaVersion.VERSION_19 to GradleVersion.version("7.6"),
JavaVersion.VERSION_20 to GradleVersion.version("8.3"),
JavaVersion.VERSION_21 to GradleVersion.version("8.5"),
JavaVersion.VERSION_22 to GradleVersion.version("8.8"),
JavaVersion.VERSION_23 to GradleVersion.version("8.10"),
)
fun assumeCompatibleGradleAndJavaVersions() {
assume().that(testGradleVersion >= COMPATIBLE_GRADLE_VERSIONS[testJavaVersion] ?: GradleVersion.version("6.8")).isTrue()
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import java.io.File
import java.util.Properties

class GroovyDslIntegrationTest {

@TempDir
lateinit var testProjectDir: File
lateinit var settingsFile: File
Expand All @@ -25,25 +24,27 @@ class GroovyDslIntegrationTest {
store(it, null)
}
}
settingsFile = testProjectDir.resolve("settings.gradle").apply {
createNewFile()
}
buildFile = testProjectDir.resolve("build.gradle").apply {
appendText(
"""
plugins {
id("java-library")
id("${ErrorPronePlugin.PLUGIN_ID}")
}
repositories {
mavenCentral()
}
dependencies {
errorprone "com.google.errorprone:error_prone_core:$errorproneVersion"
}
""".trimIndent(),
)
}
settingsFile =
testProjectDir.resolve("settings.gradle").apply {
createNewFile()
}
buildFile =
testProjectDir.resolve("build.gradle").apply {
appendText(
"""
plugins {
id("java-library")
id("${ErrorPronePlugin.PLUGIN_ID}")
}
repositories {
mavenCentral()
}
dependencies {
errorprone "com.google.errorprone:error_prone_core:$errorproneVersion"
}
""".trimIndent(),
)
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ import org.junit.jupiter.api.Test
import java.io.File

class Java8IntegrationTest : AbstractPluginIntegrationTest() {

companion object {
private val FORKED = "${System.lineSeparator()}Fork: true${System.lineSeparator()}"
private val NOT_FORKED = "${System.lineSeparator()}Fork: false${System.lineSeparator()}"
private val JVM_ARG = "${System.lineSeparator()}JVM Arg: "
private val JVM_ARG_BOOTCLASSPATH = jvmArg("-Xbootclasspath/p:")
private val JVM_ARG_BOOTCLASSPATH_ERRORPRONE_JAVAC =
"""\Q$JVM_ARG_BOOTCLASSPATH\E.*\Q${File.separator}com.google.errorprone${File.separator}javac${File.separator}9+181-r4173-1${File.separator}\E.*\Q${File.separator}javac-9+181-r4173-1.jar\E(?:\Q${File.pathSeparator}\E|${Regex.escape(System.lineSeparator())})"""
"""\Q$JVM_ARG_BOOTCLASSPATH\E.*\Q${File.separator}com.google.errorprone${File.separator}javac${File.separator}9+181-r4173-1${File.separator}\E.*\Q${File.separator}javac-9+181-r4173-1.jar\E(?:\Q${File.pathSeparator}\E|${Regex.escape(
System.lineSeparator(),
)})"""
.toPattern()
private val JVM_ARGS_STRONG_ENCAPSULATION = ErrorPronePlugin.JVM_ARGS_STRONG_ENCAPSULATION.joinToString(prefix = JVM_ARG, separator = JVM_ARG)
private val JVM_ARGS_STRONG_ENCAPSULATION =
ErrorPronePlugin.JVM_ARGS_STRONG_ENCAPSULATION.joinToString(
prefix = JVM_ARG,
separator = JVM_ARG,
)

private fun jvmArg(argPrefix: String) = "$JVM_ARG$argPrefix"

Expand Down Expand Up @@ -225,16 +230,20 @@ class Java8IntegrationTest : AbstractPluginIntegrationTest() {

// given
val javaHome = System.getProperty("java.home")
val ext = when {
System.getProperty("os.name").startsWith("Windows") -> ".exe"
else -> ""
}
val ext =
when {
System.getProperty("os.name").startsWith("Windows") -> ".exe"
else -> ""
}
buildFile.appendText(
"""
compileJava.apply {
options.isFork = true
options.forkOptions.executable = ""${'"'}${javaHome.replace("\$", "\${'\$'}")}${File.separator}bin${File.separator}javac$ext${'"'}""
options.forkOptions.executable = ""${'"'}${javaHome.replace(
"\$",
"\${'\$'}",
)}${File.separator}bin${File.separator}javac$ext${'"'}""
}
""".trimIndent(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.gradle.util.GradleVersion
import org.junit.jupiter.api.Test

class ManualConfigurationIntegrationTest : AbstractPluginIntegrationTest() {

@Test
fun `in non-java project with applied plugin`() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ import org.junit.jupiter.api.TestInfo
import java.io.File

class ToolchainsIntegrationTest : AbstractPluginIntegrationTest() {

companion object {
private val FORKED = "${System.lineSeparator()}Fork: true${System.lineSeparator()}"
private val NOT_FORKED = "${System.lineSeparator()}Fork: false${System.lineSeparator()}"
private val JVM_ARG = "${System.lineSeparator()}JVM Arg: "
private val JVM_ARG_BOOTCLASSPATH = jvmArg("-Xbootclasspath/p:")
private val JVM_ARG_BOOTCLASSPATH_ERRORPRONE_JAVAC =
"""\Q$JVM_ARG_BOOTCLASSPATH\E.*\Q${File.separator}com.google.errorprone${File.separator}javac${File.separator}9+181-r4173-1${File.separator}\E.*\Q${File.separator}javac-9+181-r4173-1.jar\E(?:\Q${File.pathSeparator}\E|${Regex.escape(System.lineSeparator())})"""
"""\Q$JVM_ARG_BOOTCLASSPATH\E.*\Q${File.separator}com.google.errorprone${File.separator}javac${File.separator}9+181-r4173-1${File.separator}\E.*\Q${File.separator}javac-9+181-r4173-1.jar\E(?:\Q${File.pathSeparator}\E|${Regex.escape(
System.lineSeparator(),
)})"""
.toPattern()
private val JVM_ARGS_STRONG_ENCAPSULATION = ErrorPronePlugin.JVM_ARGS_STRONG_ENCAPSULATION.joinToString(prefix = JVM_ARG, separator = JVM_ARG)
private val JVM_ARGS_STRONG_ENCAPSULATION =
ErrorPronePlugin.JVM_ARGS_STRONG_ENCAPSULATION.joinToString(
prefix = JVM_ARG,
separator = JVM_ARG,
)

private fun jvmArg(argPrefix: String) = "$JVM_ARG$argPrefix"

Expand All @@ -47,7 +52,14 @@ class ToolchainsIntegrationTest : AbstractPluginIntegrationTest() {
mavenCentral()
}
dependencies {
errorprone("com.google.errorprone:error_prone_core:${if (testInfo.displayName.contains("JDK 8 VM")) MAX_JDK8_COMPATIBLE_ERRORPRONE_VERSION else errorproneVersion}")
errorprone("com.google.errorprone:error_prone_core:${if (testInfo.displayName.contains(
"JDK 8 VM",
)
) {
MAX_JDK8_COMPATIBLE_ERRORPRONE_VERSION
} else {
errorproneVersion
}}")
}
tasks {
Expand Down
Loading

0 comments on commit 89aae31

Please sign in to comment.