Skip to content

Commit

Permalink
Issues 21, 22: Log stacktrace on Scalastyle failure and reduce comman…
Browse files Browse the repository at this point in the history
…d line length
  • Loading branch information
Oleksii Lisikh authored Apr 19, 2020
1 parent 984372f commit 7db82d9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -31,6 +32,10 @@ class ScalastyleCheckTask extends SourceTask {
@InputFile
final Property<File> config = project.objects.property(File)

@PathSensitive(PathSensitivity.ABSOLUTE)
@InputFiles
final SetProperty<File> sourceDirs = project.objects.setProperty(File)

@OutputFile
final Property<File> output = project.objects.property(File)

Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class ScalastylePlugin implements Plugin<Project> {

source = sourceSet.scala.srcDirs

sourceDirs.set(sourceSet.scala.srcDirs)
output.set(sourceSetConfig.output)
config.set(resolveScalastyleConfig(sourceSetConfig, sourceSet.name))
failOnWarning.set(sourceSetConfig.failOnWarning.isPresent() ?
Expand Down

0 comments on commit 7db82d9

Please sign in to comment.