Skip to content

Commit

Permalink
Revise the bundler to only require JDK 15 for macOS packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwilkes committed Jun 3, 2020
1 parent a452a6e commit b511483
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ tag. These directions are for the latest source, which may have experimental cod
are incompatible with the current data files. These build instructions may have also changed since
a given release, so be sure to review them again with the version you plan to build.*

1. Make sure you have JDK 14 (JDK 15 for macOS) installed and set to be used as your default Java
compiler. You can download it for your platform here: http://jdk.java.net/14/
(http://jdk.java.net/15/ for macOS)
1. Make sure you have JDK 14 installed and set to be used as your default Java compiler. You can
download it for your platform here: http://jdk.java.net/14/

2. If you are building on Windows, you'll need to install the WiX Toolset from here:
2. If you are building on macOS, you will also need to download and extract a copy of JDK 15 into
`~/jdk-15.jdk`. You can download it from here: http://jdk.java.net/15/

3. If you are building on Windows, you'll need to install the WiX Toolset from here:
https://github.com/wixtoolset/wix3/releases/tag/wix3112rtm

3. Clone the source repositories:
4. Clone the source repositories:
```
% git clone https://github.com/richardwilkes/gcs
```
Expand All @@ -28,7 +30,7 @@ a given release, so be sure to review them again with the version you plan to bu
% git clone https://github.com/richardwilkes/gcs_library
```

4. Build and bundle the code for your platform:
5. Build and bundle the code for your platform:

macOS and Linux:
```
Expand Down
45 changes: 38 additions & 7 deletions bundler/bundler/Bundler.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class Bundler {
private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
private static String OS;
private static Path PKG;
private static Path JPACKAGE_15;
private static String ICON_TYPE;

/**
Expand All @@ -69,11 +70,6 @@ public class Bundler {
*/
public static void main(String[] args) {
checkPlatform();
if (MACOS.equals(OS)) {
// We only want JDK 15 for its updated jpackage tool, which otherwise is incapable of
// signing a macOS application.
JDK_MAJOR_VERSION = "15";
}

boolean sign = false;
boolean notarize = false;
Expand Down Expand Up @@ -142,7 +138,7 @@ private static void checkPlatform() {
}

private static void checkJDK() {
ProcessBuilder builder = new ProcessBuilder("javac", "-version");
ProcessBuilder builder = new ProcessBuilder("javac", "--version");
builder.redirectOutput(Redirect.PIPE).redirectErrorStream(true);
try {
String versionLine = "";
Expand All @@ -164,6 +160,37 @@ private static void checkJDK() {
System.err.println("JDK " + JDK_MAJOR_VERSION + " is not installed!");
emitInstallJDKMessageAndExit();
}

if (OS.equals(MACOS)) {
boolean failed = false;
Path dir = Paths.get(System.getProperty("user.home", "."), "jdk-15.jdk").toAbsolutePath();
JPACKAGE_15 = dir.resolve(Paths.get("Contents", "Home", "bin", "jpackage"));
builder = new ProcessBuilder(JPACKAGE_15.toString(), "--version");
builder.redirectOutput(Redirect.PIPE).redirectErrorStream(true);
try {
String versionLine = "";
Process process = builder.start();
try (BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
String prefix = "15";
String line;
while ((line = in.readLine()) != null) {
if (line.startsWith(prefix)) {
versionLine = line;
}
}
}
if (!versionLine.startsWith("15")) {
failed = true;
}
} catch (IOException exception) {
failed = true;
}
if (failed) {
System.err.println("jpackage 15 is not available!");
System.err.println("Unpack JDK 15 from http://jdk.java.net/15/ into " + " and try again.");
System.exit(1);
}
}
}

private static void emitInstallJDKMessageAndExit() {
Expand Down Expand Up @@ -565,7 +592,11 @@ private static void packageApp(boolean sign) {
args.add("com.trollworks.gcs");
runNoOutputCmd("jlink", "--module-path", MODULE_DIR.toString(), "--output", JRE.toString(), "--compress=2", "--no-header-files", "--no-man-pages", "--strip-debug", "--strip-native-commands", "--add-modules", "com.trollworks.gcs");
args.clear();
args.add("jpackage");
if (OS.equals(MACOS)) {
args.add(JPACKAGE_15.toString());
} else {
args.add("jpackage");
}
args.add("--module");
args.add("com.trollworks.gcs/com.trollworks.gcs.GCS");
args.add("--app-version");
Expand Down

0 comments on commit b511483

Please sign in to comment.