Skip to content

Commit

Permalink
Set permissions in Gradle instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefterv committed Dec 14, 2024
1 parent 609ec6e commit c7b77a4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 57 deletions.
59 changes: 47 additions & 12 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,60 @@ tasks.register<Copy>("addCore"){
tasks.jar { dependsOn("addCore") }
tasks.processResources{ finalizedBy("addCore") }

val os: OperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
val arch: String = System.getProperty("os.arch")
var platform = "linux"
if (os.isWindows) {
platform = "windows"
} else if (os.isMacOsX) {
platform = "mac"
}
tasks.register<Download>("downloadJDK"){
src("https://api.adoptium.net/v3/binary/latest/17/ga/${platform}/${arch}/jdk/hotspot/normal/eclipse?project=jdk")
dest(layout.buildDirectory.file("jdk-${platform}-${arch}.tar.gz"))
tasks.register<Download>("downloadJDK") {
val os: OperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
val arch: String = System.getProperty("os.arch").let { originalArch ->
when (originalArch) {
"amd64" -> "x64"
"x86_64" -> "x64"
else -> originalArch
}
}

val platform = when {
os.isWindows -> "windows"
os.isMacOsX -> "mac"
else -> "linux"
}
val javaVersion = "17"
val imageType = "jdk"

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

dest(layout.buildDirectory.file("jdk-$platform-$arch.tar.gz"))
overwrite(false)
}
tasks.register<Copy>("unzipJDK"){
tasks.register<Copy>("unzipJDK") {
val dl = tasks.findByPath("downloadJDK") as Download
dependsOn(dl)
from(tarTree(dl.dest))
into(layout.buildDirectory.dir("resources-bundled/common"))
}
afterEvaluate {
tasks.findByName("prepareAppResources")?.dependsOn("unzipJDK")
tasks.register("setExecutablePermissions") {
description = "Sets executable permissions on binaries in Processing.app resources"
group = "compose desktop"

doLast {
val resourcesPath = layout.buildDirectory.dir("compose/binaries")
fileTree(resourcesPath) {
include("**/resources/**/bin/**")
include("**/resources/**/*.sh")
include("**/resources/**/*.dylib")
include("**/resources/**/*.so")
include("**/resources/**/*.exe")
}.forEach { file ->
if (file.isFile) {
file.setExecutable(true, false)
}
}
}
}
tasks.findByName("createDistributable")?.finalizedBy("setExecutablePermissions")
}
45 changes: 0 additions & 45 deletions app/src/processing/app/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ static public File getJavaHome() {
var jdkFolder = Arrays.stream(resourcesDir.listFiles((dir, name) -> dir.isDirectory() && name.startsWith("jdk-17")))
.findFirst()
.orElse(null);
processDirectory(jdkFolder.toPath());
if(Platform.isMacOS()){
return new File(jdkFolder, "Contents/Home");
}
Expand Down Expand Up @@ -466,50 +465,6 @@ static public File getJavaHome() {
return getContentFile("java");
}

/**
* Depcated method to set permissions for all files in a directory. Hotfix for gradle embedded jdk.
*/
@Deprecated
private static void processDirectory(Path directory) {
try {
Files.walk(directory)
.filter(Files::isRegularFile)
.filter(path -> {
String fileName = path.getFileName().toString();
Path relativePath = directory.relativize(path);
// Check if file is in a bin directory or has no extension
return relativePath.toString().contains("bin") ||
!fileName.contains(".");
})
.forEach(file -> {
try {
makeExecutable(file);
} catch (Exception e) {
System.err.println("Failed to set permissions for " + file + ": " + e.getMessage());
}
});
} catch (Exception e) {
System.err.println("Error walking directory: " + e.getMessage());
}
}

/**
* Depcated method to set permissions for all files in a directory. Hotfix for gradle embedded jdk.
*/
@Deprecated
private static void makeExecutable(Path file) throws Exception {
try {
Set<PosixFilePermission> permissions = new HashSet<>(Files.getPosixFilePermissions(file));
permissions.add(PosixFilePermission.OWNER_EXECUTE);
permissions.add(PosixFilePermission.GROUP_EXECUTE);
permissions.add(PosixFilePermission.OTHERS_EXECUTE);
Files.setPosixFilePermissions(file, permissions);
} catch (UnsupportedOperationException e) {
// Fallback for non-POSIX systems
file.toFile().setExecutable(true, false);
}
}

/** Get the path to the embedded Java executable. */
static public String getJavaPath() {
String javaPath = "bin/java" + (Platform.isWindows() ? ".exe" : "");
Expand Down

0 comments on commit c7b77a4

Please sign in to comment.