From 8510d333d201a99bb422eb1e3760de07613e021d Mon Sep 17 00:00:00 2001 From: Andres Almiray Date: Mon, 13 Apr 2020 13:36:56 +0200 Subject: [PATCH] Let the testing directory be configurable. Fixes #277. Fixes #278 --- .../plugins/functionaltest-gradle-plugin.adoc | 4 +- .../integrationtest-gradle-plugin.adoc | 4 +- .../plugins/testing-gradle-plugin.adoc | 16 +-- gradle.properties | 2 +- .../base/ProjectConfigurationExtension.groovy | 8 +- .../plugin/base/plugins/Functional.groovy | 12 ++- .../plugin/base/plugins/Integration.groovy | 12 ++- .../gradle/plugin/base/plugins/Jacoco.groovy | 8 +- .../gradle/plugin/base/plugins/Stats.groovy | 19 +++- .../gradle/plugin/base/plugins/Testing.groovy | 5 + .../FunctionalTestPlugin.groovy | 96 +++++++++++------- .../IntegrationTestPlugin.groovy | 98 ++++++++++++------- .../plugin/stats/SourceStatsTask.groovy | 6 +- 13 files changed, 193 insertions(+), 97 deletions(-) diff --git a/docs/guide/src/docs/asciidoc/plugins/functionaltest-gradle-plugin.adoc b/docs/guide/src/docs/asciidoc/plugins/functionaltest-gradle-plugin.adoc index 6a297290c..7e242403f 100644 --- a/docs/guide/src/docs/asciidoc/plugins/functionaltest-gradle-plugin.adoc +++ b/docs/guide/src/docs/asciidoc/plugins/functionaltest-gradle-plugin.adoc @@ -13,8 +13,8 @@ Responsibilities: * Create two additional configurations: `functionalTestImplementation` and `functionalTestRuntimeOnly`. These configurations extend from `imlementation` and `runtimeOnly` respectively. - * Create a `SourceSet` named `functionalTest` pointing to `src/main/[java|groovy|kotlin|scala]`. - * Create a `Test` task named `functionalTest` pointing to `src/functional-test/[java|groovy|kotlin|scala]`. + * Create a `SourceSet` named `functionalTest` pointing to `${config.testing.functional.baseDir}/[java|groovy|kotlin|scala]`. + * Create a `Test` task named `functionalTest` pointing to `${config.testing.functional.baseDir}/[java|groovy|kotlin|scala]`. * Create a `TestReport` task named `functionalTestReport`. This task is added as a dependency to `check`. NOTE: You must add testing dependencies to `functionalTestImplementation` as this configuration is independent from `testImplementation`. diff --git a/docs/guide/src/docs/asciidoc/plugins/integrationtest-gradle-plugin.adoc b/docs/guide/src/docs/asciidoc/plugins/integrationtest-gradle-plugin.adoc index f3907e495..5a00d28ea 100644 --- a/docs/guide/src/docs/asciidoc/plugins/integrationtest-gradle-plugin.adoc +++ b/docs/guide/src/docs/asciidoc/plugins/integrationtest-gradle-plugin.adoc @@ -13,7 +13,7 @@ Responsibilities: * Create two additional configurations: `integrationTestImplementation` and `integrationTestRuntimeOnly`. These configurations extend from `testImplementation` and `testRuntimeOnly` respectively. - * Create a `SourceSet` named `integrationTest` pointing to `src/integration-test/[java|groovy|kotlin|scala]`. - * Create a `Test` task named `integrationTest` pointing to `src/integration-test/[java|groovy|kotlin|scala]`. + * Create a `SourceSet` named `integrationTest` pointing to `${config.testing.integration.baseDir}/[java|groovy|kotlin|scala]`. + * Create a `Test` task named `integrationTest` pointing to `${config.testing.integration.baseDir}/[java|groovy|kotlin|scala]`. * Create a `TestReport` task named `integrationTestReport`. This task is added as a dependency to `check`. diff --git a/docs/guide/src/docs/asciidoc/plugins/testing-gradle-plugin.adoc b/docs/guide/src/docs/asciidoc/plugins/testing-gradle-plugin.adoc index 513e71f34..a845f388c 100644 --- a/docs/guide/src/docs/asciidoc/plugins/testing-gradle-plugin.adoc +++ b/docs/guide/src/docs/asciidoc/plugins/testing-gradle-plugin.adoc @@ -25,10 +25,12 @@ config { integration { logging aggregate + baseDir } functional { logging aggregate + baseDir } } } @@ -47,9 +49,10 @@ config { [options="header", cols="5*"] |=== -| Name | Type | Required | Default Value | Description -| logging | boolean | no | true | Enables verbose output -| aggregate | boolean | no | true | Enables test report aggregation +| Name | Type | Required | Default Value | Description +| logging | boolean | no | true | Enables verbose output +| aggregate | boolean | no | true | Enables test report aggregation +| baseDir | String | no | src/integration-test | |=== [[_testing_functional]] @@ -57,9 +60,10 @@ config { [options="header", cols="5*"] |=== -| Name | Type | Required | Default Value | Description -| logging | boolean | no | true | Enables verbose output -| aggregate | boolean | no | true | Enables test report aggregation +| Name | Type | Required | Default Value | Description +| logging | boolean | no | true | Enables verbose output +| aggregate | boolean | no | true | Enables test report aggregation +| baseDir | String | no | src/functional-test | |=== [[_org_kordamp_gradle_testing_tasks]] diff --git a/gradle.properties b/gradle.properties index 513518ce8..83446bc41 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ targetCompatibility = 1.8 kordampPluginVersion = 0.33.0 spockVersion = 1.3-groovy-2.5 -bintrayVersion = 1.8.4 +bintrayVersion = 1.8.5 kotlinVersion = 1.3.71 detektVersion = 1.7.2 diff --git a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/ProjectConfigurationExtension.groovy b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/ProjectConfigurationExtension.groovy index 85aa0d60d..741dbebd5 100644 --- a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/ProjectConfigurationExtension.groovy +++ b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/ProjectConfigurationExtension.groovy @@ -466,14 +466,16 @@ class ProjectConfigurationExtension { plugin.normalize() publishing.normalize() docs.normalize() - coverage.normalize() quality.normalize() this } ProjectConfigurationExtension postMerge() { + testing.postMerge() docs.postMerge() quality.postMerge() + coverage.postMerge() + stats.postMerge() this } @@ -688,8 +690,8 @@ class ProjectConfigurationExtension { o1 } - Coverage normalize() { - jacoco.normalize() + Coverage postMerge() { + jacoco.postMerge() this } } diff --git a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Functional.groovy b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Functional.groovy index 917f80341..72063a020 100644 --- a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Functional.groovy +++ b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Functional.groovy @@ -20,6 +20,8 @@ package org.kordamp.gradle.plugin.base.plugins import groovy.transform.Canonical import groovy.transform.CompileStatic +import static org.kordamp.gradle.StringUtils.isNotBlank + /** * @author Andres Almiray * @since 0.14.0 @@ -31,6 +33,7 @@ class Functional { boolean logging = true boolean aggregate = true + String baseDir private boolean loggingSet = false private boolean aggregateSet = false @@ -67,7 +70,8 @@ class Functional { Map toMap() { new LinkedHashMap<>([ logging : logging, - aggregate: aggregate + aggregate: aggregate, + baseDir : baseDir ]) } @@ -76,6 +80,7 @@ class Functional { copy.@loggingSet = loggingSet copy.@aggregate = aggregate copy.@aggregateSet = aggregateSet + copy.@baseDir = baseDir } static void merge(Functional o1, Functional o2) { @@ -86,5 +91,10 @@ class Functional { boolean thisAggregate = (boolean) (o1.aggregateSet ? o1.aggregate : o2.aggregate) boolean superAggregate = (boolean) (o1.test.aggregateSet) ? o1.test.aggregate : o2.aggregate o1.setAggregate(thisAggregate ?: superAggregate) + o1.setBaseDir(isNotBlank(o1.baseDir) ? o1.baseDir : o2.baseDir) + } + + void postMerge() { + baseDir = baseDir ?: 'src/functional-test' } } diff --git a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Integration.groovy b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Integration.groovy index efef4fc1a..61247d492 100644 --- a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Integration.groovy +++ b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Integration.groovy @@ -20,6 +20,8 @@ package org.kordamp.gradle.plugin.base.plugins import groovy.transform.Canonical import groovy.transform.CompileStatic +import static org.kordamp.gradle.StringUtils.isNotBlank + /** * @author Andres Almiray * @since 0.14.0 @@ -31,6 +33,7 @@ class Integration { boolean logging = true boolean aggregate = true + String baseDir private boolean loggingSet = false private boolean aggregateSet = false @@ -67,7 +70,8 @@ class Integration { Map toMap() { new LinkedHashMap([ logging : logging, - aggregate: aggregate + aggregate: aggregate, + baseDir : baseDir ]) } @@ -76,10 +80,16 @@ class Integration { copy.@loggingSet = loggingSet copy.@aggregate = aggregate copy.@aggregateSet = aggregateSet + copy.@baseDir = baseDir } static void merge(Integration o1, Integration o2) { o1.setLogging((boolean) (o1.loggingSet ? o1.logging : (o2.loggingSet ? o2.logging : (o1.test.loggingSet ? o1.test.logging : o2.test.logging)))) o1.setAggregate((boolean) (o1.aggregateSet ? o1.aggregate : (o2.aggregateSet ? o2.aggregate : (o1.test.aggregateSet ? o1.test.aggregate : o2.test.aggregate)))) + o1.setBaseDir(isNotBlank(o1.baseDir) ? o1.baseDir : o2.baseDir) + } + + void postMerge() { + baseDir = baseDir ?: 'src/integration-test' } } diff --git a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Jacoco.groovy b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Jacoco.groovy index cac1dbd5b..2616dec3b 100644 --- a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Jacoco.groovy +++ b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Jacoco.groovy @@ -118,7 +118,7 @@ class Jacoco extends AbstractFeature { new LinkedHashMap<>('jacoco': map) } - void normalize() { + void postMerge() { if (!enabledSet) { if (isRoot()) { if (project.childProjects.isEmpty()) { @@ -136,8 +136,8 @@ class Jacoco extends AbstractFeature { boolean hasTestSourceSets() { hasTestsAt(project.file('src/test')) || - hasTestsAt(project.file('src/integration-test')) || - hasTestsAt(project.file('src/functional-test')) + hasTestsAt(project.file(config.testing.integration.baseDir)) || + hasTestsAt(project.file(config.testing.functional.baseDir)) } private static boolean hasTestsAt(File testDir) { @@ -156,7 +156,7 @@ class Jacoco extends AbstractFeature { } static void merge(Jacoco o1, Jacoco o2) { - AbstractFeature.merge(o1, o2) + // AbstractFeature.merge(o1, o2) o1.aggregateExecFile = o1.aggregateExecFile ?: o2.aggregateExecFile o1.aggregateReportHtmlFile = o1.aggregateReportHtmlFile ?: o2.aggregateReportHtmlFile o1.aggregateReportXmlFile = o1.aggregateReportXmlFile ?: o2.aggregateReportXmlFile diff --git a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Stats.groovy b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Stats.groovy index 5a93e8c93..4d2421a84 100644 --- a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Stats.groovy +++ b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Stats.groovy @@ -45,7 +45,6 @@ class Stats extends AbstractAggregateFeature { Stats(ProjectConfigurationExtension config, Project project) { super(config, project, PLUGIN_ID, 'stats') - paths.putAll(defaultPaths()) } @Override @@ -55,7 +54,7 @@ class Stats extends AbstractAggregateFeature { map.paths = paths } - static Map> defaultPaths() { + private Map> defaultPaths() { Map> basePaths = [:] [ @@ -75,9 +74,12 @@ class Stats extends AbstractAggregateFeature { yaml : 'YAML', clojure : 'Clojure' ].each { extension, name -> - ['test', 'integration-test', 'functional-test'].each { source -> - String classifier = getPropertyNameForLowerCaseHyphenSeparatedName(source) - basePaths[classifier + extension.capitalize()] = [name: name + ' ' + getNaturalName(classifier) + ' Sources', path: 'src/' + source, extension: extension] + ['src/test', + config.testing.integration.baseDir, + config.testing.functional.baseDir].each { source -> + String[] parts = source.split(File.separator) + String classifier = getPropertyNameForLowerCaseHyphenSeparatedName(parts[-1]) + basePaths[classifier + extension.capitalize()] = [name: name + ' ' + getNaturalName(classifier) + ' Sources', path: source, extension: extension] } } @@ -116,4 +118,11 @@ class Stats extends AbstractAggregateFeature { o1.paths.putAll(o2.paths) CollectionUtils.merge(o1.formats, o2?.formats) } + + void postMerge() { + Map> mergedPaths = [:] + mergedPaths.putAll(defaultPaths()) + mergedPaths.putAll(paths) + paths.putAll(mergedPaths) + } } diff --git a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Testing.groovy b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Testing.groovy index 4de8fbb83..2ac6e9a38 100644 --- a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Testing.groovy +++ b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/base/plugins/Testing.groovy @@ -124,6 +124,11 @@ class Testing extends AbstractFeature { Functional.merge(o1.functional, o2.functional) } + void postMerge() { + integration.postMerge() + functional.postMerge() + } + Set testTasks() { testTasks } diff --git a/plugins/functionaltest-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/functionaltest/FunctionalTestPlugin.groovy b/plugins/functionaltest-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/functionaltest/FunctionalTestPlugin.groovy index 3d33970ce..396ea9b07 100644 --- a/plugins/functionaltest-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/functionaltest/FunctionalTestPlugin.groovy +++ b/plugins/functionaltest-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/functionaltest/FunctionalTestPlugin.groovy @@ -25,8 +25,10 @@ import org.gradle.api.tasks.SourceSetContainer import org.gradle.api.tasks.testing.TestReport import org.kordamp.gradle.plugin.AbstractKordampPlugin import org.kordamp.gradle.plugin.base.BasePlugin +import org.kordamp.gradle.plugin.base.ProjectConfigurationExtension import org.kordamp.gradle.plugin.test.tasks.FunctionalTest +import static org.kordamp.gradle.PluginUtils.resolveEffectiveConfig import static org.kordamp.gradle.PluginUtils.resolveSourceSets import static org.kordamp.gradle.PluginUtils.supportsApiConfiguration @@ -49,25 +51,25 @@ class FunctionalTestPlugin extends AbstractKordampPlugin { BasePlugin.applyIfMissing(project) project.pluginManager.withPlugin('java-base') { - createSourceSetsIfNeeded(project, 'java') + createSourceSetsIfNeeded(project) createConfigurationsIfNeeded(project) createTasksIfNeeded(project) } project.pluginManager.withPlugin('groovy-base') { - createSourceSetsIfNeeded(project, 'groovy') + createSourceSetsIfNeeded(project) createConfigurationsIfNeeded(project) createTasksIfNeeded(project) } project.pluginManager.withPlugin('org.jetbrains.kotlin.jvm') { - createSourceSetsIfNeeded(project, 'kotlin') + createSourceSetsIfNeeded(project) createConfigurationsIfNeeded(project) createTasksIfNeeded(project) } project.pluginManager.withPlugin('scala-base') { - createSourceSetsIfNeeded(project, 'scala') + createSourceSetsIfNeeded(project) createConfigurationsIfNeeded(project) createTasksIfNeeded(project) } @@ -81,14 +83,33 @@ class FunctionalTestPlugin extends AbstractKordampPlugin { private void adjustSourceSets(Project project) { SourceSet sourceSet = resolveSourceSets(project).functionalTest + + ProjectConfigurationExtension config = resolveEffectiveConfig(project) + String sourceSetDir = config.testing.functional.baseDir + project.pluginManager.withPlugin('java-base') { + adjustSourceSet(project, sourceSetDir, 'java') + } + + project.pluginManager.withPlugin('groovy-base') { + adjustSourceSet(project, sourceSetDir, 'groovy') + } + + project.pluginManager.withPlugin('org.jetbrains.kotlin.jvm') { + adjustSourceSet(project, sourceSetDir, 'kotlin') + } + + project.pluginManager.withPlugin('scala-base') { + adjustSourceSet(project, sourceSetDir, 'scala') + } + sourceSet.compileClasspath += resolveSourceSets(project).main.output sourceSet.compileClasspath += project.configurations.compileClasspath sourceSet.runtimeClasspath += sourceSet.compileClasspath project.configurations.findByName('functionalTestCompileClasspath') - .extendsFrom(project.configurations.compileClasspath) + .extendsFrom(project.configurations.compileClasspath) project.configurations.findByName('functionalTestRuntimeClasspath') - .extendsFrom(project.configurations.compileClasspath) + .extendsFrom(project.configurations.compileClasspath) } @CompileStatic @@ -101,9 +122,9 @@ class FunctionalTestPlugin extends AbstractKordampPlugin { } project.configurations.findByName('functionalTest' + compileSuffix) - .extendsFrom project.configurations.findByName(compileSuffix.uncapitalize()) + .extendsFrom project.configurations.findByName(compileSuffix.uncapitalize()) project.configurations.findByName('functionalTest' + runtimeSuffix) - .extendsFrom project.configurations.findByName(runtimeSuffix.uncapitalize()) + .extendsFrom project.configurations.findByName(runtimeSuffix.uncapitalize()) } @CompileStatic @@ -132,46 +153,51 @@ class FunctionalTestPlugin extends AbstractKordampPlugin { project.configurations.maybeCreate('functionalTest' + runtimeSuffix) } - private void createSourceSetsIfNeeded(Project project, String sourceSetName) { + private void createSourceSetsIfNeeded(Project project) { + project.sourceSets.maybeCreate('functionalTest') + } + + private void adjustSourceSet(Project project, String sourceSetDir, String sourceSetName) { SourceSet sourceSet = project.sourceSets.maybeCreate('functionalTest') - if (project.file('src/functional-test/' + sourceSetName).exists()) { - sourceSet[sourceSetName].srcDirs project.file('src/functional-test/' + sourceSetName) + + if (project.file(sourceSetDir + File.separator + sourceSetName).exists()) { + sourceSet[sourceSetName].srcDirs project.file(sourceSetDir + File.separator + sourceSetName) } - if (project.file('src/functional-test/resources').exists()) { - sourceSet.resources.srcDir project.file('src/functional-test/resources') + if (project.file(sourceSetDir + File.separator + 'resources').exists()) { + sourceSet.resources.srcDir project.file(sourceSetDir + File.separator + 'resources') } } private void createTasksIfNeeded(Project project) { if (!project.tasks.findByName('functionalTest')) { project.tasks.register('functionalTest', FunctionalTest, - new Action() { - @Override - void execute(FunctionalTest t) { - t.group = 'Verification' - t.description = 'Runs the functional tests.' - t.testClassesDirs = resolveSourceSets(project).functionalTest.output.classesDirs - t.classpath = resolveSourceSets(project).functionalTest.runtimeClasspath - t.reports.html.enabled = false - t.forkEvery = Runtime.runtime.availableProcessors() - - t.testLogging { - events 'passed', 'skipped', 'failed' - } + new Action() { + @Override + void execute(FunctionalTest t) { + t.group = 'Verification' + t.description = 'Runs the functional tests.' + t.testClassesDirs = resolveSourceSets(project).functionalTest.output.classesDirs + t.classpath = resolveSourceSets(project).functionalTest.runtimeClasspath + t.reports.html.enabled = false + t.forkEvery = Runtime.runtime.availableProcessors() + + t.testLogging { + events 'passed', 'skipped', 'failed' } - }) + } + }) } if (!project.tasks.findByName('functionalTestReport')) { project.tasks.register('functionalTestReport', TestReport, - new Action() { - @Override - void execute(TestReport t) { - t.group = 'Reporting' - t.description = 'Generates a report on functional tests.' - t.destinationDir = project.file("${project.reporting.baseDir.path}/functional-tests") - } - }) + new Action() { + @Override + void execute(TestReport t) { + t.group = 'Reporting' + t.description = 'Generates a report on functional tests.' + t.destinationDir = project.file("${project.reporting.baseDir.path}/functional-tests") + } + }) } } diff --git a/plugins/integrationtest-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/integrationtest/IntegrationTestPlugin.groovy b/plugins/integrationtest-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/integrationtest/IntegrationTestPlugin.groovy index e3d99c211..41a695c97 100644 --- a/plugins/integrationtest-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/integrationtest/IntegrationTestPlugin.groovy +++ b/plugins/integrationtest-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/integrationtest/IntegrationTestPlugin.groovy @@ -25,8 +25,10 @@ import org.gradle.api.tasks.SourceSetContainer import org.gradle.api.tasks.testing.TestReport import org.kordamp.gradle.plugin.AbstractKordampPlugin import org.kordamp.gradle.plugin.base.BasePlugin +import org.kordamp.gradle.plugin.base.ProjectConfigurationExtension import org.kordamp.gradle.plugin.test.tasks.IntegrationTest +import static org.kordamp.gradle.PluginUtils.resolveEffectiveConfig import static org.kordamp.gradle.PluginUtils.resolveSourceSets import static org.kordamp.gradle.PluginUtils.supportsApiConfiguration @@ -49,25 +51,25 @@ class IntegrationTestPlugin extends AbstractKordampPlugin { BasePlugin.applyIfMissing(project) project.pluginManager.withPlugin('java-base') { - createSourceSetsIfNeeded(project, 'java') + createSourceSetsIfNeeded(project) createConfigurationsIfNeeded(project) createTasksIfNeeded(project) } project.pluginManager.withPlugin('groovy-base') { - createSourceSetsIfNeeded(project, 'groovy') + createSourceSetsIfNeeded(project) createConfigurationsIfNeeded(project) createTasksIfNeeded(project) } project.pluginManager.withPlugin('org.jetbrains.kotlin.jvm') { - createSourceSetsIfNeeded(project, 'kotlin') + createSourceSetsIfNeeded(project) createConfigurationsIfNeeded(project) createTasksIfNeeded(project) } project.pluginManager.withPlugin('scala-base') { - createSourceSetsIfNeeded(project, 'scala') + createSourceSetsIfNeeded(project) createConfigurationsIfNeeded(project) createTasksIfNeeded(project) } @@ -81,6 +83,25 @@ class IntegrationTestPlugin extends AbstractKordampPlugin { private void adjustSourceSets(Project project) { SourceSet sourceSet = resolveSourceSets(project).integrationTest + + ProjectConfigurationExtension config = resolveEffectiveConfig(project) + String sourceSetDir = config.testing.integration.baseDir + project.pluginManager.withPlugin('java-base') { + adjustSourceSet(project, sourceSetDir, 'java') + } + + project.pluginManager.withPlugin('groovy-base') { + adjustSourceSet(project, sourceSetDir, 'groovy') + } + + project.pluginManager.withPlugin('org.jetbrains.kotlin.jvm') { + adjustSourceSet(project, sourceSetDir, 'kotlin') + } + + project.pluginManager.withPlugin('scala-base') { + adjustSourceSet(project, sourceSetDir, 'scala') + } + sourceSet.compileClasspath += resolveSourceSets(project).main.output sourceSet.compileClasspath += project.configurations.compileClasspath sourceSet.compileClasspath += project.configurations.testCompileClasspath @@ -88,9 +109,9 @@ class IntegrationTestPlugin extends AbstractKordampPlugin { sourceSet.runtimeClasspath += project.configurations.testRuntimeClasspath project.configurations.findByName('integrationTestCompileClasspath') - .extendsFrom(project.configurations.compileClasspath, project.configurations.testCompileClasspath) + .extendsFrom(project.configurations.compileClasspath, project.configurations.testCompileClasspath) project.configurations.findByName('integrationTestRuntimeClasspath') - .extendsFrom(project.configurations.compileClasspath, project.configurations.testRuntimeClasspath) + .extendsFrom(project.configurations.compileClasspath, project.configurations.testRuntimeClasspath) } @CompileStatic @@ -103,9 +124,9 @@ class IntegrationTestPlugin extends AbstractKordampPlugin { } project.configurations.findByName('integrationTest' + compileSuffix) - .extendsFrom(project.configurations.findByName('test' + compileSuffix)) + .extendsFrom(project.configurations.findByName('test' + compileSuffix)) project.configurations.findByName('integrationTest' + runtimeSuffix) - .extendsFrom(project.configurations.findByName('test' + runtimeSuffix)) + .extendsFrom(project.configurations.findByName('test' + runtimeSuffix)) } @CompileStatic @@ -134,46 +155,51 @@ class IntegrationTestPlugin extends AbstractKordampPlugin { project.configurations.maybeCreate('integrationTest' + runtimeSuffix) } - private void createSourceSetsIfNeeded(Project project, String sourceSetName) { + private void createSourceSetsIfNeeded(Project project) { + project.sourceSets.maybeCreate('integrationTest') + } + + private void adjustSourceSet(Project project, String sourceSetDir, String sourceSetName) { SourceSet sourceSet = project.sourceSets.maybeCreate('integrationTest') - if (project.file('src/integration-test/' + sourceSetName).exists()) { - sourceSet[sourceSetName].srcDirs project.file('src/integration-test/' + sourceSetName) + + if (project.file(sourceSetDir + File.separator + sourceSetName).exists()) { + sourceSet[sourceSetName].srcDirs project.file(sourceSetDir + File.separator + sourceSetName) } - if (project.file('src/integration-test/resources').exists()) { - sourceSet.resources.srcDir project.file('src/integration-test/resources') + if (project.file(sourceSetDir + File.separator + 'resources').exists()) { + sourceSet.resources.srcDir project.file(sourceSetDir + File.separator + 'resources') } } private void createTasksIfNeeded(Project project) { if (!project.tasks.findByName('integrationTest')) { project.tasks.register('integrationTest', IntegrationTest, - new Action() { - @Override - void execute(IntegrationTest t) { - t.group = 'Verification' - t.description = 'Runs the integration tests.' - t.testClassesDirs = resolveSourceSets(project).integrationTest.output.classesDirs - t.classpath = resolveSourceSets(project).integrationTest.runtimeClasspath - t.reports.html.enabled = false - t.forkEvery = Runtime.runtime.availableProcessors() - - t.testLogging { - events 'passed', 'skipped', 'failed' - } + new Action() { + @Override + void execute(IntegrationTest t) { + t.group = 'Verification' + t.description = 'Runs the integration tests.' + t.testClassesDirs = resolveSourceSets(project).integrationTest.output.classesDirs + t.classpath = resolveSourceSets(project).integrationTest.runtimeClasspath + t.reports.html.enabled = false + t.forkEvery = Runtime.runtime.availableProcessors() + + t.testLogging { + events 'passed', 'skipped', 'failed' } - }) + } + }) } if (!project.tasks.findByName('integrationTestReport')) { project.tasks.register('integrationTestReport', TestReport, - new Action() { - @Override - void execute(TestReport t) { - t.group = 'Reporting' - t.description = 'Generates a report on integration tests.' - t.destinationDir = project.file("${project.reporting.baseDir.path}/integration-tests") - } - }) + new Action() { + @Override + void execute(TestReport t) { + t.group = 'Reporting' + t.description = 'Generates a report on integration tests.' + t.destinationDir = project.file("${project.reporting.baseDir.path}/integration-tests") + } + }) } } @@ -183,4 +209,4 @@ class IntegrationTestPlugin extends AbstractKordampPlugin { project.pluginManager.apply(IntegrationTestPlugin) } } -} +} \ No newline at end of file diff --git a/plugins/sourcestats-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/stats/SourceStatsTask.groovy b/plugins/sourcestats-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/stats/SourceStatsTask.groovy index 3c74dad84..1bd8f9c79 100644 --- a/plugins/sourcestats-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/stats/SourceStatsTask.groovy +++ b/plugins/sourcestats-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/stats/SourceStatsTask.groovy @@ -29,6 +29,7 @@ import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskAction import org.kordamp.gradle.PluginUtils +import org.kordamp.gradle.plugin.base.ProjectConfigurationExtension import org.kordamp.gradle.plugin.base.plugins.Stats import org.kordamp.gradle.plugin.stats.counter.CssCounter import org.kordamp.gradle.plugin.stats.counter.HashCounter @@ -38,6 +39,7 @@ import org.kordamp.gradle.plugin.stats.counter.SemiColonCounter import org.kordamp.gradle.plugin.stats.counter.SqlCounter import org.kordamp.gradle.plugin.stats.counter.XmlCounter +import static org.kordamp.gradle.PluginUtils.resolveEffectiveConfig import static org.kordamp.gradle.StringUtils.getFilenameExtension import static org.kordamp.gradle.plugin.base.plugins.Stats.HTML import static org.kordamp.gradle.plugin.base.plugins.Stats.TXT @@ -72,8 +74,10 @@ class SourceStatsTask extends DefaultTask { Map counterInstances = resolveCounterInstances() + ProjectConfigurationExtension config = resolveEffectiveConfig(project) + Map> merged = [:] - merged.putAll(Stats.defaultPaths()) + merged.putAll(config.stats.paths) // deep copy paths.each { key, val -> Map map = [:]