Skip to content

Commit

Permalink
Removed IdeaPlugin sources directory assignment for integration tests…
Browse files Browse the repository at this point in the history
… to support internal references for Intellij IDEA within the integration directory
  • Loading branch information
wartoshika authored and pmendelski committed Sep 11, 2022
1 parent fdc3633 commit b67f75a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ package com.coditory.gradle.integration

import org.gradle.api.Project
import org.gradle.plugins.ide.idea.IdeaPlugin
import org.gradle.plugins.ide.idea.model.IdeaModule

internal object IdeaPluginConfiguration {
fun apply(project: Project) {
applyIdeaPluginIfNeeded(project)
if (!project.plugins.hasPlugin(IdeaPlugin::class.java)) {
return
}
project.afterEvaluate {
project.plugins.findPlugin(IdeaPlugin::class.java)
?.let { configureIdeaModule(project, it.model.module) }
}
}

private fun applyIdeaPluginIfNeeded(project: Project) {
Expand All @@ -25,11 +20,4 @@ internal object IdeaPluginConfiguration {
project.plugins.apply(IdeaPlugin::class.java)
}
}

private fun configureIdeaModule(project: Project, module: IdeaModule) {
val integrationTest = SourceSetExtractor.sourceSets(project)
.getByName(IntegrationTestPlugin.INTEGRATION_CONFIG_PREFIX)
module.testSourceDirs = module.testSourceDirs + integrationTest.allSource.srcDirs
module.testResourceDirs = module.testResourceDirs + integrationTest.resources.srcDirs
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.coditory.gradle.integration
import com.coditory.gradle.integration.base.TestProjectBuilder.Companion.project
import org.assertj.core.api.Assertions.assertThat
import org.gradle.api.Project
import org.gradle.api.plugins.GroovyPlugin
import org.gradle.api.plugins.scala.ScalaPlugin
import org.gradle.plugins.ide.idea.IdeaPlugin
import org.junit.jupiter.api.Test
import java.io.File
Expand Down Expand Up @@ -33,44 +31,16 @@ class IdeaConfigurationTest {
assertThat(hasIdeaPlugin(project)).isFalse()
}

@Test
fun `should add integration tests to idea module test dirs`() {
// when
val project = project()
.withPlugins(IdeaPlugin::class, IntegrationTestPlugin::class)
.build()

// then
val module = getIdeaPlugin(project).model.module
assertThat(module.testSourceDirs)
.containsAll(toIntegrationSrcFiles(project, "java"))
assertThat(module.testResourceDirs)
.containsAll(toIntegrationSrcFiles(project, "resources"))
}

@Test
fun `should add integration tests from groovy and scala to idea module test dirs`() {
// when
val project = project()
.withPlugins(IdeaPlugin::class, IntegrationTestPlugin::class, GroovyPlugin::class, ScalaPlugin::class)
.build()

// then
val module = getIdeaPlugin(project).model.module
assertThat(module.testSourceDirs)
.containsAll(toIntegrationSrcFiles(project, "java", "groovy", "scala"))
assertThat(module.testResourceDirs)
.containsAll(toIntegrationSrcFiles(project, "resources"))
}

private fun hasIdeaPlugin(project: Project): Boolean {
return project.plugins.hasPlugin(IdeaPlugin::class.java)
}

@Suppress("unused")
private fun getIdeaPlugin(project: Project): IdeaPlugin {
return project.plugins.getPlugin(IdeaPlugin::class.java)
}

@Suppress("unused")
private fun toIntegrationSrcFiles(project: Project, vararg paths: String): Set<File> {
return paths
.map { "${project.projectDir}/src/integration/$it" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.TaskProvider
import org.gradle.language.base.plugins.LifecycleBasePlugin.VERIFICATION_GROUP
import org.junit.jupiter.api.Test
import java.io.File
import org.gradle.api.tasks.testing.Test as TestTask

class IntegrationTestTaskConfigurationTest {
Expand Down Expand Up @@ -91,7 +92,9 @@ class IntegrationTestTaskConfigurationTest {
}

private fun toBuildPath(paths: List<String>, project: Project = this.project): String {
return paths.joinToString(":") { "${project.buildDir}/$it" }
return paths.joinToString(File.pathSeparator) {
"${project.buildDir}${File.separator}${it.replace("/", File.separator)}"
}
}

private fun getSourceSet(project: Project = this.project): SourceSet {
Expand Down

0 comments on commit b67f75a

Please sign in to comment.