-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getting the production client to launch
- Loading branch information
Showing
7 changed files
with
140 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
buildSrc/src/main/java/net/neoforged/neodev/e2e/TestProductionClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package net.neoforged.neodev.e2e; | ||
|
||
import org.gradle.api.GradleException; | ||
import org.gradle.process.ExecOperations; | ||
|
||
import javax.inject.Inject; | ||
import java.io.File; | ||
import java.time.Duration; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public abstract class TestProductionClient extends RunProductionClient { | ||
@Inject | ||
public TestProductionClient(ExecOperations execOperations) { | ||
super(execOperations); | ||
|
||
getTimeout().set(Duration.of(5, ChronoUnit.MINUTES)); | ||
} | ||
|
||
@Override | ||
public void exec() { | ||
var selfTestReport = new File(getTemporaryDir(), "client_self_test.txt"); | ||
|
||
environment("NEOFORGE_CLIENT_SELFTEST", selfTestReport.getAbsolutePath()); | ||
|
||
super.exec(); | ||
|
||
if (!selfTestReport.exists()) { | ||
throw new GradleException("Missing self test report file after running client: " + selfTestReport); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/main/java/net/neoforged/neoforge/common/util/SelfTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.common.util; | ||
|
||
import net.minecraft.DetectedVersion; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.screens.LoadingOverlay; | ||
import net.minecraft.client.gui.screens.Overlay; | ||
import net.minecraft.server.dedicated.DedicatedServer; | ||
import net.neoforged.api.distmarker.Dist; | ||
import net.neoforged.fml.loading.FMLLoader; | ||
import net.neoforged.neoforge.client.event.ClientTickEvent; | ||
import net.neoforged.neoforge.common.NeoForge; | ||
import net.neoforged.neoforge.event.tick.ServerTickEvent; | ||
import net.neoforged.neoforge.internal.versions.neoforge.NeoForgeVersion; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
@ApiStatus.Internal | ||
public final class SelfTest { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(SelfTest.class); | ||
|
||
private SelfTest() { | ||
} | ||
|
||
public static void initClient() { | ||
var clientSelfTestDestination = System.getenv("NEOFORGE_CLIENT_SELFTEST"); | ||
if (clientSelfTestDestination != null) { | ||
NeoForge.EVENT_BUS.addListener((ClientTickEvent.Pre e) -> { | ||
if (Minecraft.getInstance().getOverlay() instanceof LoadingOverlay) { | ||
return; | ||
} | ||
writeSelfTestReport(clientSelfTestDestination); | ||
Minecraft.getInstance().getSoundManager().emergencyShutdown(); | ||
Minecraft.getInstance().stop(); | ||
}); | ||
} | ||
} | ||
|
||
public static void initCommon() { | ||
var serverSelfTestDestination = System.getenv("NEOFORGE_DEDICATED_SERVER_SELFTEST"); | ||
if (serverSelfTestDestination != null) { | ||
if (FMLLoader.getDist() != Dist.DEDICATED_SERVER) { | ||
LOGGER.error("The server self-test ran with a dist of {} instead of dedicated server!", FMLLoader.getDist()); | ||
System.exit(1); | ||
} | ||
NeoForge.EVENT_BUS.addListener((ServerTickEvent.Pre e) -> { | ||
writeSelfTestReport(serverSelfTestDestination); | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* This is used by our GitHub Actions pipeline to run an E2E test for PRs. | ||
* It writes a small self-test report to the file indicated by the system property and exits. | ||
*/ | ||
private static void writeSelfTestReport(String path) { | ||
try (var out = new FileOutputStream(path)) { | ||
Properties p = new Properties(); | ||
p.setProperty("neoforge_version", NeoForgeVersion.getVersion()); | ||
p.setProperty("minecraft_version", DetectedVersion.BUILT_IN.getName()); | ||
p.store(out, ""); | ||
} catch (IOException e) { | ||
LOGGER.error("Failed to write self-test to '{}'", path, e); | ||
System.exit(1); | ||
} | ||
|
||
LOGGER.info("Exiting after writing self-test to '{}'", path); | ||
System.exit(0); | ||
} | ||
} |