Skip to content

Commit

Permalink
epic: continue launcher clean-up (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
skaldarnar authored Nov 30, 2020
1 parent 52ef300 commit 0ca6912
Show file tree
Hide file tree
Showing 27 changed files with 94 additions and 314 deletions.
21 changes: 5 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ repositories {
// for spf4j dependencies that haven't been merged upstream
// i.e. org.apache.avro:avro
name "spf4j dependencies"
url "https://dl.bintray.com/zolyfarkas/core"
url "https://dl.bintray.com/zolyfarkas/core"
}
maven {
name "JitPack" // used by org.everit.json.schema
Expand Down Expand Up @@ -201,27 +201,16 @@ def convertGitBranch = { gitBranch ->
}

task createVersionInfoFile {

inputs.property('version', version.toString())

File versionInfoFileDir = new File('src/main/resources', 'org/terasology/launcher/version')
File versionInfoFile = new File(versionInfoFileDir, 'versionInfo.properties')
File versionInfoFileDir = new File(sourceSets.main.output.resourcesDir, 'org/terasology/launcher/')
File versionFile = new File(versionInfoFileDir, 'version.txt')

outputs.file(versionInfoFile)
outputs.file(versionFile)

doLast {
versionInfoFileDir.mkdirs()
ant.propertyfile(file: versionInfoFile) {
ant.entry(key: 'buildNumber', value: env.BUILD_NUMBER)
ant.entry(key: 'buildId', value: env.BUILD_ID)
ant.entry(key: 'buildTag', value: env.BUILD_TAG)
ant.entry(key: 'buildUrl', value: env.BUILD_URL)
ant.entry(key: 'jobName', value: env.JOB_NAME)
ant.entry(key: 'gitBranch', value: convertGitBranch(env.GIT_BRANCH))
ant.entry(key: 'gitCommit', value: env.GIT_COMMIT)
ant.entry(key: 'dateTime', value: startDateTimeString)
ant.entry(key: 'version', value: version)
}
versionFile.text = version
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/terasology/launcher/LauncherInitTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.launcher.game.GameManager;
import org.terasology.launcher.gui.javafx.Dialogs;
import org.terasology.launcher.ui.Dialogs;
import org.terasology.launcher.model.GameIdentifier;
import org.terasology.launcher.model.GameRelease;
import org.terasology.launcher.repositories.RepositoryManager;
Expand All @@ -28,7 +28,7 @@
import org.terasology.launcher.util.LauncherManagedDirectory;
import org.terasology.launcher.util.LauncherStartFailedException;
import org.terasology.launcher.util.Platform;
import org.terasology.launcher.version.TerasologyLauncherVersionInfo;
import org.terasology.launcher.model.LauncherVersion;

import java.io.IOException;
import java.net.URI;
Expand Down Expand Up @@ -172,7 +172,7 @@ private LauncherSettings getLauncherSettings(Path settingsFile) throws LauncherS
private void checkForLauncherUpdates(Path downloadDirectory, Path tempDirectory, boolean saveDownloadedFiles) {
logger.trace("Check for launcher updates...");
updateMessage(BundleUtils.getLabel("splash_launcherUpdateCheck"));
final LauncherUpdater updater = new LauncherUpdater(TerasologyLauncherVersionInfo.getInstance());
final LauncherUpdater updater = new LauncherUpdater(LauncherVersion.getInstance());
final GHRelease release = updater.updateAvailable();
if (release != null) {
logger.info("Launcher update available: {}", release.getTagName());
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/terasology/launcher/TerasologyLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import javafx.util.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.launcher.gui.javafx.ApplicationController;
import org.terasology.launcher.model.LauncherVersion;
import org.terasology.launcher.ui.ApplicationController;
import org.terasology.launcher.util.BundleUtils;
import org.terasology.launcher.util.HostServices;
import org.terasology.launcher.util.Languages;
import org.terasology.launcher.util.LauncherStartFailedException;
import org.terasology.launcher.version.TerasologyLauncherVersionInfo;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -199,7 +199,7 @@ private void logSystemInformation() {
logger.debug("Max. Memory: {} bytes", Runtime.getRuntime().maxMemory());

// TerasologyLauncherVersionInfo
logger.debug("Launcher version: {}", TerasologyLauncherVersionInfo.getInstance());
logger.debug("Launcher version: {}", LauncherVersion.getInstance());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;
import org.terasology.launcher.gui.javafx.FxTimer;
import org.terasology.launcher.ui.FxTimer;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/org/terasology/launcher/model/LauncherVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.launcher.model;

import com.google.common.io.Resources;
import com.vdurmont.semver4j.Semver;
import com.vdurmont.semver4j.SemverException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Optional;

public final class LauncherVersion {

private static final Logger logger = LoggerFactory.getLogger(LauncherVersion.class);
private static final String VERSION_INFO_FILE = "/org/terasology/launcher/version.txt";
private static LauncherVersion instance;

private final Semver semver;

private LauncherVersion(Semver semver) {
this.semver = semver;
}

//TODO: Should this be instantiated once at startup and then passed to respective classes? Prepare for dependency injection
public static synchronized LauncherVersion getInstance() {
if (instance == null) {
String version = "";
Semver semver = null;
try {
version = Resources.toString(Resources.getResource(LauncherVersion.class, VERSION_INFO_FILE), StandardCharsets.UTF_8);
semver = new Semver(version);
} catch (SemverException e) {
logger.error("Failed to load launcher version info from '{}': Invalid semver '{}'.", VERSION_INFO_FILE, version, e);
} catch (IOException e) {
logger.error("Loading launcher version info from '{}' failed.", VERSION_INFO_FILE, e);
}
instance = new LauncherVersion(semver);
}
return instance;
}

public String getDisplayName() {
return Optional.ofNullable(semver).map(Semver::getValue).orElse("n/a");
}

public Semver getSemver() {
return semver;
}

@Override
public String toString() {
return getDisplayName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,15 @@ public final class BaseLauncherSettings extends LauncherSettings {
public static final String PROPERTY_USER_GAME_PARAMETERS = "userGameParameters";
public static final String PROPERTY_LOG_LEVEL = "logLevel";
public static final String PROPERTY_DEFAULT_GAME_JOB = "defaultGameJob";
public static final String PROPERTY_LAST_PLAYED_GAME_JOB = "lastPlayedGameJob";
public static final String PROPERTY_LAST_PLAYED_GAME_VERSION = "lastPlayedGameVersion";
public static final String PROPERTY_LAST_INSTALLED_GAME_JOB = "lastInstalledGameJob";
public static final String PROPERTY_LAST_INSTALLED_GAME_VERSION = "lastInstalledGameVersion";

public static final JavaHeapSize MAX_HEAP_SIZE_DEFAULT = JavaHeapSize.NOT_USED;
public static final JavaHeapSize INITIAL_HEAP_SIZE_DEFAULT = JavaHeapSize.NOT_USED;
public static final boolean SEARCH_FOR_LAUNCHER_UPDATES_DEFAULT = true;
public static final boolean CLOSE_LAUNCHER_AFTER_GAME_START_DEFAULT = true;
public static final boolean SAVE_DOWNLOADED_FILES_DEFAULT = false;
public static final String DEFAULT_GAME_JOB_DEFAULT = "DistroOmegaRelease";
public static final String LAST_PLAYED_GAME_JOB_DEFAULT = "";
public static final String LAST_PLAYED_GAME_VERSION_DEFAULT = "";
public static final String LAST_INSTALLED_GAME_JOB_DEFAULT = "";
public static final String LAST_INSTALLED_GAME_VERSION_DEFAULT = "";

public static final String LAUNCHER_SETTINGS_FILE_NAME = "TerasologyLauncherSettings.properties";
Expand Down Expand Up @@ -197,34 +192,13 @@ protected void initGameDataDirectory() {
}
}

protected void initDefaultGameJob() {
final String defaultGameJobStr = properties.getProperty(PROPERTY_DEFAULT_GAME_JOB);
if (defaultGameJobStr == null || defaultGameJobStr.isEmpty()) {
properties.setProperty(PROPERTY_DEFAULT_GAME_JOB, DEFAULT_GAME_JOB_DEFAULT);
}
}

protected void initLastPlayedGameJob() {
final String lastPlayedGameJobStr = properties.getProperty(PROPERTY_LAST_PLAYED_GAME_JOB);
if (lastPlayedGameJobStr == null || lastPlayedGameJobStr.isEmpty()) {
properties.setProperty(PROPERTY_LAST_PLAYED_GAME_JOB, LAST_PLAYED_GAME_JOB_DEFAULT);
}
}

protected void initLastPlayedGameVersion() {
final String lastPlayedGameVersionStr = properties.getProperty(PROPERTY_LAST_PLAYED_GAME_VERSION);
if (lastPlayedGameVersionStr == null || lastPlayedGameVersionStr.isEmpty()) {
properties.setProperty(PROPERTY_LAST_PLAYED_GAME_VERSION, LAST_PLAYED_GAME_VERSION_DEFAULT);
}
}

protected void initLastInstalledGameJob() {
final String lastInstalledGameJobStr = properties.getProperty(PROPERTY_LAST_INSTALLED_GAME_JOB);
if (lastInstalledGameJobStr == null || lastInstalledGameJobStr.isEmpty()) {
properties.setProperty(PROPERTY_LAST_INSTALLED_GAME_JOB, LAST_INSTALLED_GAME_JOB_DEFAULT);
}
}

protected void initLastInstalledGameVersion() {
final String lastInstalledGameVersionStr = properties.getProperty(PROPERTY_LAST_INSTALLED_GAME_VERSION);
if (lastInstalledGameVersionStr == null || lastInstalledGameVersionStr.isEmpty()) {
Expand Down Expand Up @@ -307,16 +281,6 @@ public synchronized boolean isKeepDownloadedFiles() {
return Boolean.valueOf(properties.getProperty(PROPERTY_SAVE_DOWNLOADED_FILES));
}

@Override
public synchronized String getDefaultGameJob() {
return properties.getProperty(PROPERTY_DEFAULT_GAME_JOB);
}

@Override
public synchronized String getLastPlayedGameJob() {
return properties.getProperty(PROPERTY_LAST_PLAYED_GAME_JOB);
}

@Override
public synchronized Optional<GameIdentifier> getLastPlayedGameVersion() {
String property = properties.getProperty(PROPERTY_LAST_PLAYED_GAME_VERSION);
Expand All @@ -328,12 +292,6 @@ public synchronized String getLastInstalledGameJob() {
return properties.getProperty(PROPERTY_LAST_INSTALLED_GAME_JOB);
}

@Override
public synchronized Optional<GameIdentifier> getLastInstalledGameVersion() {
String property = properties.getProperty(PROPERTY_LAST_INSTALLED_GAME_VERSION);
return Optional.ofNullable(GameIdentifier.fromString(property));
}

// --------------------------------------------------------------------- //
// SETTERS
// --------------------------------------------------------------------- //
Expand Down Expand Up @@ -393,11 +351,6 @@ public synchronized void setDefaultGameJob(String defaultGameJob) {
properties.setProperty(PROPERTY_DEFAULT_GAME_JOB, defaultGameJob);
}

@Override
public synchronized void setLastPlayedGameJob(String lastPlayedGameJob) {
properties.setProperty(PROPERTY_LAST_PLAYED_GAME_JOB, lastPlayedGameJob);
}

@Override
public synchronized void setLastPlayedGameVersion(GameIdentifier lastPlayedGameVersion) {
if (lastPlayedGameVersion == null) {
Expand All @@ -407,20 +360,6 @@ public synchronized void setLastPlayedGameVersion(GameIdentifier lastPlayedGameV
}
}

@Override
public synchronized void setLastInstalledGameJob(String lastInstalledGameJob) {
properties.setProperty(PROPERTY_LAST_INSTALLED_GAME_JOB, lastInstalledGameJob);
}

@Override
public synchronized void setLastInstalledGameVersion(GameIdentifier lastInstalledGameVersion) {
if (lastInstalledGameVersion == null) {
properties.setProperty(PROPERTY_LAST_INSTALLED_GAME_VERSION, "");
} else {
properties.setProperty(PROPERTY_LAST_INSTALLED_GAME_VERSION, lastInstalledGameVersion.toString());
}
}

@Override
public String toString() {
return this.getClass().getName() + "[" + properties.toString() + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public synchronized void init() {
initUserJavaParameters();
initUserGameParameters();
initLogLevel();
initDefaultGameJob();
initLastPlayedGameJob();
initLastPlayedGameVersion();
initLastInstalledGameJob();
initLastInstalledGameVersion();
}

Expand Down Expand Up @@ -70,14 +67,8 @@ public synchronized void init() {

protected abstract void initLocale();

protected abstract void initDefaultGameJob();

protected abstract void initLastPlayedGameJob();

protected abstract void initLastPlayedGameVersion();

protected abstract void initLastInstalledGameJob();

protected abstract void initLastInstalledGameVersion();

// --------------------------------------------------------------------- //
Expand Down Expand Up @@ -125,16 +116,10 @@ public synchronized List<String> getUserGameParameterList() {

public abstract boolean isKeepDownloadedFiles();

public abstract String getDefaultGameJob();

public abstract String getLastPlayedGameJob();

public abstract Optional<GameIdentifier> getLastPlayedGameVersion();

public abstract String getLastInstalledGameJob();

public abstract Optional<GameIdentifier> getLastInstalledGameVersion();

// --------------------------------------------------------------------- //
// SETTERS
// --------------------------------------------------------------------- //
Expand All @@ -161,11 +146,5 @@ public synchronized List<String> getUserGameParameterList() {

public abstract void setDefaultGameJob(String lastPlayedGameJob);

public abstract void setLastPlayedGameJob(String lastPlayedGameJob);

public abstract void setLastPlayedGameVersion(GameIdentifier lastPlayedGameVersion);

public abstract void setLastInstalledGameJob(String lastInstalledGameJob);

public abstract void setLastInstalledGameVersion(GameIdentifier lastInstalledGameVersion);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.launcher.gui.javafx;
package org.terasology.launcher.ui;

import com.google.common.io.Files;
import javafx.fxml.FXML;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.launcher.gui.javafx;
package org.terasology.launcher.ui;

import com.google.common.collect.Lists;
import javafx.animation.Transition;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.launcher.gui.javafx;
package org.terasology.launcher.ui;

import javafx.fxml.FXML;
import javafx.scene.effect.BlendMode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.launcher.gui.javafx;
package org.terasology.launcher.ui;

import javafx.application.Platform;
import javafx.concurrent.Task;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.launcher.gui.javafx;
package org.terasology.launcher.ui;

import javafx.animation.ScaleTransition;
import javafx.scene.Node;
Expand Down
Loading

0 comments on commit 0ca6912

Please sign in to comment.