Skip to content

Commit

Permalink
Refactor JavaRuntimeFinder into subclasses & clean up
Browse files Browse the repository at this point in the history
The getAvailableRuntimes function is now parseable, & the new
PlatformRuntimeFinder interface makes it clear what each stage does.
  • Loading branch information
hedgehog1029 committed Dec 12, 2021
1 parent 8c9f903 commit 0833563
Show file tree
Hide file tree
Showing 16 changed files with 461 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
package com.skcraft.launcher;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.skcraft.launcher.launch.JavaRuntime;
import com.skcraft.launcher.launch.JavaRuntimeFinder;
import com.skcraft.launcher.launch.runtime.JavaRuntime;
import com.skcraft.launcher.launch.runtime.JavaRuntimeFinder;
import lombok.Data;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.skcraft.launcher;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.skcraft.launcher.launch.JavaRuntime;
import com.skcraft.launcher.launch.MemorySettings;
import com.skcraft.launcher.launch.runtime.JavaRuntime;
import lombok.Data;

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import com.skcraft.launcher.Configuration;
import com.skcraft.launcher.Launcher;
import com.skcraft.launcher.dialog.component.BetterComboBox;
import com.skcraft.launcher.launch.AddJavaRuntime;
import com.skcraft.launcher.launch.JavaRuntime;
import com.skcraft.launcher.launch.JavaRuntimeFinder;
import com.skcraft.launcher.launch.runtime.AddJavaRuntime;
import com.skcraft.launcher.launch.runtime.JavaRuntime;
import com.skcraft.launcher.launch.runtime.JavaRuntimeFinder;
import com.skcraft.launcher.persistence.Persistence;
import com.skcraft.launcher.swing.*;
import com.skcraft.launcher.util.SharedLocale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.skcraft.launcher.Instance;
import com.skcraft.launcher.InstanceSettings;
import com.skcraft.launcher.dialog.component.BetterComboBox;
import com.skcraft.launcher.launch.JavaRuntime;
import com.skcraft.launcher.launch.JavaRuntimeFinder;
import com.skcraft.launcher.launch.MemorySettings;
import com.skcraft.launcher.launch.runtime.JavaRuntime;
import com.skcraft.launcher.launch.runtime.JavaRuntimeFinder;
import com.skcraft.launcher.persistence.Persistence;
import com.skcraft.launcher.swing.FormPanel;
import com.skcraft.launcher.swing.LinedBoxPanel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.skcraft.launcher.launch;

import com.skcraft.launcher.launch.runtime.JavaRuntime;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.skcraft.launcher.*;
import com.skcraft.launcher.auth.Session;
import com.skcraft.launcher.install.ZipExtract;
import com.skcraft.launcher.launch.runtime.JavaRuntime;
import com.skcraft.launcher.launch.runtime.JavaRuntimeFinder;
import com.skcraft.launcher.model.minecraft.*;
import com.skcraft.launcher.persistence.Persistence;
import com.skcraft.launcher.util.Environment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.skcraft.launcher.launch;
package com.skcraft.launcher.launch.runtime;

import java.io.File;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.skcraft.launcher.launch.runtime;

import com.skcraft.launcher.util.EnvironmentParser;
import lombok.extern.java.Log;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.logging.Level;

@Log
public class JavaReleaseFile {
private Map<String, String> backingMap;

private JavaReleaseFile(Map<String, String> releaseDetails) {
this.backingMap = releaseDetails;
}

public String getVersion() {
return backingMap.get("JAVA_VERSION");
}

public String getArch() {
return backingMap.get("OS_ARCH");
}

public boolean isArch64Bit() {
return getArch() == null || getArch().matches("x64|x86_64|amd64|aarch64");
}

public static JavaReleaseFile parseFromRelease(File javaPath) {
File releaseFile = new File(javaPath, "release");

if (releaseFile.exists()) {
try {
Map<String, String> releaseDetails = EnvironmentParser.parse(releaseFile);

return new JavaReleaseFile(releaseDetails);
} catch (IOException e) {
log.log(Level.WARNING, "Failed to read release file " + releaseFile.getAbsolutePath(), e);
return null;
}
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.skcraft.launcher.launch;
package com.skcraft.launcher.launch.runtime;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down
Loading

0 comments on commit 0833563

Please sign in to comment.