Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
94e674658f | |||
47a9d6454f | |||
7f828767a8 | |||
2020b895b9 |
13
CHANGELOG.md
13
CHANGELOG.md
@ -1,5 +1,18 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
**1.0.5**
|
||||||
|
* Allow Forcing Preview Features With ``freshcoffee:preview_features_required``
|
||||||
|
|
||||||
|
**1.0.4**
|
||||||
|
* Replace Reflection With New Fabric Loader API
|
||||||
|
* Enable Java Preview Features
|
||||||
|
|
||||||
|
**1.0.3**
|
||||||
|
* Improve Java Binary Testing
|
||||||
|
|
||||||
|
**1.0.2**
|
||||||
|
* Fix 32-Bit OpenJDk Installation
|
||||||
|
|
||||||
**1.0.1**
|
**1.0.1**
|
||||||
* Add Wrapping To Conflict Dialog
|
* Add Wrapping To Conflict Dialog
|
||||||
|
|
||||||
|
@ -36,3 +36,12 @@ You can set a maximum version of Java by adding this to ``fabric.mod.json``:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also force Java preview features:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"custom": {
|
||||||
|
"freshcoffee:preview_features_required": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
@ -3,14 +3,14 @@ org.gradle.jvmargs = -Xmx1G
|
|||||||
|
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://fabricmc.net/use
|
# check these on https://fabricmc.net/use
|
||||||
minecraft_version = 1.16.2
|
minecraft_version = 1.16.3
|
||||||
curseforge_id = 398250
|
curseforge_id = 398250
|
||||||
simple_minecraft_version = 1.16.2
|
simple_minecraft_version = 1.16.3
|
||||||
yarn_build = 6
|
yarn_build = 47
|
||||||
fabric_loader_version = 0.9.0+build.204
|
fabric_loader_version = 0.10.3+build.211
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.0.1
|
mod_version = 1.0.5
|
||||||
maven_group = com.thebrokenrail
|
maven_group = com.thebrokenrail
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
@ -4,6 +4,7 @@ import com.thebrokenrail.freshcoffee.config.HardcodedConfig;
|
|||||||
import com.thebrokenrail.freshcoffee.dialog.Dialog;
|
import com.thebrokenrail.freshcoffee.dialog.Dialog;
|
||||||
import com.thebrokenrail.freshcoffee.download.AdoptOpenJDK;
|
import com.thebrokenrail.freshcoffee.download.AdoptOpenJDK;
|
||||||
import com.thebrokenrail.freshcoffee.util.PlatformUtil;
|
import com.thebrokenrail.freshcoffee.util.PlatformUtil;
|
||||||
|
import com.thebrokenrail.freshcoffee.util.PreviewUtil;
|
||||||
import com.thebrokenrail.freshcoffee.util.ReLaunchUtil;
|
import com.thebrokenrail.freshcoffee.util.ReLaunchUtil;
|
||||||
import com.thebrokenrail.freshcoffee.util.Util;
|
import com.thebrokenrail.freshcoffee.util.Util;
|
||||||
import com.thebrokenrail.freshcoffee.util.ExtractUtil;
|
import com.thebrokenrail.freshcoffee.util.ExtractUtil;
|
||||||
@ -17,13 +18,13 @@ import java.net.URL;
|
|||||||
public class FreshCoffee implements PreLaunchEntrypoint {
|
public class FreshCoffee implements PreLaunchEntrypoint {
|
||||||
@Override
|
@Override
|
||||||
public void onPreLaunch() {
|
public void onPreLaunch() {
|
||||||
if (Util.JAVA_VERSION < LimitUtil.getMinimumJavaVersion().getValue() || Util.JAVA_VERSION > LimitUtil.getMaximumJavaVersion().getValue()) {
|
if (Util.JAVA_VERSION < LimitUtil.getMinimumJavaVersion().getValue() || Util.JAVA_VERSION > LimitUtil.getMaximumJavaVersion().getValue() || (PreviewUtil.arePreviewFeaturesRequired() && !PreviewUtil.arePreviewFeaturesEnabled())) {
|
||||||
if (LimitUtil.getMinimumJavaVersion().getValue() > LimitUtil.getMaximumJavaVersion().getValue()) {
|
if (LimitUtil.getMinimumJavaVersion().getValue() > LimitUtil.getMaximumJavaVersion().getValue()) {
|
||||||
Dialog.getInstance().showErrorDialog(String.format(HardcodedConfig.MINIMUM_HIGHER_THAN_MAXIMUM_MESSAGE, LimitUtil.getMinimumJavaVersion().toString(), LimitUtil.getMaximumJavaVersion().toString()));
|
Dialog.getInstance().showErrorDialog(String.format(HardcodedConfig.MINIMUM_HIGHER_THAN_MAXIMUM_MESSAGE, LimitUtil.getMinimumJavaVersion().toString(), LimitUtil.getMaximumJavaVersion().toString()));
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReLaunchUtil.reLaunch();
|
ReLaunchUtil.reLaunch(true);
|
||||||
|
|
||||||
// Download Available JDKs
|
// Download Available JDKs
|
||||||
AdoptOpenJDK.JDK jdk = AdoptOpenJDK.get().get(PlatformUtil.getPlatform());
|
AdoptOpenJDK.JDK jdk = AdoptOpenJDK.get().get(PlatformUtil.getPlatform());
|
||||||
@ -44,13 +45,12 @@ public class FreshCoffee implements PreLaunchEntrypoint {
|
|||||||
File dir = Util.getJavaDir(jdk.version.semver);
|
File dir = Util.getJavaDir(jdk.version.semver);
|
||||||
|
|
||||||
if (dir.exists()) {
|
if (dir.exists()) {
|
||||||
Util.getLogger().info("Removing Invalid Java Installation: " + dir.getAbsolutePath());
|
Util.removeInvalidJDK(dir);
|
||||||
Util.deleteDirectory(dir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtractUtil.extract(url, dir);
|
ExtractUtil.extract(url, dir);
|
||||||
|
|
||||||
ReLaunchUtil.reLaunch();
|
ReLaunchUtil.reLaunch(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
@ -5,6 +5,7 @@ import java.io.File;
|
|||||||
public final class HardcodedConfig {
|
public final class HardcodedConfig {
|
||||||
public static final String MINIMUM_JSON_KEY = "freshcoffee:minimum_java_version";
|
public static final String MINIMUM_JSON_KEY = "freshcoffee:minimum_java_version";
|
||||||
public static final String MAXIMUM_JSON_KEY = "freshcoffee:maximum_java_version";
|
public static final String MAXIMUM_JSON_KEY = "freshcoffee:maximum_java_version";
|
||||||
|
public static final String PREVIEW_JSON_KEY = "freshcoffee:preview_features_required";
|
||||||
|
|
||||||
public static final String TITLE = "FreshCoffee";
|
public static final String TITLE = "FreshCoffee";
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ public final class HardcodedConfig {
|
|||||||
public static final String LIMIT_TEXT = "version %s required by %s";
|
public static final String LIMIT_TEXT = "version %s required by %s";
|
||||||
|
|
||||||
public static final String JAVA_IMPLEMENTATION = "hotspot";
|
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_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.";
|
public static final String OUTDATED_JAVA_WITH_OFFER_MESSAGE = OUTDATED_JAVA_MESSAGE + " Would you like to install it?\n%s will be downloaded.";
|
||||||
|
@ -31,7 +31,7 @@ public final class AdoptOpenJDK {
|
|||||||
private String project;
|
private String project;
|
||||||
|
|
||||||
private boolean isValid() {
|
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[] 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;
|
private static final Platform[] PLATFORMS;
|
||||||
|
|
||||||
|
@ -22,13 +22,13 @@ public final class PlatformUtil {
|
|||||||
case "x86":
|
case "x86":
|
||||||
case "i386":
|
case "i386":
|
||||||
case "i686": {
|
case "i686": {
|
||||||
return "i686";
|
return "x32";
|
||||||
}
|
}
|
||||||
case "amd64": {
|
case "amd64": {
|
||||||
return "x64";
|
return "x64";
|
||||||
}
|
}
|
||||||
case "arm": {
|
case "arm": {
|
||||||
return "arm32";
|
return "arm";
|
||||||
}
|
}
|
||||||
case "aarch64_be":
|
case "aarch64_be":
|
||||||
case "armv8b":
|
case "armv8b":
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.thebrokenrail.freshcoffee.util;
|
||||||
|
|
||||||
|
import com.thebrokenrail.freshcoffee.config.HardcodedConfig;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.fabricmc.loader.api.ModContainer;
|
||||||
|
import net.fabricmc.loader.api.metadata.ModMetadata;
|
||||||
|
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public final class PreviewUtil {
|
||||||
|
public static boolean arePreviewFeaturesRequired() {
|
||||||
|
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
|
||||||
|
ModMetadata metadata = mod.getMetadata();
|
||||||
|
if (metadata.containsCustomValue(HardcodedConfig.PREVIEW_JSON_KEY)) {
|
||||||
|
try {
|
||||||
|
boolean newValue = metadata.getCustomValue(HardcodedConfig.PREVIEW_JSON_KEY).getAsBoolean();
|
||||||
|
if (newValue) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
Util.getLogger().error("Invalid Value For Preview Features: " + metadata.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean arePreviewFeaturesEnabled() {
|
||||||
|
List<String> vmArgs = new ArrayList<>(ManagementFactory.getRuntimeMXBean().getInputArguments());
|
||||||
|
return vmArgs.contains("--enable-preview");
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,13 @@
|
|||||||
package com.thebrokenrail.freshcoffee.util;
|
package com.thebrokenrail.freshcoffee.util;
|
||||||
|
|
||||||
import com.thebrokenrail.freshcoffee.config.HardcodedConfig;
|
import com.thebrokenrail.freshcoffee.config.HardcodedConfig;
|
||||||
import net.fabricmc.loader.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.fabricmc.loader.game.MinecraftGameProvider;
|
|
||||||
import net.fabricmc.loader.util.Arguments;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UncheckedIOException;
|
import java.io.UncheckedIOException;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -47,15 +44,7 @@ public final class ReLaunchUtil {
|
|||||||
// Set Entry-Point
|
// Set Entry-Point
|
||||||
mainArgs.add(Util.getMainClass());
|
mainArgs.add(Util.getMainClass());
|
||||||
// Get Parameters
|
// Get Parameters
|
||||||
String[] launchArgs;
|
String[] launchArgs = FabricLoader.getInstance().getLaunchArguments(false);
|
||||||
try {
|
|
||||||
Field launchArgsField = MinecraftGameProvider.class.getDeclaredField("arguments");
|
|
||||||
launchArgsField.setAccessible(true);
|
|
||||||
//noinspection deprecation
|
|
||||||
launchArgs = ((Arguments) launchArgsField.get(FabricLoader.INSTANCE.getGameProvider())).toArray();
|
|
||||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
// Add Parameters
|
// Add Parameters
|
||||||
mainArgs.addAll(Arrays.asList(launchArgs));
|
mainArgs.addAll(Arrays.asList(launchArgs));
|
||||||
return mainArgs;
|
return mainArgs;
|
||||||
@ -68,6 +57,14 @@ public final class ReLaunchUtil {
|
|||||||
List<String> vmArgs = new ArrayList<>(ManagementFactory.getRuntimeMXBean().getInputArguments());
|
List<String> vmArgs = new ArrayList<>(ManagementFactory.getRuntimeMXBean().getInputArguments());
|
||||||
// Remove Debugger
|
// Remove Debugger
|
||||||
vmArgs.removeIf(arg -> arg.startsWith("-agentlib") || arg.startsWith("-javaagent"));
|
vmArgs.removeIf(arg -> arg.startsWith("-agentlib") || arg.startsWith("-javaagent"));
|
||||||
|
// Enable Java Preview Features
|
||||||
|
if (PreviewUtil.arePreviewFeaturesRequired()) {
|
||||||
|
if (!vmArgs.contains("--enable-preview")) {
|
||||||
|
vmArgs.add("--enable-preview");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
vmArgs.remove("--enable-preview");
|
||||||
|
}
|
||||||
|
|
||||||
List<String> mainArgs = getMainArgs();
|
List<String> mainArgs = getMainArgs();
|
||||||
|
|
||||||
@ -110,7 +107,33 @@ public final class ReLaunchUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reLaunch() {
|
private static void javaBinaryTestFailed(String reason) {
|
||||||
|
Util.getLogger().debug("Java Binary Test Failed: " + reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean testJavaBinary(String javaBinary) {
|
||||||
|
Util.getLogger().debug("Testing Java Binary: " + javaBinary);
|
||||||
|
|
||||||
|
Process process;
|
||||||
|
try {
|
||||||
|
process = new ProcessBuilder(javaBinary, "-version").start();
|
||||||
|
} catch (IOException e) {
|
||||||
|
javaBinaryTestFailed(e.toString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int status = process.waitFor();
|
||||||
|
javaBinaryTestFailed("Exit Code: " + status);
|
||||||
|
return status == 0;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
javaBinaryTestFailed(e.toString());
|
||||||
|
process.destroy();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reLaunch(boolean testJavaBinary) {
|
||||||
File[] files = HardcodedConfig.INSTALL_DIR.listFiles();
|
File[] files = HardcodedConfig.INSTALL_DIR.listFiles();
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
@ -123,10 +146,13 @@ public final class ReLaunchUtil {
|
|||||||
String newestVersion = JavaVersionUtil.getNewest(list.toArray(new String[0]));
|
String newestVersion = JavaVersionUtil.getNewest(list.toArray(new String[0]));
|
||||||
|
|
||||||
if (newestVersion != null) {
|
if (newestVersion != null) {
|
||||||
File javaBinary = new File(new File(Util.getJavaDir(newestVersion), "bin"), "java" + PlatformUtil.getExecutableExtension());
|
File javaDir = Util.getJavaDir(newestVersion);
|
||||||
if (javaBinary.exists() && javaBinary.canExecute()) {
|
File javaBinary = new File(new File(javaDir, "bin"), "java" + PlatformUtil.getExecutableExtension());
|
||||||
|
if (!testJavaBinary || testJavaBinary(javaBinary.getAbsolutePath())) {
|
||||||
Util.getLogger().info("Using Java Executable: " + javaBinary.getAbsolutePath());
|
Util.getLogger().info("Using Java Executable: " + javaBinary.getAbsolutePath());
|
||||||
reLaunch(javaBinary.getAbsolutePath());
|
reLaunch(javaBinary.getAbsolutePath());
|
||||||
|
} else {
|
||||||
|
Util.removeInvalidJDK(javaDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public final class Util {
|
|||||||
return new File(HardcodedConfig.INSTALL_DIR, version);
|
return new File(HardcodedConfig.INSTALL_DIR, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteDirectory(File directoryToBeDeleted) {
|
private static void deleteDirectory(File directoryToBeDeleted) {
|
||||||
File[] allContents = directoryToBeDeleted.listFiles();
|
File[] allContents = directoryToBeDeleted.listFiles();
|
||||||
if (allContents != null) {
|
if (allContents != null) {
|
||||||
for (File file : allContents) {
|
for (File file : allContents) {
|
||||||
@ -66,4 +66,9 @@ public final class Util {
|
|||||||
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
|
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
|
||||||
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user