Skip to content

Change for includeJDK to grab the running JDK #1054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 21 additions & 36 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.gradle.internal.jvm.Jvm
import org.gradle.kotlin.dsl.support.zipTo
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
Expand Down Expand Up @@ -250,7 +251,6 @@ tasks.register("generateSnapConfiguration"){
- openjdk-17-jre
override-prime: |
snapcraftctl prime
chmod -R +x opt/processing/lib/app/resources/jdk-*
rm -vf usr/lib/jvm/java-17-openjdk-*/lib/security/cacerts
""".trimIndent()
dir.file("../snapcraft.yaml").asFile.writeText(content)
Expand Down Expand Up @@ -322,40 +322,26 @@ tasks.register<Copy>("includeJavaMode") {
into(composeResources("modes/java/mode"))
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.register<Download>("includeJdk") {
val os = DefaultNativePlatform.getCurrentOperatingSystem()
val arch = when (System.getProperty("os.arch")) {
"amd64", "x86_64" -> "x64"
else -> System.getProperty("os.arch")
}
val platform = when {
os.isWindows -> "windows"
os.isMacOsX -> "mac"
else -> "linux"
}

val javaVersion = System.getProperty("java.version").split(".")[0]
val imageType = "jdk"

src("https://api.adoptium.net/v3/binary/latest/" +
"$javaVersion/ga/" +
"$platform/" +
"$arch/" +
"$imageType/" +
"hotspot/normal/eclipse?project=jdk")

val extension = if (os.isWindows) "zip" else "tar.gz"
val jdk = layout.buildDirectory.file("tmp/jdk-$platform-$arch.$extension")
dest(jdk)
overwrite(false)
doLast {
copy {
val archive = if (os.isWindows) { zipTree(jdk) } else { tarTree(jdk) }
from(archive){ eachFile{ permissions{ unix("755") } } }
into(composeResources(""))
tasks.register("includeJdk") {
dependsOn("createDistributable")
doFirst {
val jdk = Jvm.current().javaHome.absolutePath
val target = layout.buildDirectory.dir("compose/binaries").get().asFileTree.matching { include("**/include.jdk") }
.files
.firstOrNull()
?.parentFile
?.resolve("jdk")
?.absolutePath
?: error("Could not find include.jdk")

val isWindows = System.getProperty("os.name").lowercase().contains("win")
val command = if (isWindows) {
listOf("xcopy", "/E", "/I", "/Q", jdk, target)
} else {
listOf("cp", "-a", jdk, target)
}
ProcessBuilder(command).inheritIO().start().waitFor()
}
finalizedBy("prepareAppResources")
}
tasks.register<Copy>("includeSharedAssets"){
from("../build/shared/")
Expand Down Expand Up @@ -427,7 +413,6 @@ tasks.register("signResources"){
dependsOn(
"includeCore",
"includeJavaMode",
"includeJdk",
"includeSharedAssets",
"includeProcessingExamples",
"includeProcessingWebsiteExamples",
Expand Down Expand Up @@ -540,7 +525,7 @@ afterEvaluate {
}
}
tasks.named("createDistributable").configure {
dependsOn("signResources", "includeJdk")
finalizedBy("setExecutablePermissions")
dependsOn("signResources")
finalizedBy( "includeJdk","setExecutablePermissions")
}
}
11 changes: 4 additions & 7 deletions app/src/processing/app/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,14 @@ static public File getContentFile(String name) {
static public File getJavaHome() {
var resourcesDir = System.getProperty("compose.application.resources.dir");
if(resourcesDir != null) {
var jdkFolder = Arrays.stream(new File(resourcesDir).listFiles((dir, name) -> dir.isDirectory() && name.startsWith("jdk-")))
.findFirst()
.orElse(null);
if(Platform.isMacOS()){
return new File(jdkFolder, "Contents/Home");
}
var jdkFolder = new File(resourcesDir,"jdk");
if(jdkFolder.exists()){
return jdkFolder;
}
}

var home = System.getProperty("java.home");
if(home != null && new File(home, "bin/java").exists()){
if(home != null){
return new File(home);
}
if (Platform.isMacOS()) {
Expand Down
Empty file added build/shared/include.jdk
Empty file.