Skip to content

Commit e2ea01b

Browse files
authored
Code formatting & cleanup - broken out from AGP 9 update PR (#482)
* Code cleanup: formatting and expression body conversions Apply ktlint/kotlinter formatting fixes: - Multi-line chain formatting for readability - Convert block body functions to expression body syntax - Add trailing commas to constructor parameters - Reformat when expressions with braces - Reformat block comments to inline comments * Lint fixes - converting runAndFail() functions from block body to expression body syntax
1 parent 4888b52 commit e2ea01b

19 files changed

Lines changed: 130 additions & 85 deletions

File tree

fladle-plugin/src/main/java/com/osacky/flank/gradle/FladleConfig.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ interface FladleConfig {
5151
@get:Input
5252
val testTargets: ListProperty<String>
5353

54+
// The maximum number of shards. Value will be overwritten by [maxTestShards] if both used in configuration
5455
@Deprecated(
5556
message = "testShards is deprecated. Use maxTestShards instead",
5657
replaceWith = ReplaceWith("maxTestShards"),
5758
)
58-
/**
59-
* The maximum number of shards. Value will be overwritten by [maxTestShards] if both used in configuration
60-
*/
6159
@get:Input
6260
@get:Optional
6361
val testShards: Property<Int>
@@ -473,7 +471,8 @@ interface FladleConfig {
473471

474472
@Internal
475473
fun getPresentProperties() =
476-
this::class.memberProperties
474+
this::class
475+
.memberProperties
477476
.filter {
478477
when (val prop = it.call(this)) {
479478
is Property<*> -> prop.isPresent

fladle-plugin/src/main/java/com/osacky/flank/gradle/FladlePluginDelegate.kt

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ class FladlePluginDelegate {
2424

2525
target.tasks.register("flankAuth", FlankJavaExec::class.java) {
2626
doFirst {
27-
target.layout.fladleDir.get().asFile.mkdirs()
27+
target.layout.fladleDir
28+
.get()
29+
.asFile
30+
.mkdirs()
2831
}
2932
classpath = project.fladleConfig
3033
args = listOf("auth", "login")
@@ -34,7 +37,6 @@ class FladlePluginDelegate {
3437
}
3538

3639
private fun checkMinimumGradleVersion() {
37-
// Gradle 4.9 is required because we use the lazy task configuration API.
3840
if (GRADLE_MIN_VERSION > GradleVersion.current()) {
3941
throw GradleException("Fladle requires at minimum version $GRADLE_MIN_VERSION. Detected version ${GradleVersion.current()}.")
4042
}
@@ -102,15 +104,34 @@ class FladlePluginDelegate {
102104
group = TASK_GROUP
103105
dependsOn(writeConfigProps)
104106
doLast {
105-
println(writeConfigProps.get().fladleConfigFile.get().asFile.readText())
107+
println(
108+
writeConfigProps
109+
.get()
110+
.fladleConfigFile
111+
.get()
112+
.asFile
113+
.readText(),
114+
)
106115
}
107116
}
108117

109118
register("flankDoctor$name", FlankJavaExec::class.java) {
110119
if (useDefaultDir) setUpWorkingDir(configName)
111120
description = "Finds problems with the current configuration."
112121
classpath = project.fladleConfig
113-
args = listOf("firebase", "test", "android", "doctor", "-c", writeConfigProps.get().fladleConfigFile.get().asFile.absolutePath)
122+
args =
123+
listOf(
124+
"firebase",
125+
"test",
126+
"android",
127+
"doctor",
128+
"-c",
129+
writeConfigProps
130+
.get()
131+
.fladleConfigFile
132+
.get()
133+
.asFile.absolutePath,
134+
)
114135
dependsOn(writeConfigProps)
115136
}
116137

@@ -122,13 +143,30 @@ class FladlePluginDelegate {
122143
args =
123144
if (project.hasProperty("dumpShards")) {
124145
listOf(
125-
"firebase", "test", "android", "run", "-c",
126-
writeConfigProps.get().fladleConfigFile.get().asFile.absolutePath, "--dump-shards",
146+
"firebase",
147+
"test",
148+
"android",
149+
"run",
150+
"-c",
151+
writeConfigProps
152+
.get()
153+
.fladleConfigFile
154+
.get()
155+
.asFile.absolutePath,
156+
"--dump-shards",
127157
)
128158
} else {
129159
listOf(
130-
"firebase", "test", "android", "run", "-c",
131-
writeConfigProps.get().fladleConfigFile.get().asFile.absolutePath,
160+
"firebase",
161+
"test",
162+
"android",
163+
"run",
164+
"-c",
165+
writeConfigProps
166+
.get()
167+
.fladleConfigFile
168+
.get()
169+
.asFile.absolutePath,
132170
)
133171
}
134172
if (config.serviceAccountCredentials.isPresent) {

fladle-plugin/src/main/java/com/osacky/flank/gradle/FlankExecutionTask.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ open class FlankExecutionTask
2222

2323
private fun checkFilesExist(base: FladleConfig) {
2424
if (base.serviceAccountCredentials.isPresent) {
25-
check(base.serviceAccountCredentials.get().asFile.exists()) {
25+
check(
26+
base.serviceAccountCredentials
27+
.get()
28+
.asFile
29+
.exists(),
30+
) {
2631
"serviceAccountCredential file doesn't exist ${base.serviceAccountCredentials.get()}"
2732
}
2833
}

fladle-plugin/src/main/java/com/osacky/flank/gradle/FlankGradleExtension.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import javax.inject.Inject
1616

1717
open class FlankGradleExtension
1818
@Inject
19-
constructor(objects: ObjectFactory) : FladleConfig {
19+
constructor(
20+
objects: ObjectFactory,
21+
) : FladleConfig {
2022
companion object {
2123
const val FLANK_VERSION = "23.10.1"
2224
}

fladle-plugin/src/main/java/com/osacky/flank/gradle/FlankJavaExec.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import javax.inject.Inject
1010
)
1111
open class FlankJavaExec
1212
@Inject
13-
constructor(projectLayout: ProjectLayout) : JavaExec() {
13+
constructor(
14+
projectLayout: ProjectLayout,
15+
) : JavaExec() {
1416
init {
1517
group = FladlePluginDelegate.TASK_GROUP
1618
mainClass.set("ftl.Main")

fladle-plugin/src/main/java/com/osacky/flank/gradle/FulladleModuleExtension.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import javax.inject.Inject
99

1010
open class FulladleModuleExtension
1111
@Inject
12-
constructor(objects: ObjectFactory) {
12+
constructor(
13+
objects: ObjectFactory,
14+
) {
1315
/**
1416
* When set to false, Fulladle will not automatically add this module to additionalTestApks.
1517
*

fladle-plugin/src/main/java/com/osacky/flank/gradle/FulladlePlugin.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,12 @@ class FulladlePlugin : Plugin<Project> {
2323
val fulladleConfigureTask =
2424
root.tasks.register("configureFulladle") {
2525
var modulesEnabled = false
26-
/**
27-
* we will first configure all app modules
28-
* then configure all library modules
29-
* we force this order of configuration because
30-
* app modules are better candidates to become
31-
* root level test/app APKs, since they produce
32-
* app APKs
33-
* if no app module had tests or was enabled
34-
* we will choose a library module to become
35-
* a root level module, in which case we will
36-
* have to check if it has its debugApk set
37-
*/
26+
// We first configure all app modules, then configure all library modules.
27+
// We force this order because app modules are better candidates to become
28+
// root level test/app APKs, since they produce app APKs.
29+
// If no app module had tests or was enabled, we will choose a library module
30+
// to become a root level module, in which case we will have to check if it
31+
// has its debugApk set.
3832
doLast {
3933
// first configure all app modules
4034
root.subprojects {
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
package com.osacky.flank.gradle
22

3-
data class RequiredDeviceKeyMissingException(val key: String) : Exception("Device should have '$key' key set to a value.")
3+
data class RequiredDeviceKeyMissingException(
4+
val key: String,
5+
) : Exception("Device should have '$key' key set to a value.")

fladle-plugin/src/main/java/com/osacky/flank/gradle/SanityConfigValidation.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@ import java.lang.IllegalArgumentException
66

77
fun checkIfSanityAndValidateConfigs(config: FladleConfig) =
88
when (config) {
9-
is FlankGradleExtension ->
9+
is FlankGradleExtension -> {
1010
config.checkAndValidateConfig { option, name ->
1111
"Incorrect [$name] configuration. [$option] can't be used together with sanityRobo."
1212
}
13-
is FladleConfigImpl ->
13+
}
14+
15+
is FladleConfigImpl -> {
1416
config.checkAndValidateConfig(config.name) { option, name ->
1517
"Incorrect [$name] configuration. [$option] can't be used together with sanityRobo. " +
1618
"To configure sanityRobo, add clearPropertiesForSanityRobo() to the [$name] configuration"
1719
}
18-
else -> throw IllegalArgumentException("Unexpected configuration when validating parameters. Did not expect: $config.")
20+
}
21+
22+
else -> {
23+
throw IllegalArgumentException("Unexpected configuration when validating parameters. Did not expect: $config.")
24+
}
1925
}
2026

2127
private fun FladleConfig.checkAndValidateConfig(

fladle-plugin/src/main/java/com/osacky/flank/gradle/YamlConfigWriterTask.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,18 @@ open class YamlConfigWriterTask
3838

3939
@get:Input
4040
val additionalTestApks: ListProperty<String> =
41-
objects.listProperty(String::class.java)
41+
objects
42+
.listProperty(String::class.java)
4243
.convention(config.additionalTestApks)
4344

4445
@OutputFile
4546
val fladleConfigFile: Provider<RegularFile> = fladleDir.map { it.file("flank.yml") }
4647

4748
@Internal
48-
override fun getDescription(): String {
49-
return "Writes a flank.yml file based on the current FlankGradleExtension configuration."
50-
}
49+
override fun getDescription(): String = "Writes a flank.yml file based on the current FlankGradleExtension configuration."
5150

5251
@Internal
53-
override fun getGroup(): String {
54-
return FladlePluginDelegate.TASK_GROUP
55-
}
52+
override fun getGroup(): String = FladlePluginDelegate.TASK_GROUP
5653

5754
@TaskAction
5855
fun writeFile() {

0 commit comments

Comments
 (0)