Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
assert no duplicated source folder in integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaquimmnetto committed Jun 5, 2023
1 parent 9564f12 commit d3e1197
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/main/groovy/wooga/gradle/plugins/LocalPluginsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ResolutionStrategy
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.plugins.GroovyPlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.provider.Provider
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
import org.gradle.api.publish.plugins.PublishingPlugin
import org.gradle.api.reporting.ReportingExtension
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.Sync
import org.gradle.api.tasks.TaskContainer
Expand Down Expand Up @@ -174,14 +178,14 @@ class LocalPluginsPlugin implements Plugin<Project> {

def integrationTestSourceSet = setupIntegrationTestSourceSet(project, javaConvention)
setupIntegrationTestConfiguration(project, javaConvention)
setupIntegrationTestIdeaModule(project, integrationTestSourceSet)
setupIntegrationTestIdeaModule(project, integrationTestSourceSet.get())

def integrationTestTask = tasks.register(INTEGRATION_TEST_TASK_NAME, Test)
def testTask = tasks.named(JavaPlugin.TEST_TASK_NAME)
integrationTestTask.configure {
it.with {
setTestClassesDirs(integrationTestSourceSet.output.classesDirs)
classpath = integrationTestSourceSet.runtimeClasspath
setTestClassesDirs(integrationTestSourceSet.get().output.classesDirs)
classpath = integrationTestSourceSet.get().runtimeClasspath
outputs.upToDateWhen { false }
}
it.mustRunAfter testTask
Expand Down Expand Up @@ -215,19 +219,29 @@ class LocalPluginsPlugin implements Plugin<Project> {
integrationTestRuntimeOnly.extendsFrom(testRuntimeOnly)
}

private static SourceSet setupIntegrationTestSourceSet(final Project project, final JavaPluginExtension javaExt) {
def main = javaExt.sourceSets.getByName("main")
def test = javaExt.sourceSets.getByName("test")

SourceSet sourceSet = javaExt.sourceSets.maybeCreate("integrationTest")
sourceSet.setCompileClasspath(project.files(main.compileClasspath, test.compileClasspath, sourceSet.compileClasspath))
sourceSet.setRuntimeClasspath(project.files(main.compileClasspath, test.compileClasspath, sourceSet.runtimeClasspath))
private static void addSrcDirIfNotExists(SourceDirectorySet dirSet, File toAdd) {
if(!dirSet.srcDirs.contains(toAdd)) {
dirSet.srcDir(toAdd)
}
}

sourceSet.groovy.srcDir("src/" + sourceSet.getName() + "/groovy");
sourceSet.resources.srcDir("src/" + sourceSet.getName() + "/resources");
sourceSet
private static Provider<SourceSet> setupIntegrationTestSourceSet(final Project project, final JavaPluginExtension javaExt) {
def main = javaExt.sourceSets.named("main")
def test = javaExt.sourceSets.named("test")
def sourceSet = javaExt.sourceSets.register("integrationTest") {sourceSet ->
sourceSet.compileClasspath = project.files(main.get().compileClasspath, test.get().compileClasspath, sourceSet.compileClasspath)
sourceSet.runtimeClasspath = project.files(main.get().compileClasspath, test.get().compileClasspath, sourceSet.runtimeClasspath)
//duplicate avoidance needed due to gradle bug: https://github.com/gradle/gradle/issues/17236
addSrcDirIfNotExists(sourceSet.groovy as SourceDirectorySet,
new File(project.projectDir, "src/" + sourceSet.getName() + "/groovy"))
addSrcDirIfNotExists(sourceSet.resources,
new File(project.projectDir, "src/" + sourceSet.getName() + "/resources"))
}
return sourceSet
}



static void configureSourceCompatibility(Project project, JavaVersion javaVersion) {
JavaPluginExtension javaExtension = project.extensions.getByType(JavaPluginExtension)
javaExtension.sourceCompatibility = javaVersion
Expand Down

0 comments on commit d3e1197

Please sign in to comment.