Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkstyle 8.36 -> 8.37 (and keep it up to date using excavator) #1546

Merged
merged 5 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-1546.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: improvement
improvement:
description: checkstyle 8.36 -> 8.37, to benefit from some bugfixes to do with new
java language features (e.g. records)
links:
- https://github.com/palantir/gradle-baseline/pull/1546
18 changes: 18 additions & 0 deletions gradle-baseline-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,21 @@ project.ext.'gradle.publish.secret' = System.env["GRADLE_SECRET"]
tasks.withType(Test) {
systemProperty 'recreate', System.getProperty('recreate', 'false')
}

configurations {
checkstyleVersion
}

dependencies {
checkstyleVersion 'com.puppycrawl.tools:checkstyle'
}

task writeCheckstyleVersion() {
doLast {
file('src/main/resources/checkstyle.version').text = getVersion('com.puppycrawl.tools', 'checkstyle', configurations.checkstyleVersion)
}
}

if (gradle.startParameter.isWriteDependencyLocks()) {
gradle.startParameter.taskNames += 'writeCheckstyleVersion'
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an alternative approach here is to generate the resource just-in-time as a dependency of the ./gradlew idea task... no super strong opinions, i just kinda like that this one is reasonably bulletproof

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also no strong opinion but I like doing this as part of "--write-locks" as people already expect their version numbers to change through this run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, in general I hate it when i open intellij and something crucial is missing because it failed to generate somehow. this seemed more idiot dan-proof

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

package com.palantir.baseline.plugins;

import com.google.common.base.Preconditions;
import com.google.common.io.Resources;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPluginConvention;
Expand All @@ -29,8 +34,6 @@
/** Configures the Gradle "checkstyle" task with Baseline settings. */
public final class BaselineCheckstyle extends AbstractBaselinePlugin {

private static final String DEFAULT_CHECKSTYLE_VERSION = "8.36.1";

@Override
public void apply(Project project) {
this.project = project;
Expand All @@ -39,7 +42,7 @@ public void apply(Project project) {

// Set default version (outside afterEvaluate so it can be overridden).
project.getExtensions()
.configure(CheckstyleExtension.class, ext -> ext.setToolVersion(DEFAULT_CHECKSTYLE_VERSION));
.configure(CheckstyleExtension.class, ext -> ext.setToolVersion(getCheckstyleVersionFromResource()));

// Configure checkstyle
project.getPluginManager().withPlugin("java", plugin -> {
Expand All @@ -66,4 +69,15 @@ public void apply(Project project) {
eclipseProject.buildCommand("net.sf.eclipsecs.core.CheckstyleBuilder");
});
}

// The idea is the checkstyle.version file can be more easily updated by excavator
private static String getCheckstyleVersionFromResource() {
URL url = Resources.getResource(BaselineCheckstyle.class, "/checkstyle.version");
Preconditions.checkNotNull(url, "Unable to find 'checkstyle.version' resource");
try {
return Resources.toString(url, StandardCharsets.UTF_8).trim();
} catch (IOException e) {
throw new RuntimeException("Unable to lookup checkstyle version", e);
}
}
}
1 change: 1 addition & 0 deletions gradle-baseline-java/src/main/resources/checkstyle.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.37
1 change: 1 addition & 0 deletions versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ org.slf4j:slf4j-api = 1.7.30
org.immutables:* = 2.8.8
org.ow2.asm:asm = 9.0
com.googlecode.java-diff-utils:diffutils = 1.3.0
com.puppycrawl.tools:checkstyle = 8.37

# test deps
com.fasterxml.jackson.*:* = 2.11.1
Expand Down