diff --git a/src/main/groovy/com/github/alisiikh/scalastyle/ScalastyleCheckTask.groovy b/src/main/groovy/com/github/alisiikh/scalastyle/ScalastyleCheckTask.groovy index a351ec7..bb32b30 100644 --- a/src/main/groovy/com/github/alisiikh/scalastyle/ScalastyleCheckTask.groovy +++ b/src/main/groovy/com/github/alisiikh/scalastyle/ScalastyleCheckTask.groovy @@ -21,6 +21,7 @@ package com.github.alisiikh.scalastyle import org.gradle.api.GradleException import org.gradle.api.provider.Property +import org.gradle.api.provider.SetProperty import org.gradle.api.tasks.* import org.gradle.process.internal.ExecException @@ -31,6 +32,10 @@ class ScalastyleCheckTask extends SourceTask { @InputFile final Property config = project.objects.property(File) + @PathSensitive(PathSensitivity.ABSOLUTE) + @InputFiles + final SetProperty sourceDirs = project.objects.setProperty(File) + @OutputFile final Property output = project.objects.property(File) @@ -48,22 +53,32 @@ class ScalastyleCheckTask extends SourceTask { @TaskAction def run() { try { + def arguments = [ + '-c', config.get().absolutePath, + '-v', verbose.get().toString(), + '-q', quiet.get().toString(), + '--xmlOutput', output.get().absolutePath, + '--xmlEncoding', outputEncoding.get(), + '--inputEncoding', inputEncoding.get(), + '-w', failOnWarning.get().toString() + ] + + def srcDirs = sourceDirs.get().collect { it.absolutePath }.toList() + + logger.debug("Arguments to be used by Scalastyle: ${arguments.join(" ")}") + logger.debug("""Source folders to be inspected by Scalastyle: + |${srcDirs.join(System.lineSeparator())}""".stripMargin()) + project.javaexec { main = 'org.scalastyle.Main' - args([ - '-c', config.get(), - '-v', verbose.get(), - '-q', quiet.get(), - '--xmlOutput', output.get(), - '--xmlEncoding', outputEncoding.get(), - '--inputEncoding', inputEncoding.get(), - '-w', failOnWarning.get() - ] + source.collect { it.absolutePath }) + args(arguments + srcDirs) classpath = project.configurations.scalastyle } } catch (ExecException e) { - throw new GradleException("Scalastyle check failed.") + throw new GradleException("Scalastyle check failed.", e) + } catch (Throwable e) { + throw new GradleException("Failed to execute Scalastyle inspection", e) } } } diff --git a/src/main/groovy/com/github/alisiikh/scalastyle/ScalastylePlugin.groovy b/src/main/groovy/com/github/alisiikh/scalastyle/ScalastylePlugin.groovy index e3e512f..63ffda3 100644 --- a/src/main/groovy/com/github/alisiikh/scalastyle/ScalastylePlugin.groovy +++ b/src/main/groovy/com/github/alisiikh/scalastyle/ScalastylePlugin.groovy @@ -76,6 +76,7 @@ class ScalastylePlugin implements Plugin { source = sourceSet.scala.srcDirs + sourceDirs.set(sourceSet.scala.srcDirs) output.set(sourceSetConfig.output) config.set(resolveScalastyleConfig(sourceSetConfig, sourceSet.name)) failOnWarning.set(sourceSetConfig.failOnWarning.isPresent() ?