Skip to content

Commit

Permalink
build(win): gradle jpackage to create installer
Browse files Browse the repository at this point in the history
  • Loading branch information
ktgw0316 committed Mar 1, 2024
1 parent 87bb4d2 commit 32e65ea
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
java
application
kotlin("jvm") version "1.9.22"
id("org.beryx.runtime") version "1.13.1" apply false
}
repositories {
mavenCentral()
Expand All @@ -17,10 +18,10 @@ subprojects {
group = "com.lightcrafts"
version = rootProject.file("lightcrafts/version.txt").readText().trim()
application {
applicationName = "LightZone"
applicationDefaultJvmArgs += listOf(
"--add-exports=java.desktop/sun.awt.image=ALL-UNNAMED",
"-Xmx512m",
"-Dlensfun.dir=./share/lensfun",
)
}
repositories {
Expand Down
11 changes: 6 additions & 5 deletions lightcrafts/src/main/java/com/lightcrafts/utils/Lensfun.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import lombok.RequiredArgsConstructor;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -34,12 +33,14 @@ public class Lensfun {
private int _fullHeight;

private static String pathName = "";

static {
if (!Platform.isLinux()) {
final String baseDirName = System.getProperty("lensfun.dir");
try {
pathName = Files.find(Paths.get(baseDirName), 1,
(path, attr) -> attr.isDirectory() && path.getFileName().toString().startsWith("version_"))
final var appDir = Paths.get(System.getProperty("jpackage.app-path")).getParent();
final var lensfunDir = appDir.resolve("app/share/lensfun");
try (final var stream = Files.walk(lensfunDir, 1)) {
pathName = stream.filter(Files::isDirectory)
.filter(path -> path.getFileName().toString().startsWith("version_"))
.findFirst()
.orElse(Path.of(""))
.toString();
Expand Down
11 changes: 4 additions & 7 deletions lightcrafts/src/main/java/com/lightcrafts/utils/raw/DCRaw.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.time.ZoneId;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -171,13 +173,8 @@ private static String readln(InputStream s) {
private static final String DCRAW_NAME = "dcraw_lz";
private static String DCRAW_PATH;
static {
DCRAW_PATH = System.getProperty("java.library.path") + File.separatorChar + DCRAW_NAME;
if (! new File(DCRAW_PATH).canExecute()) {
String dir = System.getProperty("install4j.appDir");
if (dir == null)
dir = ".";
DCRAW_PATH = dir + File.separatorChar + DCRAW_NAME;
}
final var appDir = Paths.get(System.getProperty("jpackage.app-path")).getParent();
DCRAW_PATH = appDir.resolve("app").resolve(DCRAW_NAME).toString();
}

private static String match(@NonNull String s, @NonNull String tag) {
Expand Down
43 changes: 43 additions & 0 deletions windows/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
plugins {
id("org.beryx.runtime")
}
dependencies {
"implementation"(project(":lightcrafts"))
}
application {
mainClass.set("com.lightcrafts.platform.windows.WindowsLauncher")
}
tasks {
named("jpackage") {
doFirst {
copy {
from("products/")
include("share/**")
include("dcraw_lz*")
include("*.dll")
into("build/jpackage/LightZone/app")
}
}
}
}
runtime {
options.set(listOf("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages"))
modules.set(
listOf(
"java.base", "java.desktop", "java.logging", "java.management", "java.prefs", "java.rmi", "jdk.management"
)
)
jpackage {
imageName = "LightZone"
installerName = "LightZone-Installer"
skipInstaller = false
installerOptions =
listOf(
"--win-dir-chooser",
"--win-menu-group",
"LightZone",
"--win-menu",
"--win-shortcut",
"--vendor",
"LightZone Project"
)
imageOptions = listOf("--icon", "src/main/resources/icons/LightZone.ico")
}
launcher {
jvmArgs = listOf("--add-exports=java.desktop/sun.awt.image=ALL-UNNAMED")
}
}

0 comments on commit 32e65ea

Please sign in to comment.