Skip to content

Commit

Permalink
Improve Spotless ktfmt integration
Browse files Browse the repository at this point in the history
1. Let integration_tests to use SpotlessPlugin.
2. Bump ktfmt to 0.49.
3. Re-format existing Kotlin files with new ktfmt.

Signed-off-by: utzcoz <utzcoz@outlook.com>
  • Loading branch information
utzcoz committed May 4, 2024
1 parent da1352f commit 078ad11
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SpotlessPlugin implements Plugin<Project> {
kotlin {
// Add configurations for Kotlin files
target '**/*.kt'
ktfmt('0.42').googleStyle()
ktfmt('0.49').googleStyle()
}
groovy {
// Add configurations for Groovy files
Expand All @@ -21,7 +21,6 @@ class SpotlessPlugin implements Plugin<Project> {
// Add configurations for Groovy Gradle files
target('*.gradle', "**/*.gradle")
}

}
}
}
4 changes: 4 additions & 0 deletions integration_tests/kotlin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.robolectric.gradle.RoboJavaModulePlugin
import org.robolectric.gradle.SpotlessPlugin

apply plugin: RoboJavaModulePlugin
apply plugin: 'kotlin'
apply plugin: SpotlessPlugin

compileKotlin {
compilerOptions.jvmTarget = JvmTarget.JVM_1_8
}
Expand Down
10 changes: 2 additions & 8 deletions integration_tests/mockito-kotlin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.robolectric.gradle.RoboJavaModulePlugin
import org.robolectric.gradle.SpotlessPlugin

apply plugin: RoboJavaModulePlugin
apply plugin: 'kotlin'
apply plugin: "com.diffplug.spotless"
apply plugin: SpotlessPlugin
apply plugin: "io.gitlab.arturbosch.detekt"

spotless {
kotlin {
target '**/*.kt'
ktfmt('0.42').googleStyle()
}
}

compileKotlin {
compilerOptions.jvmTarget = JvmTarget.JVM_1_8
}
Expand Down
10 changes: 2 additions & 8 deletions integration_tests/mockk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.robolectric.gradle.RoboJavaModulePlugin
import org.robolectric.gradle.SpotlessPlugin

apply plugin: RoboJavaModulePlugin
apply plugin: 'kotlin'
apply plugin: "com.diffplug.spotless"
apply plugin: SpotlessPlugin
apply plugin: "io.gitlab.arturbosch.detekt"

spotless {
kotlin {
target '**/*.kt'
ktfmt('0.42').googleStyle()
}
}

compileKotlin {
compilerOptions.jvmTarget = JvmTarget.JVM_1_8
}
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/roborazzi/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import org.robolectric.gradle.AndroidProjectConfigPlugin
import org.robolectric.gradle.SpotlessPlugin

apply plugin: 'com.android.library'
apply plugin: AndroidProjectConfigPlugin
apply plugin: 'kotlin-android'
apply plugin: "io.github.takahirom.roborazzi"
apply plugin: SpotlessPlugin

android {
compileSdk 34
namespace 'org.robolectric.integration.roborazzi'
Expand Down
10 changes: 2 additions & 8 deletions integration_tests/sdkcompat/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import org.robolectric.gradle.AndroidProjectConfigPlugin
import org.robolectric.gradle.SpotlessPlugin

apply plugin: 'com.android.library'
apply plugin: AndroidProjectConfigPlugin
apply plugin: 'kotlin-android'
apply plugin: "com.diffplug.spotless"
apply plugin: SpotlessPlugin
apply plugin: "io.gitlab.arturbosch.detekt"

spotless {
kotlin {
target '**/*.kt'
ktfmt('0.42').googleStyle()
}
}

android {
compileSdk 29
namespace 'org.robolectric.integrationtests.sdkcompat'
Expand Down
5 changes: 5 additions & 0 deletions integration_tests/sparsearray/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import org.robolectric.gradle.AndroidProjectConfigPlugin
import org.robolectric.gradle.SpotlessPlugin

apply plugin: 'com.android.library'
apply plugin: AndroidProjectConfigPlugin
apply plugin: 'kotlin-android'
apply plugin: SpotlessPlugin
apply plugin: "io.gitlab.arturbosch.detekt"

android {
compileSdk 34
namespace 'org.robolectric.sparsearray'
Expand All @@ -27,6 +31,7 @@ android {
}
}
}

dependencies {
compileOnly AndroidSdk.MAX_SDK.coordinates
implementation project(path: ':shadowapi', configuration: 'default')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MavenRoboSettingsTest {
private var originalMavenRepositoryPassword: String? = null
private var originalMavenRepositoryProxyHost: String? = null
private var originalMavenProxyPort = 0

@Before
fun setUp() {
originalMavenRepositoryId = MavenRoboSettings.getMavenRepositoryId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MavenDependencyResolverTest {
PROXY_HOST,
PROXY_PORT,
localRepositoryDir,
executorService
executorService,
)
mavenDependencyResolver = TestMavenDependencyResolver()
}
Expand Down Expand Up @@ -151,7 +151,7 @@ class MavenDependencyResolverTest {
proxyHost: String?,
proxyPort: Int,
localRepositoryDir: File,
executorService: ExecutorService
executorService: ExecutorService,
): MavenArtifactFetcher {
return mavenArtifactFetcher
}
Expand All @@ -176,7 +176,7 @@ class MavenDependencyResolverTest {
proxyHost: String?,
proxyPort: Int,
localRepositoryDir: File,
private val executorService: ExecutorService
private val executorService: ExecutorService,
) :
MavenArtifactFetcher(
repositoryUrl,
Expand All @@ -185,7 +185,7 @@ class MavenDependencyResolverTest {
proxyHost,
proxyPort,
localRepositoryDir,
executorService
executorService,
) {
var numRequests = 0
private set
Expand All @@ -199,7 +199,7 @@ class MavenDependencyResolverTest {
return super.call()
}
},
executorService
executorService,
)
}
}
Expand All @@ -216,7 +216,7 @@ class MavenDependencyResolverTest {
arrayOf(
DependencyJar("group", "artifact", "1"),
DependencyJar("org.group2", "artifact2-name", "2.4.5"),
DependencyJar("org.robolectric", "android-all", "10-robolectric-5803371")
DependencyJar("org.robolectric", "android-all", "10-robolectric-5803371"),
)

init {
Expand All @@ -240,20 +240,20 @@ class MavenDependencyResolverTest {
val jarContents = "$mavenJarArtifact jar contents"
Files.write(
jarContents.toByteArray(StandardCharsets.UTF_8),
File(REPOSITORY_DIR, mavenJarArtifact.jarPath())
File(REPOSITORY_DIR, mavenJarArtifact.jarPath()),
)
Files.write(
sha512(jarContents).toByteArray(),
File(REPOSITORY_DIR, mavenJarArtifact.jarSha512Path())
File(REPOSITORY_DIR, mavenJarArtifact.jarSha512Path()),
)
val pomContents = "$mavenJarArtifact pom contents"
Files.write(
pomContents.toByteArray(StandardCharsets.UTF_8),
File(REPOSITORY_DIR, mavenJarArtifact.pomPath())
File(REPOSITORY_DIR, mavenJarArtifact.pomPath()),
)
Files.write(
sha512(pomContents).toByteArray(),
File(REPOSITORY_DIR, mavenJarArtifact.pomSha512Path())
File(REPOSITORY_DIR, mavenJarArtifact.pomSha512Path()),
)
} catch (e: MalformedURLException) {
throw AssertionError(e)
Expand All @@ -269,13 +269,13 @@ class MavenDependencyResolverTest {
Files.write(jarContents.toByteArray(), File(REPOSITORY_DIR, mavenJarArtifact.jarPath()))
Files.write(
sha512("No the same content").toByteArray(),
File(REPOSITORY_DIR, mavenJarArtifact.jarSha512Path())
File(REPOSITORY_DIR, mavenJarArtifact.jarSha512Path()),
)
val pomContents = "$mavenJarArtifact pom contents"
Files.write(pomContents.toByteArray(), File(REPOSITORY_DIR, mavenJarArtifact.pomPath()))
Files.write(
sha512("Really not the same content").toByteArray(),
File(REPOSITORY_DIR, mavenJarArtifact.pomSha512Path())
File(REPOSITORY_DIR, mavenJarArtifact.pomSha512Path()),
)
} catch (e: MalformedURLException) {
throw AssertionError(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class PerfStatsCollectorTest {

private class FakeClock : Clock {
private var timeNs = 0

override fun nanoTime(): Long {
return timeNs.toLong()
}
Expand Down
16 changes: 8 additions & 8 deletions utils/src/test/java/org/robolectric/util/SchedulerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ class SchedulerTest {
transcript.add("two")
scheduler.postDelayed(AddToTranscript("three"), 1000)
},
1000
1000,
)
},
1000
1000,
)
scheduler.advanceBy(1000)
assertThat(transcript).containsExactly("one")
Expand Down Expand Up @@ -278,7 +278,7 @@ class SchedulerTest {
scheduler.post { order.add(4) }
order.add(2)
},
0
0,
)
scheduler.postDelayed({ order.add(3) }, 0)
scheduler.runOneTask()
Expand All @@ -302,7 +302,7 @@ class SchedulerTest {
scheduler.post { order.add(3) }
order.add(2)
},
0
0,
)
assertWithMessage("order").that(order).containsExactly(1, 2, 3)
assertWithMessage("size").that(scheduler.size()).isEqualTo(0)
Expand All @@ -317,7 +317,7 @@ class SchedulerTest {
scheduler.postAtFrontOfQueue { order.add(3) }
order.add(2)
},
0
0,
)
scheduler.postDelayed({ order.add(4) }, 0)
scheduler.advanceToLastPostedRunnable()
Expand All @@ -335,7 +335,7 @@ class SchedulerTest {
scheduler.postAtFrontOfQueue { order.add(3) }
order.add(2)
},
0
0,
)
assertWithMessage("order").that(order).containsExactly(1, 2, 3)
assertWithMessage("size").that(scheduler.size()).isEqualTo(0)
Expand All @@ -351,7 +351,7 @@ class SchedulerTest {
scheduler.postDelayed({ order.add(3) }, 1)
order.add(2)
},
0
0,
)
assertWithMessage("order:before").that(order).containsExactly(1, 2)
assertWithMessage("size:before").that(scheduler.size()).isEqualTo(1)
Expand All @@ -371,7 +371,7 @@ class SchedulerTest {
scheduler.postDelayed({ order.add(3) }, 1)
order.add(2)
},
0
0,
)
assertWithMessage("order").that(order).containsExactly(1, 2, 3)
assertWithMessage("size").that(scheduler.size()).isEqualTo(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PluginFinderTest {
ImplMinus1::class.java,
ImplZeroA::class.java,
ImplOne::class.java,
ImplZeroB::class.java
ImplZeroB::class.java,
)
)
Truth.assertThat(pluginFinder.findPlugin(Iface::class.java)).isEqualTo(ImplOne::class.java)
Expand Down Expand Up @@ -55,15 +55,15 @@ class PluginFinderTest {
ImplMinus1::class.java,
ImplZeroA::class.java,
ImplOne::class.java,
ImplZeroB::class.java
ImplZeroB::class.java,
)
)
Truth.assertThat(pluginFinder.findPlugins(Iface::class.java))
.containsExactly(
ImplOne::class.java,
ImplZeroA::class.java,
ImplZeroB::class.java,
ImplMinus1::class.java
ImplMinus1::class.java,
)
.inOrder()
}
Expand All @@ -77,7 +77,7 @@ class PluginFinderTest {
ImplZeroXSupercedesA::class.java,
ImplZeroA::class.java,
ImplOne::class.java,
ImplZeroB::class.java
ImplZeroB::class.java,
)
)
val plugins = pluginFinder.findPlugins(Iface::class.java)
Expand All @@ -86,7 +86,7 @@ class PluginFinderTest {
ImplOne::class.java,
ImplZeroB::class.java,
ImplZeroXSupercedesA::class.java,
ImplMinus1::class.java
ImplMinus1::class.java,
)
.inOrder()
}
Expand All @@ -95,10 +95,12 @@ class PluginFinderTest {
@Priority(-1) private class ImplMinus1 : Iface

@Priority(0) private class ImplZeroA : Iface

private class ImplZeroB : Iface

@Priority(1) private class ImplOne : Iface

@Supercedes(ImplZeroA::class) private class ImplZeroXSupercedesA : Iface

private interface Iface
}

0 comments on commit 078ad11

Please sign in to comment.