Skip to content

Commit

Permalink
feat!: scalaCompilerPlugins configuration used for plugin integration F…
Browse files Browse the repository at this point in the history
…ixes #73
  • Loading branch information
augi committed Mar 11, 2022
1 parent d77a3af commit 59d06dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ class WartremoverPlugin implements Plugin<Project> {
void apply(Project project) {
def extension = project.extensions.create('wartremover', WartremoverExtension)
project.afterEvaluate {
def configuration = project.configurations.create('wartremover')
project.dependencies.add(configuration.name, "org.wartremover:wartremover_${getWartremoverArtifactSuffix(project)}")
File pluginFile = configuration.resolve().find { it.toString().toLowerCase().contains("wartremover_") && it.toString().toLowerCase().endsWith('.jar') }
if (pluginFile == null) {
throw new RuntimeException('Wartremover JAR cannot be found')
}
project.dependencies { scalaCompilerPlugins "org.wartremover:wartremover_${getWartremoverArtifactSuffix(project)}" }
project.tasks.withType(ScalaCompile).all { scalaTask ->
if (scalaTask.scalaCompileOptions.additionalParameters == null) {
scalaTask.scalaCompileOptions.additionalParameters = new ArrayList<String>()
}
scalaTask.scalaCompileOptions.additionalParameters.add("-Xplugin:${pluginFile.canonicalPath}".toString())
WartremoverSettings settings = scalaTask.name.toLowerCase().contains('test') ? extension.getTest() : extension
scalaTask.scalaCompileOptions.additionalParameters.addAll(settings.errorWarts.collect { getErrorWartDirective(it) })
scalaTask.scalaCompileOptions.additionalParameters.addAll(settings.warningWarts.collect { getWarningWartDirective(it) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class WartremoverPluginTest extends Specification {
mavenCentral()
}
project.dependencies {
implementation 'org.scala-lang:scala-library:2.12.3'
implementation 'org.scala-lang:scala-library:2.12.15'
}
project.wartremover {
warningWarts.add('MyProduction')
Expand All @@ -24,7 +24,7 @@ class WartremoverPluginTest extends Specification {
}
project.evaluate()
then:
assert project.configurations.getByName("wartremover").dependencies.find { it.name == 'wartremover_2.12' }
assert project.configurations.getByName('scalaCompilerPlugins').dependencies.find { it.name == 'wartremover_2.12.15' }
def compileTask = project.tasks.compileScala as ScalaCompile
assert compileTask.scalaCompileOptions.additionalParameters.find { it.contains('MyProduction') }
assert !compileTask.scalaCompileOptions.additionalParameters.find { it.contains('MyTest') }
Expand All @@ -46,6 +46,6 @@ class WartremoverPluginTest extends Specification {
}
project.evaluate()
then:
assert project.configurations.getByName("wartremover").dependencies.find { it.name == 'wartremover_2.11.12' }
assert project.configurations.getByName('scalaCompilerPlugins').dependencies.find { it.name == 'wartremover_2.11.12' }
}
}

0 comments on commit 59d06dd

Please sign in to comment.