Skip to content

Commit f51c549

Browse files
committed
Use shared resources
Found a better method that doesn't require copy the jar resources to a temporary folder
1 parent 8ddc54e commit f51c549

File tree

2 files changed

+10
-45
lines changed

2 files changed

+10
-45
lines changed

app/build.gradle.kts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,12 @@ dependencies {
9191
implementation("com.charleskorn.kaml:kaml:0.65.0")
9292
}
9393

94-
tasks.register<Copy>("addCore"){
94+
tasks.register<Copy>("copyCore"){
9595
dependsOn(project(":core").tasks.jar)
9696
from("../core/build/libs/")
9797
include("*.jar")
98-
into("build/resources/main/core/library")
98+
into(layout.buildDirectory.dir("resources-bundled/common/core/library"))
9999
}
100-
tasks.jar { dependsOn("addCore") }
101-
tasks.processResources{ finalizedBy("addCore") }
102-
103100
tasks.register<Download>("downloadJDK") {
104101
val os: OperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
105102
val arch: String = System.getProperty("os.arch").let { originalArch ->
@@ -143,8 +140,12 @@ tasks.register<Copy>("unzipJDK") {
143140
from(archive)
144141
into(layout.buildDirectory.dir("resources-bundled/common"))
145142
}
143+
tasks.register<Copy>("copyShared"){
144+
from("../build/shared/")
145+
into(layout.buildDirectory.dir("resources-bundled/common"))
146+
}
146147
afterEvaluate {
147-
tasks.findByName("prepareAppResources")?.dependsOn("unzipJDK")
148+
tasks.findByName("prepareAppResources")?.dependsOn("unzipJDK","copyShared", "copyCore")
148149
tasks.register("setExecutablePermissions") {
149150
description = "Sets executable permissions on binaries in Processing.app resources"
150151
group = "compose desktop"

app/src/processing/app/Platform.java

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,9 @@ static public boolean isLinux() {
336336
@Deprecated
337337
static public File getContentFile(String name) {
338338
if (processingRoot == null) {
339-
var url = Platform.class.getClassLoader().getResource("lib/defaults.txt");
340-
if(url != null){
341-
try {
342-
processingRoot = Files.createTempDirectory("processing").toFile();
343-
copyFromJar("/", processingRoot.toPath());
344-
return new File(processingRoot, name);
345-
} catch (IOException | URISyntaxException e) {
346-
e.printStackTrace();
347-
}
339+
var resourcesDir = new File(System.getProperty("compose.application.resources.dir"));
340+
if(resourcesDir.exists()) {
341+
return new File(resourcesDir, name);
348342
}
349343
// Get the path to the .jar file that contains Base.class
350344
URL pathURL =
@@ -394,36 +388,6 @@ static public File getContentFile(String name) {
394388
return new File(processingRoot, name);
395389
}
396390

397-
public static void copyFromJar(String source, final Path target) throws URISyntaxException, IOException {
398-
var resource = Platform.class.getResource("").toURI();
399-
var fileSystem = FileSystems.newFileSystem(
400-
resource,
401-
Collections.<String, String>emptyMap()
402-
);
403-
404-
405-
final Path jarPath = fileSystem.getPath(source);
406-
407-
Files.walkFileTree(jarPath, new SimpleFileVisitor<Path>() {
408-
409-
private Path currentTarget;
410-
411-
@Override
412-
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
413-
currentTarget = target.resolve(jarPath.relativize(dir).toString());
414-
Files.createDirectories(currentTarget);
415-
return FileVisitResult.CONTINUE;
416-
}
417-
418-
@Override
419-
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
420-
Files.copy(file, target.resolve(jarPath.relativize(file).toString()), StandardCopyOption.REPLACE_EXISTING);
421-
return FileVisitResult.CONTINUE;
422-
}
423-
424-
});
425-
}
426-
427391
static public File getJavaHome() {
428392
var resourcesDir = new File(System.getProperty("compose.application.resources.dir"));
429393
if(resourcesDir.exists()) {

0 commit comments

Comments
 (0)