Pill: Pack embedded dependencies to artifacts
This commit is contained in:
@@ -103,9 +103,22 @@ class JpsCompatiblePluginTasks(private val rootProject: Project, private val pla
|
|||||||
removeJpsAndPillRunConfigurations()
|
removeJpsAndPillRunConfigurations()
|
||||||
removeAllArtifactConfigurations()
|
removeAllArtifactConfigurations()
|
||||||
|
|
||||||
val artifactDependencyMapper = object : OpaqueDependencyMapper {
|
val artifactDependencyMapper = object : ArtifactDependencyMapper {
|
||||||
override fun map(dependency: PDependency): List<PDependency> {
|
override fun map(dependency: PDependency): List<PDependency> {
|
||||||
return jpsProject.mapDependency(dependency, dependencyMappers)
|
val result = mutableListOf<PDependency>()
|
||||||
|
|
||||||
|
for (mappedDependency in jpsProject.mapDependency(dependency, dependencyMappers)) {
|
||||||
|
result += mappedDependency
|
||||||
|
|
||||||
|
if (mappedDependency is PDependency.Module) {
|
||||||
|
val module = jpsProject.modules.find { it.name == mappedDependency.name }
|
||||||
|
if (module != null) {
|
||||||
|
result += module.embeddedDependencies
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class PArtifact(val artifactName: String, private val outputDir: File, private v
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OpaqueDependencyMapper {
|
interface ArtifactDependencyMapper {
|
||||||
fun map(dependency: PDependency): List<PDependency>
|
fun map(dependency: PDependency): List<PDependency>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ sealed class ArtifactElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateKotlinPluginArtifactFile(rootProject: Project, dependencyMapper: OpaqueDependencyMapper): PFile {
|
fun generateKotlinPluginArtifactFile(rootProject: Project, dependencyMapper: ArtifactDependencyMapper): PFile {
|
||||||
val root = Root()
|
val root = Root()
|
||||||
|
|
||||||
fun Project.getProject(name: String) = findProject(name) ?: error("Cannot find project $name")
|
fun Project.getProject(name: String) = findProject(name) ?: error("Cannot find project $name")
|
||||||
@@ -107,7 +107,7 @@ fun generateKotlinPluginArtifactFile(rootProject: Project, dependencyMapper: Opa
|
|||||||
add(Directory("jps").apply {
|
add(Directory("jps").apply {
|
||||||
val prepareJpsPluginProject = rootProject.getProject(":kotlin-jps-plugin")
|
val prepareJpsPluginProject = rootProject.getProject(":kotlin-jps-plugin")
|
||||||
add(Archive(prepareJpsPluginProject.name + ".jar").apply {
|
add(Archive(prepareJpsPluginProject.name + ".jar").apply {
|
||||||
val jpsPluginConfiguration = prepareIdeaPluginProject.configurations.getByName("jpsPlugin")
|
val jpsPluginConfiguration = prepareJpsPluginProject.configurations.getByName(EMBEDDED_CONFIGURATION_NAME)
|
||||||
add(getArtifactElements(jpsPluginConfiguration, dependencyMapper, true))
|
add(getArtifactElements(jpsPluginConfiguration, dependencyMapper, true))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -129,14 +129,12 @@ fun generateKotlinPluginArtifactFile(rootProject: Project, dependencyMapper: Opa
|
|||||||
|
|
||||||
private fun getArtifactElements(
|
private fun getArtifactElements(
|
||||||
configuration: Configuration,
|
configuration: Configuration,
|
||||||
dependencyMapper: OpaqueDependencyMapper,
|
dependencyMapper: ArtifactDependencyMapper,
|
||||||
extractDependencies: Boolean
|
extractDependencies: Boolean
|
||||||
): List<ArtifactElement> {
|
): List<ArtifactElement> {
|
||||||
val dependencies = parseDependencies(configuration, dependencyMapper)
|
|
||||||
|
|
||||||
val artifacts = mutableListOf<ArtifactElement>()
|
val artifacts = mutableListOf<ArtifactElement>()
|
||||||
|
|
||||||
for (dependency in dependencies) {
|
fun process(dependency: PDependency) {
|
||||||
when (dependency) {
|
when (dependency) {
|
||||||
is PDependency.Module -> {
|
is PDependency.Module -> {
|
||||||
val moduleOutput = ModuleOutput(dependency.name)
|
val moduleOutput = ModuleOutput(dependency.name)
|
||||||
@@ -161,10 +159,11 @@ private fun getArtifactElements(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parseDependencies(configuration, dependencyMapper).forEach(::process)
|
||||||
return artifacts
|
return artifacts
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseDependencies(configuration: Configuration, dependencyMapper: OpaqueDependencyMapper): List<PDependency> {
|
private fun parseDependencies(configuration: Configuration, dependencyMapper: ArtifactDependencyMapper): List<PDependency> {
|
||||||
val dependencies = mutableListOf<PDependency>()
|
val dependencies = mutableListOf<PDependency>()
|
||||||
for (file in configuration.resolve()) {
|
for (file in configuration.resolve()) {
|
||||||
val library = PLibrary(file.name, listOf(file))
|
val library = PLibrary(file.name, listOf(file))
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.pill
|
package org.jetbrains.kotlin.pill
|
||||||
|
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.artifacts.Configuration
|
||||||
import org.gradle.api.tasks.*
|
import org.gradle.api.tasks.*
|
||||||
import org.gradle.api.plugins.JavaPlugin
|
import org.gradle.api.plugins.JavaPlugin
|
||||||
import org.gradle.api.plugins.JavaPluginConvention
|
import org.gradle.api.plugins.JavaPluginConvention
|
||||||
@@ -43,7 +44,8 @@ data class PModule(
|
|||||||
val contentRoots: List<PContentRoot>,
|
val contentRoots: List<PContentRoot>,
|
||||||
val orderRoots: List<POrderRoot>,
|
val orderRoots: List<POrderRoot>,
|
||||||
val kotlinOptions: PSourceRootKotlinOptions?,
|
val kotlinOptions: PSourceRootKotlinOptions?,
|
||||||
val moduleForProductionSources: PModule? = null
|
val moduleForProductionSources: PModule? = null,
|
||||||
|
val embeddedDependencies: List<PDependency>
|
||||||
)
|
)
|
||||||
|
|
||||||
data class PContentRoot(
|
data class PContentRoot(
|
||||||
@@ -192,6 +194,9 @@ private fun parseModules(project: Project, excludedProjects: List<Project>): Lis
|
|||||||
return File(project.rootProject.projectDir, ".idea/modules/$relativePath")
|
return File(project.rootProject.projectDir, ".idea/modules/$relativePath")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val embeddedDependencies = project.configurations.findByName(EMBEDDED_CONFIGURATION_NAME)
|
||||||
|
?.let { parseDependencies(it) } ?: emptyList()
|
||||||
|
|
||||||
val sourceSets = parseSourceSets(project).sortedBy { it.forTests }
|
val sourceSets = parseSourceSets(project).sortedBy { it.forTests }
|
||||||
for (sourceSet in sourceSets) {
|
for (sourceSet in sourceSets) {
|
||||||
val sourceRoots = mutableListOf<PSourceRoot>()
|
val sourceRoots = mutableListOf<PSourceRoot>()
|
||||||
@@ -229,7 +234,8 @@ private fun parseModules(project: Project, excludedProjects: List<Project>): Lis
|
|||||||
contentRoots = contentRoots,
|
contentRoots = contentRoots,
|
||||||
orderRoots = orderRoots,
|
orderRoots = orderRoots,
|
||||||
kotlinOptions = sourceSet.kotlinOptions,
|
kotlinOptions = sourceSet.kotlinOptions,
|
||||||
moduleForProductionSources = productionModule
|
moduleForProductionSources = productionModule,
|
||||||
|
embeddedDependencies = embeddedDependencies
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,7 +253,8 @@ private fun parseModules(project: Project, excludedProjects: List<Project>): Lis
|
|||||||
contentRoots = listOf(PContentRoot(project.projectDir, listOf(), getExcludedDirs(project, excludedProjects))),
|
contentRoots = listOf(PContentRoot(project.projectDir, listOf(), getExcludedDirs(project, excludedProjects))),
|
||||||
orderRoots = emptyList(),
|
orderRoots = emptyList(),
|
||||||
kotlinOptions = null,
|
kotlinOptions = null,
|
||||||
moduleForProductionSources = null
|
moduleForProductionSources = null,
|
||||||
|
embeddedDependencies = emptyList()
|
||||||
)
|
)
|
||||||
|
|
||||||
return modules
|
return modules
|
||||||
@@ -376,11 +383,7 @@ private fun parseDependencies(project: Project, sourceSet: PSourceSet): List<POr
|
|||||||
|
|
||||||
fun process(name: String, scope: Scope) {
|
fun process(name: String, scope: Scope) {
|
||||||
val configuration = project.configurations.findByName(name) ?: return
|
val configuration = project.configurations.findByName(name) ?: return
|
||||||
for (file in configuration.resolve()) {
|
roots += parseDependencies(configuration).map { POrderRoot(it, scope) }
|
||||||
val library = PLibrary(file.name, listOf(file))
|
|
||||||
val dependency = PDependency.ModuleLibrary(library)
|
|
||||||
roots += POrderRoot(dependency, scope)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process(sourceSet.compileClasspathConfigurationName, Scope.PROVIDED)
|
process(sourceSet.compileClasspathConfigurationName, Scope.PROVIDED)
|
||||||
@@ -393,6 +396,13 @@ private fun parseDependencies(project: Project, sourceSet: PSourceSet): List<POr
|
|||||||
return roots
|
return roots
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun parseDependencies(configuration: Configuration): List<PDependency> {
|
||||||
|
return configuration.resolve().map { file ->
|
||||||
|
val library = PLibrary(file.name, listOf(file))
|
||||||
|
return@map PDependency.ModuleLibrary(library)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val Project.pillModuleName: String
|
val Project.pillModuleName: String
|
||||||
get() = path.removePrefix(":").replace(':', '.')
|
get() = path.removePrefix(":").replace(':', '.')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user