Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: sandbox for experimenting with JRE management. #707

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/runConfigurations/Test_All.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions .idea/runConfigurations/run.xml

This file was deleted.

6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Special thanks to everyone that contributed to this release:

### 🧰 Maintenance

- #536 feat: merge 'games' directory into launcher installation directory (@skaldarnar)
- #536 feat: merge 'games' directory into launcher gameInstallation directory (@skaldarnar)
- #534 chore: Resovle Checkstyle warnings (@skaldarnar)
- #529 fix: remove HostServices (only working with Oracle JRE) (@skaldarnar)
- #524 chore(settings): clean up properties (@jdrueckert)
Expand Down Expand Up @@ -386,7 +386,7 @@ Special thanks to everyone that contributed to this release:

- Allow all memory (heap size) values (512 MB - 16 GB)
- Optimize zip file download (checks, logging, timeout, file name, ...)
- Delete content of game installation sub directory before downloading and extracting a game version
- Delete content of game gameInstallation sub directory before downloading and extracting a game version

## 1.3.0 (2014-02-23)

Expand Down Expand Up @@ -440,7 +440,7 @@ Special thanks to everyone that contributed to this release:
## 1.0.0 (2013-07-22)

- Download, install and start the game _Terasology_
- Supports setting a custom game installation directory and managing multiple installations / versions
- Supports setting a custom game gameInstallation directory and managing multiple installations / versions
- Supports three game types
- STABLE : TerasologyStable (master)
- NIGHTLY : Terasology (develop)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<h3 align="center"><b>
<a href="#community">Community</a> |
<a href="#installation-">Installation</a> |
<a href="#gameInstallation-">Installation</a> |
<a href="#features">Features</a> |
<a href="#troubleshooting">Troubleshooting</a> |
<a href="#development">Development</a> |
Expand Down Expand Up @@ -85,7 +85,7 @@ We are present in nearly the complete round-up of social networks. Follow/friend

## Features

The *launcher installation directory* is the folder you extracted the launcher archive into.
The *launcher gameInstallation directory* is the folder you extracted the launcher archive into.
This directory will also hold different versions of _Terasology_ that are installed via the launcher.

On first start-up, the _Terasology Launcher_ will prompt you with the selection of the _Terasology_ data directory.
Expand Down Expand Up @@ -117,7 +117,7 @@ Further, you have access to the social media representation of _Terasology_.

![Terasology Launcher Settings UI](docs/images/200314_TerasologyLauncher_UI-settings.png)

The *settings view* enables you to open the launcher installation, game installation and data directories for quick access.
The *settings view* enables you to open the launcher gameInstallation, game gameInstallation and data directories for quick access.
You can configure the memory settings for the game and even specify additional Java or game arguments as well as the logging level for the game.
Please note, that the "Initial Game Memory" and "Maximum Game Memory" settings only apply to the game itself.
The actual resource consumption may be higher due to additional resources required by the Java Virtual Machine (JVM).
Expand Down Expand Up @@ -218,7 +218,7 @@ Apart from Git, basically everything can be done using the [Gradle][gradle] [wra
</tr>
<tr>
<td width="50%"><code>gradlew install</code></td>
<td width="50%"><i>Create a local runnable installation (placed in <code>./build/install/TerasologyLauncher</code>).</i></td>
<td width="50%"><i>Create a local runnable gameInstallation (placed in <code>./build/install/TerasologyLauncher</code>).</i></td>
</tr>
<tr>
<td width="50%"><code>gradlew run</code></td>
Expand Down
4 changes: 2 additions & 2 deletions buildres/scripts/unixStartScript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ if [ -n "\$JAVA_HOME" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: \$JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
location of your Java gameInstallation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
location of your Java gameInstallation."
fi

# Increase the maximum file descriptors if we can.
Expand Down
4 changes: 2 additions & 2 deletions buildres/scripts/windowsStartScript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo location of your Java gameInstallation.

goto fail

Expand All @@ -68,7 +68,7 @@ echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo location of your Java gameInstallation.

goto fail

Expand Down
Binary file modified buildres/windows64/TerasologyLauncher.x64.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo location of your Java gameInstallation.

goto fail

Expand All @@ -60,7 +60,7 @@ echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo location of your Java gameInstallation.

goto fail

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

import com.google.common.base.MoreObjects;
import com.vdurmont.semver4j.Semver;
import org.terasology.launcher.model.Build;
import org.terasology.launcher.model.GameIdentifier;
import org.terasology.launcher.model.Profile;
import org.terasology.launcher.util.Installation;

import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -24,21 +28,21 @@
/**
* A local installation of a Terasology release.
*/
public class Installation {
final Path path;
public class GameInstallation implements Installation<GameIdentifier> {
private final Path path;

Installation(Path installDirectory) {
GameInstallation(Path installDirectory) {
path = checkNotNull(installDirectory);
}

/**
* Return an Installation after confirming it is present.
*/
static Installation getExisting(Path directory) throws FileNotFoundException {
static GameInstallation getExisting(Path directory) throws FileNotFoundException {
if (!Files.exists(directory)) {
throw new FileNotFoundException("No installation present in " + directory);
}
return new Installation(directory);
return new GameInstallation(directory);
}

/**
Expand All @@ -59,19 +63,19 @@ Semver getEngineVersion() throws IOException {
* build (i.e., custom {@code libs} or default {@code lib}).
*/
Path getGameJarPath() throws IOException {
return findJar(path, Installation::matchGameJar, "game");
return findJar(path, GameInstallation::matchGameJar, "game");
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Installation)) {
if (!(o instanceof GameInstallation)) {
return false;
}

Installation that = (Installation) o;
GameInstallation that = (GameInstallation) o;

return path.equals(that.path);
}
Expand Down Expand Up @@ -115,7 +119,7 @@ static Path findJar(Path searchPath, BiPredicate<Path, BasicFileAttributes> pred
* @throws FileNotFoundException if the engine or the version info could not be found
*/
static Semver getEngineVersion(Path versionDirectory) throws IOException {
Path engineJar = findJar(versionDirectory, Installation::matchEngineJar, "engine");
Path engineJar = findJar(versionDirectory, GameInstallation::matchEngineJar, "engine");
Properties versionInfo = getVersionPropertiesFromJar(engineJar);
return new Semver(versionInfo.getProperty("engineVersion"), Semver.SemverType.IVY);
}
Expand Down Expand Up @@ -189,4 +193,21 @@ static Properties getVersionPropertiesFromJar(Path jarLocation) throws IOExcepti
return properties;
}
}

@Override
public Path getPath() {
return path;
}

@Override
public GameIdentifier getInfo() {
try {
Path jarPath = getGameJarPath();
Properties info = getVersionPropertiesFromJar(jarPath);
//TODO: better derive the game identifier with build and profile from the installation
return new GameIdentifier(info.getProperty("displayVersion"), Build.STABLE, Profile.OMEGA);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
31 changes: 23 additions & 8 deletions src/main/java/org/terasology/launcher/game/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
import org.terasology.launcher.tasks.ProgressListener;
import org.terasology.launcher.util.DownloadException;
import org.terasology.launcher.util.DownloadUtils;
import org.terasology.launcher.util.Downloadable;
import org.terasology.launcher.util.FileUtils;
import org.terasology.launcher.util.Installation;
import org.terasology.launcher.util.Manager;

import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -27,10 +30,11 @@
import java.util.Comparator;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

public class GameManager {
public class GameManager implements Manager<GameIdentifier> {

private static final Logger logger = LoggerFactory.getLogger(GameManager.class);

Expand All @@ -56,13 +60,23 @@ public GameManager(Path cacheDirectory, Path installDirectory) {

/**
* Derive the file name for the downloaded ZIP package from the game release.
*
* @deprecated Use {@link GameRelease#getFilename()} instead.
*/
@Deprecated
private String getFileNameFor(GameRelease release) {
GameIdentifier id = release.getId();
String profileString = id.getProfile().toString().toLowerCase();
String versionString = id.getDisplayVersion();
String buildString = id.getBuild().toString().toLowerCase();
return "terasology-" + profileString + "-" + versionString + "-" + buildString + ".zip";
return release.getFilename();
}

@Override
public CompletableFuture<Installation<GameIdentifier>> install(Downloadable<GameIdentifier> downloadable, ProgressListener listener) throws IOException {
final Path cachedZip = cacheDirectory.resolve(downloadable.getFilename());
if (Files.notExists(cachedZip)) {
final Path cacheZipPart = cachedZip.resolveSibling(cachedZip.getFileName().toString() + ".part");
Files.deleteIfExists(cacheZipPart);
DownloadUtils.downloadToFile(downloadable.getUrl(), cacheZipPart, listener);
}
return null;
}

/**
Expand All @@ -87,6 +101,7 @@ public void install(GameRelease release, ProgressListener listener) throws IOExc
}
}

//TODO: should move to DownloadUtils (or a common DownloadManager abstract class)
private void download(GameRelease release, Path targetLocation, ProgressListener listener)
throws DownloadException, IOException, InterruptedException {
final URL downloadUrl = release.getUrl();
Expand Down Expand Up @@ -142,8 +157,8 @@ public Path getInstallDirectory(GameIdentifier id) {
return installDirectory.resolve(id.getProfile().name()).resolve(id.getBuild().name()).resolve(id.getDisplayVersion());
}

public Installation getInstallation(GameIdentifier id) throws FileNotFoundException {
return Installation.getExisting(getInstallDirectory(id));
public GameInstallation getInstallation(GameIdentifier id) throws FileNotFoundException {
return GameInstallation.getExisting(getInstallDirectory(id));
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/terasology/launcher/game/GameService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* This service starts and monitors the game process.
* <p>
* Its {@linkplain #GameService() constructor} requires no arguments. Use {@link #start(Installation, Settings)} to
* Its {@linkplain #GameService() constructor} requires no arguments. Use {@link #start(GameInstallation, Settings)} to
* start the game process; the zero-argument form of {@code start()} will not have enough information.
* <p>
* The Boolean value of this service is true when it believes the game process has started <em>successfully.</em>
Expand All @@ -44,7 +44,7 @@
public class GameService extends Service<Boolean> {
private static final Logger logger = LoggerFactory.getLogger(GameService.class);

private Installation gamePath;
private GameInstallation gamePath;
private Settings settings;

public GameService() {
Expand All @@ -59,20 +59,20 @@ public GameService() {

/**
* Start a new game process with these settings.
* @param installation the directory under which we will find libs/Terasology.jar, also used as the process's
* @param gameInstallation the directory under which we will find libs/Terasology.jar, also used as the process's
* working directory
* @param settings supplies other settings relevant to configuring a process
*/
@SuppressWarnings("checkstyle:HiddenField")
public void start(Installation installation, Settings settings) {
this.gamePath = installation;
public void start(GameInstallation gameInstallation, Settings settings) {
this.gamePath = gameInstallation;
this.settings = settings;

start();
}

/**
* Use {@link #start(Installation, Settings)} instead.
* Use {@link #start(GameInstallation, Settings)} instead.
* <p>
* It is an error to call this method before providing the configuration.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/terasology/launcher/game/GameStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class GameStarter implements Callable<Process> {
final ProcessBuilder processBuilder;

/**
* @param installation the directory under which we will find {@code libs/Terasology.jar}, also used as the process's
* @param gameInstallation the directory under which we will find {@code libs/Terasology.jar}, also used as the process's
* working directory
* @param gameDataDirectory {@code -homedir}, the directory where Terasology's data files (saves & etc) are kept
* @param heapMin java's {@code -Xms}
Expand All @@ -37,10 +37,10 @@ final class GameStarter implements Callable<Process> {
* @param gameParams additional arguments for the Terasology command line
* @param logLevel the minimum level of log events Terasology will include on its output stream to us
*/
GameStarter(Installation installation, Path gameDataDirectory, JavaHeapSize heapMin, JavaHeapSize heapMax,
GameStarter(GameInstallation gameInstallation, Path gameDataDirectory, JavaHeapSize heapMin, JavaHeapSize heapMax,
List<String> javaParams, List<String> gameParams, Level logLevel) throws IOException, GameVersionNotSupportedException {
Semver engineVersion = installation.getEngineVersion();
var gamePath = installation.path;
Semver engineVersion = gameInstallation.getEngineVersion();
var gamePath = gameInstallation.getPath();

final boolean isMac = Platform.getPlatform().isMac();
final List<String> processParameters = new ArrayList<>();
Expand All @@ -65,7 +65,7 @@ final class GameStarter implements Callable<Process> {
processParameters.addAll(javaParams);

processParameters.add("-jar");
processParameters.add(installation.getGameJarPath().toString());
processParameters.add(gameInstallation.getGameJarPath().toString());

// Parameters after this are for the game facade, not the java runtime.
processParameters.add(homeDirParameter(gameDataDirectory, engineVersion));
Expand Down
Loading
Loading