Skip to content

Commit c7b77a4

Browse files
committed
Set permissions in Gradle instead
1 parent 609ec6e commit c7b77a4

File tree

2 files changed

+47
-57
lines changed

2 files changed

+47
-57
lines changed

app/build.gradle.kts

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,60 @@ tasks.register<Copy>("addCore"){
100100
tasks.jar { dependsOn("addCore") }
101101
tasks.processResources{ finalizedBy("addCore") }
102102

103-
val os: OperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
104-
val arch: String = System.getProperty("os.arch")
105-
var platform = "linux"
106-
if (os.isWindows) {
107-
platform = "windows"
108-
} else if (os.isMacOsX) {
109-
platform = "mac"
110-
}
111-
tasks.register<Download>("downloadJDK"){
112-
src("https://api.adoptium.net/v3/binary/latest/17/ga/${platform}/${arch}/jdk/hotspot/normal/eclipse?project=jdk")
113-
dest(layout.buildDirectory.file("jdk-${platform}-${arch}.tar.gz"))
103+
tasks.register<Download>("downloadJDK") {
104+
val os: OperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
105+
val arch: String = System.getProperty("os.arch").let { originalArch ->
106+
when (originalArch) {
107+
"amd64" -> "x64"
108+
"x86_64" -> "x64"
109+
else -> originalArch
110+
}
111+
}
112+
113+
val platform = when {
114+
os.isWindows -> "windows"
115+
os.isMacOsX -> "mac"
116+
else -> "linux"
117+
}
118+
val javaVersion = "17"
119+
val imageType = "jdk"
120+
121+
src("https://api.adoptium.net/v3/binary/latest/" +
122+
"$javaVersion/ga/" +
123+
"$platform/" +
124+
"$arch/" +
125+
"$imageType/" +
126+
"hotspot/normal/eclipse?project=jdk")
127+
128+
dest(layout.buildDirectory.file("jdk-$platform-$arch.tar.gz"))
114129
overwrite(false)
115130
}
116-
tasks.register<Copy>("unzipJDK"){
131+
tasks.register<Copy>("unzipJDK") {
117132
val dl = tasks.findByPath("downloadJDK") as Download
118133
dependsOn(dl)
119134
from(tarTree(dl.dest))
120135
into(layout.buildDirectory.dir("resources-bundled/common"))
121136
}
122137
afterEvaluate {
123138
tasks.findByName("prepareAppResources")?.dependsOn("unzipJDK")
139+
tasks.register("setExecutablePermissions") {
140+
description = "Sets executable permissions on binaries in Processing.app resources"
141+
group = "compose desktop"
142+
143+
doLast {
144+
val resourcesPath = layout.buildDirectory.dir("compose/binaries")
145+
fileTree(resourcesPath) {
146+
include("**/resources/**/bin/**")
147+
include("**/resources/**/*.sh")
148+
include("**/resources/**/*.dylib")
149+
include("**/resources/**/*.so")
150+
include("**/resources/**/*.exe")
151+
}.forEach { file ->
152+
if (file.isFile) {
153+
file.setExecutable(true, false)
154+
}
155+
}
156+
}
157+
}
158+
tasks.findByName("createDistributable")?.finalizedBy("setExecutablePermissions")
124159
}

app/src/processing/app/Platform.java

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ static public File getJavaHome() {
431431
var jdkFolder = Arrays.stream(resourcesDir.listFiles((dir, name) -> dir.isDirectory() && name.startsWith("jdk-17")))
432432
.findFirst()
433433
.orElse(null);
434-
processDirectory(jdkFolder.toPath());
435434
if(Platform.isMacOS()){
436435
return new File(jdkFolder, "Contents/Home");
437436
}
@@ -466,50 +465,6 @@ static public File getJavaHome() {
466465
return getContentFile("java");
467466
}
468467

469-
/**
470-
* Depcated method to set permissions for all files in a directory. Hotfix for gradle embedded jdk.
471-
*/
472-
@Deprecated
473-
private static void processDirectory(Path directory) {
474-
try {
475-
Files.walk(directory)
476-
.filter(Files::isRegularFile)
477-
.filter(path -> {
478-
String fileName = path.getFileName().toString();
479-
Path relativePath = directory.relativize(path);
480-
// Check if file is in a bin directory or has no extension
481-
return relativePath.toString().contains("bin") ||
482-
!fileName.contains(".");
483-
})
484-
.forEach(file -> {
485-
try {
486-
makeExecutable(file);
487-
} catch (Exception e) {
488-
System.err.println("Failed to set permissions for " + file + ": " + e.getMessage());
489-
}
490-
});
491-
} catch (Exception e) {
492-
System.err.println("Error walking directory: " + e.getMessage());
493-
}
494-
}
495-
496-
/**
497-
* Depcated method to set permissions for all files in a directory. Hotfix for gradle embedded jdk.
498-
*/
499-
@Deprecated
500-
private static void makeExecutable(Path file) throws Exception {
501-
try {
502-
Set<PosixFilePermission> permissions = new HashSet<>(Files.getPosixFilePermissions(file));
503-
permissions.add(PosixFilePermission.OWNER_EXECUTE);
504-
permissions.add(PosixFilePermission.GROUP_EXECUTE);
505-
permissions.add(PosixFilePermission.OTHERS_EXECUTE);
506-
Files.setPosixFilePermissions(file, permissions);
507-
} catch (UnsupportedOperationException e) {
508-
// Fallback for non-POSIX systems
509-
file.toFile().setExecutable(true, false);
510-
}
511-
}
512-
513468
/** Get the path to the embedded Java executable. */
514469
static public String getJavaPath() {
515470
String javaPath = "bin/java" + (Platform.isWindows() ? ".exe" : "");

0 commit comments

Comments
 (0)