mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Fix shadow jar logic (#998)
Fix an incorrect relocation setting. Also, add tests to start the shadow jar, and also to test the shadow jar settings.
This commit is contained in:
@@ -42,20 +42,20 @@ val relocations =
|
|||||||
"org.organicdesign.fp." to "org.pkl.thirdparty.paguro.",
|
"org.organicdesign.fp." to "org.pkl.thirdparty.paguro.",
|
||||||
"org.snakeyaml.engine." to "org.pkl.thirdparty.snakeyaml.engine.",
|
"org.snakeyaml.engine." to "org.pkl.thirdparty.snakeyaml.engine.",
|
||||||
"org.msgpack." to "org.pkl.thirdparty.msgpack.",
|
"org.msgpack." to "org.pkl.thirdparty.msgpack.",
|
||||||
"org.w3c.dom." to "org.pkl.thirdparty.w3c.dom",
|
"org.w3c.dom." to "org.pkl.thirdparty.w3c.dom.",
|
||||||
"com.oracle.svm.core." to "org.pkl.thirdparty.svm.",
|
"com.oracle.svm.core." to "org.pkl.thirdparty.svm.",
|
||||||
|
|
||||||
// pkl-cli dependencies
|
// pkl-cli dependencies
|
||||||
"org.jline." to "org.pkl.thirdparty.jline.",
|
"org.jline." to "org.pkl.thirdparty.jline.",
|
||||||
"com.github.ajalt.clikt." to "org.pkl.thirdparty.clikt.",
|
"com.github.ajalt.clikt." to "org.pkl.thirdparty.clikt.",
|
||||||
"com.github.ajalt.colormath" to "org.pkl.thirdparty.colormath.",
|
"com.github.ajalt.colormath." to "org.pkl.thirdparty.colormath.",
|
||||||
"com.github.ajalt.mordant" to "org.pkl.thirdparty.mordant",
|
"com.github.ajalt.mordant." to "org.pkl.thirdparty.mordant.",
|
||||||
"com.sun.jna" to "org.pkl.thirdparty.jna",
|
"com.sun.jna." to "org.pkl.thirdparty.jna.",
|
||||||
"kotlin." to "org.pkl.thirdparty.kotlin.",
|
"kotlin." to "org.pkl.thirdparty.kotlin.",
|
||||||
"kotlinx." to "org.pkl.thirdparty.kotlinx.",
|
"kotlinx." to "org.pkl.thirdparty.kotlinx.",
|
||||||
"org.intellij." to "org.pkl.thirdparty.intellij.",
|
"org.intellij." to "org.pkl.thirdparty.intellij.",
|
||||||
"org.fusesource.jansi." to "org.pkl.thirdparty.jansi",
|
"org.fusesource.jansi." to "org.pkl.thirdparty.jansi.",
|
||||||
"org.fusesource.hawtjni." to "org.pkl.thirdparty.hawtjni",
|
"org.fusesource.hawtjni." to "org.pkl.thirdparty.hawtjni.",
|
||||||
|
|
||||||
// pkl-doc dependencies
|
// pkl-doc dependencies
|
||||||
"org.commonmark." to "org.pkl.thirdparty.commonmark.",
|
"org.commonmark." to "org.pkl.thirdparty.commonmark.",
|
||||||
@@ -71,6 +71,19 @@ val relocations =
|
|||||||
"com.squareup.kotlinpoet." to "org.pkl.thirdparty.kotlinpoet.",
|
"com.squareup.kotlinpoet." to "org.pkl.thirdparty.kotlinpoet.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for ((key, value) in relocations) {
|
||||||
|
if (!key.endsWith(".")) {
|
||||||
|
throw GradleException(
|
||||||
|
"Invalid relocation `\"$key\" to \"$value\"`: `$key` should end with a dot"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (!value.endsWith(".")) {
|
||||||
|
throw GradleException(
|
||||||
|
"Invalid relocation `\"$key\" to \"$value\"`: `$value` should end with a dot"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val nonRelocations = listOf("com/oracle/truffle/", "org/graalvm/")
|
val nonRelocations = listOf("com/oracle/truffle/", "org/graalvm/")
|
||||||
|
|
||||||
tasks.shadowJar {
|
tasks.shadowJar {
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.io.path.createDirectories
|
||||||
|
import kotlin.io.path.writeText
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
pklAllProjects
|
pklAllProjects
|
||||||
@@ -65,6 +67,63 @@ val javadocJar by
|
|||||||
|
|
||||||
tasks.shadowJar { archiveBaseName.set("pkl-tools-all") }
|
tasks.shadowJar { archiveBaseName.set("pkl-tools-all") }
|
||||||
|
|
||||||
|
private fun Exec.configureTestStartFatJar(launcher: Provider<JavaLauncher>) {
|
||||||
|
dependsOn(tasks.shadowJar)
|
||||||
|
group = "verification"
|
||||||
|
|
||||||
|
// placeholder output to satisfy up-to-date check
|
||||||
|
val outputFile = layout.buildDirectory.file("testStartFatJar/${name}.txt")
|
||||||
|
outputs.file(outputFile)
|
||||||
|
|
||||||
|
inputs.files(tasks.shadowJar)
|
||||||
|
executable = launcher.get().executablePath.asFile.absolutePath
|
||||||
|
|
||||||
|
argumentProviders.add(
|
||||||
|
CommandLineArgumentProvider {
|
||||||
|
buildList {
|
||||||
|
add("-cp")
|
||||||
|
add(tasks.shadowJar.get().outputs.files.singleFile.absolutePath)
|
||||||
|
add("org.pkl.cli.Main")
|
||||||
|
add("eval")
|
||||||
|
add("-x")
|
||||||
|
add("1 + 1")
|
||||||
|
add("pkl:base")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
outputFile.get().asFile.toPath().let { file ->
|
||||||
|
file.parent.createDirectories()
|
||||||
|
file.writeText("OK")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val testStartFatJar by
|
||||||
|
tasks.registering(Exec::class) { configureTestStartFatJar(buildInfo.javaTestLauncher) }
|
||||||
|
|
||||||
|
tasks.validateFatJar { dependsOn(testStartFatJar) }
|
||||||
|
|
||||||
|
for (jdkTarget in buildInfo.jdkTestRange) {
|
||||||
|
if (buildInfo.jdkToolchainVersion == jdkTarget) {
|
||||||
|
tasks.register("testStartFatJarJdk${jdkTarget.asInt()}") {
|
||||||
|
group = "verification"
|
||||||
|
description = "alias for testStartFatJar"
|
||||||
|
dependsOn(testStartFatJar)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val task =
|
||||||
|
tasks.register("testStartFatJarJdk${jdkTarget.asInt()}", Exec::class) {
|
||||||
|
val launcher = project.javaToolchains.launcherFor { languageVersion = jdkTarget }
|
||||||
|
configureTestStartFatJar(launcher)
|
||||||
|
}
|
||||||
|
if (buildInfo.multiJdkTesting) {
|
||||||
|
tasks.validateFatJar { dependsOn(task) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
named<MavenPublication>("fatJar") {
|
named<MavenPublication>("fatJar") {
|
||||||
|
|||||||
Reference in New Issue
Block a user