From 303e3d910b65efcd61ab790ab0bf9a79d9dd5b40 Mon Sep 17 00:00:00 2001 From: KartoffelChipss Date: Sun, 24 May 2026 22:23:47 +0200 Subject: [PATCH] Add seperate install and run goal --- pom.xml | 2 +- .../strassburger/mcrun/InstallServerMojo.java | 74 +++++++++++++++ .../org/strassburger/mcrun/RunServerMojo.java | 95 +++++++++++++++++++ .../strassburger/mcrun/StartServerMojo.java | 16 ++++ 4 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/strassburger/mcrun/InstallServerMojo.java create mode 100644 src/main/java/org/strassburger/mcrun/RunServerMojo.java diff --git a/pom.xml b/pom.xml index 808b213..f9f1b34 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.strassburger mcrun-maven-plugin - 0.0.13 + 0.0.14 maven-plugin MCRun Maven Plugin diff --git a/src/main/java/org/strassburger/mcrun/InstallServerMojo.java b/src/main/java/org/strassburger/mcrun/InstallServerMojo.java new file mode 100644 index 0000000..ec2953c --- /dev/null +++ b/src/main/java/org/strassburger/mcrun/InstallServerMojo.java @@ -0,0 +1,74 @@ +package org.strassburger.mcrun; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.strassburger.mcrun.config.ServerInstallConfig; +import org.strassburger.mcrun.steps.ServerInstallStep; +import org.strassburger.mcrun.steps.Step; +import org.strassburger.mcrun.steps.StepExecutionException; + +import java.io.File; + +@Mojo(name = "install") +public class InstallServerMojo extends AbstractMojo { + /** + * Path to the plugin jar to deploy. Defaults to the project's build output jar. + * Override if your jar is assembled elsewhere or has a classifier. + */ + @Parameter(defaultValue = "${project.build.directory}/${project.build.finalName}.jar") + private File pluginJar; + + /** + * Directory where the test server will be created and run. + * The server jar, plugins folder, and all generated files (eula.txt, world, logs, etc.) + * will be placed here. Defaults to ${project.basedir}/server. + */ + @Parameter(defaultValue = "${project.basedir}/server") + private File serverDirectory; + + /** + * File name for the downloaded or provided server jar, relative to {@code serverDirectory}. + * Defaults to server.jar. + */ + @Parameter(defaultValue = "server.jar") + private String serverJarName; + + /** + * The server software to download. Defaults to paper. + * Can be one paper or spigot. + */ + @Parameter(defaultValue = "paper") + private String serverSoftware; + + /** + * When {@code true}, automatically creates {@code eula.txt} with {@code eula=true} + * in the server directory if it does not already exist, bypassing the manual + * acceptance step. Defaults to {@code false}. + * + *

By setting this to {@code true} you are indicating that you accept the + * Minecraft End User License Agreement.

+ */ + @Parameter(defaultValue = "false") + private boolean acceptEula; + + /** + * The Minecraft version to run, e.g. 1.21.4. Required. + */ + @Parameter(required = true) + private String mcVersion; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + Step step = new ServerInstallStep(getLog(), + new ServerInstallConfig(serverDirectory, pluginJar, serverJarName, serverSoftware, mcVersion, acceptEula) + ); + try { + step.run(); + } catch (StepExecutionException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + } +} diff --git a/src/main/java/org/strassburger/mcrun/RunServerMojo.java b/src/main/java/org/strassburger/mcrun/RunServerMojo.java new file mode 100644 index 0000000..491efdb --- /dev/null +++ b/src/main/java/org/strassburger/mcrun/RunServerMojo.java @@ -0,0 +1,95 @@ +package org.strassburger.mcrun; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.strassburger.mcrun.config.ServerRunStepConfig; +import org.strassburger.mcrun.steps.ServerRunStep; +import org.strassburger.mcrun.steps.Step; +import org.strassburger.mcrun.steps.StepExecutionException; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +@Mojo(name = "run") +public class RunServerMojo extends AbstractMojo { + /** + * Heap size passed to both {@code -Xmx} and {@code -Xms}. + * Accepts standard JVM memory notation, e.g. 2G, 512M. + * Defaults to 2G. + */ + @Parameter(defaultValue = "2G") + private String memory; + + /** + * Additional JVM arguments to pass to the server process. + * These are inserted after -Xmx/-Xms and before -jar. + * + *
{@code
+     * 
+     *     -XX:+UseG1GC
+     *     -XX:+ParallelRefProcEnabled
+     * 
+     * }
+ */ + @Parameter + private List jvmArgs = new ArrayList<>(); + + /** + * Whether to start the server with JDWP remote debugging enabled. + * When set to true, the JVM is launched with: + * -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:{debugPort}. + * Attach your IDE's remote debugger to the configured {@code debugPort} to use this feature. + * Defaults to false. + */ + @Parameter(defaultValue = "false") + private boolean remoteDebug; + + /** + * The port the JDWP remote debugger will listen on when {@code remoteDebug} is enabled. + * Defaults to 5005. + * + *
{@code
+     * true
+     * 5005
+     * }
+ */ + @Parameter(defaultValue = "5005") + private int debugPort; + + /** + * The port the Minecraft server will listen on. Passed to the server via --port. + */ + @Parameter + private Integer port; + + /** + * Directory where the test server will be created and run. + * The server jar, plugins folder, and all generated files (eula.txt, world, logs, etc.) + * will be placed here. Defaults to ${project.basedir}/server. + */ + @Parameter(defaultValue = "${project.basedir}/server") + private File serverDirectory; + + /** + * File name for the downloaded or provided server jar, relative to {@code serverDirectory}. + * Defaults to server.jar. + */ + @Parameter(defaultValue = "server.jar") + private String serverJarName; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + Step step = new ServerRunStep(getLog(), + new ServerRunStepConfig(memory, jvmArgs, remoteDebug, debugPort, port, serverDirectory, serverJarName) + ); + try { + step.run(); + } catch (StepExecutionException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + } +} diff --git a/src/main/java/org/strassburger/mcrun/StartServerMojo.java b/src/main/java/org/strassburger/mcrun/StartServerMojo.java index c7ed8e2..7108b77 100644 --- a/src/main/java/org/strassburger/mcrun/StartServerMojo.java +++ b/src/main/java/org/strassburger/mcrun/StartServerMojo.java @@ -88,9 +88,25 @@ public class StartServerMojo extends AbstractMojo { @Parameter private List jvmArgs = new ArrayList<>(); + /** + * Whether to start the server with JDWP remote debugging enabled. + * When set to true, the JVM is launched with: + * -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:{debugPort}. + * Attach your IDE's remote debugger to the configured {@code debugPort} to use this feature. + * Defaults to false. + */ @Parameter(defaultValue = "false") private boolean remoteDebug; + /** + * The port the JDWP remote debugger will listen on when {@code remoteDebug} is enabled. + * Defaults to 5005. + * + *
{@code
+     * true
+     * 5005
+     * }
+ */ @Parameter(defaultValue = "5005") private int debugPort;