Skip to content

Commit 8b8369f

Browse files
More accurate spotless config (#4499)
* More accurate, faster spotless config This PR ensures that spotless is actually running over all our files. It wasn't before and you can see this generated a massive diff. There are still a number of exceptions that were suppressed in order to save time going through the hundreds of them. In other news, this moves the spotless logic to its own convention plugin and runs over each source set of each project separately. This means that most of the tasks should be cached independently. * Format code * Format with ktfmt --------- Co-authored-by: Sentry Github Bot <[email protected]>
1 parent 43b3a68 commit 8b8369f

File tree

722 files changed

+99001
-97901
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

722 files changed

+99001
-97901
lines changed

.editorconfig

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ root = true
22

33
[*]
44
indent_style = space
5+
indent_size = 2
56
trim_trailing_whitespace = true
67
insert_final_newline = true
8+
max_line_length = 140
9+
ij_java_names_count_to_use_import_on_demand = 9999
10+
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
711

812
[*.md]
913
trim_trailing_whitespace = false
1014

1115
[*.java]
12-
indent_size = 2
1316
charset = utf-8
1417

1518
[*.{kt,kts}]
16-
indent_size = 4
1719
charset = utf-8
18-
19-
[*.xml]
20-
indent_size = 2

build-logic/build.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
plugins {
2-
`kotlin-dsl`
2+
`kotlin-dsl`
33
}
44

55
repositories {
6-
gradlePluginPortal()
6+
gradlePluginPortal()
7+
}
8+
9+
dependencies {
10+
implementation(libs.spotlessLib)
711
}

build-logic/settings.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1+
dependencyResolutionManagement {
2+
versionCatalogs {
3+
create("libs") {
4+
from(files("../gradle/libs.versions.toml"))
5+
}
6+
}
7+
}
8+
19
rootProject.name = "build-logic"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import com.diffplug.spotless.LineEnding
2+
3+
plugins {
4+
id("com.diffplug.spotless")
5+
}
6+
7+
spotless {
8+
lineEndings = LineEnding.UNIX
9+
java {
10+
target("src/*/java/**/*.java")
11+
removeUnusedImports()
12+
googleJavaFormat()
13+
targetExclude("src/**/java/io/sentry/vendor/**")
14+
}
15+
kotlin {
16+
target("src/*/kotlin/**/*.kt", "src/*/java/**/*.kt")
17+
ktfmt().googleStyle()
18+
targetExclude("src/test/java/io/sentry/apollo4/generated/**", "src/test/java/io/sentry/apollo3/adapter/**")
19+
}
20+
kotlinGradle {
21+
target("*.gradle.kts")
22+
ktfmt().googleStyle()
23+
}
24+
}
25+

build.gradle.kts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import com.diffplug.spotless.LineEnding
21
import com.vanniktech.maven.publish.JavaLibrary
32
import com.vanniktech.maven.publish.JavadocJar
43
import com.vanniktech.maven.publish.MavenPublishBaseExtension
@@ -10,7 +9,7 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent
109

1110
plugins {
1211
`java-library`
13-
alias(libs.plugins.spotless)
12+
alias(libs.plugins.spotless) apply false
1413
jacoco
1514
alias(libs.plugins.detekt)
1615
`maven-publish`
@@ -105,6 +104,8 @@ allprojects {
105104
}
106105

107106
subprojects {
107+
apply { plugin("io.sentry.spotless") }
108+
108109
val jacocoAndroidModules = listOf(
109110
"sentry-android-core",
110111
"sentry-android-fragment",
@@ -225,26 +226,6 @@ subprojects {
225226
}
226227
}
227228

228-
spotless {
229-
lineEndings = LineEnding.UNIX
230-
java {
231-
target("**/*.java")
232-
removeUnusedImports()
233-
googleJavaFormat()
234-
targetExclude("**/generated/**", "**/vendor/**", "**/sentry-native/**")
235-
}
236-
kotlin {
237-
target("**/*.kt")
238-
ktlint()
239-
targetExclude("**/sentry-native/**", "**/build/**")
240-
}
241-
kotlinGradle {
242-
target("**/*.kts")
243-
ktlint()
244-
targetExclude("**/sentry-native/**")
245-
}
246-
}
247-
248229
tasks.register("buildForCodeQL") {
249230
subprojects
250231
.filter {

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ springboot3 = "3.5.0"
3232
targetSdk = "34"
3333
compileSdk = "34"
3434
minSdk = "21"
35+
spotless = "7.0.4"
3536

3637
[plugins]
3738
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
@@ -43,7 +44,7 @@ binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibil
4344
compose-compiler = { id = "org.jetbrains.compose", version.ref = "jetbrainsCompose" }
4445
errorprone = { id = "net.ltgt.errorprone", version = "3.0.1" }
4546
gradle-versions = { id = "com.github.ben-manes.versions", version = "0.42.0" }
46-
spotless = { id = "com.diffplug.spotless", version = "6.11.0" }
47+
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
4748
detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.23.8" }
4849
jacoco-android = { id = "com.mxalbert.gradle.jacoco-android", version = "0.2.0" }
4950
kover = { id = "org.jetbrains.kotlinx.kover", version = "0.7.3" }
@@ -121,6 +122,7 @@ servlet-jakarta-api = { module = "jakarta.servlet:jakarta.servlet-api", version
121122
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
122123
slf4j-jdk14 = { module = "org.slf4j:slf4j-jdk14", version.ref = "slf4j" }
123124
slf4j2-api = { module = "org.slf4j:slf4j-api", version = "2.0.5" }
125+
spotlessLib = { module = "com.diffplug.spotless:com.diffplug.spotless.gradle.plugin", version.ref = "spotless"}
124126
springboot-starter = { module = "org.springframework.boot:spring-boot-starter", version.ref = "springboot2" }
125127
springboot-starter-graphql = { module = "org.springframework.boot:spring-boot-starter-graphql", version.ref = "springboot2" }
126128
springboot-starter-quartz = { module = "org.springframework.boot:spring-boot-starter-quartz", version.ref = "springboot2" }

sentry-android-core/build.gradle.kts

Lines changed: 83 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,115 +2,109 @@ import net.ltgt.gradle.errorprone.errorprone
22
import org.jetbrains.kotlin.config.KotlinCompilerVersion
33

44
plugins {
5-
id("com.android.library")
6-
kotlin("android")
7-
jacoco
8-
alias(libs.plugins.jacoco.android)
9-
alias(libs.plugins.errorprone)
10-
alias(libs.plugins.gradle.versions)
5+
id("com.android.library")
6+
kotlin("android")
7+
jacoco
8+
alias(libs.plugins.jacoco.android)
9+
alias(libs.plugins.errorprone)
10+
alias(libs.plugins.gradle.versions)
1111
}
1212

1313
android {
14-
compileSdk = libs.versions.compileSdk.get().toInt()
15-
namespace = "io.sentry.android.core"
14+
compileSdk = libs.versions.compileSdk.get().toInt()
15+
namespace = "io.sentry.android.core"
1616

17-
defaultConfig {
18-
minSdk = libs.versions.minSdk.get().toInt()
17+
defaultConfig {
18+
minSdk = libs.versions.minSdk.get().toInt()
1919

20-
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
20+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2121

22-
buildConfigField("String", "SENTRY_ANDROID_SDK_NAME", "\"${Config.Sentry.SENTRY_ANDROID_SDK_NAME}\"")
22+
buildConfigField(
23+
"String",
24+
"SENTRY_ANDROID_SDK_NAME",
25+
"\"${Config.Sentry.SENTRY_ANDROID_SDK_NAME}\"",
26+
)
2327

24-
// for AGP 4.1
25-
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
26-
}
28+
// for AGP 4.1
29+
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
30+
}
2731

28-
buildTypes {
29-
getByName("debug") {
30-
consumerProguardFiles("proguard-rules.pro")
31-
}
32-
getByName("release") {
33-
consumerProguardFiles("proguard-rules.pro")
34-
}
35-
}
32+
buildTypes {
33+
getByName("debug") { consumerProguardFiles("proguard-rules.pro") }
34+
getByName("release") { consumerProguardFiles("proguard-rules.pro") }
35+
}
3636

37-
kotlinOptions {
38-
jvmTarget = JavaVersion.VERSION_1_8.toString()
39-
}
37+
kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() }
4038

41-
testOptions {
42-
animationsDisabled = true
43-
unitTests.apply {
44-
isReturnDefaultValues = true
45-
isIncludeAndroidResources = true
46-
}
39+
testOptions {
40+
animationsDisabled = true
41+
unitTests.apply {
42+
isReturnDefaultValues = true
43+
isIncludeAndroidResources = true
4744
}
45+
}
4846

49-
lint {
50-
warningsAsErrors = true
51-
checkDependencies = true
47+
lint {
48+
warningsAsErrors = true
49+
checkDependencies = true
5250

53-
// We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks.
54-
checkReleaseBuilds = false
55-
}
51+
// We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks.
52+
checkReleaseBuilds = false
53+
}
5654

57-
buildFeatures {
58-
buildConfig = true
59-
}
55+
buildFeatures { buildConfig = true }
6056

61-
// needed because of Kotlin 1.4.x
62-
configurations.all {
63-
resolutionStrategy.force(libs.jetbrains.annotations.get())
64-
}
57+
// needed because of Kotlin 1.4.x
58+
configurations.all { resolutionStrategy.force(libs.jetbrains.annotations.get()) }
6559

66-
androidComponents.beforeVariants {
67-
it.enable = !Config.Android.shouldSkipDebugVariant(it.buildType)
68-
}
60+
androidComponents.beforeVariants {
61+
it.enable = !Config.Android.shouldSkipDebugVariant(it.buildType)
62+
}
6963
}
7064

7165
tasks.withType<JavaCompile>().configureEach {
72-
options.errorprone {
73-
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
74-
option("NullAway:AnnotatedPackages", "io.sentry")
75-
}
66+
options.errorprone {
67+
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
68+
option("NullAway:AnnotatedPackages", "io.sentry")
69+
}
7670
}
7771

7872
dependencies {
79-
api(projects.sentry)
80-
compileOnly(libs.jetbrains.annotations)
81-
compileOnly(libs.nopen.annotations)
82-
compileOnly(projects.sentryAndroidFragment)
83-
compileOnly(projects.sentryAndroidTimber)
84-
compileOnly(projects.sentryAndroidReplay)
85-
compileOnly(projects.sentryCompose)
86-
87-
// lifecycle processor, session tracking
88-
implementation(libs.androidx.lifecycle.common.java8)
89-
implementation(libs.androidx.lifecycle.process)
90-
implementation(libs.androidx.core)
91-
92-
errorprone(libs.errorprone.core)
93-
errorprone(libs.nopen.checker)
94-
errorprone(libs.nullaway)
95-
96-
// tests
97-
testImplementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION))
98-
testImplementation(libs.roboelectric)
99-
testImplementation(libs.kotlin.test.junit)
100-
testImplementation(libs.androidx.core.ktx)
101-
testImplementation(libs.androidx.test.core)
102-
testImplementation(libs.androidx.test.ext.junit)
103-
testImplementation(libs.androidx.test.runner)
104-
testImplementation(libs.awaitility.kotlin)
105-
testImplementation(libs.mockito.kotlin)
106-
testImplementation(libs.mockito.inline)
107-
testImplementation(projects.sentryTestSupport)
108-
testImplementation(projects.sentryAndroidFragment)
109-
testImplementation(projects.sentryAndroidTimber)
110-
testImplementation(projects.sentryAndroidReplay)
111-
testImplementation(projects.sentryCompose)
112-
testImplementation(projects.sentryAndroidNdk)
113-
testRuntimeOnly(libs.androidx.compose.ui)
114-
testRuntimeOnly(libs.androidx.fragment.ktx)
115-
testRuntimeOnly(libs.timber)
73+
api(projects.sentry)
74+
compileOnly(libs.jetbrains.annotations)
75+
compileOnly(libs.nopen.annotations)
76+
compileOnly(projects.sentryAndroidFragment)
77+
compileOnly(projects.sentryAndroidTimber)
78+
compileOnly(projects.sentryAndroidReplay)
79+
compileOnly(projects.sentryCompose)
80+
81+
// lifecycle processor, session tracking
82+
implementation(libs.androidx.lifecycle.common.java8)
83+
implementation(libs.androidx.lifecycle.process)
84+
implementation(libs.androidx.core)
85+
86+
errorprone(libs.errorprone.core)
87+
errorprone(libs.nopen.checker)
88+
errorprone(libs.nullaway)
89+
90+
// tests
91+
testImplementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION))
92+
testImplementation(libs.roboelectric)
93+
testImplementation(libs.kotlin.test.junit)
94+
testImplementation(libs.androidx.core.ktx)
95+
testImplementation(libs.androidx.test.core)
96+
testImplementation(libs.androidx.test.ext.junit)
97+
testImplementation(libs.androidx.test.runner)
98+
testImplementation(libs.awaitility.kotlin)
99+
testImplementation(libs.mockito.kotlin)
100+
testImplementation(libs.mockito.inline)
101+
testImplementation(projects.sentryTestSupport)
102+
testImplementation(projects.sentryAndroidFragment)
103+
testImplementation(projects.sentryAndroidTimber)
104+
testImplementation(projects.sentryAndroidReplay)
105+
testImplementation(projects.sentryCompose)
106+
testImplementation(projects.sentryAndroidNdk)
107+
testRuntimeOnly(libs.androidx.compose.ui)
108+
testRuntimeOnly(libs.androidx.fragment.ktx)
109+
testRuntimeOnly(libs.timber)
116110
}

sentry-android-core/src/main/java/io/sentry/android/core/ANRWatchDog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ final class ANRWatchDog extends Thread {
4747
private final ANRListener anrListener;
4848
private final MainLooperHandler uiHandler;
4949
private final ICurrentDateProvider timeProvider;
50+
5051
/** the interval in which we check if there's an ANR, in ms */
5152
private long pollingIntervalMs;
5253

sentry-android-core/src/main/java/io/sentry/android/core/AnrV2EventProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ private void setOptionsTags(final @NotNull SentryBaseEvent event) {
516516
}
517517
}
518518
}
519+
519520
// endregion
520521

521522
@Override

sentry-android-core/src/main/java/io/sentry/android/core/BuildInfoProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public final class BuildInfoProvider {
1717
public BuildInfoProvider(final @NotNull ILogger logger) {
1818
this.logger = Objects.requireNonNull(logger, "The ILogger object is required.");
1919
}
20+
2021
/**
2122
* Returns the Build.VERSION.SDK_INT
2223
*

0 commit comments

Comments
 (0)