Skip to content

Commit

Permalink
feat: maintain more info on minimal Java versions (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
skaldarnar authored Nov 28, 2023
1 parent 1410948 commit 223ef54
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/terasology/launcher/game/GameStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public Process call() throws IOException {
* @return the executable {@code java} file to run the game with
*/
Path getRuntimePath(Semver engineVersion) throws GameVersionNotSupportedException {
//TODO: Select the right JRE based on VersionHistory#getJavaVersionForEngine. Probably something along the lines
// of the following:
// Semver minJavaVersion = VersionHistory.getJavaVersionForEngine(engineVersion); // may throw GameVersionNotSupportedException
// <Installation> JRE jre = JreManager.getJreFor(platform, minJavaVersion); // may throw GameVersionNotSupportedException
// return Paths.get(jre.getPath(), "bin", "java");
if (VersionHistory.JAVA17.isProvidedBy(engineVersion)) {
// throw exception as the version is not supported
throw new GameVersionNotSupportedException(engineVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
import org.semver4j.Semver;

public class GameVersionNotSupportedException extends RuntimeException {
private final Semver engineVersion;

public GameVersionNotSupportedException(Semver engineVersion) {
this.engineVersion = engineVersion;
this(engineVersion, null);
}

public GameVersionNotSupportedException(Semver engineVersion, String message) {
super(errorMessage(engineVersion, message));
}

@Override
public String getMessage() {
return "Unsupported engine version: " + engineVersion.toString();
private static String errorMessage(Semver engineVersion, String additionalInfo) {
String message = "Unsupported engine version: " + engineVersion.toString();
String details = ((additionalInfo != null) ? " (" + additionalInfo + ")" : "");
return message + details;
}
}
31 changes: 30 additions & 1 deletion src/main/java/org/terasology/launcher/game/VersionHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,20 @@ public enum VersionHistory {
*/
PICOCLI("5.2.0-SNAPSHOT"),

/** Since 3aa68c04f192243575f7f78de5b6ce268bb2da1a Terasology requires at least Java 17.
/**
* Since 1813b15388760a036ed91e6e4d89c67a59bd92e3 Terasology requires at least Java 8.
* See <a href="https://github.com/MovingBlocks/Terasology/commit/1813b15388760a036ed91e6e4d89c67a59bd92e3">1813b153</a>
*/
JAVA8("0.54.0"),

/**
* Since 901f35aa135215e463c8600405702af35d507005 Terasology requires at least Java 11.
* See <a href="https://github.com/MovingBlocks/Terasology/commit/901f35aa135215e463c8600405702af35d507005">901f35aa</a>
*/
JAVA11("5.2.0-rc.4"),

/**
* Since 3aa68c04f192243575f7f78de5b6ce268bb2da1a Terasology requires at least Java 17.
* See <a href="https://github.com/MovingBlocks/Terasology/commit/3aa68c04f192243575f7f78de5b6ce268bb2da1a">3aa68c04</a>
*/
JAVA17("6.0.0-SNAPSHOT");
Expand All @@ -37,4 +50,20 @@ public enum VersionHistory {
boolean isProvidedBy(Semver version) {
return version.isGreaterThanOrEqualTo(engineVersion);
}

public static Semver getJavaVersionForEngine(Semver engineVersion) throws GameVersionNotSupportedException {
final Semver javaVersion;
if (JAVA17.isProvidedBy(engineVersion)) {
javaVersion = new Semver("17.0.0");
} else if (JAVA11.isProvidedBy(engineVersion)) {
javaVersion = new Semver("11.0.0");
} else if (JAVA8.isProvidedBy(engineVersion)) {
// Java 11 is backwards compatible to Java 8, so we can use that to serve old games
javaVersion = new Semver("11.0.0");
} else {
// older game releases require even older Java versions and are currently not supported.
throw new GameVersionNotSupportedException(engineVersion, "JRE older than Java 8 not supported.");
}
return javaVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.kohsuke.github.extras.okhttp3.OkHttpConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.launcher.game.GameVersionNotSupportedException;
import org.terasology.launcher.game.VersionHistory;
import org.terasology.launcher.model.Build;
import org.terasology.launcher.model.GameIdentifier;
import org.terasology.launcher.model.GameRelease;
Expand Down Expand Up @@ -64,6 +66,8 @@ static GameRelease fromGithubRelease(GHRelease ghRelease) {
} else {
engineVersion = new Semver(tagName);
}
//TODO: check whether the launcher can fulfil this requirement
final Semver minJavaVersion = VersionHistory.getJavaVersionForEngine(engineVersion);

final Optional<GHAsset> gameAsset = ghRelease.assets().stream().filter(asset -> asset.getName().matches("Terasology.*zip")).findFirst();
final URL url = new URL(gameAsset.map(GHAsset::getBrowserDownloadUrl).orElseThrow(() -> new IOException("Missing game asset.")));
Expand All @@ -74,9 +78,13 @@ static GameRelease fromGithubRelease(GHRelease ghRelease) {
ReleaseMetadata metadata = new ReleaseMetadata(changelog, ghRelease.getPublished_at());
return new GameRelease(id, url, metadata);
} catch (SemverException | IOException e) {
logger.info("Could not create game release from Github release {}: {}", ghRelease.getHtmlUrl(), e.getMessage());
return null;
logger.info("Could not create game release from Github release {}: {}",
ghRelease.getHtmlUrl(), e.getMessage());
} catch (GameVersionNotSupportedException e) {
logger.debug("Game release {} with engine version {} is not supported. ({})",
ghRelease.getHtmlUrl(), tagName, e.getMessage());
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ private Optional<GameRelease> computeReleaseFrom(Jenkins.Build jenkinsBuildInfo)
final ReleaseMetadata metadata = computeReleaseMetadataFrom(jenkinsBuildInfo);
final Optional<GameIdentifier> id = computeIdentifierFrom(jenkinsBuildInfo);

//TODO: check whether the game release is supported (minimal Java version)
// we probably need to encode the engine version explicitly in the GameIdentifier (instead of just the display version)

if (url != null && id.isPresent()) {
return Optional.of(new GameRelease(id.get(), url, metadata));
} else {
Expand Down

0 comments on commit 223ef54

Please sign in to comment.