mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
A pack that loads none of the built-in modules is told once, with the jar to copy and where
This commit is contained in:
1 parent
9147acca0c
commit
ee2a0425e2
6 files changed
+202
-1
No files matched your search
@@ -58,6 +58,12 @@ public final class IrisModuleHost {
|
||||
public static final List<String> SHARED_LIBRARY_PACKAGES = List.of("art.arcane.volmlib", "com.google.gson");
|
||||
/** Every package pack modules may use besides the IrisApi. {@code exposedHostPackages} in IrisModule's build lists the same. */
|
||||
public static final List<String> EXPOSED_PACKAGES = Stream.concat(Stream.of(BUILT_IN_API_PACKAGE), SHARED_LIBRARY_PACKAGES.stream()).toList();
|
||||
/**
|
||||
* The ids of the built-in modules that ship in the built-ins jar ({@code iris-builtins.jar}, listed in
|
||||
* {@code IrisModule/builtin-modules.txt}) instead of being compiled into Iris. A pack loads them from its {@code modules}
|
||||
* folder, and {@link MissingBuiltInModules} warns when it loads none; a test keeps this equal to the jar's list.
|
||||
*/
|
||||
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter");
|
||||
/** Iris's pack object model: built-in settings may hold these classes, which Iris reads and describes itself. */
|
||||
public static final String HOST_TYPE_PACKAGE = "art.arcane.iris.engine.object";
|
||||
private static final String[] JAR_COPY_FOLDER = {"cache", "module-jars"};
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.core.modules;
|
||||
|
||||
import com.volmit.host.DiscoveredModule;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Notices a pack that loads without the built-in modules jar. Such a pack still loads and generates, but quietly without
|
||||
* what the jar's modules do, so the owner is told once, with the fix.
|
||||
*/
|
||||
final class MissingBuiltInModules {
|
||||
static final String JAR_NAME = "iris-builtins.jar";
|
||||
|
||||
private MissingBuiltInModules() {
|
||||
}
|
||||
|
||||
/** What to tell the owner of {@code packFolder} whose pack loaded {@code packModules}; empty when the built-ins jar is there. */
|
||||
static Optional<String> warning(File packFolder, Collection<DiscoveredModule> packModules) {
|
||||
boolean builtInsLoaded = packModules.stream()
|
||||
.map(module -> module.info().id().toString())
|
||||
.anyMatch(IrisModuleHost.JAR_MODULE_IDS::contains);
|
||||
if (builtInsLoaded) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of("Pack " + packFolder.getName() + " loads without the built-in modules (" + JAR_NAME + "): its chunks get"
|
||||
+ " no objects or structures, no surface smoothing and no clean-up of floating decorations. Copy " + JAR_NAME
|
||||
+ " into " + new File(packFolder, PackModuleSet.MODULES_FOLDER).getPath() + " to fix it.");
|
||||
}
|
||||
}
|
||||
@@ -37,8 +37,9 @@ import java.util.function.Supplier;
|
||||
public final class PackModuleSet implements AutoCloseable {
|
||||
private enum State { NOT_LOADED, LOADED, FAILED, CLOSED }
|
||||
|
||||
private static final String MODULES_FOLDER = "modules";
|
||||
static final String MODULES_FOLDER = "modules";
|
||||
private static final String JAR_EXTENSION = ".jar";
|
||||
private static final String MISSING_BUILT_INS_KEY = "missing-built-in-modules:";
|
||||
|
||||
private final File packFolder;
|
||||
private final Supplier<Gson> irisGson;
|
||||
@@ -113,6 +114,7 @@ public final class PackModuleSet implements AutoCloseable {
|
||||
pack = loaded;
|
||||
settings = new ModuleSettingsDecoder(loaded.catalog(), packFolder.toPath(), irisGson);
|
||||
state = State.LOADED;
|
||||
warnWhenBuiltInModulesAreMissing(loaded);
|
||||
} catch (RuntimeException loadFailure) {
|
||||
failure = new PackModulesException(packFolder, loadFailure);
|
||||
state = State.FAILED;
|
||||
@@ -121,6 +123,11 @@ public final class PackModuleSet implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
private void warnWhenBuiltInModulesAreMissing(LoadedPack loaded) {
|
||||
MissingBuiltInModules.warning(packFolder, loaded.packModules())
|
||||
.ifPresent(warning -> IrisLogging.warnOnce(MISSING_BUILT_INS_KEY + packFolder.getAbsolutePath(), "%s", warning));
|
||||
}
|
||||
|
||||
/** Each module jar's name, size and modification time, in name order. */
|
||||
private List<String> jarFingerprint() {
|
||||
File[] jars = new File(packFolder, MODULES_FOLDER).listFiles(file -> file.isFile() && file.getName().endsWith(JAR_EXTENSION));
|
||||
|
||||
@@ -66,6 +66,17 @@ public class BuiltInModulesJarTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theIdsIrisLooksForAreTheOnesTheJarProvides() throws IOException {
|
||||
Path pack = BuiltInPack.newPackFolder(folder);
|
||||
BuiltInModulesJar.writeInto(pack);
|
||||
|
||||
try (LoadedPack loaded = loadWithStandIns(pack)) {
|
||||
List<String> provided = loaded.packModules().stream().map(module -> module.info().id().toString()).toList();
|
||||
assertEquals(provided, IrisModuleHost.JAR_MODULE_IDS);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theJarsModulesGenerateWhatTheirCompiledInCopiesGenerate() throws IOException {
|
||||
Path pack = BuiltInPack.newPackFolder(folder);
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.core.modules;
|
||||
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.host.DiscoveredModule;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class MissingBuiltInModulesTest {
|
||||
private static final File PACK = new File("packs", "overworld");
|
||||
|
||||
@Test
|
||||
public void aPackWithNoModulesIsToldWhichJarToCopyWhere() {
|
||||
String warning = MissingBuiltInModules.warning(PACK, List.of()).orElseThrow();
|
||||
|
||||
assertTrue(warning, warning.startsWith("Pack overworld loads without the built-in modules (iris-builtins.jar)"));
|
||||
assertTrue(warning, warning.contains("Copy iris-builtins.jar into " + new File(PACK, "modules").getPath() + " to fix it."));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackWithOnlyOtherModulesIsToldToo() {
|
||||
assertTrue(MissingBuiltInModules.warning(PACK, List.of(module("pack:ruins"))).isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anyOfTheJarsModulesCountsAsHavingTheJar() {
|
||||
for (String id : IrisModuleHost.JAR_MODULE_IDS) {
|
||||
assertEquals(id, Optional.empty(), MissingBuiltInModules.warning(PACK, List.of(module("pack:ruins"), module(id))));
|
||||
}
|
||||
}
|
||||
|
||||
private static DiscoveredModule module(String id) {
|
||||
return DiscoveredModule.builtIn(new IrisModule() {
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of(id, "Stand-in " + id, "test");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -18,16 +18,22 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -60,4 +66,57 @@ public class PackModuleSetTest {
|
||||
assertTrue(first.getMessage(), first.getMessage().startsWith("Pack broken cannot load its modules: "));
|
||||
modules.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackWithoutTheBuiltInsJarIsToldHowToGetThem() throws IOException {
|
||||
File pack = folder.newFolder("without-builtins");
|
||||
|
||||
String warnings = warningsWhile(() -> new PackModuleSet(pack, Gson::new).pack());
|
||||
|
||||
assertTrue(warnings, warnings.contains("[Iris/WARN] Pack without-builtins loads without the built-in modules (iris-builtins.jar)"));
|
||||
assertTrue(warnings, warnings.contains("Copy iris-builtins.jar into " + new File(pack, "modules").getPath()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackIsToldOnceHoweverOftenItLoadsAndAWorldCopyOfItIsToldToo() throws IOException {
|
||||
File pack = folder.newFolder("original");
|
||||
File worldCopy = folder.newFolder("world", "iris", "pack");
|
||||
|
||||
String warnings = warningsWhile(() -> {
|
||||
new PackModuleSet(pack, Gson::new).pack();
|
||||
new PackModuleSet(pack, Gson::new).pack();
|
||||
new PackModuleSet(worldCopy, Gson::new).pack();
|
||||
});
|
||||
|
||||
assertEquals(warnings, 1, occurrences(warnings, "Pack original loads without"));
|
||||
assertEquals(warnings, 1, occurrences(warnings, "Pack pack loads without"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackWithTheBuiltInsJarIsNotWarned() throws IOException {
|
||||
File pack = folder.newFolder("with-builtins");
|
||||
BuiltInModulesJar.writeInto(pack.toPath());
|
||||
|
||||
String warnings = warningsWhile(() -> assertFalse(new PackModuleSet(pack, Gson::new).pack().packModules().isEmpty()));
|
||||
|
||||
assertFalse(warnings, warnings.contains("built-in modules"));
|
||||
}
|
||||
|
||||
/** What Iris's log said at WARN while {@code load} ran: with no platform bound it goes to the error stream. */
|
||||
private static String warningsWhile(Runnable load) {
|
||||
Assume.assumeFalse("a platform is bound, so the log does not go to the error stream", IrisPlatforms.isBound());
|
||||
PrintStream original = System.err;
|
||||
ByteArrayOutputStream captured = new ByteArrayOutputStream();
|
||||
System.setErr(new PrintStream(captured, true, StandardCharsets.UTF_8));
|
||||
try {
|
||||
load.run();
|
||||
} finally {
|
||||
System.setErr(original);
|
||||
}
|
||||
return captured.toString(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static int occurrences(String text, String fragment) {
|
||||
return text.split(java.util.regex.Pattern.quote(fragment), -1).length - 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user