Skip to content

Commit

Permalink
Fix: Checkstyle no longer verifies resources (#830)
Browse files Browse the repository at this point in the history
Checkstyle tasks only check their own source set and only actual java sources. They don't look in your `src/*/resources` directory anymore.
  • Loading branch information
dansanduleac authored and bulldozer-bot[bot] committed Sep 13, 2019
1 parent c5d4a9d commit 6e4a472
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-830.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: Checkstyle tasks only check their own source set and only actual java
sources. They don't look in your `src/*/resources` directory anymore.
links:
- https://github.com/palantir/gradle-baseline/pull/830
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
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;
Expand Down Expand Up @@ -55,20 +53,6 @@ public void apply(Project project) {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@
package com.palantir.baseline

import com.palantir.baseline.plugins.BaselineCheckstyle
import com.palantir.baseline.plugins.BaselineEclipse
import nebula.test.multiproject.MultiProjectIntegrationHelper
import org.gradle.api.Project
import org.gradle.api.plugins.quality.Checkstyle
import org.gradle.api.plugins.quality.CheckstylePlugin
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification

class BaselineCheckstyleTest extends Specification {
Expand All @@ -46,7 +42,7 @@ class BaselineCheckstyleTest extends Specification {
project.plugins.hasPlugin(CheckstylePlugin.class)
}

def includesResources() {
def doesNotIncludeResources() {
def file = new File(project.projectDir, 'src/test/resources/checkstyle.xml')
file.getParentFile().mkdirs()
when:
Expand All @@ -57,7 +53,7 @@ class BaselineCheckstyleTest extends Specification {
then:
def tasks = project.tasks.withType(Checkstyle.class)
for (Checkstyle task : tasks) {
assert task.getSource().getFiles().contains(file)
assert !task.getSource().getFiles().contains(file)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ private XmlReportFailuresSupplier(
@Override
public List<Failure> getFailures() throws IOException {
File sourceReport = reporting.getReports().findByName("xml").getDestination();
return XmlUtils.parseXml(reportHandler, new FileInputStream(sourceReport)).failures();
try {
return XmlUtils.parseXml(reportHandler, new FileInputStream(sourceReport)).failures();
} catch (Exception e) {
throw new RuntimeException(String.format("Failed to parse failures XML: %s", sourceReport), e);
}
}

@Override
Expand Down

0 comments on commit 6e4a472

Please sign in to comment.