Pill: Replace most of the hardcoded library coordinates with info from Gradle

This commit is contained in:
Yan Zhulanow
2018-02-28 00:12:57 +03:00
parent 6e65a4810e
commit 6950c256ce
7 changed files with 71 additions and 70 deletions
+52 -63
View File
@@ -2,6 +2,8 @@ package org.jetbrains.kotlin.pill
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.BasePluginConvention
import org.gradle.kotlin.dsl.extra
import shadow.org.jdom2.input.SAXBuilder
import shadow.org.jdom2.*
import shadow.org.jdom2.output.Format
@@ -10,71 +12,55 @@ import java.io.File
class JpsCompatiblePlugin : Plugin<Project> {
companion object {
private const val JPS_LIBRARY_PATH = "jpsLibraryPath"
private fun mapper(module: String, vararg configurations: String): DependencyMapper {
return DependencyMapper("org.jetbrains.kotlin", module, *configurations) { MappedDependency(PDependency.Library(module)) }
}
private val dependencyMappers = listOf(
mapper("protobuf-relocated", "default"),
mapper("kotlin-test-junit", "distJar", "runtimeElements"),
mapper("kotlin-script-runtime", "distJar", "runtimeElements"),
mapper("kotlin-reflect", "distJar", "runtimeElements"),
mapper("kotlin-test-jvm", "distJar", "runtimeElements"),
DependencyMapper("org.jetbrains.kotlin", "kotlin-stdlib", "distJar", "runtimeElements") {
MappedDependency(
PDependency.Library("kotlin-stdlib"),
listOf(PDependency.Library("annotations-13.0"))
)
},
DependencyMapper("org.jetbrains.kotlin", "kotlin-reflect-api", "runtimeElements") {
MappedDependency(PDependency.Library("kotlin-reflect"))
},
DependencyMapper("org.jetbrains.kotlin", "kotlin-compiler-embeddable", "runtimeJar") { null },
DependencyMapper("org.jetbrains.kotlin", "kotlin-stdlib-js", "distJar") { null },
DependencyMapper("org.jetbrains.kotlin", "kotlin-compiler", "runtimeJar") { null },
DependencyMapper("org.jetbrains.kotlin", "compiler", "runtimeElements") { null }
)
private fun getDependencyMappers(projectLibraries: List<PLibrary>): List<DependencyMapper> {
val mappersForKotlinLibrariesExeptStdlib = projectLibraries
.filter { it.name != "kotlin-stdlib" }
.mapTo(mutableListOf()) { mapper(it.name, "default", "distJar", "runtimeElements") }
fun getProjectLibraries(project: Project): List<PLibrary> {
fun distJar(name: String) = File(project.projectDir, "dist/kotlinc/lib/$name.jar")
fun projectFile(path: String) = File(project.projectDir, path)
return listOf(
PLibrary(
"kotlin-stdlib",
classes = listOf(distJar("kotlin-stdlib")),
sources = listOf(distJar("kotlin-stdlib-sources"))
),
PLibrary(
"kotlin-reflect",
classes = listOf(distJar("kotlin-reflect")),
sources = listOf(distJar("kotlin-reflect-sources"))
),
PLibrary(
"annotations-13.0",
classes = listOf(distJar("annotations-13.0"))
),
PLibrary(
"kotlin-test-jvm",
classes = listOf(distJar("kotlin-test")),
sources = listOf(distJar("kotlin-test-sources"))
),
PLibrary(
"kotlin-test-junit",
classes = listOf(distJar("kotlin-test-junit")),
sources = listOf(distJar("kotlin-test-junit-sources"))
),
PLibrary(
"kotlin-script-runtime",
classes = listOf(distJar("kotlin-script-runtime")),
sources = listOf(distJar("kotlin-script-runtime-sources"))
),
PLibrary(
"protobuf-relocated",
classes = listOf(projectFile("custom-dependencies/protobuf-relocated/build/libs/protobuf-java-relocated-2.6.1.jar"))
)
return mappersForKotlinLibrariesExeptStdlib + listOf(
DependencyMapper("org.jetbrains.kotlin", "kotlin-stdlib", "distJar", "runtimeElements") {
MappedDependency(
PDependency.Library("kotlin-stdlib"),
listOf(PDependency.Library("annotations-13.0"))
)
},
DependencyMapper("org.jetbrains.kotlin", "kotlin-reflect-api", "runtimeElements") {
MappedDependency(PDependency.Library("kotlin-reflect"))
},
DependencyMapper("org.jetbrains.kotlin", "kotlin-compiler-embeddable", "runtimeJar") { null },
DependencyMapper("org.jetbrains.kotlin", "kotlin-stdlib-js", "distJar") { null },
DependencyMapper("org.jetbrains.kotlin", "kotlin-compiler", "runtimeJar") { null },
DependencyMapper("org.jetbrains.kotlin", "compiler", "runtimeElements") { null }
)
}
fun getProjectLibraries(rootProject: Project): List<PLibrary> {
fun distJar(name: String) = File(rootProject.projectDir, "dist/kotlinc/lib/$name.jar")
fun projectFile(path: String) = File(rootProject.projectDir, path)
val libraries = rootProject.allprojects
.filter { it.extra.has(JPS_LIBRARY_PATH) }
.map { library ->
val libraryPath = library.extra.get(JPS_LIBRARY_PATH).toString()
val archivesBaseName = library.convention.findPlugin(BasePluginConvention::class.java)?.archivesBaseName ?: library.name
fun List<File>.filterExisting() = filter { it.exists() }
PLibrary(
library.name,
classes = listOf(File(libraryPath, archivesBaseName + ".jar")).filterExisting(),
sources = listOf(File(libraryPath, archivesBaseName + "-sources.jar")).filterExisting()
)
}
return libraries + PLibrary("annotations-13.0", classes = listOf(distJar("annotations-13.0")))
}
}
override fun apply(project: Project) {
@@ -105,13 +91,16 @@ class JpsCompatiblePlugin : Plugin<Project> {
platformDir = IntellijRootUtils.getRepositoryRootDir(project)
}
private fun pill(project: Project) {
initEnvironment(project)
private fun pill(rootProject: Project) {
initEnvironment(rootProject)
val jpsProject = parse(project, getProjectLibraries(project), ParserContext(dependencyMappers))
val projectLibraries = getProjectLibraries(rootProject)
val parserContext = ParserContext(getDependencyMappers(projectLibraries))
val jpsProject = parse(rootProject, projectLibraries, parserContext)
.mapLibraries(this::attachPlatformSources, this::attachAsmSources)
generateKotlinPluginArtifactFile(project).write()
generateKotlinPluginArtifactFile(rootProject).write()
val files = render(jpsProject)
@@ -119,7 +108,7 @@ class JpsCompatiblePlugin : Plugin<Project> {
removeJpsRunConfigurations()
copyRunConfigurations()
setOptionsForDefaultJunitRunConfiguration(project)
setOptionsForDefaultJunitRunConfiguration(rootProject)
files.forEach { it.write() }
}
@@ -1,9 +1,12 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.io.File
apply { plugin("base") }
val baseProtobuf by configurations.creating
val baseProtobufSources by configurations.creating
val resultsCfg = configurations.create("default")
val resultsCfg = configurations.getByName("default")
val resultsSourcesCfg = configurations.create("sources")
val protobufVersion = rootProject.extra["versions.protobuf-java"] as String
@@ -13,6 +16,10 @@ val renamedSources = "$buildDir/renamedSrc/"
val outputJarsPath = "$buildDir/libs"
val artifactBaseName = "protobuf-java-relocated"
val jpsLibraryPath by extra(outputJarsPath)
setProperty("archivesBaseName", "$artifactBaseName-$protobufVersion")
dependencies {
baseProtobuf("com.google.protobuf:protobuf-java:$protobufVersion")
baseProtobufSources("com.google.protobuf:protobuf-java:$protobufVersion:sources")
@@ -47,8 +54,4 @@ val prepareSources by task<Jar> {
from(relocateSources)
project.addArtifact("archives", this, this)
addArtifact(resultsSourcesCfg.name, this, this)
}
val clean by task<Delete> {
delete(buildDir)
}
}
+1
View File
@@ -6,6 +6,7 @@ configureJvm6Project(project)
configureDist(project)
configurePublishing(project)
project.ext["jpsLibraryPath"] = rootProject.distLibDir
dependencies {
expectedBy project(':kotlin-test:kotlin-test-annotations-common')
+2 -1
View File
@@ -7,6 +7,8 @@ configureJvm6Project(project)
configureDist(project)
configurePublishing(project)
project.ext["jpsLibraryPath"] = rootProject.distLibDir
dependencies {
expectedBy project(':kotlin-test:kotlin-test-common')
compile project(':kotlin-stdlib')
@@ -14,7 +16,6 @@ dependencies {
testCompile('junit:junit:4.12')
}
archivesBaseName = 'kotlin-test'
jar {
+3
View File
@@ -1,6 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext
import org.gradle.kotlin.dsl.extra
import org.jetbrains.kotlin.serialization.jvm.JvmModuleProtoBuf
import proguard.gradle.ProGuardTask
import shadow.org.apache.tools.zip.ZipEntry
@@ -25,6 +26,8 @@ plugins { java }
callGroovy("configureJavaOnlyJvm6Project", this)
publish()
val jpsLibraryPath by extra(rootProject.extra["distLibDir"])
val core = "$rootDir/core"
val annotationsSrc = "$buildDir/annotations"
val relocatedCoreSrc = "$buildDir/core-relocated"
+2
View File
@@ -6,6 +6,8 @@ configureJvm6Project(project)
configureDist(project)
configurePublishing(project)
project.ext["jpsLibraryPath"] = rootProject.distLibDir
sourceSets {
annotations {
if(!System.properties.'idea.active') {
@@ -6,6 +6,8 @@ configureJvm6Project(project)
configureDist(project)
configurePublishing(project)
project.ext["jpsLibraryPath"] = rootProject.distLibDir
dependencies {
compileOnly project(':kotlin-stdlib')
}