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