From f72628bdca73ee58ed956ce8df5a537834b6bb1e Mon Sep 17 00:00:00 2001 From: Dereck Bridie Date: Fri, 26 Sep 2025 16:06:26 +0200 Subject: [PATCH 1/4] Upgrade Spotless to Spotless 7 --- .github/workflows/apply_spotless.yml | 2 +- build.gradle.kts | 83 ++++++++++++++++++++++++++++ gradle/init.gradle.kts | 52 ----------------- gradle/libs.versions.toml | 3 + spotless/copyright.kts | 16 ++++++ spotless/copyright.xml | 16 ++++++ 6 files changed, 119 insertions(+), 53 deletions(-) delete mode 100644 gradle/init.gradle.kts create mode 100644 spotless/copyright.kts create mode 100644 spotless/copyright.xml diff --git a/.github/workflows/apply_spotless.yml b/.github/workflows/apply_spotless.yml index d69f817b0..3727da63a 100644 --- a/.github/workflows/apply_spotless.yml +++ b/.github/workflows/apply_spotless.yml @@ -42,7 +42,7 @@ jobs: java-version: '17' - name: Run spotlessApply - run: ./gradlew spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace + run: ./gradlew spotlessApply --stacktrace - name: Auto-commit if spotlessApply has changes uses: stefanzweifel/git-auto-commit-action@v5 diff --git a/build.gradle.kts b/build.gradle.kts index 899385a15..bafd85c4e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,6 +13,89 @@ plugins { alias(libs.plugins.kotlin.multiplatform) apply false alias(libs.plugins.android.kotlin.multiplatform.library) apply false alias(libs.plugins.android.lint) apply false + alias(libs.plugins.spotless) apply false +} + +subprojects { + apply(plugin = "com.diffplug.spotless") + extensions.configure { + kotlin { + target("**/*.kt") + targetExclude("**/build/**/*.kt") + + val disabledRules = arrayOf( + // These rules were introduced in ktlint 0.46.0 and should not be + // enabled without further discussion. They are disabled for now. + // See: https://github.com/pinterest/ktlint/releases/tag/0.46.0 + "filename", + "annotation", + "annotation-spacing", + "argument-list-wrapping", + "double-colon-spacing", + "enum-entry-name-case", + "multiline-if-else", + "no-empty-first-line-in-method-block", + "package-name", + "trailing-comma", + "spacing-around-angle-brackets", + "spacing-between-declarations-with-annotations", + "spacing-between-declarations-with-comments", + "unary-op-spacing", + "no-trailing-spaces", + "max-line-length", + // Disabled rules that were introduced or changed between 0.46.0 ~ 1.50.0 + "class-signature", + "trailing-comma-on-call-site", + "trailing-comma-on-declaration-site", + "comment-wrapping", + "function-literal", + "function-signature", + "function-expression-body", + "function-start-of-body-spacing", + "multiline-expression-wrapping", + ) + + ktlint(libs.versions.ktlint.get()).editorConfigOverride( + mapOf( + "android" to "true", + "ktlint_code_style" to "android_studio", + "ij_kotlin_allow_trailing_comma" to "true", + ) + disabledRules.map { Pair("ktlint_standard_$it", "disabled") } + ) + + // ktlint 7.0.0 introduces lints, which existing snippets do not satisfy + val kotlinSuppressLints = arrayOf( + "standard:function-naming", + "standard:property-naming", + "standard:class-naming", + "standard:max-line-length", + "standard:comment-wrapping", + "standard:import-ordering", + "standard:filename", + "standard:backing-property-naming", + ) + for (lint in kotlinSuppressLints) { + suppressLintsFor { + step = "ktlint" + shortCode = lint + } + } + + licenseHeaderFile(rootProject.file("spotless/copyright.kt")) + } + kotlinGradle { + target("**/*.kts") + targetExclude("**/build/**/*.kts") + // Look for the first line that doesn't have a block comment (assumed to be the license) + licenseHeaderFile(rootProject.file("spotless/copyright.kts"), "(^(?![\\/ ]\\*).*$)") + } + format("xml") { + target("**/*.xml") + targetExclude("**/build/**/*.xml") + // Look for the root tag or a tag that is a snippet + licenseHeaderFile(rootProject.file("spotless/copyright.xml"), "(<[a-zA-Z])|( \ No newline at end of file From b460f89ca6c89c97c172493a39c1e357189cc8f1 Mon Sep 17 00:00:00 2001 From: Dereck Bridie Date: Fri, 26 Sep 2025 17:09:21 +0200 Subject: [PATCH 2/4] Apply new spotless rules for kotlin files --- .../main/java/com/example/compose/snippets/ui/theme/Type.kt | 2 +- .../com/example/snippets/ActivityEmbeddingKotlinSnippets.kt | 4 +++- misc/src/main/java/com/example/snippets/ui/theme/Type.kt | 2 +- xr/src/main/java/com/example/xr/scenecore/GltfEntity.kt | 2 +- xr/src/main/java/com/example/xr/scenecore/SpatialAudio.kt | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/compose/snippets/src/main/java/com/example/compose/snippets/ui/theme/Type.kt b/compose/snippets/src/main/java/com/example/compose/snippets/ui/theme/Type.kt index acf007bfd..ab604e852 100644 --- a/compose/snippets/src/main/java/com/example/compose/snippets/ui/theme/Type.kt +++ b/compose/snippets/src/main/java/com/example/compose/snippets/ui/theme/Type.kt @@ -46,5 +46,5 @@ val Typography = Typography( lineHeight = 16.sp, letterSpacing = 0.5.sp ) - */ + */ ) diff --git a/misc/src/main/java/com/example/snippets/ActivityEmbeddingKotlinSnippets.kt b/misc/src/main/java/com/example/snippets/ActivityEmbeddingKotlinSnippets.kt index d00308286..7871e78d5 100644 --- a/misc/src/main/java/com/example/snippets/ActivityEmbeddingKotlinSnippets.kt +++ b/misc/src/main/java/com/example/snippets/ActivityEmbeddingKotlinSnippets.kt @@ -276,7 +276,9 @@ class ActivityEmbeddingKotlinSnippets { /** * Function used by snippet. */ - fun classForItem(item: Int): Class<*> { return Class::class.java } + fun classForItem(item: Int): Class<*> { + return Class::class.java + } // [START android_activity_embedding_MenuActivity_class_kotlin] inner class MenuActivity : AppCompatActivity() { diff --git a/misc/src/main/java/com/example/snippets/ui/theme/Type.kt b/misc/src/main/java/com/example/snippets/ui/theme/Type.kt index f383a07ba..db2e63291 100644 --- a/misc/src/main/java/com/example/snippets/ui/theme/Type.kt +++ b/misc/src/main/java/com/example/snippets/ui/theme/Type.kt @@ -46,5 +46,5 @@ val Typography = Typography( lineHeight = 16.sp, letterSpacing = 0.5.sp ) - */ + */ ) diff --git a/xr/src/main/java/com/example/xr/scenecore/GltfEntity.kt b/xr/src/main/java/com/example/xr/scenecore/GltfEntity.kt index 997436ddf..cf39f9f4f 100644 --- a/xr/src/main/java/com/example/xr/scenecore/GltfEntity.kt +++ b/xr/src/main/java/com/example/xr/scenecore/GltfEntity.kt @@ -36,7 +36,7 @@ private suspend fun loadGltfFile(session: Session) { private fun createModelEntity(session: Session, gltfModel: GltfModel) { // [START androidxr_scenecore_gltfmodelentity_create] if (session.scene.spatialCapabilities - .hasCapability(SpatialCapabilities.SPATIAL_CAPABILITY_3D_CONTENT) + .hasCapability(SpatialCapabilities.SPATIAL_CAPABILITY_3D_CONTENT) ) { val gltfEntity = GltfModelEntity.create(session, gltfModel) } diff --git a/xr/src/main/java/com/example/xr/scenecore/SpatialAudio.kt b/xr/src/main/java/com/example/xr/scenecore/SpatialAudio.kt index b68e67713..25b1556a4 100644 --- a/xr/src/main/java/com/example/xr/scenecore/SpatialAudio.kt +++ b/xr/src/main/java/com/example/xr/scenecore/SpatialAudio.kt @@ -40,7 +40,7 @@ private fun playSpatialAudioAtEntity(session: Session, appContext: Context, enti // [START androidxr_scenecore_playSpatialAudio] // Check spatial capabilities before using spatial audio if (session.scene.spatialCapabilities - .hasCapability(SpatialCapabilities.SPATIAL_CAPABILITY_SPATIAL_AUDIO) + .hasCapability(SpatialCapabilities.SPATIAL_CAPABILITY_SPATIAL_AUDIO) ) { // The session has spatial audio capabilities val maxVolume = 1F val lowPriority = 0 From 08db9cbb969b4f2e9e600ce06542e8b5310700c5 Mon Sep 17 00:00:00 2001 From: Dereck Bridie Date: Fri, 26 Sep 2025 18:27:35 +0200 Subject: [PATCH 3/4] Normalize XML files --- bluetoothle/src/main/AndroidManifest.xml | 17 ++++++++++- .../src/main/res/layout/activity_main.xml | 17 ++++++++++- bluetoothle/src/main/res/values/strings.xml | 16 ++++++++++ .../src/main/AndroidManifest.xml | 15 ++++++++++ .../src/main/res/values/strings.xml | 26 ++++++++++------- .../src/main/res/values/themes.xml | 18 +++++++++++- .../src/main/AndroidManifest.xml | 27 +++++++++-------- .../drawable-v24/ic_launcher_foreground.xml | 18 +++++++++++- .../res/drawable/ic_launcher_background.xml | 15 ++++++++++ .../src/main/res/layout-v34/xmlsnippets.xml | 29 +++++++++---------- .../res/mipmap-anydpi-v26/ic_launcher.xml | 17 ++++++++++- .../mipmap-anydpi-v26/ic_launcher_round.xml | 17 ++++++++++- .../src/main/res/values/colors.xml | 17 ++++++++++- .../src/main/res/values/strings.xml | 18 +++++++++++- .../src/main/res/values/themes.xml | 17 ++++++++++- .../src/main/res/xml/provider.xml | 15 ++++++++++ .../src/main/res/xml/provider_settings.xml | 15 ++++++++++ kmp/androidApp/src/main/AndroidManifest.xml | 17 ++++++++++- .../src/androidMain/AndroidManifest.xml | 17 ++++++++++- kotlin/src/main/AndroidManifest.xml | 15 ++++++++++ misc/src/main/AndroidManifest.xml | 15 ++++++++++ .../res/drawable/ic_launcher_background.xml | 15 ++++++++++ .../res/drawable/ic_launcher_foreground.xml | 18 +++++++++++- misc/src/main/res/layout/activity_main.xml | 16 +++++++++- .../res/mipmap-anydpi-v26/ic_launcher.xml | 17 ++++++++++- .../mipmap-anydpi-v26/ic_launcher_round.xml | 17 ++++++++++- misc/src/main/res/values/colors.xml | 15 ++++++++++ misc/src/main/res/values/strings.xml | 18 +++++++++++- misc/src/main/res/values/themes.xml | 17 ++++++++++- misc/src/main/res/xml/main_split_config.xml | 18 ++++++++++-- views/src/main/AndroidManifest.xml | 23 +++++++-------- .../main/res/layout/system_bar_protection.xml | 25 +++++++--------- views/src/main/res/layout/widget_preview.xml | 24 +++++++-------- wear/lint.xml | 19 ++++++++++-- wear/src/main/AndroidManifest.xml | 15 ++++++++++ wear/src/main/res/drawable/animated_walk.xml | 4 +-- .../main/res/drawable/complication_icon.xml | 16 ++++++++++ .../res/drawable/ic_launcher_background.xml | 15 ++++++++++ .../res/drawable/ic_launcher_foreground.xml | 18 +++++++++++- wear/src/main/res/drawable/ic_walk.xml | 16 ++++++++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 17 ++++++++++- .../mipmap-anydpi-v26/ic_launcher_round.xml | 17 ++++++++++- wear/src/main/res/values/strings.xml | 18 +++++++++++- 43 files changed, 650 insertions(+), 106 deletions(-) diff --git a/bluetoothle/src/main/AndroidManifest.xml b/bluetoothle/src/main/AndroidManifest.xml index d15b213e2..b42865576 100644 --- a/bluetoothle/src/main/AndroidManifest.xml +++ b/bluetoothle/src/main/AndroidManifest.xml @@ -1,4 +1,19 @@ + @@ -24,4 +39,4 @@ - \ No newline at end of file + diff --git a/bluetoothle/src/main/res/layout/activity_main.xml b/bluetoothle/src/main/res/layout/activity_main.xml index b692bf4a3..b46563beb 100644 --- a/bluetoothle/src/main/res/layout/activity_main.xml +++ b/bluetoothle/src/main/res/layout/activity_main.xml @@ -1,4 +1,19 @@ + - \ No newline at end of file + diff --git a/bluetoothle/src/main/res/values/strings.xml b/bluetoothle/src/main/res/values/strings.xml index 7abc06d3b..fa7796f20 100644 --- a/bluetoothle/src/main/res/values/strings.xml +++ b/bluetoothle/src/main/res/values/strings.xml @@ -1 +1,17 @@ + + diff --git a/compose/recomposehighlighter/src/main/AndroidManifest.xml b/compose/recomposehighlighter/src/main/AndroidManifest.xml index 051708e50..93e77f2eb 100644 --- a/compose/recomposehighlighter/src/main/AndroidManifest.xml +++ b/compose/recomposehighlighter/src/main/AndroidManifest.xml @@ -1,4 +1,19 @@ + + Copyright 2018 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> RecomposeHighlighter diff --git a/compose/recomposehighlighter/src/main/res/values/themes.xml b/compose/recomposehighlighter/src/main/res/values/themes.xml index 918929c1b..f94279433 100644 --- a/compose/recomposehighlighter/src/main/res/values/themes.xml +++ b/compose/recomposehighlighter/src/main/res/values/themes.xml @@ -1,5 +1,21 @@ + + - \ No newline at end of file + diff --git a/identity/credentialmanager/src/main/AndroidManifest.xml b/identity/credentialmanager/src/main/AndroidManifest.xml index fb060cc44..b0f129562 100644 --- a/identity/credentialmanager/src/main/AndroidManifest.xml +++ b/identity/credentialmanager/src/main/AndroidManifest.xml @@ -1,20 +1,19 @@ + Copyright 2025 The Android Open Source Project + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> diff --git a/identity/credentialmanager/src/main/res/drawable-v24/ic_launcher_foreground.xml b/identity/credentialmanager/src/main/res/drawable-v24/ic_launcher_foreground.xml index 2b068d114..8760078c8 100644 --- a/identity/credentialmanager/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ b/identity/credentialmanager/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -1,3 +1,19 @@ + + - \ No newline at end of file + diff --git a/identity/credentialmanager/src/main/res/drawable/ic_launcher_background.xml b/identity/credentialmanager/src/main/res/drawable/ic_launcher_background.xml index 07d5da9cb..e6202fbb1 100644 --- a/identity/credentialmanager/src/main/res/drawable/ic_launcher_background.xml +++ b/identity/credentialmanager/src/main/res/drawable/ic_launcher_background.xml @@ -1,4 +1,19 @@ + + Copyright 2025 The Android Open Source Project + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> @@ -25,4 +24,4 @@ android:isCredential="true" /> - \ No newline at end of file + diff --git a/identity/credentialmanager/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/identity/credentialmanager/src/main/res/mipmap-anydpi-v26/ic_launcher.xml index 6f3b755bf..b8ff0f029 100644 --- a/identity/credentialmanager/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ b/identity/credentialmanager/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -1,6 +1,21 @@ + - \ No newline at end of file + diff --git a/identity/credentialmanager/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/identity/credentialmanager/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml index 6f3b755bf..b8ff0f029 100644 --- a/identity/credentialmanager/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ b/identity/credentialmanager/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -1,6 +1,21 @@ + - \ No newline at end of file + diff --git a/identity/credentialmanager/src/main/res/values/colors.xml b/identity/credentialmanager/src/main/res/values/colors.xml index f8c6127d3..732ae206f 100644 --- a/identity/credentialmanager/src/main/res/values/colors.xml +++ b/identity/credentialmanager/src/main/res/values/colors.xml @@ -1,4 +1,19 @@ + #FFBB86FC #FF6200EE @@ -7,4 +22,4 @@ #FF018786 #FF000000 #FFFFFFFF - \ No newline at end of file + diff --git a/identity/credentialmanager/src/main/res/values/strings.xml b/identity/credentialmanager/src/main/res/values/strings.xml index 8f5fb8e80..cb1497463 100644 --- a/identity/credentialmanager/src/main/res/values/strings.xml +++ b/identity/credentialmanager/src/main/res/values/strings.xml @@ -1,3 +1,19 @@ + + credentialmanager // [START android_identity_assetlinks_app_association] @@ -7,4 +23,4 @@ }] // [END android_identity_assetlinks_app_association] - \ No newline at end of file + diff --git a/identity/credentialmanager/src/main/res/values/themes.xml b/identity/credentialmanager/src/main/res/values/themes.xml index 65078ebe0..e2cf423e7 100644 --- a/identity/credentialmanager/src/main/res/values/themes.xml +++ b/identity/credentialmanager/src/main/res/values/themes.xml @@ -1,5 +1,20 @@ +