Skip to content

Commit

Permalink
[#205] Detect unsupported configuration in rootProject
Browse files Browse the repository at this point in the history
A result of #62
applied in 1.5.0. Fail with meaningful error message, if detected,
and suggest checking the project FAQ.

Fixes #205.
  • Loading branch information
szpak committed May 6, 2020
1 parent 6bd4a4f commit 142ede7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/main/groovy/info/solidsoft/gradle/pitest/PitestPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import info.solidsoft.gradle.pitest.internal.GradleVersionEnforcer
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
Expand Down Expand Up @@ -81,6 +82,7 @@ class PitestPlugin implements Plugin<Project> {
project.plugins.withType(JavaPlugin).configureEach {
setupExtensionWithDefaults()
project.tasks.register(PITEST_TASK_NAME, PitestTask) { t ->
failWithMeaningfulErrorMessageOnUnsupportedConfigurationInRootProjectBuildScript()
t.description = "Run PIT analysis for java classes"
t.group = PITEST_TASK_GROUP
configureTaskDefault(t)
Expand Down Expand Up @@ -110,6 +112,14 @@ class PitestPlugin implements Plugin<Project> {
extension.useClasspathFile.set(false)
}

private void failWithMeaningfulErrorMessageOnUnsupportedConfigurationInRootProjectBuildScript() {
if (project.rootProject.buildscript.configurations.findByName(PITEST_CONFIGURATION_NAME) != null) {
throw new GradleException("The '${PITEST_CONFIGURATION_NAME}' buildscript configuration found in the root project. " +
"This is no longer supported in 1.5.0+ and has to be changed to the regular (sub)project configuration. " +
"See the project FAQ for migration details.")
}
}

@CompileDynamic //To keep Gradle <6.0 compatibility - see https://github.com/gradle/gradle/issues/10953
private void setupReportDirInExtensionWithProblematicTypeForGradle5() {
extension.reportDir.set(new File(project.extensions.getByType(ReportingExtension).baseDir, "pitest"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,34 @@
package info.solidsoft.gradle.pitest

import groovy.transform.CompileDynamic
import spock.lang.Specification
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.gradle.api.Task
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Issue
import spock.lang.Specification

@CompileDynamic
@SuppressWarnings("PrivateFieldCouldBeFinal")
class PitestPluginTest extends Specification {

private Project project = ProjectBuilder.builder().build()

void "add pitest task to java project in proper group"() {
given:
Project project = ProjectBuilder.builder().build()
project.pluginManager.apply('java') //to add SourceSets
when:
project.pluginManager.apply('info.solidsoft.pitest')
project.pluginManager.apply(PitestPlugin.PLUGIN_ID)
then:
project.plugins.hasPlugin(PitestPlugin)
assertThatTasksAreInGroup(project, [PitestPlugin.PITEST_TASK_NAME], PitestPlugin.PITEST_TASK_GROUP)
assertThatTasksAreInGroup([PitestPlugin.PITEST_TASK_NAME], PitestPlugin.PITEST_TASK_GROUP)
}

void "do nothing if Java plugin is not applied but react to it becoming applied"() {
given:
Project project = ProjectBuilder.builder().build()
expect:
!project.plugins.hasPlugin("java")
when:
project.pluginManager.apply('info.solidsoft.pitest')
project.pluginManager.apply(PitestPlugin.PLUGIN_ID)
then:
project.tasks.withType(PitestTask).isEmpty()
when:
Expand All @@ -50,12 +52,33 @@ class PitestPluginTest extends Specification {
!project.tasks.withType(PitestTask).isEmpty()
}

void assertThatTasksAreInGroup(Project project, List<String> taskNames, String group) {
@Issue("https://github.com/szpak/gradle-pitest-plugin/issues/205")
void "fail with meaningful error on no longer supporter pitest configuration in rootproject.buildscript "() {
given:
project.pluginManager.apply('java')
and:
project.buildscript {
configurations.maybeCreate(PitestPlugin.PITEST_CONFIGURATION_NAME)
}
when:
project.pluginManager.apply(PitestPlugin.PLUGIN_ID)
forceTaskCreation()
then:
GradleException e = thrown()
e.cause.message.contains("no longer supported")
e.cause.message.contains("FAQ")
}

private void assertThatTasksAreInGroup(List<String> taskNames, String group) {
taskNames.each { String taskName ->
Task task = project.tasks[taskName]
assert task != null
assert task.group == group
}
}

private int forceTaskCreation() {
project.tasks.withType(PitestTask).size()
}

}

0 comments on commit 142ede7

Please sign in to comment.