Skip to content

Commit

Permalink
feat: maintain more info on minimal Java versions
Browse files Browse the repository at this point in the history
  • Loading branch information
skaldarnar committed Nov 24, 2023
1 parent 1d0c05b commit fb033b0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
32 changes: 31 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,21 @@ 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 +51,20 @@ public enum VersionHistory {
boolean isProvidedBy(Semver version) {
return version.isGreaterThanOrEqualTo(engineVersion);
}

//TODO: I would prefer if the game release asset itself would contain this information, but I don't think we have
// that readily available. Therefore, matching against these milestones to figure out the minimal required
// Java version.
//TODO: Should this return a range instead?
public static Semver javaVersionForEngine(Semver engineVersion) throws GameVersionNotSupportedException {
if (JAVA17.isProvidedBy(engineVersion)) {
return new Semver("17.0.0");
} else if (JAVA11.isProvidedBy(engineVersion)) {
return new Semver("11.0.0");
} else if (JAVA8.isProvidedBy(engineVersion)) {
return new Semver("8.0.0");
} else {
throw new GameVersionNotSupportedException(engineVersion);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
public class ReleaseMetadata {
private final String changelog;
private final Date timestamp;
private final Semver minJavaVersion;

public ReleaseMetadata(String changelog, Date timestamp) {
public ReleaseMetadata(String changelog, Date timestamp, Semver minJavaVersion) {
this.changelog = changelog;
this.timestamp = timestamp;
this.minJavaVersion = minJavaVersion;
}

/**
Expand All @@ -33,4 +35,8 @@ public String getChangelog() {
public Date getTimestamp() {
return timestamp;
}

public Semver getMinJavaVersion() {
return minJavaVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ static GameRelease fromGithubRelease(GHRelease ghRelease) {
final String changelog = ghRelease.getBody();
GameIdentifier id = new GameIdentifier(engineVersion.toString(), build, profile);

ReleaseMetadata metadata = new ReleaseMetadata(changelog, ghRelease.getPublished_at());
final Semver minJavaVersion = VersionHistory.javaVersionForEngine(engineVersion);
ReleaseMetadata metadata = new ReleaseMetadata(changelog, ghRelease.getPublished_at(), minJavaVersion);
return new GameRelease(id, url, metadata);
} catch (GameVersionNotSupportedException e) {
logger.debug("Game release {} with engine version {} is not supported. ({})", ghRelease.getHtmlUrl(), tagName, e.getMessage());
} catch (SemverException | IOException e) {
logger.info("Could not create game release from Github release {}: {}", ghRelease.getHtmlUrl(), e.getMessage());
return null;
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

package org.terasology.launcher.repositories;

import com.vdurmont.semver4j.Semver;
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 @@ -86,11 +89,15 @@ private Optional<GameRelease> computeReleaseFrom(Jenkins.Build jenkinsBuildInfo)
if (hasAcceptableResult(jenkinsBuildInfo)) {
final URL url = client.getArtifactUrl(jenkinsBuildInfo, TERASOLOGY_ZIP_PATTERN);

final ReleaseMetadata metadata = computeReleaseMetadataFrom(jenkinsBuildInfo);
final Optional<GameIdentifier> id = computeIdentifierFrom(jenkinsBuildInfo);

if (url != null && id.isPresent()) {
return Optional.of(new GameRelease(id.get(), url, metadata));
final Optional<GameIdentifier> maybeId = computeIdentifierFrom(jenkinsBuildInfo);
if (url != null && maybeId.isPresent()) {
GameIdentifier id = maybeId.get();
try {
final ReleaseMetadata metadata = computeReleaseMetadataFrom(jenkinsBuildInfo, new Semver(id.getDisplayVersion()));
return Optional.of(new GameRelease(id, url, metadata));
} catch (GameVersionNotSupportedException e) {
logger.debug("Skipping build for unsupported engine version {} from {}", id.getDisplayVersion(), jenkinsBuildInfo.url);
}
} else {
logger.debug("Skipping build without game artifact or version identifier: '{}'", jenkinsBuildInfo.url);
}
Expand All @@ -117,11 +124,12 @@ private Optional<GameIdentifier> computeIdentifierFrom(Jenkins.Build jenkinsBuil
});
}

private ReleaseMetadata computeReleaseMetadataFrom(Jenkins.Build jenkinsBuildInfo) {
private ReleaseMetadata computeReleaseMetadataFrom(Jenkins.Build jenkinsBuildInfo, Semver engineVersion) throws GameVersionNotSupportedException {
String changelog = computeChangelogFrom(jenkinsBuildInfo.changeSet);
final Date timestamp = new Date(jenkinsBuildInfo.timestamp);
Semver minJavaVersion = VersionHistory.javaVersionForEngine(engineVersion);
// all builds from this Jenkins are using LWJGL v3
return new ReleaseMetadata(changelog, timestamp);
return new ReleaseMetadata(changelog, timestamp, minJavaVersion);
}

private String computeChangelogFrom(Jenkins.ChangeSet changeSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private void initComboBoxes() {
Set<GameIdentifier> onlineIds = onlineReleases.stream().map(GameRelease::getId).collect(Collectors.toSet());
Stream<GameRelease> localGames = installedGames.stream()
.filter(id -> !onlineIds.contains(id))
.map(id -> new GameRelease(id, null, new ReleaseMetadata("", new Date())));
.map(id -> new GameRelease(id, null, new ReleaseMetadata("", new Date(), new Semver("0.0.1"))));

Stream<GameRelease> allReleases = Stream.concat(onlineReleases.stream(), localGames);

Expand Down

0 comments on commit fb033b0

Please sign in to comment.