-
-
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.
E2E Self-Tests of production server and client (#1700)
- Loading branch information
Showing
14 changed files
with
858 additions
and
4 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
64 changes: 64 additions & 0 deletions
64
buildSrc/src/main/java/net/neoforged/neodev/e2e/InstallProductionClient.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,64 @@ | ||
package net.neoforged.neodev.e2e; | ||
|
||
import org.gradle.api.GradleException; | ||
import org.gradle.api.file.ConfigurableFileCollection; | ||
import org.gradle.api.file.DirectoryProperty; | ||
import org.gradle.api.tasks.InputFiles; | ||
import org.gradle.api.tasks.JavaExec; | ||
import org.gradle.api.tasks.OutputDirectory; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
import javax.inject.Inject; | ||
import java.io.BufferedOutputStream; | ||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.Files; | ||
|
||
/** | ||
* Downloads and installs a production NeoForge client. | ||
* By extending this task from {@link JavaExec}, it's possible to debug the actual legacy installer | ||
* via IntelliJ directly. | ||
*/ | ||
public abstract class InstallProductionClient extends JavaExec { | ||
/** | ||
* This file collection should contain exactly one file: | ||
* The NeoForge Installer Jar-File. | ||
*/ | ||
@InputFiles | ||
public abstract ConfigurableFileCollection getInstaller(); | ||
|
||
/** | ||
* Where NeoForge should be installed. | ||
*/ | ||
@OutputDirectory | ||
public abstract DirectoryProperty getInstallationDir(); | ||
|
||
@Inject | ||
public InstallProductionClient() { | ||
classpath(getInstaller()); | ||
} | ||
|
||
@TaskAction | ||
@Override | ||
public void exec() { | ||
var installDir = getInstallationDir().getAsFile().get().toPath().toAbsolutePath(); | ||
|
||
// Installer looks for this file | ||
var profilesJsonPath = installDir.resolve("launcher_profiles.json"); | ||
try { | ||
Files.writeString(profilesJsonPath, "{}"); | ||
} catch (IOException e) { | ||
throw new GradleException("Failed to write fake launcher profiles file.", e); | ||
} | ||
|
||
setWorkingDir(installDir.toFile()); | ||
args("--install-client", installDir.toString()); | ||
try { | ||
setStandardOutput(new BufferedOutputStream(Files.newOutputStream(installDir.resolve("install.log")))); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
|
||
super.exec(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
buildSrc/src/main/java/net/neoforged/neodev/e2e/InstallProductionServer.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,63 @@ | ||
package net.neoforged.neodev.e2e; | ||
|
||
import org.gradle.api.file.ConfigurableFileCollection; | ||
import org.gradle.api.file.DirectoryProperty; | ||
import org.gradle.api.file.RegularFileProperty; | ||
import org.gradle.api.tasks.InputFiles; | ||
import org.gradle.api.tasks.JavaExec; | ||
import org.gradle.api.tasks.OutputDirectory; | ||
import org.gradle.api.tasks.OutputFile; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
import javax.inject.Inject; | ||
import java.io.BufferedOutputStream; | ||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.Files; | ||
|
||
/** | ||
* Runs the installer produced by the main build to install a dedicated server in a chosen directory. | ||
*/ | ||
public abstract class InstallProductionServer extends JavaExec { | ||
/** | ||
* The NeoForge installer jar is expected to be the only file in this file collection. | ||
*/ | ||
@InputFiles | ||
public abstract ConfigurableFileCollection getInstaller(); | ||
|
||
/** | ||
* Where the server should be installed. | ||
*/ | ||
@OutputDirectory | ||
public abstract DirectoryProperty getInstallationDir(); | ||
|
||
/** | ||
* Points to the server.jar produced by the installer. | ||
*/ | ||
@OutputFile | ||
public abstract RegularFileProperty getServerLauncher(); | ||
|
||
@Inject | ||
public InstallProductionServer() { | ||
classpath(getInstaller()); | ||
getServerLauncher().set(getInstallationDir().map(id -> id.file("server.jar"))); | ||
getServerLauncher().finalizeValueOnRead(); | ||
} | ||
|
||
@TaskAction | ||
@Override | ||
public void exec() { | ||
var installDir = getInstallationDir().getAsFile().get().toPath().toAbsolutePath(); | ||
|
||
setWorkingDir(installDir.toFile()); | ||
args("--install-server", installDir.toString()); | ||
args("--server.jar"); | ||
try { | ||
setStandardOutput(new BufferedOutputStream(Files.newOutputStream(installDir.resolve("install.log")))); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
|
||
super.exec(); | ||
} | ||
} |
Oops, something went wrong.