mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Download the studio app at startup
- Bundle the built app in the Bukkit jar - Fetch the pinned Electron build when the host has a display - Add studio.downloadApp to turn it off
This commit is contained in:
1 parent
c6a7225fa8
commit
9489ffd4ad
34 files changed
+1152
-26
No files matched your search
@@ -21,6 +21,7 @@ package art.arcane.iris;
|
||||
import art.arcane.iris.api.terrain.IrisTerrainService;
|
||||
import art.arcane.iris.command.CommandSVC;
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.studio.app.StudioAppInstaller;
|
||||
import art.arcane.iris.configuration.SettingsHotloadWatch;
|
||||
import art.arcane.iris.diagnostics.LogFilterSVC;
|
||||
import art.arcane.iris.diagnostics.splash.IrisSplashComposer;
|
||||
@@ -976,6 +977,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
||||
return;
|
||||
}
|
||||
BukkitGuiHost.install();
|
||||
StudioAppInstaller.installInBackground();
|
||||
// super.onEnable() already registers this instance as a listener.
|
||||
plugin.enablePlugin();
|
||||
if (IrisStartupValidation.isRestartRequired()) {
|
||||
|
||||
@@ -46,6 +46,7 @@ import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeEntityBehavior;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeStateMerger;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.ModdedServerAccess;
|
||||
|
||||
import art.arcane.iris.studio.app.StudioAppInstaller;
|
||||
import art.arcane.iris.studio.view.GuiHost;
|
||||
import art.arcane.iris.localization.IrisLanguage;
|
||||
import art.arcane.iris.generation.decoration.DecoratorPlatformHooks;
|
||||
@@ -492,6 +493,7 @@ public final class ModdedEngineBootstrap {
|
||||
GuiHost.Provider previousGuiHost = GuiHost.get();
|
||||
ModdedGuiHost.install();
|
||||
rollback.add(() -> GuiHost.set(previousGuiHost));
|
||||
StudioAppInstaller.installInBackground();
|
||||
|
||||
ModdedDecoratorHooks decoratorHooks = new ModdedDecoratorHooks();
|
||||
DecoratorPlatformHooks.Bindings previousDecoratorBindings = DecoratorPlatformHooks.bind(decoratorHooks, decoratorHooks);
|
||||
|
||||
@@ -190,6 +190,63 @@ def generateNoiseNatives = tasks.register('generateNoiseNatives') {
|
||||
}
|
||||
}
|
||||
}
|
||||
// The studio app ships inside the Bukkit jar. The Electron build it runs on is 100+ MB per platform, so it stays out
|
||||
// and is pinned instead: StudioAppInstaller downloads the host's archive from Electron's release at startup and
|
||||
// checks it against these checksums.
|
||||
File studioAppDirectory = file('studio')
|
||||
List<String> electronPlatforms = ['linux-x64', 'linux-arm64', 'win32-x64', 'win32-arm64', 'darwin-x64', 'darwin-arm64']
|
||||
Provider<String> electronVersion = providers.fileContents(layout.projectDirectory.file('studio/package-lock.json')).asText.map { String lock ->
|
||||
(String) ((Map) ((Map) new groovy.json.JsonSlurper().parseText(lock)).packages).get('node_modules/electron').version
|
||||
}
|
||||
List<String> npmCommand = System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('win') ? ['cmd', '/c', 'npm'] : ['npm']
|
||||
def installStudioDependencies = tasks.register('installStudioDependencies', Exec) {
|
||||
inputs.files('studio/package.json', 'studio/package-lock.json')
|
||||
outputs.file('studio/node_modules/.package-lock.json')
|
||||
workingDir(studioAppDirectory)
|
||||
commandLine(npmCommand + ['ci', '--no-audit', '--no-fund'])
|
||||
}
|
||||
def buildStudioApp = tasks.register('buildStudioApp', Exec) {
|
||||
dependsOn(installStudioDependencies)
|
||||
inputs.dir('studio/src')
|
||||
inputs.files('studio/package.json', 'studio/package-lock.json', 'studio/electron.vite.config.ts', 'studio/tsconfig.json', 'studio/components.json')
|
||||
outputs.dir('studio/out')
|
||||
workingDir(studioAppDirectory)
|
||||
commandLine(npmCommand + ['run', 'build'])
|
||||
}
|
||||
def bundleStudioApp = tasks.register('bundleStudioApp', Zip) {
|
||||
from(buildStudioApp) {
|
||||
into('out')
|
||||
}
|
||||
from('studio/package.json')
|
||||
archiveFileName.set('studio-app.zip')
|
||||
destinationDirectory.set(layout.buildDirectory.dir('generated/studio-app'))
|
||||
preserveFileTimestamps = false
|
||||
reproducibleFileOrder = true
|
||||
}
|
||||
def pinElectronRuntime = tasks.register('pinElectronRuntime') {
|
||||
inputs.property('electronVersion', electronVersion)
|
||||
inputs.property('platforms', electronPlatforms)
|
||||
def pins = layout.buildDirectory.file('generated/studio-app-pins/studio-app.properties')
|
||||
outputs.file(pins)
|
||||
doLast {
|
||||
String version = electronVersion.get()
|
||||
String checksums = URI.create("https://github.com/electron/electron/releases/download/v${version}/SHASUMS256.txt")
|
||||
.toURL().getText('UTF-8')
|
||||
Map<String, String> checksumByArchive = checksums.readLines().collectEntries { String line ->
|
||||
def match = line.trim() =~ /^([0-9a-f]{64}) \*?(\S+)$/
|
||||
match.matches() ? [(match.group(2)): match.group(1)] : [:]
|
||||
}
|
||||
List<String> lines = ["electron.version=${version}".toString()]
|
||||
electronPlatforms.each { String platform ->
|
||||
String checksum = checksumByArchive.get("electron-v${version}-${platform}.zip".toString())
|
||||
if (checksum == null) {
|
||||
throw new GradleException("Electron ${version} publishes no ${platform} archive")
|
||||
}
|
||||
lines.add("${platform}.sha256=${checksum}".toString())
|
||||
}
|
||||
pins.get().asFile.setText(lines.join('\n') + '\n', 'UTF-8')
|
||||
}
|
||||
}
|
||||
def jarJar = configurations.create('jarJar')
|
||||
dependencies {
|
||||
add('included', project(path: ':core', configuration: 'shadow'))
|
||||
@@ -208,6 +265,12 @@ tasks.named('jar', Jar).configure {
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
includeEmptyDirs = false
|
||||
from(jarJar)
|
||||
from(bundleStudioApp) {
|
||||
into('META-INF/iris')
|
||||
}
|
||||
from(pinElectronRuntime) {
|
||||
into('META-INF/iris')
|
||||
}
|
||||
from(provider { included.resolve().collect { zipTree(it) } }) {
|
||||
exclude('META-INF/INDEX.LIST')
|
||||
exclude('languages/**')
|
||||
@@ -529,6 +592,8 @@ List<String> requiredBukkitArtifactEntries = [
|
||||
'slimjar-resolutions.dat',
|
||||
'META-INF/iris/native-runtime.properties',
|
||||
NoiseNativeArtifacts.MANIFEST,
|
||||
'META-INF/iris/studio-app.zip',
|
||||
'META-INF/iris/studio-app.properties',
|
||||
'META-INF/volmit/volmlib.properties',
|
||||
'iris-language-source.properties',
|
||||
'agent.jar',
|
||||
|
||||
@@ -404,6 +404,7 @@ public class IrisSettings {
|
||||
public boolean disableTimeAndWeather = true;
|
||||
public boolean entitySpawning = true;
|
||||
public boolean autoStartDefaultStudio = false;
|
||||
public boolean downloadApp = true;
|
||||
public String studioApp = "";
|
||||
public String electron = "electron";
|
||||
}
|
||||
|
||||
@@ -78,7 +78,10 @@ public final class RuntimeUiMessages {
|
||||
public static final TextKey DUST_OBJECTS_IN_CHUNK = TextKey.of("iris.runtime.dust.objects_in_chunk", "Objects in chunk: {objects}");
|
||||
public static final TextKey DUST_COPY_BUTTON = TextKey.of("iris.runtime.dust.copy_button", "[Click to copy these stats]");
|
||||
public static final TextKey DUST_COPY_HOVER = TextKey.of("iris.runtime.dust.copy_hover", "Copy block stats to clipboard");
|
||||
public static final TextKey STUDIO_APP_NOT_CONFIGURED = TextKey.of("iris.runtime.studio.app_not_configured", "Studio app not set up: point studio.studioApp in iris.json at a studio build.");
|
||||
public static final TextKey STUDIO_APP_DOWNLOAD_OFF = TextKey.of("iris.runtime.studio.app_download_off", "Studio app download is off: set studio.downloadApp to true in iris.json.");
|
||||
public static final TextKey STUDIO_APP_NO_DISPLAY = TextKey.of("iris.runtime.studio.app_no_display", "This server has no display to open the studio app on.");
|
||||
public static final TextKey STUDIO_APP_DOWNLOADING = TextKey.of("iris.runtime.studio.app_downloading", "Studio app is still downloading; try again in a moment.");
|
||||
public static final TextKey STUDIO_APP_UNAVAILABLE = TextKey.of("iris.runtime.studio.app_unavailable", "Studio app unavailable; see the console.");
|
||||
public static final TextKey STUDIO_APP_NOT_BUILT = TextKey.of("iris.runtime.studio.app_not_built", "Studio app not built: run npm run build in its folder.");
|
||||
public static final TextKey STUDIO_APP_FAILED_TO_START = TextKey.of("iris.runtime.studio.app_failed_to_start", "Studio app failed to start; see the console.");
|
||||
public static final TextKey STUDIO_LINK_COPY_BUTTON = TextKey.of("iris.runtime.studio.link_copy_button", "[Copy studio link]");
|
||||
@@ -201,7 +204,10 @@ public final class RuntimeUiMessages {
|
||||
DUST_OBJECTS_IN_CHUNK,
|
||||
DUST_COPY_BUTTON,
|
||||
DUST_COPY_HOVER,
|
||||
STUDIO_APP_NOT_CONFIGURED,
|
||||
STUDIO_APP_DOWNLOAD_OFF,
|
||||
STUDIO_APP_NO_DISPLAY,
|
||||
STUDIO_APP_DOWNLOADING,
|
||||
STUDIO_APP_UNAVAILABLE,
|
||||
STUDIO_APP_NOT_BUILT,
|
||||
STUDIO_APP_FAILED_TO_START,
|
||||
STUDIO_LINK_COPY_BUTTON,
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
/** The studio app the jar carries, unpacked into a folder named by its checksum so each build gets its own copy. */
|
||||
final class BundledStudioApp {
|
||||
static final String RESOURCE = "META-INF/iris/studio-app.zip";
|
||||
private static final String FOLDER_PREFIX = "app-";
|
||||
private static final int FOLDER_CHECKSUM_LENGTH = 12;
|
||||
|
||||
private BundledStudioApp() {
|
||||
}
|
||||
|
||||
static Path install(Path root, ClassLoader resources) throws IOException {
|
||||
Path archive = root.resolve("studio-app.zip.part");
|
||||
try {
|
||||
copyResource(resources, archive);
|
||||
Path folder = root.resolve(FOLDER_PREFIX + ElectronRuntime.sha256(archive).substring(0, FOLDER_CHECKSUM_LENGTH));
|
||||
if (!Files.isRegularFile(folder.resolve("package.json"))) {
|
||||
ZipArchives.extract(archive, folder);
|
||||
}
|
||||
return folder;
|
||||
} finally {
|
||||
Files.deleteIfExists(archive);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isAppFolder(Path folder) {
|
||||
return folder.getFileName().toString().startsWith(FOLDER_PREFIX);
|
||||
}
|
||||
|
||||
private static void copyResource(ClassLoader resources, Path archive) throws IOException {
|
||||
try (InputStream input = resources.getResourceAsStream(RESOURCE)) {
|
||||
if (input == null) {
|
||||
throw new IOException("this build does not bundle the studio app; point studio.studioApp at a studio checkout");
|
||||
}
|
||||
Files.createDirectories(archive.getParent());
|
||||
Files.copy(input, archive, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.Duration;
|
||||
import java.util.HexFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* The Electron build the studio app runs on. The build pins its version and each platform's SHA-256 in the studio app
|
||||
* manifest; the archive comes from Electron's own GitHub release and is unpacked once into the studio folder.
|
||||
*/
|
||||
final class ElectronRuntime {
|
||||
private static final String RELEASE_ROOT = "https://github.com/electron/electron/releases/download/";
|
||||
private static final String VERSION_KEY = "electron.version";
|
||||
private static final String CHECKSUM_SUFFIX = ".sha256";
|
||||
private static final Duration CONNECT_TIMEOUT = Duration.ofSeconds(10);
|
||||
private static final Duration DOWNLOAD_TIMEOUT = Duration.ofMinutes(15);
|
||||
|
||||
private final String version;
|
||||
private final Platform platform;
|
||||
private final String sha256;
|
||||
|
||||
private ElectronRuntime(String version, Platform platform, String sha256) {
|
||||
this.version = version;
|
||||
this.platform = platform;
|
||||
this.sha256 = sha256;
|
||||
}
|
||||
|
||||
static ElectronRuntime pinned(Properties manifest, Platform platform) throws IOException {
|
||||
String version = manifest.getProperty(VERSION_KEY);
|
||||
String sha256 = manifest.getProperty(platform.name() + CHECKSUM_SUFFIX);
|
||||
if (version == null || sha256 == null) {
|
||||
throw new IOException("no Electron build is pinned for " + platform.name());
|
||||
}
|
||||
return new ElectronRuntime(version, platform, sha256.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
String folderName() {
|
||||
return "electron-v" + version + "-" + platform.name();
|
||||
}
|
||||
|
||||
URI source() {
|
||||
return URI.create(RELEASE_ROOT + "v" + version + "/" + folderName() + ".zip");
|
||||
}
|
||||
|
||||
/** The Electron executable under {@code root}, downloaded, checked and unpacked first when it is not there yet. */
|
||||
Path install(Path root, Downloader downloader) throws IOException {
|
||||
Path executable = root.resolve(folderName()).resolve(platform.executable());
|
||||
if (Files.isRegularFile(executable)) {
|
||||
return executable;
|
||||
}
|
||||
Path archive = root.resolve(folderName() + ".zip.part");
|
||||
try {
|
||||
downloader.download(source(), archive);
|
||||
requireChecksum(archive);
|
||||
if (platform.macOS()) {
|
||||
ZipArchives.extractWithDitto(archive, root.resolve(folderName()));
|
||||
} else {
|
||||
ZipArchives.extract(archive, root.resolve(folderName()));
|
||||
}
|
||||
} finally {
|
||||
Files.deleteIfExists(archive);
|
||||
}
|
||||
if (!Files.isRegularFile(executable)) {
|
||||
throw new IOException(source() + " has no " + platform.executable());
|
||||
}
|
||||
return executable;
|
||||
}
|
||||
|
||||
private void requireChecksum(Path archive) throws IOException {
|
||||
String actual = sha256(archive);
|
||||
if (!actual.equals(sha256)) {
|
||||
throw new IOException(source() + " failed its checksum (expected " + sha256 + ", got " + actual + ")");
|
||||
}
|
||||
}
|
||||
|
||||
static String sha256(Path file) throws IOException {
|
||||
try (InputStream input = Files.newInputStream(file)) {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
byte[] buffer = new byte[1 << 16];
|
||||
int read;
|
||||
while ((read = input.read(buffer)) >= 0) {
|
||||
digest.update(buffer, 0, read);
|
||||
}
|
||||
return HexFormat.of().formatHex(digest.digest());
|
||||
} catch (NoSuchAlgorithmException missing) {
|
||||
throw new IllegalStateException(missing);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface Downloader {
|
||||
void download(URI source, Path target) throws IOException;
|
||||
|
||||
static Downloader http() {
|
||||
return (source, target) -> {
|
||||
HttpClient client = HttpClient.newBuilder()
|
||||
.connectTimeout(CONNECT_TIMEOUT)
|
||||
.followRedirects(HttpClient.Redirect.NORMAL)
|
||||
.build();
|
||||
HttpRequest request = HttpRequest.newBuilder(source)
|
||||
.timeout(DOWNLOAD_TIMEOUT)
|
||||
.header("User-Agent", "Iris")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<Path> response = client.send(request, HttpResponse.BodyHandlers.ofFile(target));
|
||||
if (response.statusCode() != 200) {
|
||||
throw new IOException(source + " answered HTTP " + response.statusCode());
|
||||
}
|
||||
} catch (InterruptedException interrupted) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IOException("download of " + source + " was interrupted", interrupted);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/** An Electron release platform, named as its archives are, and where the executable sits inside them. */
|
||||
record Platform(String name, String executable) {
|
||||
static Platform current() {
|
||||
return of(System.getProperty("os.name", ""), System.getProperty("os.arch", ""));
|
||||
}
|
||||
|
||||
/** Null for a system Electron publishes no build for. */
|
||||
static Platform of(String operatingSystem, String architecture) {
|
||||
String os = operatingSystem.toLowerCase(Locale.ROOT);
|
||||
String arch = switch (architecture) {
|
||||
case "aarch64", "arm64" -> "arm64";
|
||||
case "amd64", "x86_64" -> "x64";
|
||||
default -> null;
|
||||
};
|
||||
if (arch == null) {
|
||||
return null;
|
||||
}
|
||||
if (os.contains("linux")) {
|
||||
return new Platform("linux-" + arch, "electron");
|
||||
}
|
||||
if (os.contains("win")) {
|
||||
return new Platform("win32-" + arch, "electron.exe");
|
||||
}
|
||||
if (os.contains("mac")) {
|
||||
return new Platform("darwin-" + arch, "Electron.app/Contents/MacOS/Electron");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean macOS() {
|
||||
return name.startsWith("darwin");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
/** A studio app ready to start: the Electron executable and the app folder it runs. */
|
||||
public record StudioAppInstall(Path electron, Path app) {
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.studio.view.GuiHost;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Installs the studio app into the Iris data folder in the background at startup: the app from the jar, and the
|
||||
* Electron build it runs on from Electron's release. Servers without a display skip it, since the window could not
|
||||
* open there anyway.
|
||||
*/
|
||||
public final class StudioAppInstaller {
|
||||
static final String MANIFEST = "META-INF/iris/studio-app.properties";
|
||||
private static final String DATA_FOLDER = "studio";
|
||||
private static final String STAGING_SUFFIX = ".part";
|
||||
|
||||
private static StudioAppState state = StudioAppState.NOT_STARTED;
|
||||
private static StudioAppInstall installed;
|
||||
private static String unavailableReason = "";
|
||||
|
||||
private StudioAppInstaller() {
|
||||
}
|
||||
|
||||
/** Starts the install unless it is done, running, or off; the state it leaves, for a caller about to open the app. */
|
||||
public static synchronized StudioAppState installInBackground() {
|
||||
if (state == StudioAppState.DOWNLOADING || state == StudioAppState.READY || state == StudioAppState.UNAVAILABLE) {
|
||||
return state;
|
||||
}
|
||||
state = blockedState();
|
||||
if (state != StudioAppState.DOWNLOADING) {
|
||||
return state;
|
||||
}
|
||||
Thread.ofPlatform().daemon().name("Iris Studio install").start(StudioAppInstaller::install);
|
||||
return state;
|
||||
}
|
||||
|
||||
public static synchronized StudioAppInstall installed() {
|
||||
return installed;
|
||||
}
|
||||
|
||||
public static synchronized String unavailableReason() {
|
||||
return unavailableReason;
|
||||
}
|
||||
|
||||
static boolean hasDisplay(String operatingSystem, Map<String, String> environment) {
|
||||
String os = operatingSystem.toLowerCase(Locale.ROOT);
|
||||
if (os.contains("win") || os.contains("mac")) {
|
||||
return true;
|
||||
}
|
||||
return isSet(environment.get("DISPLAY")) || isSet(environment.get("WAYLAND_DISPLAY"));
|
||||
}
|
||||
|
||||
private static StudioAppState blockedState() {
|
||||
if (!IrisSettings.get().getStudio().isDownloadApp()) {
|
||||
return StudioAppState.DOWNLOAD_OFF;
|
||||
}
|
||||
if (GuiHost.isDesktopSuppressed() || !hasDisplay(System.getProperty("os.name", ""), System.getenv())) {
|
||||
return StudioAppState.NO_DISPLAY;
|
||||
}
|
||||
return StudioAppState.DOWNLOADING;
|
||||
}
|
||||
|
||||
private static void install() {
|
||||
long startedNanos = System.nanoTime();
|
||||
try {
|
||||
ElectronRuntime.Platform platform = ElectronRuntime.Platform.current();
|
||||
if (platform == null) {
|
||||
throw new IOException("Electron has no build for " + System.getProperty("os.name") + " " + System.getProperty("os.arch"));
|
||||
}
|
||||
ElectronRuntime electron = ElectronRuntime.pinned(manifest(), platform);
|
||||
Path root = IrisPlatforms.get().dataFolder(DATA_FOLDER).toPath();
|
||||
Path executable = installElectron(electron, root);
|
||||
Path app = BundledStudioApp.install(root, StudioAppInstaller.class.getClassLoader());
|
||||
removeStaleInstalls(root, List.of(app, root.resolve(electron.folderName())));
|
||||
ready(new StudioAppInstall(executable, app), (System.nanoTime() - startedNanos) / 1_000_000L);
|
||||
} catch (IOException | RuntimeException error) {
|
||||
unavailable(error.getMessage() == null ? error.getClass().getSimpleName() : error.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static Path installElectron(ElectronRuntime electron, Path root) throws IOException {
|
||||
if (!Files.isDirectory(root.resolve(electron.folderName()))) {
|
||||
IrisLogging.info("Downloading the studio app runtime from %s", electron.source());
|
||||
}
|
||||
return electron.install(root, ElectronRuntime.Downloader.http());
|
||||
}
|
||||
|
||||
private static Properties manifest() throws IOException {
|
||||
Properties manifest = new Properties();
|
||||
try (InputStream input = StudioAppInstaller.class.getClassLoader().getResourceAsStream(MANIFEST)) {
|
||||
if (input == null) {
|
||||
throw new IOException("this build does not bundle the studio app; point studio.studioApp at a studio checkout");
|
||||
}
|
||||
manifest.load(input);
|
||||
}
|
||||
return manifest;
|
||||
}
|
||||
|
||||
/** Drops the Electron builds and app copies earlier versions left, and any half-finished download or unpack. */
|
||||
private static void removeStaleInstalls(Path root, List<Path> current) {
|
||||
try (Stream<Path> children = Files.list(root)) {
|
||||
for (Path child : children.toList()) {
|
||||
if (current.contains(child) || !isInstallArtifact(child)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
ZipArchives.deleteRecursively(child);
|
||||
} catch (IOException error) {
|
||||
IrisLogging.debug("Could not remove the old studio install %s: %s", child, error.getMessage());
|
||||
}
|
||||
}
|
||||
} catch (IOException error) {
|
||||
IrisLogging.debug("Could not list the studio folder %s: %s", root, error.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isInstallArtifact(Path child) {
|
||||
String name = child.getFileName().toString();
|
||||
return name.startsWith("electron-v") || BundledStudioApp.isAppFolder(child) || name.endsWith(STAGING_SUFFIX);
|
||||
}
|
||||
|
||||
private static synchronized void ready(StudioAppInstall install, long elapsedMillis) {
|
||||
installed = install;
|
||||
unavailableReason = "";
|
||||
state = StudioAppState.READY;
|
||||
IrisLogging.info("Studio app ready in %d ms", elapsedMillis);
|
||||
}
|
||||
|
||||
private static synchronized void unavailable(String reason) {
|
||||
installed = null;
|
||||
unavailableReason = reason;
|
||||
state = StudioAppState.UNAVAILABLE;
|
||||
IrisLogging.warn("Studio app unavailable: %s", reason);
|
||||
}
|
||||
|
||||
private static boolean isSet(String value) {
|
||||
return value != null && !value.isBlank();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
/** Where the downloaded studio app stands on this server. */
|
||||
public enum StudioAppState {
|
||||
NOT_STARTED,
|
||||
DOWNLOAD_OFF,
|
||||
NO_DISPLAY,
|
||||
DOWNLOADING,
|
||||
READY,
|
||||
UNAVAILABLE
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.AtomicMoveNotSupportedException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* Unpacks archives into a folder that only appears once it is complete: everything lands in a staging folder first,
|
||||
* which is then moved into place, so a crash halfway never leaves a folder that looks installed.
|
||||
*/
|
||||
final class ZipArchives {
|
||||
private static final long DITTO_TIMEOUT_MINUTES = 5;
|
||||
private static final int FILE_TYPE_MASK = 0170000;
|
||||
private static final int SYMLINK_TYPE = 0120000;
|
||||
private static final int PERMISSION_MASK = 0777;
|
||||
private static final List<PosixFilePermission> PERMISSION_BITS = List.of(
|
||||
PosixFilePermission.OTHERS_EXECUTE, PosixFilePermission.OTHERS_WRITE, PosixFilePermission.OTHERS_READ,
|
||||
PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.GROUP_WRITE, PosixFilePermission.GROUP_READ,
|
||||
PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_READ);
|
||||
|
||||
private ZipArchives() {
|
||||
}
|
||||
|
||||
/** Keeps each entry's Unix mode and symlinks, so executables stay executable. */
|
||||
static void extract(Path archive, Path folder) throws IOException {
|
||||
Path staging = staging(folder);
|
||||
boolean posix = staging.getFileSystem().supportedFileAttributeViews().contains("posix");
|
||||
Map<String, Integer> modes = posix ? unixModes(archive) : Map.of();
|
||||
try (ZipFile zip = new ZipFile(archive.toFile())) {
|
||||
for (ZipEntry entry : Collections.list(zip.entries())) {
|
||||
extractEntry(zip, entry, staging, modes.getOrDefault(entry.getName(), 0), posix);
|
||||
}
|
||||
}
|
||||
moveIntoPlace(staging, folder);
|
||||
}
|
||||
|
||||
/** Unpacks with macOS's ditto, which keeps everything an app bundle relies on. */
|
||||
static void extractWithDitto(Path archive, Path folder) throws IOException {
|
||||
Path staging = staging(folder);
|
||||
Process ditto = new ProcessBuilder("ditto", "-x", "-k", archive.toString(), staging.toString())
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
try {
|
||||
if (!ditto.waitFor(DITTO_TIMEOUT_MINUTES, TimeUnit.MINUTES)) {
|
||||
ditto.destroyForcibly();
|
||||
throw new IOException("ditto did not finish unpacking " + archive);
|
||||
}
|
||||
} catch (InterruptedException interrupted) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IOException("unpacking " + archive + " was interrupted", interrupted);
|
||||
}
|
||||
if (ditto.exitValue() != 0) {
|
||||
throw new IOException("ditto could not unpack " + archive + ": "
|
||||
+ new String(ditto.getInputStream().readAllBytes(), StandardCharsets.UTF_8).trim());
|
||||
}
|
||||
moveIntoPlace(staging, folder);
|
||||
}
|
||||
|
||||
static void deleteRecursively(Path path) throws IOException {
|
||||
if (!Files.exists(path, java.nio.file.LinkOption.NOFOLLOW_LINKS)) {
|
||||
return;
|
||||
}
|
||||
try (Stream<Path> walk = Files.walk(path)) {
|
||||
for (Path entry : walk.sorted(Comparator.reverseOrder()).toList()) {
|
||||
Files.delete(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void extractEntry(ZipFile zip, ZipEntry entry, Path staging, int mode, boolean posix) throws IOException {
|
||||
Path target = insideStaging(staging, staging.resolve(entry.getName()));
|
||||
if (entry.isDirectory()) {
|
||||
Files.createDirectories(target);
|
||||
return;
|
||||
}
|
||||
Files.createDirectories(target.getParent());
|
||||
try (InputStream input = zip.getInputStream(entry)) {
|
||||
if (posix && (mode & FILE_TYPE_MASK) == SYMLINK_TYPE) {
|
||||
Path linkTarget = Path.of(new String(input.readAllBytes(), StandardCharsets.UTF_8));
|
||||
insideStaging(staging, target.getParent().resolve(linkTarget));
|
||||
Files.createSymbolicLink(target, linkTarget);
|
||||
return;
|
||||
}
|
||||
Files.copy(input, target);
|
||||
}
|
||||
if (posix && mode != 0) {
|
||||
Files.setPosixFilePermissions(target, permissions(mode));
|
||||
}
|
||||
}
|
||||
|
||||
private static Path insideStaging(Path staging, Path path) throws IOException {
|
||||
Path normalized = path.normalize();
|
||||
if (!normalized.startsWith(staging)) {
|
||||
throw new IOException("archive entry " + path + " points outside its folder");
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private static Set<PosixFilePermission> permissions(int mode) {
|
||||
Set<PosixFilePermission> permissions = EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE);
|
||||
int bits = mode & PERMISSION_MASK;
|
||||
for (int bit = 0; bit < PERMISSION_BITS.size(); bit++) {
|
||||
if ((bits & (1 << bit)) != 0) {
|
||||
permissions.add(PERMISSION_BITS.get(bit));
|
||||
}
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Each entry's Unix mode, read from the archive's central directory, where zip tools made on Unix keep it in the
|
||||
* high half of the external attributes. {@link ZipFile} reads the entries but not this field.
|
||||
*/
|
||||
static Map<String, Integer> unixModes(Path archive) throws IOException {
|
||||
try (FileChannel channel = FileChannel.open(archive)) {
|
||||
CentralDirectory directory = CentralDirectory.locate(channel);
|
||||
ByteBuffer records = read(channel, directory.offset(), directory.size());
|
||||
Map<String, Integer> modes = new HashMap<>();
|
||||
int position = 0;
|
||||
for (long index = 0; index < directory.entries(); index++) {
|
||||
if (records.getInt(position) != CentralDirectory.ENTRY_SIGNATURE) {
|
||||
throw new IOException(archive + " has a damaged central directory");
|
||||
}
|
||||
int madeBySystem = (records.getShort(position + 4) >> 8) & 0xFF;
|
||||
int nameLength = records.getShort(position + 28) & 0xFFFF;
|
||||
int extraLength = records.getShort(position + 30) & 0xFFFF;
|
||||
int commentLength = records.getShort(position + 32) & 0xFFFF;
|
||||
int externalAttributes = records.getInt(position + 38);
|
||||
byte[] name = new byte[nameLength];
|
||||
records.get(position + 46, name);
|
||||
if (madeBySystem == CentralDirectory.MADE_ON_UNIX) {
|
||||
modes.put(new String(name, StandardCharsets.UTF_8), externalAttributes >>> 16);
|
||||
}
|
||||
position += 46 + nameLength + extraLength + commentLength;
|
||||
}
|
||||
return modes;
|
||||
}
|
||||
}
|
||||
|
||||
private static ByteBuffer read(FileChannel channel, long offset, long length) throws IOException {
|
||||
if (length > Integer.MAX_VALUE - 8 || offset < 0 || offset + length > channel.size()) {
|
||||
throw new IOException("zip structure points outside the archive");
|
||||
}
|
||||
ByteBuffer buffer = ByteBuffer.allocate((int) length).order(ByteOrder.LITTLE_ENDIAN);
|
||||
while (buffer.hasRemaining()) {
|
||||
if (channel.read(buffer, offset + buffer.position()) < 0) {
|
||||
throw new IOException("archive ended early");
|
||||
}
|
||||
}
|
||||
return buffer.flip();
|
||||
}
|
||||
|
||||
private record CentralDirectory(long offset, long size, long entries) {
|
||||
static final int ENTRY_SIGNATURE = 0x02014b50;
|
||||
static final int MADE_ON_UNIX = 3;
|
||||
private static final int END_SIGNATURE = 0x06054b50;
|
||||
private static final int ZIP64_LOCATOR_SIGNATURE = 0x07064b50;
|
||||
private static final int ZIP64_END_SIGNATURE = 0x06064b50;
|
||||
private static final int END_RECORD_LENGTH = 22;
|
||||
private static final int ZIP64_LOCATOR_LENGTH = 20;
|
||||
private static final int MAX_COMMENT_LENGTH = 0xFFFF;
|
||||
|
||||
static CentralDirectory locate(FileChannel channel) throws IOException {
|
||||
long size = channel.size();
|
||||
int tailLength = (int) Math.min(size, END_RECORD_LENGTH + MAX_COMMENT_LENGTH);
|
||||
long tailOffset = size - tailLength;
|
||||
ByteBuffer tail = read(channel, tailOffset, tailLength);
|
||||
for (int end = tailLength - END_RECORD_LENGTH; end >= 0; end--) {
|
||||
if (tail.getInt(end) == END_SIGNATURE) {
|
||||
return fromEndRecord(channel, tail, end, tailOffset + end);
|
||||
}
|
||||
}
|
||||
throw new IOException("not a zip archive");
|
||||
}
|
||||
|
||||
private static CentralDirectory fromEndRecord(FileChannel channel, ByteBuffer tail, int end, long endOffset) throws IOException {
|
||||
long entries = tail.getShort(end + 10) & 0xFFFFL;
|
||||
long size = tail.getInt(end + 12) & 0xFFFFFFFFL;
|
||||
long offset = tail.getInt(end + 16) & 0xFFFFFFFFL;
|
||||
if (entries != 0xFFFFL && size != 0xFFFFFFFFL && offset != 0xFFFFFFFFL) {
|
||||
return new CentralDirectory(offset, size, entries);
|
||||
}
|
||||
ByteBuffer locator = read(channel, endOffset - ZIP64_LOCATOR_LENGTH, ZIP64_LOCATOR_LENGTH);
|
||||
if (locator.getInt(0) != ZIP64_LOCATOR_SIGNATURE) {
|
||||
throw new IOException("zip64 archive without its locator");
|
||||
}
|
||||
ByteBuffer zip64End = read(channel, locator.getLong(8), 56);
|
||||
if (zip64End.getInt(0) != ZIP64_END_SIGNATURE) {
|
||||
throw new IOException("zip64 archive without its end record");
|
||||
}
|
||||
return new CentralDirectory(zip64End.getLong(48), zip64End.getLong(40), zip64End.getLong(32));
|
||||
}
|
||||
}
|
||||
|
||||
private static Path staging(Path folder) throws IOException {
|
||||
Path staging = folder.resolveSibling(folder.getFileName() + ".part");
|
||||
deleteRecursively(staging);
|
||||
Files.createDirectories(staging);
|
||||
return staging;
|
||||
}
|
||||
|
||||
private static void moveIntoPlace(Path staging, Path folder) throws IOException {
|
||||
deleteRecursively(folder);
|
||||
try {
|
||||
Files.move(staging, folder, StandardCopyOption.ATOMIC_MOVE);
|
||||
} catch (AtomicMoveNotSupportedException unsupported) {
|
||||
Files.move(staging, folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,10 @@ import art.arcane.volmlib.util.localization.TextKey;
|
||||
/** How a request to show the studio window ended; every outcome but {@link #OPENED} leaves the bridge link as the only way in. */
|
||||
public enum StudioLaunch {
|
||||
OPENED(null),
|
||||
NOT_CONFIGURED(RuntimeUiMessages.STUDIO_APP_NOT_CONFIGURED),
|
||||
DOWNLOAD_OFF(RuntimeUiMessages.STUDIO_APP_DOWNLOAD_OFF),
|
||||
NO_DISPLAY(RuntimeUiMessages.STUDIO_APP_NO_DISPLAY),
|
||||
DOWNLOADING(RuntimeUiMessages.STUDIO_APP_DOWNLOADING),
|
||||
UNAVAILABLE(RuntimeUiMessages.STUDIO_APP_UNAVAILABLE),
|
||||
NOT_BUILT(RuntimeUiMessages.STUDIO_APP_NOT_BUILT),
|
||||
FAILED_TO_START(RuntimeUiMessages.STUDIO_APP_FAILED_TO_START);
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ package art.arcane.iris.studio.bridge;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.studio.app.StudioAppInstall;
|
||||
import art.arcane.iris.studio.app.StudioAppInstaller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -28,7 +30,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Opens the Iris Studio window on a bridge, from the app folder the studio settings name. The app keeps one window:
|
||||
* Opens the Iris Studio window on a bridge, from the studio checkout the settings name or else from the app the
|
||||
* server downloaded at startup. The app keeps one window:
|
||||
* a second start hands its link to the open window and exits. Windows the server started close when it stops, as
|
||||
* their bridges go with it.
|
||||
*/
|
||||
@@ -45,18 +48,41 @@ public final class StudioWindow {
|
||||
|
||||
public static synchronized StudioLaunch show(StudioBridge bridge) {
|
||||
IrisSettings.IrisSettingsStudio settings = IrisSettings.get().getStudio();
|
||||
String appFolder = settings.getStudioApp();
|
||||
if (appFolder == null || appFolder.isBlank()) {
|
||||
return StudioLaunch.NOT_CONFIGURED;
|
||||
String checkout = settings.getStudioApp();
|
||||
if (checkout != null && !checkout.isBlank()) {
|
||||
return showCheckout(Path.of(checkout), electronBinary(settings), bridge.link());
|
||||
}
|
||||
Path app = Path.of(appFolder);
|
||||
return showDownloaded(bridge.link());
|
||||
}
|
||||
|
||||
private static StudioLaunch showCheckout(Path app, String electron, String link) {
|
||||
if (!Files.isRegularFile(app.resolve(BUILT_MAIN))) {
|
||||
IrisLogging.warn("Iris Studio is not built in %s; run npm run build there.", app);
|
||||
return StudioLaunch.NOT_BUILT;
|
||||
}
|
||||
return launch(electron, app, link);
|
||||
}
|
||||
|
||||
private static StudioLaunch showDownloaded(String link) {
|
||||
return switch (StudioAppInstaller.installInBackground()) {
|
||||
case READY -> {
|
||||
StudioAppInstall install = StudioAppInstaller.installed();
|
||||
yield launch(install.electron().toString(), install.app(), link);
|
||||
}
|
||||
case NOT_STARTED, DOWNLOADING -> StudioLaunch.DOWNLOADING;
|
||||
case DOWNLOAD_OFF -> StudioLaunch.DOWNLOAD_OFF;
|
||||
case NO_DISPLAY -> StudioLaunch.NO_DISPLAY;
|
||||
case UNAVAILABLE -> {
|
||||
IrisLogging.warn("Studio app unavailable: %s", StudioAppInstaller.unavailableReason());
|
||||
yield StudioLaunch.UNAVAILABLE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static StudioLaunch launch(String electron, Path app, String link) {
|
||||
try {
|
||||
STARTED.removeIf(process -> !process.isAlive());
|
||||
STARTED.add(start(electronBinary(settings), app, bridge.link()));
|
||||
STARTED.add(start(electron, app, link));
|
||||
return StudioLaunch.OPENED;
|
||||
} catch (IOException error) {
|
||||
IrisLogging.warn("Could not open Iris Studio: %s", error.getMessage());
|
||||
|
||||
@@ -1580,7 +1580,10 @@ failed_fragment = " fehlgeschlagen {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aWelt '{world}' verwendet bereits {pack} v{version} mit denselben Generierungseinstellungen. Kein Neustart erforderlich."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "Studio-App nicht eingerichtet: Setze studio.studioApp in iris.json auf einen Studio-Build."
|
||||
app_download_off = "Studio-App-Download ist aus: Setze studio.downloadApp in iris.json auf true."
|
||||
app_no_display = "Dieser Server hat keine Anzeige, auf der sich die Studio-App öffnen kann."
|
||||
app_downloading = "Die Studio-App wird noch heruntergeladen; versuche es gleich noch einmal."
|
||||
app_unavailable = "Studio-App nicht verfügbar; siehe Konsole."
|
||||
app_not_built = "Studio-App nicht gebaut: Führe npm run build in ihrem Ordner aus."
|
||||
app_failed_to_start = "Studio-App konnte nicht starten; siehe Konsole."
|
||||
link_copy_button = "[Studio-Link kopieren]"
|
||||
|
||||
@@ -1580,7 +1580,10 @@ failed_fragment = " fallidos {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aEl mundo '{world}' ya usa {pack} v{version} con los mismos ajustes de generación. No hace falta reiniciar."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "La app de Studio no está configurada: apunta studio.studioApp en iris.json a una compilación de Studio."
|
||||
app_download_off = "La descarga de la app de Studio está desactivada: pon studio.downloadApp a true en iris.json."
|
||||
app_no_display = "Este servidor no tiene pantalla donde abrir la app de Studio."
|
||||
app_downloading = "La app de Studio aún se está descargando; vuelve a intentarlo en un momento."
|
||||
app_unavailable = "La app de Studio no está disponible; consulta la consola."
|
||||
app_not_built = "La app de Studio no está compilada: ejecuta npm run build en su carpeta."
|
||||
app_failed_to_start = "La app de Studio no pudo iniciarse; consulta la consola."
|
||||
link_copy_button = "[Copiar enlace de Studio]"
|
||||
|
||||
@@ -1585,7 +1585,10 @@ failed_fragment = " epäonnistui {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aMaailma '{world}' käyttää jo pakettia {pack} v{version} samoilla generointiasetuksilla. Uudelleenkäynnistystä ei tarvita."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "Studio-sovellusta ei ole määritetty: osoita studio.studioApp tiedostossa iris.json Studio-käännökseen."
|
||||
app_download_off = "Studio-sovelluksen lataus on pois päältä: aseta studio.downloadApp arvoon true tiedostossa iris.json."
|
||||
app_no_display = "Tällä palvelimella ei ole näyttöä, jolla Studio-sovelluksen voisi avata."
|
||||
app_downloading = "Studio-sovellusta ladataan vielä; yritä hetken päästä uudelleen."
|
||||
app_unavailable = "Studio-sovellus ei ole käytettävissä; katso konsoli."
|
||||
app_not_built = "Studio-sovellusta ei ole käännetty: suorita npm run build sen kansiossa."
|
||||
app_failed_to_start = "Studio-sovelluksen käynnistys epäonnistui; katso konsoli."
|
||||
link_copy_button = "[Kopioi Studio-linkki]"
|
||||
|
||||
@@ -1580,7 +1580,10 @@ failed_fragment = " échecs {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aLe monde '{world}' utilise déjà {pack} v{version} avec les mêmes paramètres de génération. Aucun redémarrage nécessaire."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "Application Studio non configurée : faites pointer studio.studioApp dans iris.json vers un build de Studio."
|
||||
app_download_off = "Le téléchargement de l'application Studio est désactivé : mettez studio.downloadApp à true dans iris.json."
|
||||
app_no_display = "Ce serveur n'a pas d'écran pour ouvrir l'application Studio."
|
||||
app_downloading = "L'application Studio est encore en téléchargement ; réessayez dans un instant."
|
||||
app_unavailable = "Application Studio indisponible ; consultez la console."
|
||||
app_not_built = "Application Studio non compilée : lancez npm run build dans son dossier."
|
||||
app_failed_to_start = "L'application Studio n'a pas pu démarrer ; consultez la console."
|
||||
link_copy_button = "[Copier le lien Studio]"
|
||||
|
||||
@@ -1585,7 +1585,10 @@ failed_fragment = " נכשל {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aהעולם '{world}' כבר משתמש בחבילה {pack} v{version} עם אותן הגדרות יצירה. אין צורך בהפעלה מחדש."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "אפליקציית Studio לא הוגדרה: הפנה את studio.studioApp בקובץ iris.json לבנייה של Studio."
|
||||
app_download_off = "הורדת אפליקציית Studio כבויה: הגדר את studio.downloadApp ל-true בקובץ iris.json."
|
||||
app_no_display = "לשרת הזה אין מסך שבו אפשר לפתוח את אפליקציית Studio."
|
||||
app_downloading = "אפליקציית Studio עדיין יורדת; נסה שוב בעוד רגע."
|
||||
app_unavailable = "אפליקציית Studio אינה זמינה; ראה את הקונסולה."
|
||||
app_not_built = "אפליקציית Studio לא נבנתה: הרץ npm run build בתיקייה שלה."
|
||||
app_failed_to_start = "אפליקציית Studio לא הצליחה לעלות; ראה את הקונסולה."
|
||||
link_copy_button = "[העתק קישור Studio]"
|
||||
|
||||
@@ -1580,7 +1580,10 @@ failed_fragment = " non riusciti {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aIl mondo '{world}' usa già {pack} v{version} con le stesse impostazioni di generazione. Non serve riavviare."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "App Studio non configurata: imposta studio.studioApp in iris.json su una build di Studio."
|
||||
app_download_off = "Il download dell'app Studio è disattivato: imposta studio.downloadApp su true in iris.json."
|
||||
app_no_display = "Questo server non ha uno schermo su cui aprire l'app Studio."
|
||||
app_downloading = "L'app Studio è ancora in download; riprova tra un momento."
|
||||
app_unavailable = "App Studio non disponibile; controlla la console."
|
||||
app_not_built = "App Studio non compilata: esegui npm run build nella sua cartella."
|
||||
app_failed_to_start = "Impossibile avviare l'app Studio; controlla la console."
|
||||
link_copy_button = "[Copia link Studio]"
|
||||
|
||||
@@ -1583,7 +1583,10 @@ failed_fragment = " 失敗 {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aワールド '{world}' は同じ生成設定の {pack} v{version} を使用しています。再起動は不要です。"
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "Studio アプリが未設定です: iris.json の studio.studioApp に Studio のビルドを指定してください。"
|
||||
app_download_off = "Studio アプリのダウンロードがオフです: iris.json の studio.downloadApp を true にしてください。"
|
||||
app_no_display = "このサーバーには Studio アプリを開くディスプレイがありません。"
|
||||
app_downloading = "Studio アプリはまだダウンロード中です。少し待ってから再試行してください。"
|
||||
app_unavailable = "Studio アプリを利用できません。コンソールを確認してください。"
|
||||
app_not_built = "Studio アプリがビルドされていません: そのフォルダで npm run build を実行してください。"
|
||||
app_failed_to_start = "Studio アプリを起動できませんでした。コンソールを確認してください。"
|
||||
link_copy_button = "[Studio リンクをコピー]"
|
||||
|
||||
@@ -1583,7 +1583,10 @@ failed_fragment = " 실패 {failed}"
|
||||
"commandpack.update_world_unchanged" = "§a월드 '{world}'는 이미 같은 생성 설정으로 {pack} v{version}을 사용 중입니다. 재시작할 필요가 없습니다."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "Studio 앱이 설정되지 않았습니다: iris.json의 studio.studioApp을 Studio 빌드로 지정하세요."
|
||||
app_download_off = "Studio 앱 다운로드가 꺼져 있습니다: iris.json에서 studio.downloadApp을 true로 설정하세요."
|
||||
app_no_display = "이 서버에는 Studio 앱을 열 디스플레이가 없습니다."
|
||||
app_downloading = "Studio 앱을 아직 다운로드하는 중입니다. 잠시 후 다시 시도하세요."
|
||||
app_unavailable = "Studio 앱을 사용할 수 없습니다. 콘솔을 확인하세요."
|
||||
app_not_built = "Studio 앱이 빌드되지 않았습니다: 해당 폴더에서 npm run build를 실행하세요."
|
||||
app_failed_to_start = "Studio 앱을 시작하지 못했습니다. 콘솔을 확인하세요."
|
||||
link_copy_button = "[Studio 링크 복사]"
|
||||
|
||||
@@ -1585,7 +1585,10 @@ failed_fragment = " nepavyko {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aPasaulis '{world}' jau naudoja {pack} v{version} su tais pačiais generavimo nustatymais. Paleisti iš naujo nereikia."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "Studio programa nenustatyta: iris.json faile nurodykite studio.studioApp į Studio versiją."
|
||||
app_download_off = "Studio programos atsisiuntimas išjungtas: iris.json faile nustatykite studio.downloadApp į true."
|
||||
app_no_display = "Šis serveris neturi ekrano, kuriame būtų galima atidaryti Studio programą."
|
||||
app_downloading = "Studio programa dar atsisiunčiama; netrukus bandykite dar kartą."
|
||||
app_unavailable = "Studio programa nepasiekiama; žr. konsolę."
|
||||
app_not_built = "Studio programa nesukompiliuota: jos aplanke paleiskite npm run build."
|
||||
app_failed_to_start = "Nepavyko paleisti Studio programos; žr. konsolę."
|
||||
link_copy_button = "[Kopijuoti Studio nuorodą]"
|
||||
|
||||
@@ -1580,7 +1580,10 @@ failed_fragment = " mislukt {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aWereld '{world}' gebruikt al {pack} v{version} met dezelfde generatie-instellingen. Herstarten is niet nodig."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "Studio-app niet ingesteld: wijs studio.studioApp in iris.json naar een Studio-build."
|
||||
app_download_off = "Download van de Studio-app staat uit: zet studio.downloadApp op true in iris.json."
|
||||
app_no_display = "Deze server heeft geen scherm om de Studio-app op te openen."
|
||||
app_downloading = "De Studio-app wordt nog gedownload; probeer het zo opnieuw."
|
||||
app_unavailable = "Studio-app niet beschikbaar; zie de console."
|
||||
app_not_built = "Studio-app niet gebouwd: voer npm run build uit in de map."
|
||||
app_failed_to_start = "Studio-app kon niet starten; zie de console."
|
||||
link_copy_button = "[Studio-link kopiëren]"
|
||||
|
||||
@@ -1585,7 +1585,10 @@ failed_fragment = " nieudane {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aŚwiat '{world}' już używa {pack} v{version} z tymi samymi ustawieniami generowania. Restart nie jest potrzebny."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "Aplikacja Studio nie jest skonfigurowana: ustaw studio.studioApp w iris.json na build Studio."
|
||||
app_download_off = "Pobieranie aplikacji Studio jest wyłączone: ustaw studio.downloadApp na true w iris.json."
|
||||
app_no_display = "Ten serwer nie ma ekranu, na którym można otworzyć aplikację Studio."
|
||||
app_downloading = "Aplikacja Studio wciąż się pobiera; spróbuj ponownie za chwilę."
|
||||
app_unavailable = "Aplikacja Studio jest niedostępna; sprawdź konsolę."
|
||||
app_not_built = "Aplikacja Studio nie jest zbudowana: uruchom npm run build w jej folderze."
|
||||
app_failed_to_start = "Nie udało się uruchomić aplikacji Studio; sprawdź konsolę."
|
||||
link_copy_button = "[Kopiuj link Studio]"
|
||||
|
||||
@@ -1580,7 +1580,10 @@ failed_fragment = " falhou {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aO mundo '{world}' já utiliza {pack} v{version} com as mesmas definições de geração. Não é necessário reiniciar."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "A app Studio não está configurada: aponta studio.studioApp no iris.json para uma build do Studio."
|
||||
app_download_off = "A transferência da app Studio está desligada: define studio.downloadApp como true no iris.json."
|
||||
app_no_display = "Este servidor não tem ecrã onde abrir a app Studio."
|
||||
app_downloading = "A app Studio ainda está a ser transferida; tenta novamente daqui a pouco."
|
||||
app_unavailable = "A app Studio não está disponível; vê a consola."
|
||||
app_not_built = "A app Studio não está compilada: executa npm run build na pasta dela."
|
||||
app_failed_to_start = "Não foi possível iniciar a app Studio; vê a consola."
|
||||
link_copy_button = "[Copiar link do Studio]"
|
||||
|
||||
@@ -1585,7 +1585,10 @@ failed_fragment = " ошибок {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aМир '{world}' уже использует {pack} v{version} с теми же настройками генерации. Перезапуск не требуется."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "Приложение Studio не настроено: укажите в studio.studioApp в iris.json сборку Studio."
|
||||
app_download_off = "Загрузка приложения Studio отключена: установите studio.downloadApp в true в iris.json."
|
||||
app_no_display = "У этого сервера нет дисплея, на котором можно открыть приложение Studio."
|
||||
app_downloading = "Приложение Studio ещё загружается; попробуйте снова через минуту."
|
||||
app_unavailable = "Приложение Studio недоступно; см. консоль."
|
||||
app_not_built = "Приложение Studio не собрано: выполните npm run build в его папке."
|
||||
app_failed_to_start = "Не удалось запустить приложение Studio; см. консоль."
|
||||
link_copy_button = "[Копировать ссылку Studio]"
|
||||
|
||||
@@ -1585,7 +1585,10 @@ failed_fragment = " başarısız {failed}"
|
||||
"commandpack.update_world_unchanged" = "§a'{world}' dünyası aynı üretim ayarlarıyla zaten {pack} v{version} kullanıyor. Yeniden başlatma gerekmiyor."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "Studio uygulaması ayarlanmamış: iris.json içindeki studio.studioApp değerini bir Studio derlemesine yönlendir."
|
||||
app_download_off = "Studio uygulaması indirmesi kapalı: iris.json içinde studio.downloadApp değerini true yap."
|
||||
app_no_display = "Bu sunucuda Studio uygulamasını açacak bir ekran yok."
|
||||
app_downloading = "Studio uygulaması hâlâ indiriliyor; birazdan tekrar dene."
|
||||
app_unavailable = "Studio uygulaması kullanılamıyor; konsola bak."
|
||||
app_not_built = "Studio uygulaması derlenmemiş: klasöründe npm run build çalıştır."
|
||||
app_failed_to_start = "Studio uygulaması başlatılamadı; konsola bak."
|
||||
link_copy_button = "[Studio bağlantısını kopyala]"
|
||||
|
||||
@@ -1583,7 +1583,10 @@ failed_fragment = " lỗi {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aThế giới '{world}' đã dùng {pack} v{version} với cùng thiết lập tạo địa hình. Không cần khởi động lại."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "Ứng dụng Studio chưa được thiết lập: trỏ studio.studioApp trong iris.json tới một bản build Studio."
|
||||
app_download_off = "Tải ứng dụng Studio đang tắt: đặt studio.downloadApp thành true trong iris.json."
|
||||
app_no_display = "Máy chủ này không có màn hình để mở ứng dụng Studio."
|
||||
app_downloading = "Ứng dụng Studio vẫn đang tải; hãy thử lại sau giây lát."
|
||||
app_unavailable = "Ứng dụng Studio không khả dụng; xem console."
|
||||
app_not_built = "Ứng dụng Studio chưa được build: chạy npm run build trong thư mục của nó."
|
||||
app_failed_to_start = "Không khởi động được ứng dụng Studio; xem console."
|
||||
link_copy_button = "[Sao chép liên kết Studio]"
|
||||
|
||||
@@ -1583,7 +1583,10 @@ failed_fragment = " 失败 {failed}"
|
||||
"commandpack.update_world_unchanged" = "§a世界 '{world}' 已使用 {pack} v{version},且生成设置相同。无需重启。"
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "Studio 应用未设置:请在 iris.json 中将 studio.studioApp 指向 Studio 构建。"
|
||||
app_download_off = "Studio 应用下载已关闭:请在 iris.json 中将 studio.downloadApp 设为 true。"
|
||||
app_no_display = "此服务器没有可打开 Studio 应用的显示器。"
|
||||
app_downloading = "Studio 应用仍在下载;请稍后再试。"
|
||||
app_unavailable = "Studio 应用不可用;请查看控制台。"
|
||||
app_not_built = "Studio 应用未构建:请在其文件夹中运行 npm run build。"
|
||||
app_failed_to_start = "Studio 应用启动失败;请查看控制台。"
|
||||
link_copy_button = "[复制 Studio 链接]"
|
||||
|
||||
@@ -1583,7 +1583,10 @@ failed_fragment = " 失敗 {failed}"
|
||||
"commandpack.update_world_unchanged" = "§a世界 '{world}' 已使用 {pack} v{version},且生成設定相同。無需重新啟動。"
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_not_configured = "Studio 應用程式未設定:請在 iris.json 中將 studio.studioApp 指向 Studio 建置。"
|
||||
app_download_off = "Studio 應用程式下載已關閉:請在 iris.json 中將 studio.downloadApp 設為 true。"
|
||||
app_no_display = "此伺服器沒有可開啟 Studio 應用程式的顯示器。"
|
||||
app_downloading = "Studio 應用程式仍在下載;請稍後再試。"
|
||||
app_unavailable = "Studio 應用程式無法使用;請查看主控台。"
|
||||
app_not_built = "Studio 應用程式未建置:請在其資料夾中執行 npm run build。"
|
||||
app_failed_to_start = "Studio 應用程式無法啟動;請查看主控台。"
|
||||
link_copy_button = "[複製 Studio 連結]"
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BundledStudioAppTest {
|
||||
@Rule
|
||||
public TemporaryFolder temporary = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void unpacksTheBundledAppIntoAFolderNamedByItsChecksum() throws IOException {
|
||||
Path root = temporary.newFolder("studio").toPath();
|
||||
|
||||
try (URLClassLoader resources = jarResources(appArchive("out/main/index.js"))) {
|
||||
Path app = BundledStudioApp.install(root, resources);
|
||||
|
||||
assertTrue(app.getFileName().toString().matches("app-[0-9a-f]{12}"));
|
||||
assertTrue(Files.isRegularFile(app.resolve("package.json")));
|
||||
assertTrue(Files.isRegularFile(app.resolve("out/main/index.js")));
|
||||
assertEquals(app, BundledStudioApp.install(root, resources));
|
||||
assertFalse(Files.exists(root.resolve("studio-app.zip.part")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refusesAnArchiveEntryThatLeavesItsFolder() throws IOException {
|
||||
Path root = temporary.newFolder("studio").toPath();
|
||||
|
||||
try (URLClassLoader resources = jarResources(appArchive("../../escaped.js"))) {
|
||||
assertThrows(IOException.class, () -> BundledStudioApp.install(root, resources));
|
||||
}
|
||||
assertFalse(Files.exists(root.getParent().resolve("escaped.js")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reportsABuildWithoutTheApp() throws IOException {
|
||||
Path root = temporary.newFolder("studio").toPath();
|
||||
|
||||
try (URLClassLoader resources = new URLClassLoader(new URL[0], null)) {
|
||||
assertThrows(IOException.class, () -> BundledStudioApp.install(root, resources));
|
||||
}
|
||||
}
|
||||
|
||||
private Path appArchive(String scriptEntry) throws IOException {
|
||||
Path archive = temporary.newFolder().toPath().resolve("studio-app.zip");
|
||||
try (ZipOutputStream zip = new ZipOutputStream(Files.newOutputStream(archive))) {
|
||||
zip.putNextEntry(new ZipEntry("package.json"));
|
||||
zip.write("{\"main\":\"out/main/index.js\"}".getBytes(StandardCharsets.UTF_8));
|
||||
zip.closeEntry();
|
||||
zip.putNextEntry(new ZipEntry(scriptEntry));
|
||||
zip.write("export {}".getBytes(StandardCharsets.UTF_8));
|
||||
zip.closeEntry();
|
||||
}
|
||||
return archive;
|
||||
}
|
||||
|
||||
private URLClassLoader jarResources(Path archive) throws IOException {
|
||||
Path classpath = temporary.newFolder().toPath();
|
||||
Path resource = classpath.resolve(BundledStudioApp.RESOURCE);
|
||||
Files.createDirectories(resource.getParent());
|
||||
Files.copy(archive, resource);
|
||||
return new URLClassLoader(new URL[]{classpath.toUri().toURL()}, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ElectronRuntimeTest {
|
||||
private static final ElectronRuntime.Platform LINUX = new ElectronRuntime.Platform("linux-x64", "electron");
|
||||
private static final String ELECTRON_FIXTURE = "/studio-app/electron-fixture.zip";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporary = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void namesPlatformsTheWayElectronReleasesDo() {
|
||||
assertEquals("linux-x64", ElectronRuntime.Platform.of("Linux", "amd64").name());
|
||||
assertEquals("linux-arm64", ElectronRuntime.Platform.of("Linux", "aarch64").name());
|
||||
assertEquals("electron.exe", ElectronRuntime.Platform.of("Windows 11", "amd64").executable());
|
||||
assertEquals("Electron.app/Contents/MacOS/Electron", ElectronRuntime.Platform.of("Mac OS X", "aarch64").executable());
|
||||
assertNull(ElectronRuntime.Platform.of("FreeBSD", "amd64"));
|
||||
assertNull(ElectronRuntime.Platform.of("Linux", "riscv64"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void downloadsFromTheElectronReleaseOfThePinnedVersion() throws IOException {
|
||||
ElectronRuntime electron = ElectronRuntime.pinned(pins("45.2.3", "0".repeat(64)), LINUX);
|
||||
|
||||
assertEquals(URI.create("https://github.com/electron/electron/releases/download/v45.2.3/electron-v45.2.3-linux-x64.zip"),
|
||||
electron.source());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refusesAPlatformTheBuildDidNotPin() {
|
||||
assertThrows(IOException.class, () -> ElectronRuntime.pinned(pins("45.2.3", "0".repeat(64)),
|
||||
new ElectronRuntime.Platform("darwin-arm64", "Electron.app/Contents/MacOS/Electron")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unpacksAVerifiedArchiveWithItsExecutableBitOnce() throws IOException {
|
||||
Path archive = electronArchive();
|
||||
Path root = temporary.newFolder("studio").toPath();
|
||||
ElectronRuntime electron = ElectronRuntime.pinned(pins("45.2.3", ElectronRuntime.sha256(archive)), LINUX);
|
||||
List<URI> downloads = new ArrayList<>();
|
||||
ElectronRuntime.Downloader downloader = (source, target) -> {
|
||||
downloads.add(source);
|
||||
Files.copy(archive, target);
|
||||
};
|
||||
|
||||
Path executable = electron.install(root, downloader);
|
||||
electron.install(root, downloader);
|
||||
|
||||
assertEquals(root.resolve("electron-v45.2.3-linux-x64/electron"), executable);
|
||||
Path lib = root.resolve("electron-v45.2.3-linux-x64/lib");
|
||||
assertTrue(Files.getPosixFilePermissions(executable).contains(PosixFilePermission.OWNER_EXECUTE));
|
||||
assertFalse(Files.getPosixFilePermissions(lib.resolve("libffmpeg.so")).contains(PosixFilePermission.OWNER_EXECUTE));
|
||||
assertEquals(Path.of("libffmpeg.so"), Files.readSymbolicLink(lib.resolve("libffmpeg.so.1")));
|
||||
assertEquals("library", Files.readString(lib.resolve("libffmpeg.so.1")));
|
||||
assertEquals(1, downloads.size());
|
||||
assertFalse(Files.exists(root.resolve("electron-v45.2.3-linux-x64.zip.part")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leavesNothingInstalledWhenTheChecksumIsWrong() throws IOException {
|
||||
Path archive = electronArchive();
|
||||
Path root = temporary.newFolder("studio").toPath();
|
||||
ElectronRuntime electron = ElectronRuntime.pinned(pins("45.2.3", "0".repeat(64)), LINUX);
|
||||
|
||||
assertThrows(IOException.class, () -> electron.install(root, (source, target) -> Files.copy(archive, target)));
|
||||
|
||||
try (var children = Files.list(root)) {
|
||||
assertEquals(List.of(), children.toList());
|
||||
}
|
||||
}
|
||||
|
||||
/** Made by Info-ZIP, as Electron's archives are: an executable, a plain file and a symlink to it. */
|
||||
private Path electronArchive() throws IOException {
|
||||
Path archive = temporary.getRoot().toPath().resolve("electron.zip");
|
||||
try (InputStream fixture = ElectronRuntimeTest.class.getResourceAsStream(ELECTRON_FIXTURE)) {
|
||||
Files.copy(fixture, archive);
|
||||
}
|
||||
return archive;
|
||||
}
|
||||
|
||||
private static Properties pins(String version, String linuxChecksum) {
|
||||
Properties pins = new Properties();
|
||||
pins.setProperty("electron.version", version);
|
||||
pins.setProperty("linux-x64.sha256", linuxChecksum);
|
||||
return pins;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class StudioAppInstallerTest {
|
||||
@Test
|
||||
public void seesADisplayOnlyWhenLinuxHasOne() {
|
||||
assertTrue(StudioAppInstaller.hasDisplay("Linux", Map.of("WAYLAND_DISPLAY", "wayland-1")));
|
||||
assertTrue(StudioAppInstaller.hasDisplay("Linux", Map.of("DISPLAY", ":0")));
|
||||
assertFalse(StudioAppInstaller.hasDisplay("Linux", Map.of()));
|
||||
assertFalse(StudioAppInstaller.hasDisplay("Linux", Map.of("DISPLAY", " ")));
|
||||
assertTrue(StudioAppInstaller.hasDisplay("Windows 11", Map.of()));
|
||||
assertTrue(StudioAppInstaller.hasDisplay("Mac OS X", Map.of()));
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in new issue
Block a user