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 task can no longer be configured to analyse single files #12270

Closed
davidburstrom opened this issue Feb 18, 2020 · 3 comments · Fixed by #12285
Closed

Checkstyle task can no longer be configured to analyse single files #12270

davidburstrom opened this issue Feb 18, 2020 · 3 comments · Fixed by #12285
Assignees
Labels
Milestone

Comments

@davidburstrom
Copy link
Contributor

Expected Behavior

In Gradle 6.1 it was still possible to configure a Checkstyle task to analyse a single file using e.g.

        project.tasks.create(name: 'checkstyleGradle', type: Checkstyle) { Checkstyle task ->
            task.group = 'verification'
            task.description = 'Run Checkstyle on the Gradle build script'
            task.source = ['build.gradle']
            task.classpath = project.files()
        }

Current Behavior

In Gradle 6.2, the build fails with

Caused by: : /project/build.gradle is not a directory.
        at org.apache.tools.ant.types.AbstractFileSet.getDirectoryScanner(AbstractFileSet.java:518)
        at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.scanFileSets(CheckstyleAntTask.java:560)
        at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.getFilesToCheck(CheckstyleAntTask.java:490)
        at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.processFiles(CheckstyleAntTask.java:333)
        at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.realExecute(CheckstyleAntTask.java:315)
        at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.execute(CheckstyleAntTask.java:287)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
        at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(BasicAntBuilder.java:80)
        at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:483)
        at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:195)
        at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:162)
        at org.gradle.api.internal.project.antbuilder.AntBuilderDelegate.nodeCompleted(AntBuilderDelegate.java:124)
        at org.gradle.api.plugins.quality.internal.CheckstyleInvoker$_invoke_closure1.doCall(CheckstyleInvoker.groovy:58)
        at org.gradle.util.ClosureBackedAction.execute(ClosureBackedAction.java:71)
        at org.gradle.util.ClosureBackedAction.execute(ClosureBackedAction.java:52)
        at org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder$2.execute(DefaultIsolatedAntBuilder.java:154)
        at org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder$2.execute(DefaultIsolatedAntBuilder.java:136)
        at org.gradle.api.internal.project.antbuilder.ClassPathToClassLoaderCache.withCachedClassLoader(ClassPathToClassLoaderCache.java:135)
        at org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder.execute(DefaultIsolatedAntBuilder.java:130)
        at org.gradle.api.internal.project.IsolatedAntBuilder$execute$0.call(Unknown Source)
        at org.gradle.api.plugins.quality.internal.CheckstyleInvoker.invoke(CheckstyleInvoker.groovy:51)
        at org.gradle.api.plugins.quality.Checkstyle.run(Checkstyle.java:151)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)

The workaround to use

task.source = project.fileTree(dir: '.', include: 'build.gradle')

should have been fine, but in a very large repository, the task spends minutes just to scan the directories before finally analysing the one file requested.

Context

6.1 worked, 6.2 no longer works.

The result is that it is harder for us to maintain code standards in build scripts.

Steps to Reproduce

Run gradle (6.2) in a directory with a build.gradle file with the following contents

import org.gradle.api.plugins.quality.Checkstyle

plugins {
    id 'checkstyle'
}

dependencies {
    repositories {
        mavenCentral()
    }   
}

tasks.create(name: 'checkstyleGradle', type: Checkstyle) { Checkstyle task ->
    task.group = 'verification'
    task.description = 'Run Checkstyle on the Gradle build script'
    task.source = ['build.gradle']
    task.classpath = project.files()
    task.config = project.resources.text.fromString('<?xml version="1.0"?><!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd"><module name="Checker"/>')
}

Your Environment

MacOS X 10.14.6
Build scan URL: N/A

@mateuszkwiecinski
Copy link

mateuszkwiecinski commented Feb 19, 2020

I'm experiencing exactly the same issue (on 6.2 only), but I'm able to reproduce it even when passing set of files, regardles of their number.
And I confirm workaround posted above works in my case too.

@davidburstrom
Copy link
Contributor Author

@adammurdoch I saw a rather similar issue locally but for pmd. Is it reasonable to assume your fix addressed all regressions related to explicit files?

@ljacomet
Copy link
Member

Yes that should be the case. If not, please file another issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants