From 01d5e227f01f64b44d71a50dd547543b3c8a4667 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Thu, 23 Aug 2018 23:12:42 +0500 Subject: [PATCH] Pill: Fix resource roots importing --- buildSrc/src/main/kotlin/pill/parser.kt | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/buildSrc/src/main/kotlin/pill/parser.kt b/buildSrc/src/main/kotlin/pill/parser.kt index eb18d31ab32..dbccc4a055b 100644 --- a/buildSrc/src/main/kotlin/pill/parser.kt +++ b/buildSrc/src/main/kotlin/pill/parser.kt @@ -15,6 +15,9 @@ import org.gradle.kotlin.dsl.configure import org.gradle.plugins.ide.idea.IdeaPlugin import org.gradle.api.file.SourceDirectorySet import org.gradle.api.internal.HasConvention +import org.gradle.api.internal.file.copy.CopySpecInternal +import org.gradle.api.internal.file.copy.SingleParentCopySpec +import org.gradle.language.jvm.tasks.ProcessResources import org.jetbrains.kotlin.pill.POrderRoot.* import org.jetbrains.kotlin.pill.PSourceRoot.* import org.jetbrains.kotlin.pill.PillExtension.* @@ -281,11 +284,40 @@ private fun parseSourceRoots(project: Project): List { for (directory in directories) { sourceRoots += PSourceRoot(directory, kind, kotlinOptions) } + + for (root in parseResourceRootsProcessedByProcessResourcesTask(project, sourceSet)) { + if (sourceRoots.none { it.path == root.path }) { + sourceRoots += root + } + } } return sourceRoots } +private fun parseResourceRootsProcessedByProcessResourcesTask(project: Project, sourceSet: SourceSet): List { + val isMainSourceSet = sourceSet.name == SourceSet.MAIN_SOURCE_SET_NAME + val isTestSourceSet = sourceSet.name == SourceSet.TEST_SOURCE_SET_NAME + + val resourceRootKind = if (isTestSourceSet) PSourceRoot.Kind.TEST_RESOURCES else PSourceRoot.Kind.RESOURCES + val taskNameBase = "processResources" + val taskName = if (isMainSourceSet) taskNameBase else sourceSet.name + taskNameBase.capitalize() + val task = project.tasks.findByName(taskName) as? ProcessResources ?: return emptyList() + + val roots = mutableListOf() + fun collectRoots(spec: CopySpecInternal) { + if (spec is SingleParentCopySpec && spec.children.none()) { + roots += spec.sourcePaths.map { File(project.projectDir, it.toString()) }.filter { it.exists() } + return + } + + spec.children.forEach(::collectRoots) + } + collectRoots(task.rootSpec) + + return roots.map { PSourceRoot(it, resourceRootKind, null) } +} + private fun getKotlinOptions(kotlinCompileTask: Any): PSourceRootKotlinOptions? { val compileArguments = kotlinCompileTask.invokeInternal("getSerializedCompilerArguments") as List fun parseBoolean(name: String) = compileArguments.contains("-$name")