diff --git a/CHANGELOG.md b/CHANGELOG.md index 65d5aee..dc3ede2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +**1.0.2** +* Fix 32-Bit OpenJDk Installation + **1.0.1** * Add Wrapping To Conflict Dialog diff --git a/gradle.properties b/gradle.properties index 48e372a..4dc1512 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G fabric_loader_version = 0.9.0+build.204 # Mod Properties - mod_version = 1.0.1 + mod_version = 1.0.2 maven_group = com.thebrokenrail # Dependencies diff --git a/src/main/java/com/thebrokenrail/freshcoffee/FreshCoffee.java b/src/main/java/com/thebrokenrail/freshcoffee/FreshCoffee.java index 0be6051..6e62051 100644 --- a/src/main/java/com/thebrokenrail/freshcoffee/FreshCoffee.java +++ b/src/main/java/com/thebrokenrail/freshcoffee/FreshCoffee.java @@ -44,8 +44,7 @@ public class FreshCoffee implements PreLaunchEntrypoint { File dir = Util.getJavaDir(jdk.version.semver); if (dir.exists()) { - Util.getLogger().info("Removing Invalid Java Installation: " + dir.getAbsolutePath()); - Util.deleteDirectory(dir); + Util.removeInvalidJDK(dir); } ExtractUtil.extract(url, dir); diff --git a/src/main/java/com/thebrokenrail/freshcoffee/config/HardcodedConfig.java b/src/main/java/com/thebrokenrail/freshcoffee/config/HardcodedConfig.java index 567be5c..9e7bfe8 100644 --- a/src/main/java/com/thebrokenrail/freshcoffee/config/HardcodedConfig.java +++ b/src/main/java/com/thebrokenrail/freshcoffee/config/HardcodedConfig.java @@ -16,6 +16,7 @@ public final class HardcodedConfig { public static final String LIMIT_TEXT = "version %s required by %s"; public static final String JAVA_IMPLEMENTATION = "hotspot"; + public static final String HEAP_SIZE = "normal"; public static final String OUTDATED_JAVA_MESSAGE = "An installed mod requires a newer version of Java (%s)."; public static final String OUTDATED_JAVA_WITH_OFFER_MESSAGE = OUTDATED_JAVA_MESSAGE + " Would you like to install it?\n%s will be downloaded."; diff --git a/src/main/java/com/thebrokenrail/freshcoffee/download/AdoptOpenJDK.java b/src/main/java/com/thebrokenrail/freshcoffee/download/AdoptOpenJDK.java index 9d61a42..09c9de0 100644 --- a/src/main/java/com/thebrokenrail/freshcoffee/download/AdoptOpenJDK.java +++ b/src/main/java/com/thebrokenrail/freshcoffee/download/AdoptOpenJDK.java @@ -31,7 +31,7 @@ public final class AdoptOpenJDK { private String project; private boolean isValid() { - return heap_size.equals("normal") && image_type.equals("jre") && project.equals("jdk") && (packageObj.link.endsWith(".zip") || packageObj.link.endsWith(".tar.gz")); + return heap_size.equals(HardcodedConfig.HEAP_SIZE) && image_type.equals("jre") && project.equals("jdk") && (packageObj.link.endsWith(".zip") || packageObj.link.endsWith(".tar.gz")); } } @@ -85,7 +85,7 @@ public final class AdoptOpenJDK { } private static final String[] PLATFORM_TYPES = new String[]{"linux", "win", "macosx"}; - private static final String[] ARCHITECTURE_TYPES = new String[]{"x64", "i686", "aarch64", "arm32"}; + private static final String[] ARCHITECTURE_TYPES = new String[]{"x64", "x32", "aarch64", "arm"}; private static final Platform[] PLATFORMS; diff --git a/src/main/java/com/thebrokenrail/freshcoffee/util/PlatformUtil.java b/src/main/java/com/thebrokenrail/freshcoffee/util/PlatformUtil.java index 14e2f32..2c58ac1 100644 --- a/src/main/java/com/thebrokenrail/freshcoffee/util/PlatformUtil.java +++ b/src/main/java/com/thebrokenrail/freshcoffee/util/PlatformUtil.java @@ -22,13 +22,13 @@ public final class PlatformUtil { case "x86": case "i386": case "i686": { - return "i686"; + return "x32"; } case "amd64": { return "x64"; } case "arm": { - return "arm32"; + return "arm"; } case "aarch64_be": case "armv8b": diff --git a/src/main/java/com/thebrokenrail/freshcoffee/util/ReLaunchUtil.java b/src/main/java/com/thebrokenrail/freshcoffee/util/ReLaunchUtil.java index a4a0d77..1943e56 100644 --- a/src/main/java/com/thebrokenrail/freshcoffee/util/ReLaunchUtil.java +++ b/src/main/java/com/thebrokenrail/freshcoffee/util/ReLaunchUtil.java @@ -110,6 +110,23 @@ public final class ReLaunchUtil { } } + private static boolean testJavaBinary(String javaBinary) { + Process process; + try { + process = new ProcessBuilder(javaBinary, "-version").start(); + } catch (IOException e) { + return false; + } + + try { + int status = process.waitFor(); + return status == 0; + } catch (InterruptedException e) { + process.destroy(); + return false; + } + } + public static void reLaunch() { File[] files = HardcodedConfig.INSTALL_DIR.listFiles(); if (files != null) { @@ -123,10 +140,13 @@ public final class ReLaunchUtil { String newestVersion = JavaVersionUtil.getNewest(list.toArray(new String[0])); if (newestVersion != null) { - File javaBinary = new File(new File(Util.getJavaDir(newestVersion), "bin"), "java" + PlatformUtil.getExecutableExtension()); - if (javaBinary.exists() && javaBinary.canExecute()) { + File javaDir = Util.getJavaDir(newestVersion); + File javaBinary = new File(new File(javaDir, "bin"), "java" + PlatformUtil.getExecutableExtension()); + if (javaBinary.exists() && javaBinary.canExecute() && testJavaBinary(javaBinary.getAbsolutePath())) { Util.getLogger().info("Using Java Executable: " + javaBinary.getAbsolutePath()); reLaunch(javaBinary.getAbsolutePath()); + } else { + Util.removeInvalidJDK(javaDir); } } } diff --git a/src/main/java/com/thebrokenrail/freshcoffee/util/Util.java b/src/main/java/com/thebrokenrail/freshcoffee/util/Util.java index fd00556..ef7ef13 100644 --- a/src/main/java/com/thebrokenrail/freshcoffee/util/Util.java +++ b/src/main/java/com/thebrokenrail/freshcoffee/util/Util.java @@ -27,7 +27,7 @@ public final class Util { return new File(HardcodedConfig.INSTALL_DIR, version); } - public static void deleteDirectory(File directoryToBeDeleted) { + private static void deleteDirectory(File directoryToBeDeleted) { File[] allContents = directoryToBeDeleted.listFiles(); if (allContents != null) { for (File file : allContents) { @@ -66,4 +66,9 @@ public final class Util { String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); } + + public static void removeInvalidJDK(File dir) { + Util.getLogger().info("Removing Invalid Java Installation: " + dir.getAbsolutePath()); + Util.deleteDirectory(dir); + } }