Add dependencies-maven-all artifact
This commit is contained in:
committed by
teamcityserver
parent
f7c2adae30
commit
014765a302
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import com.github.jengelman.gradle.plugins.shadow.relocation.RelocateClassContext
|
||||
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
|
||||
import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext
|
||||
import org.gradle.api.file.FileTreeElement
|
||||
import shadow.org.apache.tools.zip.ZipEntry
|
||||
import shadow.org.apache.tools.zip.ZipOutputStream
|
||||
import shadow.org.codehaus.plexus.util.IOUtil
|
||||
import shadow.org.codehaus.plexus.util.ReaderFactory
|
||||
import shadow.org.codehaus.plexus.util.WriterFactory
|
||||
import shadow.org.codehaus.plexus.util.xml.Xpp3Dom
|
||||
import shadow.org.codehaus.plexus.util.xml.Xpp3DomBuilder
|
||||
import shadow.org.codehaus.plexus.util.xml.Xpp3DomWriter
|
||||
import java.io.*
|
||||
import java.lang.Exception
|
||||
import java.util.LinkedHashMap
|
||||
|
||||
/**
|
||||
* A resource processor that aggregates plexus `components.xml` files.
|
||||
*
|
||||
* Fixed version of [com.github.jengelman.gradle.plugins.shadow.transformers.ComponentsXmlResourceTransformer],
|
||||
* may be dropped after [the fix in ShadowJAR](https://github.com/johnrengelman/shadow/pull/678/files) will be accepted
|
||||
*/
|
||||
class ComponentsXmlResourceTransformerPatched : Transformer {
|
||||
private val components: MutableMap<String, Xpp3Dom> =
|
||||
LinkedHashMap<String, Xpp3Dom>()
|
||||
|
||||
override fun canTransformResource(element: FileTreeElement): Boolean {
|
||||
val path = element.relativePath.pathString
|
||||
return COMPONENTS_XML_PATH == path
|
||||
}
|
||||
|
||||
override fun transform(context: TransformerContext) {
|
||||
val newDom: Xpp3Dom = try {
|
||||
val bis: BufferedInputStream = object : BufferedInputStream(context.getIs()) {
|
||||
override fun close() {
|
||||
// leave ZIP open
|
||||
}
|
||||
}
|
||||
val reader: Reader = ReaderFactory.newXmlReader(bis)
|
||||
Xpp3DomBuilder.build(reader)
|
||||
} catch (e: Exception) {
|
||||
throw (IOException("Error parsing components.xml in " + context.getIs()).initCause(e) as IOException)
|
||||
}
|
||||
|
||||
// Only try to merge in components if there are some elements in the component-set
|
||||
if (newDom.getChild("components") == null) {
|
||||
return
|
||||
}
|
||||
val children: Array<Xpp3Dom>? = newDom.getChild("components")?.getChildren("component")
|
||||
children?.forEach { component ->
|
||||
var role: String? = getValue(component, "role")
|
||||
role = getRelocatedClass(role, context)
|
||||
setValue(component, "role", role)
|
||||
val roleHint = getValue(component, "role-hint")
|
||||
var impl: String? = getValue(component, "implementation")
|
||||
impl = getRelocatedClass(impl, context)
|
||||
setValue(component, "implementation", impl)
|
||||
val key = "$role:$roleHint"
|
||||
if (components.containsKey(key)) {
|
||||
// configuration carry over
|
||||
val dom: Xpp3Dom? = components[key]
|
||||
if (dom?.getChild("configuration") != null) {
|
||||
component.addChild(dom.getChild("configuration"))
|
||||
}
|
||||
}
|
||||
val requirements: Xpp3Dom? = component.getChild("requirements")
|
||||
if (requirements != null && requirements.childCount > 0) {
|
||||
for (r in requirements.childCount - 1 downTo 0) {
|
||||
val requirement: Xpp3Dom = requirements.getChild(r)
|
||||
var requiredRole: String? = getValue(requirement, "role")
|
||||
requiredRole = getRelocatedClass(requiredRole, context)
|
||||
setValue(requirement, "role", requiredRole)
|
||||
}
|
||||
}
|
||||
components[key] = component
|
||||
}
|
||||
}
|
||||
|
||||
override fun modifyOutputStream(os: ZipOutputStream, preserveFileTimestamps: Boolean) {
|
||||
val data = transformedResource
|
||||
val entry = ZipEntry(COMPONENTS_XML_PATH)
|
||||
entry.time = TransformerContext.getEntryTimestamp(preserveFileTimestamps, entry.time)
|
||||
os.putNextEntry(entry)
|
||||
IOUtil.copy(data, os)
|
||||
components.clear()
|
||||
}
|
||||
|
||||
override fun hasTransformedResource(): Boolean {
|
||||
return components.isNotEmpty()
|
||||
}
|
||||
|
||||
private val transformedResource: ByteArray
|
||||
get() {
|
||||
val baos = ByteArrayOutputStream(1024 * 4)
|
||||
val writer: Writer = WriterFactory.newXmlWriter(baos)
|
||||
try {
|
||||
val dom = Xpp3Dom("component-set")
|
||||
val componentDom = Xpp3Dom("components")
|
||||
dom.addChild(componentDom)
|
||||
for (component in components.values) {
|
||||
componentDom.addChild(component)
|
||||
}
|
||||
Xpp3DomWriter.write(writer, dom)
|
||||
} finally {
|
||||
IOUtil.close(writer)
|
||||
}
|
||||
return baos.toByteArray()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val COMPONENTS_XML_PATH = "META-INF/plexus/components.xml"
|
||||
private fun getRelocatedClass(className: String?, context: TransformerContext): String? {
|
||||
val relocators = context.relocators
|
||||
val stats = context.stats
|
||||
if (className != null && className.isNotEmpty() && relocators != null) {
|
||||
for (relocator in relocators) {
|
||||
if (relocator.canRelocateClass(className)) {
|
||||
val relocateClassContext = RelocateClassContext(className, stats)
|
||||
return relocator.relocateClass(relocateClassContext)
|
||||
}
|
||||
}
|
||||
}
|
||||
return className
|
||||
}
|
||||
|
||||
private fun getValue(dom: Xpp3Dom, element: String): String {
|
||||
val child: Xpp3Dom? = dom.getChild(element)
|
||||
return if (child?.value != null) child.value else ""
|
||||
}
|
||||
|
||||
private fun setValue(dom: Xpp3Dom, element: String, value: String?) {
|
||||
val child: Xpp3Dom? = dom.getChild(element)
|
||||
if (value == null || value.isEmpty()) {
|
||||
return
|
||||
}
|
||||
child?.value = value
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import org.gradle.internal.jvm.Jvm
|
||||
|
||||
description = "Shaded Maven dependencies resolver"
|
||||
|
||||
val JDK_18: String by rootProject.extra
|
||||
val jarBaseName = property("archivesBaseName") as String
|
||||
|
||||
val embedded by configurations
|
||||
|
||||
embedded.apply {
|
||||
exclude("org.slf4j", "slf4j-api")
|
||||
exclude("org.eclipse.aether", "aether-api")
|
||||
exclude("org.eclipse.aether", "aether-util")
|
||||
exclude("org.eclipse.aether", "aether-spi")
|
||||
}
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
embedded(project(":kotlin-scripting-dependencies-maven")) { isTransitive = false }
|
||||
embedded(project(":kotlin-scripting-dependencies")) { isTransitive = false }
|
||||
|
||||
embedded("org.eclipse.aether:aether-connector-basic:1.1.0")
|
||||
embedded("org.eclipse.aether:aether-transport-wagon:1.1.0")
|
||||
embedded("org.eclipse.aether:aether-transport-file:1.1.0")
|
||||
embedded("org.apache.maven:maven-core:3.8.1")
|
||||
embedded("org.apache.maven.wagon:wagon-http:3.4.3")
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" {}
|
||||
"test" {}
|
||||
}
|
||||
|
||||
publish()
|
||||
|
||||
noDefaultJar()
|
||||
sourcesJar()
|
||||
javadocJar()
|
||||
|
||||
val relocatedJar by task<ShadowJar> {
|
||||
configurations = listOf(embedded)
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
destinationDirectory.set(File(buildDir, "libs"))
|
||||
archiveClassifier.set("before-proguard")
|
||||
|
||||
transform(ComponentsXmlResourceTransformerPatched())
|
||||
|
||||
if (kotlinBuildProperties.relocation) {
|
||||
packagesToRelocate.forEach {
|
||||
relocate(it, "$kotlinEmbeddableRootPackage.$it")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val proguard by task<CacheableProguardTask> {
|
||||
dependsOn(relocatedJar)
|
||||
configuration("dependencies-maven.pro")
|
||||
|
||||
injars(mapOf("filter" to "!META-INF/versions/**,!kotlinx/coroutines/debug/**"), relocatedJar.get().outputs.files)
|
||||
|
||||
outjars(fileFrom(buildDir, "libs", "$jarBaseName-$version-after-proguard.jar"))
|
||||
|
||||
javaLauncher.set(project.getToolchainLauncherFor(JdkMajorVersion.JDK_1_8))
|
||||
|
||||
libraryjars(
|
||||
files(
|
||||
javaLauncher.map {
|
||||
firstFromJavaHomeThatExists(
|
||||
"jre/lib/rt.jar",
|
||||
"../Classes/classes.jar",
|
||||
jdkHome = it.metadata.installationPath.asFile
|
||||
)
|
||||
},
|
||||
javaLauncher.map {
|
||||
firstFromJavaHomeThatExists(
|
||||
"jre/lib/jsse.jar",
|
||||
"../Classes/jsse.jar",
|
||||
jdkHome = it.metadata.installationPath.asFile
|
||||
)
|
||||
},
|
||||
javaLauncher.map {
|
||||
Jvm.forHome(it.metadata.installationPath.asFile).toolsJar
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
val resultJar by task<Jar> {
|
||||
val pack = if (kotlinBuildProperties.proguard) proguard else relocatedJar
|
||||
dependsOn(pack)
|
||||
setupPublicJar(jarBaseName)
|
||||
from {
|
||||
zipTree(pack.get().singleOutputFile())
|
||||
}
|
||||
}
|
||||
|
||||
addArtifact("runtime", resultJar)
|
||||
addArtifact("runtimeElements", resultJar)
|
||||
addArtifact("archives", resultJar)
|
||||
@@ -0,0 +1,41 @@
|
||||
-target 1.6
|
||||
-dontoptimize
|
||||
-dontobfuscate
|
||||
# -dontshrink
|
||||
|
||||
-keepdirectories META-INF/**
|
||||
|
||||
-dontnote **
|
||||
-dontwarn org.jetbrains.kotlin.**
|
||||
-dontwarn kotlin.script.experimental.**
|
||||
-dontwarn junit.framework.**
|
||||
-dontwarn afu.org.checkerframework.**
|
||||
-dontwarn org.checkerframework.**
|
||||
-dontwarn org.testng.**
|
||||
-dontwarn org.osgi.**
|
||||
-dontwarn javax.el.**
|
||||
-dontwarn javax.crypto.**
|
||||
-dontwarn javax.interceptor.**
|
||||
-dontwarn org.eclipse.sisu.**
|
||||
-dontwarn org.slf4j.**
|
||||
|
||||
-keep class kotlin.script.experimental.** { *; }
|
||||
|
||||
-keep class org.eclipse.sisu.** { *; }
|
||||
-keep class org.jetbrains.kotlin.org.eclipse.sisu.** { *; }
|
||||
|
||||
-keep class com.google.inject.** { *; }
|
||||
-keep class org.jetbrains.kotlin.com.google.inject.** { *; }
|
||||
|
||||
-keep class org.jetbrains.kotlin.script.util.impl.PathUtilKt { *; }
|
||||
|
||||
-keep class com.google.common.** { *; }
|
||||
-keep class org.jetbrains.kotlin.com.google.common.** { *; }
|
||||
|
||||
-keep class org.apache.maven.wagon.providers.** { *; }
|
||||
-keep class org.jetbrains.kotlin.org.apache.maven.wagon.providers.** { *; }
|
||||
|
||||
-keepclassmembers class * extends java.lang.Enum {
|
||||
<fields>;
|
||||
**[] values();
|
||||
}
|
||||
@@ -239,6 +239,7 @@ include ":benchmarks",
|
||||
":kotlin-scripting-compiler-impl-embeddable",
|
||||
":kotlin-scripting-dependencies",
|
||||
":kotlin-scripting-dependencies-maven",
|
||||
":kotlin-scripting-dependencies-maven-all",
|
||||
":kotlin-scripting-jsr223-unshaded",
|
||||
":kotlin-scripting-jsr223-test",
|
||||
":kotlin-scripting-jsr223",
|
||||
@@ -655,6 +656,7 @@ project(':kotlin-scripting-jvm-host-test').projectDir = "$rootDir/libraries/scri
|
||||
project(':kotlin-scripting-jvm-host').projectDir = "$rootDir/libraries/scripting/jvm-host-embeddable" as File
|
||||
project(':kotlin-scripting-dependencies').projectDir = "$rootDir/libraries/scripting/dependencies" as File
|
||||
project(':kotlin-scripting-dependencies-maven').projectDir = "$rootDir/libraries/scripting/dependencies-maven" as File
|
||||
project(':kotlin-scripting-dependencies-maven-all').projectDir = "$rootDir/libraries/scripting/dependencies-maven-all" as File
|
||||
project(':kotlin-scripting-jsr223-unshaded').projectDir = "$rootDir/libraries/scripting/jsr223" as File
|
||||
project(':kotlin-scripting-jsr223-test').projectDir = "$rootDir/libraries/scripting/jsr223-test" as File
|
||||
project(':kotlin-scripting-jsr223').projectDir = "$rootDir/libraries/scripting/jsr223-embeddable" as File
|
||||
|
||||
Reference in New Issue
Block a user