diff --git a/README.md b/README.md index 0a83d1e..93f845d 100644 --- a/README.md +++ b/README.md @@ -8,23 +8,13 @@ Originally forked from: https://github.com/ngbinh/gradle-scalastyle-plugin ### Instructions -https://plugins.gradle.org/plugin/com.github.alisiikh.scalastyle_2.12 +https://plugins.gradle.org/plugin/com.github.alisiikh.scalastyle Use: ```groovy plugins { - id "com.github.alisiikh.scalastyle_2.10" -} -``` -```groovy -plugins { - id "com.github.alisiikh.scalastyle_2.11" -} -``` -```groovy -plugins { - id "com.github.alisiikh.scalastyle_2.12" + id "com.github.alisiikh.scalastyle" } ``` @@ -37,32 +27,33 @@ buildscript { } } dependencies { - classpath "com.github.alisiikh:gradle-scalastyle-plugin_2.10:2.1.0" // or 2.11, 2.12 + classpath "com.github.alisiikh:gradle-scalastyle-plugin:3.0.0" } } -apply plugin: "com.github.alisiikh.scalastyle_2.10" // or 2.11, 2.12 +apply plugin: "com.github.alisiikh.scalastyle" ``` Configure the plugin ```groovy -scalaStyle { - config = file("/path/to/scalaStyle.xml") +scalastyle { + scalaVersion = '2.12' // default + scalastyleVersion = '1.0.0' // default + config = file("${projectDir}/scalastyle.xml") } ``` Other optional properties are ```groovy - output //Default => ${buildDir}/scalastyle/${sourceSet.name}/scalastyle-check.xml - outputEncoding //Default => UTF-8 - failOnViolation //Default => true - failOnWarning //Default => false - skip //Default => false - verbose //Default => false - quiet //Default => false - inputEncoding //Default => UTF-8 + output = file("${buildDir}/scalastyle/${sourceSet.name}/scalastyle-check.xml") // default + inputEncoding = 'UTF-8' // default + outputEncoding = 'UTF-8' // default + failOnWarning = false // default + skip = false // default + verbose = false // default + quiet = false // default ``` #### Full Buildscript Example @@ -74,14 +65,14 @@ Other optional properties are } dependencies { - classpath 'com.github.alisiikh:gradle-scalastyle-plugin_2.12:2.0.2' + classpath 'com.github.alisiikh:gradle-scalastyle-plugin:3.0.0' } } - apply plugin: 'com.github.alisiikh.scalastyle_2.12' + apply plugin: 'com.github.alisiikh.scalastyle' - scalaStyle { - config = file("$rootDir/scalastyle_config.xml") + scalastyle { + config = file("$rootDir/scalastyle-config.xml") } ``` @@ -94,20 +85,20 @@ Other optional properties are } dependencies { - classpath 'com.github.alisiikh:gradle-scalastyle-plugin_2.12:2.0.2' + classpath 'com.github.alisiikh:gradle-scalastyle-plugin:3.0.0' } } - apply plugin: 'com.github.alisiikh.scalastyle_2.12' + apply plugin: 'com.github.alisiikh.scalastyle' - scalaStyle { + scalastyle { config = file("$rootDir/scalastyle_config.xml") sourceSets { test { // specifically configure scalastyle for test sourceSet config = file("$rootDir/scalastyle_test.xml") - failOnWarnings = true + failOnWarning = true } intTest { diff --git a/build.gradle b/build.gradle index 7489c72..049aa6d 100644 --- a/build.gradle +++ b/build.gradle @@ -23,110 +23,79 @@ buildscript { } } -version = projectVersion -group = projectGroup +version = '3.0.0' +group = 'com.github.alisiikh' ext { - pluginSrc = "$rootDir/src" + scalaVersion = '2.12' } task wrapper(type: Wrapper) { gradleVersion = '4.7' } -['2.10', '2.11', '2.12'].each { scalaVersion -> - project(":gradle-scalastyle-plugin_$scalaVersion") { - apply plugin: 'scala' - apply plugin: 'groovy' - apply plugin: 'maven-publish' - apply plugin: 'com.gradle.plugin-publish' +apply plugin: 'groovy' +apply plugin: 'maven-publish' +apply plugin: 'com.gradle.plugin-publish' - sourceCompatibility = 1.8 - targetCompatibility = 1.8 +sourceCompatibility = 1.8 +targetCompatibility = 1.8 - version = projectVersion - group = projectGroup +ext { + projectGithub = 'https://github.com/alisiikh/gradle-scalastyle-plugin' - ext { - pluginDescription = "Gradle plugin for scalastyle ${scalaVersion}" - } + pluginId = 'com.github.alisiikh.scalastyle' + pluginDescription = 'Gradle plugin for scalastyle' +} - repositories { - mavenCentral() - jcenter() - } +repositories { + mavenCentral() + jcenter() +} - dependencies { - compile gradleApi() - compile localGroovy() +dependencies { + compile gradleApi() + compile localGroovy() - compile "org.scalastyle:scalastyle_${scalaVersion}:1.0.0" - testCompile gradleTestKit() - testCompile('org.spockframework:spock-core:1.1-groovy-2.4') { - exclude module: 'groovy-all' - } - testCompile 'commons-io:commons-io:2.5' - } + testCompile gradleTestKit() + testCompile('org.spockframework:spock-core:1.1-groovy-2.4') { + exclude module: 'groovy-all' + } + testCompile 'commons-io:commons-io:2.5' +} - sourceSets { - main { - scala { - srcDirs = ["$pluginSrc/main/scala"] - } - groovy { - srcDirs = ["$pluginSrc/main/groovy"] - compileClasspath += files([sourceSets.main.scala.outputDir]) - } - resources { - srcDirs = ["$pluginSrc/main/resources"] - } - } - test { - groovy { - srcDirs = ["$pluginSrc/test/groovy"] - } - resources { - srcDirs = ["$pluginSrc/test/resources"] - } - } - } +test { + dependsOn 'publishToMavenLocal' - test { - dependsOn 'publishToMavenLocal' + testLogging { + showStandardStreams = true + } + systemProperty 'SCALA_VERSION', scalaVersion + systemProperty 'PLUGIN_VERSION', version +} - testLogging { - showStandardStreams = true - } - systemProperty 'SCALA_VERSION', scalaVersion - systemProperty 'PLUGIN_VERSION', version +publishing { + publications { + plugin(MavenPublication) { + from components.java } + } +} - compileGroovy.dependsOn(compileScala) +pluginBundle { + mavenCoordinates { + groupId = project.group + } - publishing { - publications { - maven(MavenPublication) { - from components.java - } - } - } + website = projectGithub + vcsUrl = projectGithub + description = pluginDescription + tags = ['scalastyle', 'scala', 'code analysis', 'checkstyle'] - pluginBundle { - mavenCoordinates { - groupId = projectGroup - } - - website = projectGithub - vcsUrl = projectGithub - description = pluginDescription - tags = ['scalastyle', 'scala', 'formatter', 'checkstyle'] - - plugins { - scalaStylePlugin { - id = "com.github.alisiikh.scalastyle_${scalaVersion}" - displayName = pluginDescription - } - } + plugins { + scalastylePlugin { + id = pluginId + displayName = pluginDescription } } } diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index 5cd1a84..0000000 --- a/gradle.properties +++ /dev/null @@ -1,7 +0,0 @@ -projectName = gradle-scalastyle-plugin -projectGroup = com.github.alisiikh - -projectGithub = 'https://github.com/alisiikh/gradle-scalastyle-plugin' - -# Change every releases -projectVersion = 2.1.0 diff --git a/samples/multi_source_scala_2_11/build.gradle b/samples/multi-module/build.gradle similarity index 84% rename from samples/multi_source_scala_2_11/build.gradle rename to samples/multi-module/build.gradle index b15959a..c3e0c3a 100755 --- a/samples/multi_source_scala_2_11/build.gradle +++ b/samples/multi-module/build.gradle @@ -5,13 +5,13 @@ buildscript { jcenter() } dependencies { - classpath 'com.github.alisiikh:gradle-scalastyle-plugin_2.11:2.1.0' + classpath 'com.github.alisiikh:gradle-scalastyle-plugin:3.0.0' } } apply plugin: 'scala' -apply plugin: 'com.github.alisiikh.scalastyle_2.11' +apply plugin: 'com.github.alisiikh.scalastyle' sourceSets { @@ -28,7 +28,10 @@ configurations { garbageRuntime.extendsFrom compile } -scalaStyle { +scalastyle { + scalaVersion = '2.12' + scalastyleVersion = '1.0.0' + // global config, used in case not overriden specifically config = file("$rootDir/scalastyle.xml") verbose = false diff --git a/samples/multi_source_scala_2_11/gradle/wrapper/gradle-wrapper.properties b/samples/multi-module/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from samples/multi_source_scala_2_11/gradle/wrapper/gradle-wrapper.properties rename to samples/multi-module/gradle/wrapper/gradle-wrapper.properties diff --git a/samples/multi_source_scala_2_11/gradlew b/samples/multi-module/gradlew similarity index 100% rename from samples/multi_source_scala_2_11/gradlew rename to samples/multi-module/gradlew diff --git a/samples/multi_source_scala_2_11/gradlew.bat b/samples/multi-module/gradlew.bat similarity index 100% rename from samples/multi_source_scala_2_11/gradlew.bat rename to samples/multi-module/gradlew.bat diff --git a/samples/multi_source_scala_2_11/scalastyle.xml b/samples/multi-module/scalastyle.xml similarity index 100% rename from samples/multi_source_scala_2_11/scalastyle.xml rename to samples/multi-module/scalastyle.xml diff --git a/samples/multi_source_scala_2_11/scalastyle_main.xml b/samples/multi-module/scalastyle_main.xml similarity index 100% rename from samples/multi_source_scala_2_11/scalastyle_main.xml rename to samples/multi-module/scalastyle_main.xml diff --git a/samples/multi_source_scala_2_11/src/garbage/scala/org/gradle/sample/api/Person.scala b/samples/multi-module/src/garbage/scala/org/gradle/sample/api/Person.scala similarity index 100% rename from samples/multi_source_scala_2_11/src/garbage/scala/org/gradle/sample/api/Person.scala rename to samples/multi-module/src/garbage/scala/org/gradle/sample/api/Person.scala diff --git a/samples/multi_source_scala_2_11/src/main/scala/org/gradle/sample/api/Person.scala b/samples/multi-module/src/main/scala/org/gradle/sample/api/Person.scala similarity index 100% rename from samples/multi_source_scala_2_11/src/main/scala/org/gradle/sample/api/Person.scala rename to samples/multi-module/src/main/scala/org/gradle/sample/api/Person.scala diff --git a/samples/multi_source_scala_2_11/src/main/scala/org/gradle/sample/impl/PersonImpl.scala b/samples/multi-module/src/main/scala/org/gradle/sample/impl/PersonImpl.scala similarity index 57% rename from samples/multi_source_scala_2_11/src/main/scala/org/gradle/sample/impl/PersonImpl.scala rename to samples/multi-module/src/main/scala/org/gradle/sample/impl/PersonImpl.scala index c6743e9..0a7876d 100755 --- a/samples/multi_source_scala_2_11/src/main/scala/org/gradle/sample/impl/PersonImpl.scala +++ b/samples/multi-module/src/main/scala/org/gradle/sample/impl/PersonImpl.scala @@ -1,7 +1,4 @@ -package org.gradle.sample.impl - -import org.gradle.sample.api.Person -import org.apache.commons.collections.list.GrowthList; +package org.gradle.sample.impl; /** * Immutable implementation of {@link Person}. diff --git a/samples/multi_source_scala_2_11/src/test/scala/org/gradle/sample/api/PersonSpec.scala b/samples/multi-module/src/test/scala/org/gradle/sample/api/PersonSpec.scala similarity index 100% rename from samples/multi_source_scala_2_11/src/test/scala/org/gradle/sample/api/PersonSpec.scala rename to samples/multi-module/src/test/scala/org/gradle/sample/api/PersonSpec.scala diff --git a/samples/simple_scala_2_10/build.gradle b/samples/simple/build.gradle similarity index 55% rename from samples/simple_scala_2_10/build.gradle rename to samples/simple/build.gradle index ef96bc5..d1d2c65 100755 --- a/samples/simple_scala_2_10/build.gradle +++ b/samples/simple/build.gradle @@ -6,14 +6,17 @@ buildscript { } dependencies { - classpath 'com.github.alisiikh:gradle-scalastyle-plugin_2.10:2.1.0' + classpath 'com.github.alisiikh:gradle-scalastyle-plugin:3.0.0' } } apply plugin: 'scala' -apply plugin: 'com.github.alisiikh.scalastyle_2.10' +apply plugin: 'com.github.alisiikh.scalastyle' + +scalastyle { + scalaVersion = '2.12' + scalastyleVersion = '1.0.0' -scalaStyle { config = file("scalastyle.xml") verbose = false } @@ -23,5 +26,5 @@ repositories { } dependencies { - compile 'org.scala-lang:scala-library:2.10.1' + compile "org.scala-lang:scala-library:2.12.6" } diff --git a/samples/simple_scala_2_10/gradle/wrapper/gradle-wrapper.properties b/samples/simple/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from samples/simple_scala_2_10/gradle/wrapper/gradle-wrapper.properties rename to samples/simple/gradle/wrapper/gradle-wrapper.properties diff --git a/samples/simple_scala_2_10/gradlew b/samples/simple/gradlew similarity index 100% rename from samples/simple_scala_2_10/gradlew rename to samples/simple/gradlew diff --git a/samples/simple_scala_2_10/gradlew.bat b/samples/simple/gradlew.bat similarity index 100% rename from samples/simple_scala_2_10/gradlew.bat rename to samples/simple/gradlew.bat diff --git a/samples/simple_scala_2_10/scalastyle.xml b/samples/simple/scalastyle.xml similarity index 100% rename from samples/simple_scala_2_10/scalastyle.xml rename to samples/simple/scalastyle.xml diff --git a/samples/simple_scala_2_10/src/main/scala/org/gradle/sample/api/Person.scala b/samples/simple/src/main/scala/org/gradle/sample/api/Person.scala similarity index 100% rename from samples/simple_scala_2_10/src/main/scala/org/gradle/sample/api/Person.scala rename to samples/simple/src/main/scala/org/gradle/sample/api/Person.scala diff --git a/samples/simple_scala_2_10/src/main/scala/org/gradle/sample/impl/PersonImpl.scala b/samples/simple/src/main/scala/org/gradle/sample/impl/PersonImpl.scala similarity index 66% rename from samples/simple_scala_2_10/src/main/scala/org/gradle/sample/impl/PersonImpl.scala rename to samples/simple/src/main/scala/org/gradle/sample/impl/PersonImpl.scala index 9205947..bbbf466 100755 --- a/samples/simple_scala_2_10/src/main/scala/org/gradle/sample/impl/PersonImpl.scala +++ b/samples/simple/src/main/scala/org/gradle/sample/impl/PersonImpl.scala @@ -1,7 +1,4 @@ -package org.gradle.sample.impl - -import org.gradle.sample.api.Person -import org.apache.commons.collections.list.GrowthList; +package org.gradle.sample.impl; /** * Immutable implementation of {@link Person}. diff --git a/settings.gradle b/settings.gradle index c30c014..77a7d5e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,8 +16,4 @@ * limitations under the License. */ -rootProject.name = projectName - -include 'gradle-scalastyle-plugin_2.10', - 'gradle-scalastyle-plugin_2.11', - 'gradle-scalastyle-plugin_2.12' +rootProject.name = 'gradle-scalastyle-plugin' diff --git a/src/main/groovy/org/github/alisiikh/scalastyle/Scalastyle.groovy b/src/main/groovy/org/github/alisiikh/scalastyle/Scalastyle.groovy new file mode 100644 index 0000000..48267f4 --- /dev/null +++ b/src/main/groovy/org/github/alisiikh/scalastyle/Scalastyle.groovy @@ -0,0 +1,56 @@ +/* + * Copyright 2019. Oleksii Lisikh + * + * Copyright 2014. Binh Nguyen + * + * Copyright 2013. Muhammad Ashraf + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.github.alisiikh.scalastyle + +import org.gradle.api.NamedDomainObjectContainer + +abstract class BaseScalastyle { + Boolean skip + File config + String inputEncoding + String outputEncoding + Boolean failOnWarning + Boolean verbose + Boolean quiet +} + +class ScalastyleSourceSet extends BaseScalastyle { + String name + File output + + ScalastyleSourceSet(String name) { + this.name = name + } +} + +class Scalastyle extends BaseScalastyle { + String scalaVersion = '2.12' + String scalastyleVersion = '1.0.0' + + NamedDomainObjectContainer sourceSets + + Scalastyle(NamedDomainObjectContainer sourceSets) { + this.sourceSets = sourceSets + } + + def sourceSets(final Closure c) { + sourceSets.configure(c) + } +} diff --git a/src/main/groovy/org/github/alisiikh/scalastyle/ScalastylePlugin.groovy b/src/main/groovy/org/github/alisiikh/scalastyle/ScalastylePlugin.groovy new file mode 100644 index 0000000..092f62c --- /dev/null +++ b/src/main/groovy/org/github/alisiikh/scalastyle/ScalastylePlugin.groovy @@ -0,0 +1,155 @@ +/* + * Copyright 2019. Oleksii Lisikh + * + * Copyright 2014. Binh Nguyen + * + * Copyright 2013. Muhammad Ashraf + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.github.alisiikh.scalastyle + +import org.gradle.api.GradleException +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.scala.ScalaPlugin +import org.gradle.api.tasks.SourceTask +import org.gradle.process.internal.ExecException + + +class ScalastylePlugin implements Plugin { + private Project project + private Scalastyle extension + + void apply(Project project) { + this.project = project + this.extension = new Scalastyle(project.container(ScalastyleSourceSet)) + + project.plugins.apply(ScalaPlugin) + + project.extensions.add('scalastyle', extension) + project.configurations.create('scalastyle') + .setVisible(false) + .setTransitive(true) + .setDescription('Scalastyle libraries to be used for this project.') + + project.afterEvaluate { p -> + p.dependencies { + // scala is already included in scalastyle dependency transitively + scalastyle "org.scalastyle:scalastyle_${extension.scalaVersion}:${extension.scalastyleVersion}" + } + } + + setupScalaStyle() + } + + private def setupScalaStyle() { + def scalastyleCheckTask = project.task('scalastyleCheck') { + group = 'verification' + description = 'Runs scalastyle checks.' + + project.afterEvaluate { + setupExtensionDefaults() + + def sourceSets = project.sourceSets.findAll { !it.scala.srcDirs.isEmpty() } + .collectEntries { [it.name, it.scala.srcDirs] } + + def scalastyleTasks = sourceSets.findResults { + def sourceSetName = it.key as String + def srcDirs = it.value as List + + createScalaStyleTask(sourceSetName, srcDirs) + } + + dependsOn(scalastyleTasks) + } + } + + project.check.dependsOn(scalastyleCheckTask) + } + + private def createScalaStyleTask(String sourceSetName, List srcDirs) { + def overrides = extension.sourceSets.find { it.name == sourceSetName } ?: + new ScalastyleSourceSet(sourceSetName) + + def skip = overrides.skip != null ? overrides.skip : extension.skip + if (!skip) { + project.task(type: SourceTask, "scalastyle${sourceSetName.capitalize()}Check") { + group = 'verification' + description = "Runs scalastyle checks on source set ${sourceSetName}." + + def outputFile = overrides.output ? + project.file(overrides.output) : + project.file("${project.buildDir.absolutePath}/scalastyle/${sourceSetName}/scalastyle-check.xml") + + source = srcDirs + outputs.files(outputFile) + + def config = overrides.config ? overrides.config : extension.config + if (!config.exists() || config.isDirectory()) { + throw new GradleException("Scalastyle configuration $config file does not exist") + } + + logger.info("Using scalastyle configuration for ${sourceSetName} source set: ${config.absolutePath}") + + def options = extractOptions(overrides) + + doLast { + try { + project.javaexec { + main = 'org.scalastyle.Main' + args([ + '-c', config.absolutePath, + '-v', options.verbose, + '-q', options.quiet, + '--xmlOutput', outputFile.absolutePath, + '--xmlEncoding', options.outputEncoding, + '--inputEncoding', options.inputEncoding, + '-w', options.failOnWarning + ] + srcDirs.collect { it.absolutePath }) + + classpath = project.configurations.scalastyle + } + } catch (ExecException e) { + throw new GradleException("Scalastyle check failed for sourceSet $sourceSetName.") + } + } + } + } else { + project.logger.lifecycle("Skipping source set $sourceSetName") + null + } + } + + private def setupExtensionDefaults() { + extension.with { + skip = skip == null ? false : skip + inputEncoding = inputEncoding == null ? "UTF-8" : inputEncoding + outputEncoding = outputEncoding == null ? "UTF-8" : outputEncoding + verbose = verbose == null ? false : verbose + quiet = quiet == null ? false : quiet + failOnWarning = failOnWarning == null ? false : failOnWarning + } + } + + private def extractOptions(ScalastyleSourceSet overrides) { + [ + inputEncoding : overrides.inputEncoding ?: extension.inputEncoding, + outputEncoding: overrides.outputEncoding ?: extension.outputEncoding, + verbose : overrides.verbose != null ? overrides.verbose : extension.verbose, + quiet : overrides.quiet != null ? overrides.quiet : extension.quiet, + failOnWarning : overrides.failOnWarning != null ? overrides.failOnWarning : extension.failOnWarning + ] + } +} + diff --git a/src/main/groovy/org/github/ngbinh/scalastyle/ScalaStyle.groovy b/src/main/groovy/org/github/ngbinh/scalastyle/ScalaStyle.groovy deleted file mode 100644 index b72539e..0000000 --- a/src/main/groovy/org/github/ngbinh/scalastyle/ScalaStyle.groovy +++ /dev/null @@ -1,36 +0,0 @@ -package org.github.ngbinh.scalastyle - -import org.gradle.api.NamedDomainObjectContainer - -abstract class BaseScalaStyle { - Boolean skip - File config - String outputEncoding - Boolean failOnViolation - Boolean failOnWarning - Boolean verbose - Boolean quiet - String inputEncoding -} - -class ScalaStyleSourceSet extends BaseScalaStyle { - String name - File output - - ScalaStyleSourceSet(String name) { - this.name = name - } -} - -class ScalaStyle extends BaseScalaStyle { - - NamedDomainObjectContainer sourceSets - - ScalaStyle(NamedDomainObjectContainer sourceSets) { - this.sourceSets = sourceSets - } - - def sourceSets(final Closure configureClosure) { - sourceSets.configure(configureClosure) - } -} diff --git a/src/main/groovy/org/github/ngbinh/scalastyle/ScalaStylePlugin.groovy b/src/main/groovy/org/github/ngbinh/scalastyle/ScalaStylePlugin.groovy deleted file mode 100644 index 1903521..0000000 --- a/src/main/groovy/org/github/ngbinh/scalastyle/ScalaStylePlugin.groovy +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright 2014. Binh Nguyen - * - * Copyright 2013. Muhammad Ashraf - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.github.ngbinh.scalastyle - -import org.gradle.api.GradleException -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.tasks.SourceTask -import org.scalastyle.ScalastyleConfiguration -import org.scalastyle.TextOutput -import org.scalastyle.XmlOutput - -/** - * @author Binh Nguyen - * @since 12/16/2014 - * @author Muhammad Ashraf - * @since 5/11/13 - */ -class ScalaStylePlugin implements Plugin { - private Project project - private ScalaStyle extension - - private def scalaStyleUtils = new ScalaStyleUtils() - - void apply(Project project) { - this.project = project - this.extension = new ScalaStyle(project.container(ScalaStyleSourceSet)) - - project.extensions.add('scalaStyle', extension) - project.configurations.create('scalaStyle') - .setVisible(false) - .setTransitive(true) - .setDescription('Scalastyle libraries to be used for this project.') - - setupScalaStyle() - } - - private def setupScalaStyle() { - def scalaStyleCheckTask = project.task('scalaStyleCheck') { - group = 'verification' - description = "Runs scalastyle checks." - - project.afterEvaluate { - setupExtensionDefaults() - - ScalastyleConfiguration scalaStyleConfig - if (extension.config != null) { - logger.info("Loading scalastyle configuration: ${extension.config.absolutePath}") - scalaStyleConfig = loadScalaStyleConfig(extension.config) - } - - def srcSets = project.sourceSets.findAll { !it.scala.srcDirs.isEmpty() } - .collectEntries { [it.name, it.scala.srcDirs] } - - def scalaStyleTasks = srcSets.findResults { - def srcSetName = it.key as String - def srcDirs = it.value as List - - createScalaStyleTask(srcSetName, srcDirs, scalaStyleConfig) - } - - dependsOn scalaStyleTasks - } - } - - project.check.dependsOn(scalaStyleCheckTask) - } - - private def createScalaStyleTask(String srcSetName, List srcDirs, ScalastyleConfiguration scalaStyleConfig) { - def overrides = extension.sourceSets.find { it.name == srcSetName } ?: - new ScalaStyleSourceSet(srcSetName) // create dummy object to not fail with NPE - - def skip = overrides.skip != null ? overrides.skip : extension.skip - if (!skip) { - project.task(type: SourceTask, "scalaStyle${srcSetName.capitalize()}Check") { - group = 'verification' - description = "Runs scalastyle checks on source set ${srcSetName}." - - source = srcDirs - - def outputFile = overrides.output ? - project.file(overrides.output) : - project.file("${project.buildDir.absolutePath}/scalastyle/${srcSetName}/scalastyle-check.xml") - outputs.files(outputFile) - - def usedScalaStyleConfig = scalaStyleConfig - if (overrides.config != null) { - logger.info("Loading overriden scalastyle configuration for ${srcSetName} source set: ${overrides.config.absolutePath}") - usedScalaStyleConfig = loadScalaStyleConfig(overrides.config) - } - - def options = extractOptions(overrides) - - doLast { - try { - def startMs = System.currentTimeMillis() - - def messages = scalaStyleUtils.checkSources(usedScalaStyleConfig, srcDirs, options.encoding) - - def config = scalaStyleUtils.readConfig() - def outputResult = new TextOutput(config, options.verbose, options.quiet).output(messages) - - logger.debug("Saving to outputFile={}", outputFile.canonicalPath) - - XmlOutput.save(config, outputFile.absolutePath, options.outputEncoding, messages) - - def stopMs = System.currentTimeMillis() - if (!options.quiet) { - logger.lifecycle("Processed {} file(s)", outputResult.files()) - logger.warn("Found {} warnings", outputResult.warnings()) - logger.error("Found {} errors", outputResult.errors()) - logger.lifecycle("Finished in {} ms", stopMs - startMs) - } - - def violations = outputResult.errors() + (options.failOnWarning ? outputResult.warnings() : 0) - if (violations > 0) { - if (options.failOnViolation) { - throw new GradleException("You have $violations Scalastyle violation(s).") - } else { - logger.warn("Scalastyle:check violations detected but failOnViolation set to false") - } - } else { - logger.debug("Scalastyle:check no violations found") - } - } catch (GradleException ex) { - throw ex - } catch (Exception ex) { - throw new GradleException("Scalastyle check error", ex) - } - } - } - } else { - null - } - } - - private def setupExtensionDefaults() { - extension.with { - skip = skip == null ? false : skip - failOnWarning = failOnWarning == null ? false : failOnWarning - failOnViolation = failOnViolation == null ? true : failOnViolation - inputEncoding = inputEncoding == null ? "UTF-8" : inputEncoding - outputEncoding = outputEncoding == null ? "UTF-8" : outputEncoding - verbose = verbose == null ? false : verbose - quiet = quiet == null ? false : quiet - } - } - - private def extractOptions(ScalaStyleSourceSet overrides) { - [ - encoding : overrides.inputEncoding ?: extension.inputEncoding, - outputEncoding : overrides.outputEncoding ?: extension.outputEncoding, - verbose : overrides.verbose != null ? overrides.verbose : extension.verbose, - quiet : overrides.quiet != null ? overrides.quiet : extension.quiet, - failOnWarning : overrides.failOnWarning != null ? - overrides.failOnWarning : - extension.failOnWarning, - failOnViolation: overrides.failOnViolation != null ? - overrides.failOnViolation : - extension.failOnViolation - ] - } - - private def loadScalaStyleConfig(File config) { - if (config == null) { - throw new GradleException("No Scalastyle configuration file provided") - } - - if (!config.exists()) { - throw new GradleException("Scalastyle configuration $config file does not exist") - } - - def scalaStyleConfig = ScalastyleConfiguration.readFromXml(config.absolutePath) - if (!scalaStyleConfig) { - throw new GradleException("Failed to read scalastyle configuration from ${config.absolutePath}") - } - - scalaStyleConfig - } -} - diff --git a/src/main/resources/META-INF/gradle-plugins/com.github.alisiikh.scalastyle_2.12.properties b/src/main/resources/META-INF/gradle-plugins/com.github.alisiikh.scalastyle.properties similarity index 89% rename from src/main/resources/META-INF/gradle-plugins/com.github.alisiikh.scalastyle_2.12.properties rename to src/main/resources/META-INF/gradle-plugins/com.github.alisiikh.scalastyle.properties index 8f2e2f9..a4f83b5 100644 --- a/src/main/resources/META-INF/gradle-plugins/com.github.alisiikh.scalastyle_2.12.properties +++ b/src/main/resources/META-INF/gradle-plugins/com.github.alisiikh.scalastyle.properties @@ -3,7 +3,7 @@ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# d # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software @@ -13,4 +13,4 @@ # limitations under the License. # -implementation-class=org.github.ngbinh.scalastyle.ScalaStylePlugin +implementation-class=org.github.alisiikh.scalastyle.ScalastylePlugin diff --git a/src/main/resources/META-INF/gradle-plugins/com.github.alisiikh.scalastyle_2.10.properties b/src/main/resources/META-INF/gradle-plugins/com.github.alisiikh.scalastyle_2.10.properties deleted file mode 100644 index 8f2e2f9..0000000 --- a/src/main/resources/META-INF/gradle-plugins/com.github.alisiikh.scalastyle_2.10.properties +++ /dev/null @@ -1,16 +0,0 @@ -# -# Copyright 2013. Muhammad Ashraf -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -implementation-class=org.github.ngbinh.scalastyle.ScalaStylePlugin diff --git a/src/main/resources/META-INF/gradle-plugins/com.github.alisiikh.scalastyle_2.11.properties b/src/main/resources/META-INF/gradle-plugins/com.github.alisiikh.scalastyle_2.11.properties deleted file mode 100644 index 8f2e2f9..0000000 --- a/src/main/resources/META-INF/gradle-plugins/com.github.alisiikh.scalastyle_2.11.properties +++ /dev/null @@ -1,16 +0,0 @@ -# -# Copyright 2013. Muhammad Ashraf -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -implementation-class=org.github.ngbinh.scalastyle.ScalaStylePlugin diff --git a/src/main/scala/org/github/ngbinh/scalastyle/ScalaStyleUtils.scala b/src/main/scala/org/github/ngbinh/scalastyle/ScalaStyleUtils.scala deleted file mode 100644 index 2717484..0000000 --- a/src/main/scala/org/github/ngbinh/scalastyle/ScalaStyleUtils.scala +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2014. Binh Nguyen - * - * Copyright 2013. Muhammad Ashraf - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.github.ngbinh.scalastyle - -import org.scalastyle.{Directory, FileSpec, Message} -import org.scalastyle.ScalastyleChecker -import org.scalastyle.ScalastyleConfiguration -import com.typesafe.config.ConfigFactory -import com.typesafe.config.Config -import java.io.File -import java.util.{List => jList} -import scala.collection.JavaConverters._ - -/** - * @author Binh Nguyen - * @since 12/16/2014 - * @author Muhammad Ashraf - * @since 5/11/13 - */ -class ScalaStyleUtils { - import ScalaStyleUtils._ - - def checkSources(configuration: ScalastyleConfiguration, srcDirs: jList[File], encoding: String): jList[Message[FileSpec]] = - scalaStyleChecker - .checkFiles(configuration, Directory.getFiles(Some(encoding), srcDirs.asScala.toList)) - .toBuffer - .asJava - - def readConfig(): Config = ConfigFactory.load(this.getClass.getClassLoader) -} -object ScalaStyleUtils { - lazy val scalaStyleChecker = new ScalastyleChecker[FileSpec](Some(this.getClass.getClassLoader)) -} diff --git a/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleCheckFailSpec.groovy b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleCheckFailSpec.groovy new file mode 100644 index 0000000..0e97911 --- /dev/null +++ b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleCheckFailSpec.groovy @@ -0,0 +1,25 @@ +package org.github.alisiikh.scalastyle + +import org.gradle.testkit.runner.BuildResult + +class ScalastyleCheckFailSpec extends ScalastyleFunSpec { + + def "should run scalastyleCheck and fail on warning"() { + setup: + prepareTest("simple", """ +scalastyle { + config = file("\$rootDir/scalastyle.xml") + verbose = false + failOnWarning = true +} +""") + + when: + BuildResult result = executeGradleAndFail('scalastyleCheck') + + then: "task scalastyleCheck fails because of a warning" + result.output.contains """Processed 1 file(s) +Found 0 errors +Found 1 warnings""" + } +} diff --git a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleCheckFailsOnNoConfigSpec.groovy b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleCheckFailsOnNoConfigSpec.groovy similarity index 50% rename from src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleCheckFailsOnNoConfigSpec.groovy rename to src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleCheckFailsOnNoConfigSpec.groovy index 47dd464..98f006c 100644 --- a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleCheckFailsOnNoConfigSpec.groovy +++ b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleCheckFailsOnNoConfigSpec.groovy @@ -1,15 +1,15 @@ -package org.github.ngbinh.scalastyle +package org.github.alisiikh.scalastyle import org.gradle.testkit.runner.BuildResult -class ScalaStyleCheckFailsOnNoConfigSpec extends ScalaStyleFunSpec { +class ScalastyleCheckFailsOnNoConfigSpec extends ScalastyleFunSpec { - def "should run scalaStyleCheck and fail if no scalastyle.xml config provided"() { + def "should run scalastyleCheck and fail if no scalastyle.xml config provided"() { setup: prepareTest("noscalastyle") when: - BuildResult result = executeGradleAndFail('scalaStyleCheck') + BuildResult result = executeGradleAndFail('scalastyleCheck') then: result.output.contains "scalastyle.xml file does not exist" diff --git a/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleCheckRunsOnCheckSpec.groovy b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleCheckRunsOnCheckSpec.groovy new file mode 100644 index 0000000..a79a905 --- /dev/null +++ b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleCheckRunsOnCheckSpec.groovy @@ -0,0 +1,22 @@ +package org.github.alisiikh.scalastyle + +import org.gradle.testkit.runner.BuildResult + +import static org.gradle.testkit.runner.TaskOutcome.NO_SOURCE +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS + +class ScalastyleCheckRunsOnCheckSpec extends ScalastyleFunSpec { + + def "should run scalastyleCheck when Gradle's check task is invoked"() { + setup: + prepareTest("simple") + + when: + BuildResult result = executeGradle('check') + + then: + result.task(":scalastyleCheck").outcome == SUCCESS + result.task(':scalastyleMainCheck').outcome == SUCCESS + result.task(':scalastyleTestCheck').outcome == NO_SOURCE + } +} diff --git a/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleCheckTaskRunSpec.groovy b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleCheckTaskRunSpec.groovy new file mode 100644 index 0000000..02cb847 --- /dev/null +++ b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleCheckTaskRunSpec.groovy @@ -0,0 +1,22 @@ +package org.github.alisiikh.scalastyle + +import org.gradle.testkit.runner.BuildResult + +import static org.gradle.testkit.runner.TaskOutcome.NO_SOURCE +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS + +class ScalastyleCheckTaskRunSpec extends ScalastyleFunSpec { + + def "should run scalastyleCheck"() { + setup: + prepareTest("simple") + + when: + BuildResult result = executeGradle('scalastyleCheck') + + then: + result.task(":scalastyleCheck").outcome == SUCCESS + result.task(':scalastyleMainCheck').outcome == SUCCESS + result.task(':scalastyleTestCheck').outcome == NO_SOURCE + } +} diff --git a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleFunSpec.groovy b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleFunSpec.groovy similarity index 76% rename from src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleFunSpec.groovy rename to src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleFunSpec.groovy index fe1b99d..e4b20d0 100644 --- a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleFunSpec.groovy +++ b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleFunSpec.groovy @@ -1,14 +1,13 @@ -package org.github.ngbinh.scalastyle +package org.github.alisiikh.scalastyle import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner -import spock.lang.Shared -abstract class ScalaStyleFunSpec extends ScalaStyleSpec { +abstract class ScalastyleFunSpec extends ScalastyleSpec { - File prepareTest(String projectDir, String scalaStyleOverrides = null) { + File prepareTest(String projectDir, String scalastyleOverrides = null) { createBuildFolder(projectDir) - generateBuildGradleFile(scalaStyleOverrides) + generateBuildGradleFile(scalastyleOverrides) } GradleRunner createRunner(String task) { diff --git a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleMultiSourceSpec.groovy b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleMultiSourceSpec.groovy similarity index 62% rename from src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleMultiSourceSpec.groovy rename to src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleMultiSourceSpec.groovy index 674a874..bb054a9 100644 --- a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleMultiSourceSpec.groovy +++ b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleMultiSourceSpec.groovy @@ -1,10 +1,11 @@ -package org.github.ngbinh.scalastyle +package org.github.alisiikh.scalastyle import org.gradle.testkit.runner.BuildResult -import static org.gradle.testkit.runner.TaskOutcome.* +import static org.gradle.testkit.runner.TaskOutcome.FAILED +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS -class ScalaStyleMultiSourceSpec extends ScalaStyleFunSpec { +class ScalastyleMultiSourceSpec extends ScalastyleFunSpec { private String baseConfig = """ sourceSets { @@ -21,17 +22,17 @@ configurations { garbageRuntime.extendsFrom compile } -scalaStyle { +scalastyle { // global config, used in case not overriden specifically config = file("\$rootDir/scalastyle.xml") verbose = false } """ - def "should succeed on scalaStyleTestCheck"() { + def "should succeed on scalastyleTestCheck"() { setup: prepareTest("multi", baseConfig + """ -scalaStyle { +scalastyle { sourceSets { test { // override output folder @@ -42,14 +43,15 @@ scalaStyle { """) when: - BuildResult result = executeGradle('scalaStyleTestCheck') + BuildResult result = executeGradle('scalastyleTestCheck') then: - result.task(":scalaStyleTestCheck").outcome == SUCCESS + result.task(":scalastyleTestCheck").outcome == SUCCESS result.output.contains """ Processed 1 file(s) +Found 0 errors Found 0 warnings -Found 0 errors""" +""" and: "report is formed in custom location" def report = new File(testProjectBuildDir, "scalastyle-test-result.xml").text @@ -60,10 +62,10 @@ Found 0 errors""" """ } - def "should succeed on scalaStyleMainCheck"() { + def "should succeed on scalastyleMainCheck"() { setup: prepareTest("multi", baseConfig + """ -scalaStyle { +scalastyle { sourceSets { main { // no overrides @@ -73,20 +75,21 @@ scalaStyle { """) when: - def result = executeGradle('scalaStyleMainCheck') + def result = executeGradle('scalastyleMainCheck') then: - result.task(':scalaStyleMainCheck').outcome == SUCCESS + result.task(':scalastyleMainCheck').outcome == SUCCESS result.output.contains """ Processed 1 file(s) +Found 0 errors Found 0 warnings -Found 0 errors""" +""" } - def "should fail on scalaStyleMainCheck with custom configuration"() { + def "should fail on scalastyleMainCheck with custom configuration"() { setup: prepareTest("multi", baseConfig + """ -scalaStyle { +scalastyle { sourceSets { main { // override config @@ -97,24 +100,25 @@ scalaStyle { """) when: - def result = executeGradleAndFail('scalaStyleMain') + def result = executeGradleAndFail('scalastyleMain') then: - result.task(':scalaStyleMainCheck').outcome == FAILED - result.output.contains "Task :scalaStyleMainCheck FAILED" + result.task(':scalastyleMainCheck').outcome == FAILED + result.output.contains "Task :scalastyleMainCheck FAILED" result.output.contains """Processed 1 file(s) +Found 1 errors Found 0 warnings -Found 1 errors""" +""" result.output.contains """src/main/scala/Person.scala message=@deprecated should be used instead of @java.lang.Deprecated line=17 column=0""" } - def "should not have a task scalaStyleGarbageCheck"() { + def "should not have a task scalastyleGarbageCheck"() { setup: prepareTest("multi", baseConfig + """ -scalaStyle { +scalastyle { sourceSets { garbage { - // do not even create scalaStyleGarbageCheck task for this source set + // do not even create scalastyleGarbageCheck task for this source set skip = true } } @@ -122,9 +126,9 @@ scalaStyle { """) when: - def result = executeGradleAndFail('scalaStyleGarbageCheck') + def result = executeGradleAndFail('scalastyleGarbageCheck') then: - result.output.contains "Task 'scalaStyleGarbageCheck' not found in root project" + result.output.contains "Task 'scalastyleGarbageCheck' not found in root project" } } diff --git a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleSpec.groovy b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleSpec.groovy similarity index 78% rename from src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleSpec.groovy rename to src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleSpec.groovy index 02b88c2..e88984d 100644 --- a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleSpec.groovy +++ b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleSpec.groovy @@ -1,4 +1,4 @@ -package org.github.ngbinh.scalastyle +package org.github.alisiikh.scalastyle import org.apache.commons.io.FileUtils import org.junit.Rule @@ -6,7 +6,7 @@ import org.junit.rules.TemporaryFolder import spock.lang.Shared import spock.lang.Specification -abstract class ScalaStyleSpec extends Specification { +abstract class ScalastyleSpec extends Specification { @Rule public final TemporaryFolder testProjectDir = new TemporaryFolder() @@ -21,7 +21,7 @@ abstract class ScalaStyleSpec extends Specification { testProjectBuildDir = new File(testProjectDir.root, "build") } - def generateBuildGradleFile(String scalaStyleOverrides = null) { + def generateBuildGradleFile(String scalastyleOverrides = null) { testProjectDir.newFile("build.gradle") << """ buildscript { repositories { @@ -30,15 +30,16 @@ buildscript { } dependencies { - classpath 'com.github.alisiikh:gradle-scalastyle-plugin_${scalaVersion}:${pluginVersion}' + classpath 'com.github.alisiikh:gradle-scalastyle-plugin:${pluginVersion}' } } apply plugin: 'scala' -apply plugin: 'com.github.alisiikh.scalastyle_${scalaVersion}' +apply plugin: 'com.github.alisiikh.scalastyle' -${scalaStyleOverrides ?: """ -scalaStyle { +${scalastyleOverrides ?: """ +scalastyle { + scalaVersion = "$scalaVersion" config = file("\$rootDir/scalastyle.xml") verbose = false } diff --git a/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleUsesCacheSpec.groovy b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleUsesCacheSpec.groovy new file mode 100644 index 0000000..35af19c --- /dev/null +++ b/src/test/groovy/org/github/alisiikh/scalastyle/ScalastyleUsesCacheSpec.groovy @@ -0,0 +1,29 @@ +package org.github.alisiikh.scalastyle + +import org.gradle.testkit.runner.BuildResult + +import static org.gradle.testkit.runner.TaskOutcome.* + +class ScalastyleUsesCacheSpec extends ScalastyleFunSpec { + + def "should run scalastyleCheck"() { + setup: + prepareTest("simple") + + when: + BuildResult result = executeGradle('scalastyleCheck') + + then: "compiled successfully" + result.task(":scalastyleCheck").outcome == SUCCESS + result.task(':scalastyleMainCheck').outcome == SUCCESS + result.task(':scalastyleTestCheck').outcome == NO_SOURCE + + when: "run again without clean" + result = executeGradle('scalastyleCheck') + + then: "scalastyleCheck should not be run" + result.task(":scalastyleCheck").outcome == UP_TO_DATE + result.task(':scalastyleMainCheck').outcome == UP_TO_DATE + result.task(':scalastyleTestCheck').outcome == NO_SOURCE + } +} diff --git a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleCheckFailSpec.groovy b/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleCheckFailSpec.groovy deleted file mode 100644 index bde2292..0000000 --- a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleCheckFailSpec.groovy +++ /dev/null @@ -1,23 +0,0 @@ -package org.github.ngbinh.scalastyle - -import org.gradle.testkit.runner.BuildResult - -class ScalaStyleCheckFailSpec extends ScalaStyleFunSpec { - - def "should run scalaStyleCheck and fail on warning"() { - setup: - prepareTest("simple", """ -scalaStyle { - config = file("\$rootDir/scalastyle.xml") - verbose = false - failOnWarning = true -} -""") - - when: - BuildResult result = executeGradleAndFail('scalaStyleCheck') - - then: "task scalaStyleCheck fails because of a warning" - result.output.contains "You have 1 Scalastyle violation(s)." - } -} diff --git a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleCheckRunsOnCheckSpec.groovy b/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleCheckRunsOnCheckSpec.groovy deleted file mode 100644 index 015fb3f..0000000 --- a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleCheckRunsOnCheckSpec.groovy +++ /dev/null @@ -1,22 +0,0 @@ -package org.github.ngbinh.scalastyle - -import org.gradle.testkit.runner.BuildResult - -import static org.gradle.testkit.runner.TaskOutcome.NO_SOURCE -import static org.gradle.testkit.runner.TaskOutcome.SUCCESS - -class ScalaStyleCheckRunsOnCheckSpec extends ScalaStyleFunSpec { - - def "should run scalaStyleCheck when Gradle's check task is invoked"() { - setup: - prepareTest("simple") - - when: - BuildResult result = executeGradle('check') - - then: - result.task(":scalaStyleCheck").outcome == SUCCESS - result.task(':scalaStyleMainCheck').outcome == SUCCESS - result.task(':scalaStyleTestCheck').outcome == NO_SOURCE - } -} diff --git a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleCheckTaskRunSpec.groovy b/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleCheckTaskRunSpec.groovy deleted file mode 100644 index 4de6a6d..0000000 --- a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleCheckTaskRunSpec.groovy +++ /dev/null @@ -1,22 +0,0 @@ -package org.github.ngbinh.scalastyle - -import org.gradle.testkit.runner.BuildResult - -import static org.gradle.testkit.runner.TaskOutcome.NO_SOURCE -import static org.gradle.testkit.runner.TaskOutcome.SUCCESS - -class ScalaStyleCheckTaskRunSpec extends ScalaStyleFunSpec { - - def "should run scalaStyleCheck"() { - setup: - prepareTest("simple") - - when: - BuildResult result = executeGradle('scalaStyleCheck') - - then: - result.task(":scalaStyleCheck").outcome == SUCCESS - result.task(':scalaStyleMainCheck').outcome == SUCCESS - result.task(':scalaStyleTestCheck').outcome == NO_SOURCE - } -} diff --git a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleUsesCacheSpec.groovy b/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleUsesCacheSpec.groovy deleted file mode 100644 index fb2414d..0000000 --- a/src/test/groovy/org/github/ngbinh/scalastyle/ScalaStyleUsesCacheSpec.groovy +++ /dev/null @@ -1,29 +0,0 @@ -package org.github.ngbinh.scalastyle - -import org.gradle.testkit.runner.BuildResult - -import static org.gradle.testkit.runner.TaskOutcome.* - -class ScalaStyleUsesCacheSpec extends ScalaStyleFunSpec { - - def "should run scalaStyleCheck"() { - setup: - prepareTest("simple") - - when: - BuildResult result = executeGradle('scalaStyleCheck') - - then: "compiled successfully" - result.task(":scalaStyleCheck").outcome == SUCCESS - result.task(':scalaStyleMainCheck').outcome == SUCCESS - result.task(':scalaStyleTestCheck').outcome == NO_SOURCE - - when: "run again without clean" - result = executeGradle('scalaStyleCheck') - - then: "scalaStyleCheck should not be run" - result.task(":scalaStyleCheck").outcome == UP_TO_DATE - result.task(':scalaStyleMainCheck').outcome == UP_TO_DATE - result.task(':scalaStyleTestCheck').outcome == NO_SOURCE - } -}