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

Fix: Checkstyle no longer verifies resources #830

Merged
merged 3 commits into from
Sep 13, 2019
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-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();
Copy link
Contributor

Choose a reason for hiding this comment

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

using try-with-resources may also have shown useful error on cleanup

        try (InputStream input = new FileInputStream(sourceReport)) {
            return XmlUtils.parseXml(reportHandler, input).failures();
        } catch (Exception e) {
            throw new RuntimeException(String.format("Failed to parse failures XML: %s", sourceReport), e);
        }

} catch (Exception e) {
throw new RuntimeException(String.format("Failed to parse failures XML: %s", sourceReport), e);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I snuck this one in as well as checkstyle crashing (on files from resources) caused an unfinished xml to be written, and it wasn't obvious where that XML was

}

@Override
Expand Down