-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve baseline-checkstyle implementation and upgrade to 8.12 (#313)
- Loading branch information
1 parent
41f8151
commit 5375154
Showing
4 changed files
with
113 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 0 additions & 99 deletions
99
gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineCheckstyle.groovy
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineCheckstyle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* (c) Copyright 2015 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* 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 | ||
* | ||
* http://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.palantir.baseline.plugins; | ||
|
||
import java.nio.file.Paths; | ||
import java.util.stream.Stream; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.plugins.JavaPluginConvention; | ||
import org.gradle.api.plugins.quality.Checkstyle; | ||
import org.gradle.api.plugins.quality.CheckstyleExtension; | ||
import org.gradle.api.plugins.quality.CheckstylePlugin; | ||
import org.gradle.api.tasks.javadoc.Javadoc; | ||
import org.gradle.external.javadoc.StandardJavadocDocletOptions; | ||
import org.gradle.plugins.ide.eclipse.model.EclipseModel; | ||
import org.gradle.plugins.ide.eclipse.model.EclipseProject; | ||
|
||
/** | ||
* Configures the Gradle "checkstyle" task with Baseline settings. | ||
*/ | ||
public final class BaselineCheckstyle extends AbstractBaselinePlugin { | ||
|
||
private static final String DEFAULT_CHECKSTYLE_VERSION = "8.12"; | ||
|
||
@Override | ||
public void apply(Project project) { | ||
this.project = project; | ||
|
||
project.getPluginManager().apply(CheckstylePlugin.class); | ||
|
||
// Set default version (outside afterEvaluate so it can be overridden). | ||
project.getExtensions() | ||
.configure(CheckstyleExtension.class, ext -> ext.setToolVersion(DEFAULT_CHECKSTYLE_VERSION)); | ||
|
||
// Configure checkstyle | ||
project.getPluginManager().withPlugin("java", plugin -> { | ||
JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); | ||
// We use the "JavadocMethod" module in our Checkstyle configuration, making | ||
// Java 8+ new doclint compiler feature redundant. | ||
if (javaConvention.getSourceCompatibility().isJava8Compatible()) { | ||
project.getTasks().withType(Javadoc.class, javadoc -> | ||
javadoc.options(javadocOptions -> ((StandardJavadocDocletOptions) javadocOptions) | ||
.addStringOption("Xdoclint:none", "-quiet"))); | ||
} | ||
project.getTasks().withType(Checkstyle.class, checkstyle -> { | ||
// Make checkstyle include files in src/main/resources and src/test/resources, e.g., | ||
// for whitespace checks. | ||
javaConvention.getSourceSets() | ||
.forEach(sourceSet -> sourceSet.getResources().getSrcDirs() | ||
.forEach(resourceDir -> checkstyle.source(resourceDir.toString()))); | ||
// These sources are only checked by gradle, NOT by Eclipse. | ||
Stream.of("checks", "manifests", "scripts", "templates").forEach(checkstyle::source); | ||
// Make sure java files are still included. This should match list in etc/eclipse-template/.checkstyle. | ||
// Currently not enforced, but could be eventually. | ||
Stream.of( | ||
"java", "cfg", "coffee", "erb", "groovy", "handlebars", "json", "less", "pl", "pp", "sh", "xml") | ||
.forEach(extension -> checkstyle.include("**/*." + extension)); | ||
}); | ||
}); | ||
|
||
project.getExtensions().getByType(CheckstyleExtension.class) | ||
.setConfigDir(this.project.file(Paths.get(getConfigDir(), "checkstyle").toString())); | ||
project.getPluginManager().withPlugin("eclipse", plugin -> { | ||
EclipseProject eclipseProject = project.getExtensions().getByType(EclipseModel.class).getProject(); | ||
eclipseProject.buildCommand("net.sf.eclipsecs.core.CheckstyleBuilder"); | ||
eclipseProject.natures("net.sf.eclipsecs.core.CheckstyleNature"); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters