Skip to content

Commit

Permalink
Integrate spotless (#100)
Browse files Browse the repository at this point in the history
* Initial Spotless integration

* Reformat!

* Update copyrights

* Opportunistic beta02

* Integrate to CI

* Update spotless integration
  • Loading branch information
ZacSweers authored Feb 20, 2022
1 parent d63f4fe commit 4514930
Show file tree
Hide file tree
Showing 38 changed files with 505 additions and 362 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ If the contribution doesn't meet the above criteria, you may fail our automated

## Maintainers

There are more details about processes and workflow in the [Maintainer's Guide](https://github.com/slackhq/keeper/blob/main/.maintainers_guide.md).
There are more details about processes and workflow in the [Maintainer's Guide](https://github.com/slackhq/keeper/blob/main/.maintainers_guide.md).
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ What actually happened

#### Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.
Logs, screenshots, screencast, sample project, funny gif, etc.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ assignees: ''
Start by telling us what problem you’re trying to solve. Often a solution already exists!

Don’t send pull requests to implement significant new features without first getting our support.
Sometimes we leave features out on purpose to keep the project small.
Sometimes we leave features out on purpose to keep the project small.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fail-fast: false # We want to see all results
matrix:
java: ['11']
agp: ['7.1.0', '7.2.0-beta01']
agp: ['7.1.0', '7.2.0-beta02']
tracerefs: [true, false]
job: ['instrumentation', 'plugin']
steps:
Expand All @@ -47,6 +47,9 @@ jobs:
distribution: 'zulu'
java-version: ${{ matrix.java }}

- name: Spot check
run: ./gradlew spotlessCheck

- name: Test plugin
if: matrix.job == 'plugin'
run: ./gradlew -p keeper-gradle-plugin clean check --stacktrace -PkeeperTest.agpVersion=${{ matrix.agp }}
Expand Down
2 changes: 1 addition & 1 deletion .maintainers_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ relevant once again, reopening is great and better than creating a duplicate iss

## Everything else

When in doubt, find the other maintainers and ask.
When in doubt, find the other maintainers and ask.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Perf comparisons on the slack app:
| inferExternalStagingAndroidTestKeepRulesForKeeper | 14.126s | 11.138s |
| jarExternalStagingClassesForKeeper | 10.364s | 6.347s |
| jarExternalStagingAndroidTestClassesForKeeper | 4.504s | 2.609s |

* Keeper now only supports AGP 3.6 or higher. If you still need AGP 3.5.x support, please continue
using Keeper 0.2.0 or lower.
* Update Kotlin to 1.3.71.
Expand All @@ -221,7 +221,7 @@ using Keeper 0.2.0 or lower.
_2020-02-12_

### New Variant Filter API [#14](https://github.com/slackhq/keeper/pull/14)
You can specify a variantFilter on the keeper extension to dynamically configure which variants Keeper
You can specify a variantFilter on the keeper extension to dynamically configure which variants Keeper
operates on (similar to the Android Gradle Plugin's VariantFilter API).

```groovy
Expand All @@ -235,8 +235,8 @@ keeper {
```

### R8 Repository Management Opt-Out [#17](https://github.com/slackhq/keeper/pull/17)
If you don't want Keeper to automatically manage adding R8's maven repo, you can set disable it via
`automaticR8RepoManagement`. Note that you'll need to manually add your own repo that the `keeperR8`
If you don't want Keeper to automatically manage adding R8's maven repo, you can set disable it via
`automaticR8RepoManagement`. Note that you'll need to manually add your own repo that the `keeperR8`
configuration can resolve from.

```groovy
Expand Down
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Our goal is to maintain a safe, helpful and friendly community for everyone, reg

This code and related pro`cedures also apply to unacceptable behavior occurring outside the scope of community activities, in all community venues (online and in-person) as well as in all one-on-one communications, and anywhere such behavior has the potential to adversely affect the safety and well-being of community members.

For more information on our code of conduct, please visit [https://slackhq.github.io/code-of-conduct](https://slackhq.github.io/code-of-conduct)
For more information on our code of conduct, please visit [https://slackhq.github.io/code-of-conduct](https://slackhq.github.io/code-of-conduct)
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Releasing
6. Update the `gradle.properties` to the next SNAPSHOT version.
7. `git commit -am "Prepare next development version."`
8. `git push && git push --tags`
9. Update the website by running `./deploy_website.sh`
9. Update the website by running `./deploy_website.sh`
38 changes: 38 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ buildscript {
}
}

plugins {
id("com.diffplug.spotless") version "6.3.0" apply false
}

String resolvedJvmTarget = System.getenv().getOrDefault("ci_java_version", "1.8")
allprojects {
repositories {
Expand All @@ -47,3 +51,37 @@ allprojects {
}
}
}

apply plugin: "com.diffplug.spotless"
spotless {
format("misc") {
target("**/*.md", ".gitignore")
trimTrailingWhitespace()
endWithNewline()
}
String ktlintVersion = "0.44.0"
Map<String, String> ktlintUserData = ["indent_size": "2", "continuation_indent_size": "2"]
kotlin {
target("**/*.kt")
ktlint(ktlintVersion).userData(ktlintUserData)
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
targetExclude("**/copyright.kt")
}
kotlinGradle {
target("**/*.kts")
ktlint(ktlintVersion).userData(ktlintUserData)
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile("spotless/copyright.kt", "(import|plugins|buildscript|dependencies|pluginManagement|rootProject)")
}
java {
target("**/*.java")
googleJavaFormat('1.14.0').reflowLongStrings()
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(rootProject.file("spotless/copyright.java"))
targetExclude("**/copyright.java")
}
}
8 changes: 7 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@
#

android.useAndroidX=true
kapt.includeCompileClasspath=false

# For GJF
org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
12 changes: 7 additions & 5 deletions keeper-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2020 Slack Technologies, LLC
* Copyright (C) 2020. Slack Technologies, LLC
*
* 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
* 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,
Expand Down Expand Up @@ -56,9 +56,11 @@ tasks.withType<KotlinCompile>().configureEach {
}

tasks.withType<Test>().configureEach {
beforeTest(closureOf<TestDescriptor> {
logger.lifecycle("Running test: $this")
})
beforeTest(
closureOf<TestDescriptor> {
logger.lifecycle("Running test: $this")
}
)
}

sourceSets {
Expand Down
2 changes: 0 additions & 2 deletions keeper-gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# For dokka
org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m

kapt.include.compile.classpath=false

POM_NAME=Keeper
POM_ARTIFACT_ID=keeper
POM_PACKAGING=jar
Expand Down
7 changes: 3 additions & 4 deletions keeper-gradle-plugin/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/*
* Copyright (C) 2020 Slack Technologies, LLC
* Copyright (C) 2020. Slack Technologies, LLC
*
* 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
* 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.
*/

pluginManagement {
repositories {
google()
Expand All @@ -22,4 +21,4 @@ pluginManagement {
}
}

rootProject.name = "keeper-gradle-plugin"
rootProject.name = "keeper-gradle-plugin"
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/*
* Copyright (C) 2020 Slack Technologies, LLC
* Copyright (C) 2020. Slack Technologies, LLC
*
* 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
* 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.
*/

package com.slack.keeper

import org.gradle.api.artifacts.Configuration
Expand Down Expand Up @@ -92,10 +91,12 @@ public abstract class InferAndroidTestKeepRules : JavaExec() {
val inputJvmArgs = jvmArgsProperty.get()
if (inputJvmArgs.isNotEmpty()) {
logger.lifecycle(
"Starting infer exec with jvmArgs ${
inputJvmArgs.joinToString(", ", prefix = "[",
postfix = "]")
}. If debugging, attach the debugger now."
"Starting infer exec with jvmArgs ${
inputJvmArgs.joinToString(
", ", prefix = "[",
postfix = "]"
)
}. If debugging, attach the debugger now."
)
jvmArgs = inputJvmArgs
}
Expand All @@ -111,43 +112,43 @@ public abstract class InferAndroidTestKeepRules : JavaExec() {
}

private fun genPrintUsesArgs(): List<String> =
listOf(
"--keeprules",
androidJar.get().asFile.absolutePath,
appTargetJar.get().asFile.absolutePath,
androidTestSourceJar.get().asFile.absolutePath
).also {
// print-uses is using its output to print rules
standardOutput = outputProguardRules.asFile.get().outputStream().buffered()
}
listOf(
"--keeprules",
androidJar.get().asFile.absolutePath,
appTargetJar.get().asFile.absolutePath,
androidTestSourceJar.get().asFile.absolutePath
).also {
// print-uses is using its output to print rules
standardOutput = outputProguardRules.asFile.get().outputStream().buffered()
}

private fun genTraceReferencesArgs(): List<String?> =
listOf(
"--keep-rules" to "",
"--lib" to androidJar.get().asFile.absolutePath,
"--lib" to androidTestJar.get().asFile.takeIf { it.exists() }?.absolutePath,
"--target" to appTargetJar.get().asFile.absolutePath,
"--source" to androidTestSourceJar.get().asFile.absolutePath,
"--output" to outputProguardRules.get().asFile.absolutePath
).map { if (it.second != null) listOf(it.first, it.second) else listOf() }
.reduce { acc, any -> acc + any }
// Add user provided args coming from TraceReferences.arguments after generated ones.
.plus(traceReferencesArgs.getOrElse(listOf()))
listOf(
"--keep-rules" to "",
"--lib" to androidJar.get().asFile.absolutePath,
"--lib" to androidTestJar.get().asFile.takeIf { it.exists() }?.absolutePath,
"--target" to appTargetJar.get().asFile.absolutePath,
"--source" to androidTestSourceJar.get().asFile.absolutePath,
"--output" to outputProguardRules.get().asFile.absolutePath
).map { if (it.second != null) listOf(it.first, it.second) else listOf() }
.reduce { acc, any -> acc + any }
// Add user provided args coming from TraceReferences.arguments after generated ones.
.plus(traceReferencesArgs.getOrElse(listOf()))

public companion object {
@Suppress("UNCHECKED_CAST", "UnstableApiUsage")
public operator fun invoke(
variantName: String,
androidTestJarProvider: TaskProvider<out AndroidTestVariantClasspathJar>,
releaseClassesJarProvider: TaskProvider<out VariantClasspathJar>,
androidJar: Provider<RegularFile>,
androidTestJar: Provider<RegularFile>,
automaticallyAddR8Repo: Property<Boolean>,
enableAssertions: Property<Boolean>,
extensionJvmArgs: ListProperty<String>,
traceReferencesEnabled: Property<Boolean>,
traceReferencesArgs: ListProperty<String>,
r8Configuration: Configuration
variantName: String,
androidTestJarProvider: TaskProvider<out AndroidTestVariantClasspathJar>,
releaseClassesJarProvider: TaskProvider<out VariantClasspathJar>,
androidJar: Provider<RegularFile>,
androidTestJar: Provider<RegularFile>,
automaticallyAddR8Repo: Property<Boolean>,
enableAssertions: Property<Boolean>,
extensionJvmArgs: ListProperty<String>,
traceReferencesEnabled: Property<Boolean>,
traceReferencesArgs: ListProperty<String>,
r8Configuration: Configuration
): InferAndroidTestKeepRules.() -> Unit = {
if (automaticallyAddR8Repo.get()) {
// This is the maven repo where r8 tagged releases are hosted. Only the r8 artifact is
Expand All @@ -174,17 +175,21 @@ public abstract class InferAndroidTestKeepRules : JavaExec() {
this.traceReferencesEnabled.set(traceReferencesEnabled)
this.traceReferencesArgs.set(traceReferencesArgs)
outputProguardRules.set(
project.layout.buildDirectory.file(
"${KeeperPlugin.INTERMEDIATES_DIR}/${
variantName.capitalize(Locale.US)
}/inferredKeepRules.pro"))
project.layout.buildDirectory.file(
"${KeeperPlugin.INTERMEDIATES_DIR}/${
variantName.capitalize(Locale.US)
}/inferredKeepRules.pro"
)
)
classpath(r8Configuration)
mainClass.set(this.traceReferencesEnabled.map { enabled ->
when (enabled) {
false -> "com.android.tools.r8.PrintUses"
true -> "com.android.tools.r8.tracereferences.TraceReferences"
mainClass.set(
this.traceReferencesEnabled.map { enabled ->
when (enabled) {
false -> "com.android.tools.r8.PrintUses"
true -> "com.android.tools.r8.tracereferences.TraceReferences"
}
}
})
)

enableAssertionsProperty.set(enableAssertions)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/*
* Copyright (C) 2020 Slack Technologies, LLC
* Copyright (C) 2020. Slack Technologies, LLC
*
* 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
* 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.
*/

package com.slack.keeper

import org.gradle.api.Action
Expand Down Expand Up @@ -87,5 +86,5 @@ public abstract class TraceReferences @Inject constructor(objects: ObjectFactory
* with the R8 team.
*/
public val arguments: ListProperty<String> = objects.listProperty<String>()
.convention(listOf("--map-diagnostics:MissingDefinitionsDiagnostic", "error", "info"))
.convention(listOf("--map-diagnostics:MissingDefinitionsDiagnostic", "error", "info"))
}
Loading

0 comments on commit 4514930

Please sign in to comment.