Skip to content

Commit 1a1db1c

Browse files
committed
fix: preserve exec permissions on jspawnhelper in bundled JDK ([#1537](#1537))
Fix: - Move the permission loop in includeJdk into a doLast block so it runs after the copy, and re-apply the exec bit from the source JDK for files that should be executable. - Extend setExecutablePermissions to also cover the IDE runtime/ path (not just resources/), since the runtime's jspawnhelper had the same issue. - Add JAVA_HOME / JDK_HOME env var support in Platform.getJavaHome(), inside the existing "If the JDK is set in the environment" fallback block, so users can point Processing at a different JDK when the bundle is absent.
1 parent e119e12 commit 1a1db1c

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

app/build.gradle.kts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ dependencies {
144144
testImplementation(libs.junitJupiterParams)
145145

146146
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
147-
147+
148148
}
149149

150150
tasks.test {
@@ -451,9 +451,18 @@ tasks.register<Copy>("includeJdk") {
451451
from(jdkHome)
452452
destinationDir = composeResources("jdk").get().asFile
453453

454-
fileTree(destinationDir).files.forEach { file ->
455-
file.setWritable(true, false)
456-
file.setReadable(true, false)
454+
doLast {
455+
val sourceJdkHome = jdkHome.get()
456+
fileTree(destinationDir).files.forEach { file ->
457+
// Copy preserves the source exec bit, but some environments strip it.
458+
// Re-apply exec on files that should be executable.
459+
val sourceFile = File(sourceJdkHome, file.relativeTo(destinationDir).path)
460+
if (sourceFile.canExecute()) {
461+
file.setExecutable(true, false)
462+
}
463+
file.setWritable(true, false)
464+
file.setReadable(true, false)
465+
}
457466
}
458467
}
459468
tasks.register<Copy>("includeSharedAssets"){
@@ -648,6 +657,10 @@ tasks.register("setExecutablePermissions") {
648657
include("**/resources/**/*.dylib")
649658
include("**/resources/**/*.so")
650659
include("**/resources/**/*.exe")
660+
// Also cover the IDE runtime (jspawnhelper, jexec, bin/*) — same issue
661+
// https://github.com/processing/processing4/issues/1537
662+
include("**/runtime/**/bin/**")
663+
include("**/runtime/**/lib/**")
651664
}.forEach { file ->
652665
if (file.isFile) {
653666
file.setExecutable(true, false)

app/src/processing/app/Platform.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static public File getContentFile(String name) {
371371
}
372372

373373
static public File getJavaHome() {
374-
// Get the build in JDK location from the Jetpack Compose resources
374+
// Get the built-in JDK location from the Jetpack Compose resources
375375
var resourcesDir = System.getProperty("compose.application.resources.dir");
376376
if(resourcesDir != null) {
377377
var jdkFolder = new File(resourcesDir,"jdk");
@@ -381,6 +381,16 @@ static public File getJavaHome() {
381381
}
382382

383383
// If the JDK is set in the environment, use that.
384+
// if not, fall back to the java.home system property.
385+
for (String envKey : new String[] { "JAVA_HOME", "JDK_HOME" }) {
386+
String envPath = System.getenv(envKey);
387+
if (envPath != null && !envPath.isEmpty()) {
388+
File envHome = new File(envPath);
389+
if (new File(envHome, "bin/java" + (Platform.isWindows() ? ".exe" : "")).canExecute()) {
390+
return envHome;
391+
}
392+
}
393+
}
384394
var home = System.getProperty("java.home");
385395
if(home != null){
386396
return new File(home);

0 commit comments

Comments
 (0)