Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3fa4e518ac | |||
| 2b56362174 | |||
| 41647b158e | |||
| 8e08154d21 | |||
| b9e49b387f | |||
| 49cd788a68 | |||
| 303e3d910b | |||
| bb75bba0a1 | |||
| aed7d7d561 | |||
| cf55c2119c | |||
| 38fe412312 |
@@ -19,19 +19,11 @@ jobs:
|
|||||||
java-version: '21'
|
java-version: '21'
|
||||||
cache: 'maven'
|
cache: 'maven'
|
||||||
|
|
||||||
- uses: stCarolas/setup-maven@v5
|
- name: Set up Maven
|
||||||
|
uses: stCarolas/setup-maven@v5
|
||||||
with:
|
with:
|
||||||
maven-version: 3.9.6
|
maven-version: 3.9.6
|
||||||
|
|
||||||
- name: Debug Java setup
|
|
||||||
run: |
|
|
||||||
echo "JAVA_HOME=$JAVA_HOME"
|
|
||||||
echo "PATH=$PATH"
|
|
||||||
which java || echo "java not found"
|
|
||||||
which mvn || echo "mvn not found"
|
|
||||||
ls $JAVA_HOME/../bin/ || echo "JAVA_HOME bin not found"
|
|
||||||
cat $GITHUB_PATH || echo "GITHUB_PATH file empty or missing"
|
|
||||||
|
|
||||||
- name: Get release version
|
- name: Get release version
|
||||||
id: get_version
|
id: get_version
|
||||||
run: echo "version=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
|
run: echo "version=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
.idea/
|
||||||
|
|
||||||
# Created by https://www.toptal.com/developers/gitignore/api/java,maven
|
# Created by https://www.toptal.com/developers/gitignore/api/java,maven
|
||||||
# Edit at https://www.toptal.com/developers/gitignore?templates=java,maven
|
# Edit at https://www.toptal.com/developers/gitignore?templates=java,maven
|
||||||
|
|
||||||
|
|||||||
Generated
-13
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<annotationProcessing>
|
|
||||||
<profile name="Maven default annotation processors profile" enabled="true">
|
|
||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
|
||||||
<outputRelativeToContentRoot value="true" />
|
|
||||||
<module name="MCRun" />
|
|
||||||
</profile>
|
|
||||||
</annotationProcessing>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
Generated
-7
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Encoding">
|
|
||||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
Generated
-25
@@ -1,25 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RemoteRepositoriesConfiguration">
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="github" />
|
|
||||||
<option name="name" value="github" />
|
|
||||||
<option name="url" value="https://maven.pkg.github.com/KartoffelChipss/LifeStealZ" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Maven Central repository" />
|
|
||||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="jboss.community" />
|
|
||||||
<option name="name" value="JBoss Community repository" />
|
|
||||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="central" />
|
|
||||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
Generated
-16
@@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="DiscordProjectSettings">
|
|
||||||
<option name="show" value="ASK" />
|
|
||||||
<option name="description" value="" />
|
|
||||||
</component>
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="MavenProjectsManager">
|
|
||||||
<option name="originalFiles">
|
|
||||||
<list>
|
|
||||||
<option value="$PROJECT_DIR$/pom.xml" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="25" project-jdk-type="JavaSDK" />
|
|
||||||
</project>
|
|
||||||
Generated
-6
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
Generated
-64
@@ -1,64 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="AutoImportSettings">
|
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
|
||||||
</component>
|
|
||||||
<component name="ChangeListManager">
|
|
||||||
<list default="true" id="98c311c3-6130-4449-9bcb-07029b56b776" name="Changes" comment="">
|
|
||||||
<change beforePath="$PROJECT_DIR$/.gitea/workflows/publish.yml" beforeDir="false" afterPath="$PROJECT_DIR$/.gitea/workflows/publish.yml" afterDir="false" />
|
|
||||||
</list>
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
||||||
</component>
|
|
||||||
<component name="FileTemplateManagerImpl">
|
|
||||||
<option name="RECENT_TEMPLATES">
|
|
||||||
<list>
|
|
||||||
<option value="Exception" />
|
|
||||||
<option value="Class" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="Git.Settings">
|
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectColorInfo">{
|
|
||||||
"customColor": "",
|
|
||||||
"associatedIndex": 1
|
|
||||||
}</component>
|
|
||||||
<component name="ProjectId" id="3E8fdcRwutbLOHxizPneckuMJLe" />
|
|
||||||
<component name="ProjectViewState">
|
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
|
||||||
<option name="showLibraryContents" value="true" />
|
|
||||||
</component>
|
|
||||||
<component name="PropertiesComponent">{
|
|
||||||
"keyToString": {
|
|
||||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
|
||||||
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
|
||||||
"codeWithMe.voiceChat.enabledByDefault": "false",
|
|
||||||
"git-widget-placeholder": "main",
|
|
||||||
"kotlin-language-version-configured": "true",
|
|
||||||
"nodejs_package_manager_path": "npm",
|
|
||||||
"vue.rearranger.settings.migration": "true"
|
|
||||||
}
|
|
||||||
}</component>
|
|
||||||
<component name="TaskManager">
|
|
||||||
<task active="true" id="Default" summary="Default task">
|
|
||||||
<changelist id="98c311c3-6130-4449-9bcb-07029b56b776" name="Changes" comment="" />
|
|
||||||
<created>1779565206518</created>
|
|
||||||
<option name="number" value="Default" />
|
|
||||||
<option name="presentableId" value="Default" />
|
|
||||||
<updated>1779565206518</updated>
|
|
||||||
<workItem from="1779565207730" duration="57000" />
|
|
||||||
<workItem from="1779565274563" duration="632000" />
|
|
||||||
<workItem from="1779565913273" duration="9192000" />
|
|
||||||
</task>
|
|
||||||
<servers />
|
|
||||||
</component>
|
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
|
||||||
<option name="version" value="3" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -44,10 +44,10 @@ Add the following inside the `<build><plugins>` section of your `pom.xml`:
|
|||||||
|
|
||||||
> **Note:** Replace `LATEST` with the actual latest version, and set `<mcVersion>` to whichever Minecraft version you want to test against.
|
> **Note:** Replace `LATEST` with the actual latest version, and set `<mcVersion>` to whichever Minecraft version you want to test against.
|
||||||
|
|
||||||
### 3. Run the server
|
### 3. Start the server
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
mvn package mcrun:run
|
mvn package mcrun:start
|
||||||
```
|
```
|
||||||
|
|
||||||
This will:
|
This will:
|
||||||
@@ -62,19 +62,20 @@ This will:
|
|||||||
|
|
||||||
All options go inside the `<configuration>` block of the plugin declaration.
|
All options go inside the `<configuration>` block of the plugin declaration.
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
|---|---|---------------------------------------------------------------------------------------------------------------------------------|
|
|---|---|---|
|
||||||
| `mcVersion` | *(required)* | The Minecraft version to run, e.g. `1.21.4` |
|
| `mcVersion` | *(required)* | The Minecraft version to run, e.g. `1.21.4` |
|
||||||
| `acceptEula` | `false` | Automatically accept the [Minecraft EULA](https://aka.ms/MinecraftEULA). By setting this to `true` you confirm your acceptance. |
|
| `acceptEula` | `false` | Automatically accept the [Minecraft EULA](https://aka.ms/MinecraftEULA). By setting this to `true` you confirm your acceptance. |
|
||||||
| `serverSoftware` | `paper` | Server software to use. Supported values: `paper`, `spigot` |
|
| `serverSoftware` | `paper` | Server software to use. Supported values: `paper`, `spigot` |
|
||||||
| `serverDirectory` | `./server` | Folder where the server files will be created |
|
| `serverDirectory` | `./server` | Folder where the server files will be created |
|
||||||
| `serverJarName` | `server.jar` | File name for the server jar inside `serverDirectory` |
|
| `serverJarName` | `server.jar` | File name for the server jar inside `serverDirectory` |
|
||||||
| `memory` | `2G` | RAM allocated to the server (used for both `-Xmx` and `-Xms`), e.g. `2G`, `512M` |
|
| `minMemory` | `512M` | Minimum RAM allocated to the server (`-Xms`), e.g. `512M`, `1G` |
|
||||||
| `port` | *(Minecraft default)* | Port the server listens on |
|
| `maxMemory` | `2G` | Maximum RAM allocated to the server (`-Xmx`), e.g. `2G`, `4G` |
|
||||||
| `remoteDebug` | `false` | Enable remote JVM debugging so you can attach your IDE's debugger |
|
| `port` | *(Minecraft default)* | Port the server listens on |
|
||||||
| `debugPort` | `5005` | Port used for remote debugging (only relevant if `remoteDebug` is `true`) |
|
| `remoteDebug` | `false` | Enable remote JVM debugging so you can attach your IDE's debugger |
|
||||||
| `jvmArgs` | *(none)* | Extra JVM flags passed to the server process (see below) |
|
| `debugPort` | `5005` | Port used for remote debugging (only relevant if `remoteDebug` is `true`) |
|
||||||
| `pluginJar` | *(your built jar)* | Path to the plugin jar to deploy. You rarely need to change this |
|
| `jvmArgs` | *(none)* | Extra JVM flags passed to the server process |
|
||||||
|
| `pluginJar` | *(your built jar)* | Path to the plugin jar to deploy. You rarely need to change this |
|
||||||
|
|
||||||
### Full configuration example
|
### Full configuration example
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<groupId>org.strassburger</groupId>
|
<groupId>org.strassburger</groupId>
|
||||||
<artifactId>mcrun-maven-plugin</artifactId>
|
<artifactId>mcrun-maven-plugin</artifactId>
|
||||||
<version>0.0.12</version>
|
<version>1.0.0</version>
|
||||||
<packaging>maven-plugin</packaging>
|
<packaging>maven-plugin</packaging>
|
||||||
|
|
||||||
<name>MCRun Maven Plugin</name>
|
<name>MCRun Maven Plugin</name>
|
||||||
|
|||||||
@@ -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 <code>${project.basedir}/server</code>.
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "${project.basedir}/server")
|
||||||
|
private File serverDirectory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File name for the downloaded or provided server jar, relative to {@code serverDirectory}.
|
||||||
|
* Defaults to <code>server.jar</code>.
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "server.jar")
|
||||||
|
private String serverJarName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The server software to download. Defaults to <code>paper</code>.
|
||||||
|
* Can be one <code>paper</code> or <code>spigot</code>.
|
||||||
|
*/
|
||||||
|
@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}.
|
||||||
|
*
|
||||||
|
* <p>By setting this to {@code true} you are indicating that you accept the
|
||||||
|
* <a href="https://aka.ms/MinecraftEULA">Minecraft End User License Agreement</a>.</p>
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "false")
|
||||||
|
private boolean acceptEula;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Minecraft version to run, e.g. <code>1.21.4</code>. 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,27 +3,76 @@ package org.strassburger.mcrun;
|
|||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
import org.strassburger.mcrun.downloader.ServerJarDownloadException;
|
import org.strassburger.mcrun.config.ServerRunStepConfig;
|
||||||
import org.strassburger.mcrun.downloader.ServerJarDownloader;
|
import org.strassburger.mcrun.steps.ServerRunStep;
|
||||||
|
import org.strassburger.mcrun.steps.Step;
|
||||||
|
import org.strassburger.mcrun.steps.StepExecutionException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mojo(name = "run", defaultPhase = LifecyclePhase.PACKAGE)
|
@Mojo(name = "run")
|
||||||
public class RunServerMojo extends AbstractMojo {
|
public class RunServerMojo extends AbstractMojo {
|
||||||
/**
|
/**
|
||||||
* Path to the plugin jar to deploy. Defaults to the project's build output jar.
|
* Minimum heap size passed to {@code -Xms}.
|
||||||
* Override if your jar is assembled elsewhere or has a classifier.
|
* Accepts standard JVM memory notation, e.g. <code>512M</code>, <code>1G</code>.
|
||||||
|
* Defaults to <code>512M</code>.
|
||||||
*/
|
*/
|
||||||
@Parameter(defaultValue = "${project.build.directory}/${project.build.finalName}.jar")
|
@Parameter(defaultValue = "512M")
|
||||||
private File pluginJar;
|
private String minMemory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum heap size passed to {@code -Xmx}.
|
||||||
|
* Accepts standard JVM memory notation, e.g. <code>2G</code>, <code>4G</code>.
|
||||||
|
* Defaults to <code>2G</code>.
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "2G")
|
||||||
|
private String maxMemory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional JVM arguments to pass to the server process.
|
||||||
|
* These are inserted after -Xmx/-Xms and before -jar.
|
||||||
|
*
|
||||||
|
* <pre>{@code
|
||||||
|
* <jvmArgs>
|
||||||
|
* <arg>-XX:+UseG1GC</arg>
|
||||||
|
* <arg>-XX:+ParallelRefProcEnabled</arg>
|
||||||
|
* </jvmArgs>
|
||||||
|
* }</pre>
|
||||||
|
*/
|
||||||
|
@Parameter
|
||||||
|
private List<String> jvmArgs = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to start the server with JDWP remote debugging enabled.
|
||||||
|
* When set to <code>true</code>, the JVM is launched with:
|
||||||
|
* <code>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:{debugPort}</code>.
|
||||||
|
* Attach your IDE's remote debugger to the configured {@code debugPort} to use this feature.
|
||||||
|
* Defaults to <code>false</code>.
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "false")
|
||||||
|
private boolean remoteDebug;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The port the JDWP remote debugger will listen on when {@code remoteDebug} is enabled.
|
||||||
|
* Defaults to <code>5005</code>.
|
||||||
|
*
|
||||||
|
* <pre>{@code
|
||||||
|
* <remoteDebug>true</remoteDebug>
|
||||||
|
* <debugPort>5005</debugPort>
|
||||||
|
* }</pre>
|
||||||
|
*/
|
||||||
|
@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.
|
* Directory where the test server will be created and run.
|
||||||
@@ -40,139 +89,15 @@ public class RunServerMojo extends AbstractMojo {
|
|||||||
@Parameter(defaultValue = "server.jar")
|
@Parameter(defaultValue = "server.jar")
|
||||||
private String serverJarName;
|
private String serverJarName;
|
||||||
|
|
||||||
/**
|
|
||||||
* The server software to download. Defaults to <code>paper</code>.
|
|
||||||
* Can be one <code>paper</code> or <code>spigot</code>.
|
|
||||||
*/
|
|
||||||
@Parameter(defaultValue = "paper")
|
|
||||||
private String serverSoftware;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Minecraft version to run, e.g. <code>1.21.4</code>. Required.
|
|
||||||
*/
|
|
||||||
@Parameter(required = true)
|
|
||||||
private String mcVersion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Heap size passed to both {@code -Xmx} and {@code -Xms}.
|
|
||||||
* Accepts standard JVM memory notation, e.g. <code>2G</code>, <code>512M</code>.
|
|
||||||
* Defaults to <code>2G</code>.
|
|
||||||
*/
|
|
||||||
@Parameter(defaultValue = "2G")
|
|
||||||
private String memory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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}.
|
|
||||||
*
|
|
||||||
* <p>By setting this to {@code true} you are indicating that you accept the
|
|
||||||
* <a href="https://aka.ms/MinecraftEULA">Minecraft End User License Agreement</a>.</p>
|
|
||||||
*/
|
|
||||||
@Parameter(defaultValue = "false")
|
|
||||||
private boolean acceptEula;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Additional JVM arguments to pass to the server process.
|
|
||||||
* These are inserted after -Xmx/-Xms and before -jar.
|
|
||||||
*
|
|
||||||
* <pre>{@code
|
|
||||||
* <jvmArgs>
|
|
||||||
* <arg>-XX:+UseG1GC</arg>
|
|
||||||
* <arg>-XX:+ParallelRefProcEnabled</arg>
|
|
||||||
* </jvmArgs>
|
|
||||||
* }</pre>
|
|
||||||
*/
|
|
||||||
@Parameter
|
|
||||||
private List<String> jvmArgs = new ArrayList<>();
|
|
||||||
|
|
||||||
@Parameter(defaultValue = "false")
|
|
||||||
private boolean remoteDebug;
|
|
||||||
|
|
||||||
@Parameter(defaultValue = "5005")
|
|
||||||
private int debugPort;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The port the Minecraft server will listen on. Passed to the server via --port.
|
|
||||||
*/
|
|
||||||
@Parameter
|
|
||||||
private Integer port;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||||
copyPlugin();
|
Step<?> step = new ServerRunStep(getLog(),
|
||||||
downloadServerJar();
|
new ServerRunStepConfig(minMemory, maxMemory, jvmArgs, remoteDebug, debugPort, port, serverDirectory, serverJarName)
|
||||||
if (acceptEula) acceptEula();
|
);
|
||||||
startServerProcess();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyPlugin() throws MojoExecutionException {
|
|
||||||
File pluginsDir = new File(serverDirectory, "plugins");
|
|
||||||
pluginsDir.mkdirs();
|
|
||||||
try {
|
try {
|
||||||
Files.copy(pluginJar.toPath(),
|
step.run();
|
||||||
new File(pluginsDir, pluginJar.getName()).toPath(),
|
} catch (StepExecutionException e) {
|
||||||
StandardCopyOption.REPLACE_EXISTING);
|
throw new MojoExecutionException(e.getMessage(), e);
|
||||||
} catch (IOException e) {
|
|
||||||
throw new MojoExecutionException("Failed to copy plugin jar file: " + pluginJar.getAbsolutePath(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void downloadServerJar() throws MojoExecutionException {
|
|
||||||
try {
|
|
||||||
ServerJarDownloader jarDownloader = ServerJarDownloader.forServerSoftware(serverSoftware)
|
|
||||||
.withLog(getLog()).withServerDirectory(serverDirectory)
|
|
||||||
.withServerJarName(serverJarName).withMcVersion(mcVersion)
|
|
||||||
.build();
|
|
||||||
jarDownloader.run();
|
|
||||||
} catch (ServerJarDownloadException e) {
|
|
||||||
throw new MojoExecutionException("Failed to download server jar", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void acceptEula() throws MojoExecutionException {
|
|
||||||
File eula = new File(serverDirectory, "eula.txt");
|
|
||||||
if (eula.exists()) return;
|
|
||||||
try {
|
|
||||||
Files.writeString(eula.toPath(), "eula=true\n");
|
|
||||||
getLog().info("eula.txt created and accepted.");
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new MojoExecutionException("Failed to write eula.txt: " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> buildCommand() {
|
|
||||||
List<String> cmd = new ArrayList<>();
|
|
||||||
cmd.add("java");
|
|
||||||
cmd.add("-Xmx" + memory);
|
|
||||||
cmd.add("-Xms" + memory);
|
|
||||||
if (remoteDebug && debugPort > 0) {
|
|
||||||
cmd.add(String.format("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:%d", debugPort));
|
|
||||||
}
|
|
||||||
cmd.addAll(jvmArgs);
|
|
||||||
cmd.add("-jar");
|
|
||||||
cmd.add(serverJarName);
|
|
||||||
cmd.add("--nogui");
|
|
||||||
if (port != null) {
|
|
||||||
cmd.add("--port");
|
|
||||||
cmd.add(String.valueOf(port));
|
|
||||||
}
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startServerProcess() throws MojoExecutionException {
|
|
||||||
List<String> command = buildCommand();
|
|
||||||
getLog().info("Starting server with command: " + String.join(" ", command));
|
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder(command);
|
|
||||||
pb.directory(serverDirectory);
|
|
||||||
pb.inheritIO();
|
|
||||||
Process process;
|
|
||||||
try {
|
|
||||||
process = pb.start();
|
|
||||||
process.waitFor();
|
|
||||||
} catch (IOException | InterruptedException e) {
|
|
||||||
throw new MojoExecutionException("Failed to start server: " + e.getMessage(), e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
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.LifecyclePhase;
|
||||||
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
|
import org.strassburger.mcrun.config.ServerInstallConfig;
|
||||||
|
import org.strassburger.mcrun.config.ServerRunStepConfig;
|
||||||
|
import org.strassburger.mcrun.steps.ServerInstallStep;
|
||||||
|
import org.strassburger.mcrun.steps.ServerRunStep;
|
||||||
|
import org.strassburger.mcrun.steps.Step;
|
||||||
|
import org.strassburger.mcrun.steps.StepExecutionException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mojo(name = "start", defaultPhase = LifecyclePhase.PACKAGE)
|
||||||
|
public class StartServerMojo 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 <code>${project.basedir}/server</code>.
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "${project.basedir}/server")
|
||||||
|
private File serverDirectory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File name for the downloaded or provided server jar, relative to {@code serverDirectory}.
|
||||||
|
* Defaults to <code>server.jar</code>.
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "server.jar")
|
||||||
|
private String serverJarName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The server software to download. Defaults to <code>paper</code>.
|
||||||
|
* Can be one <code>paper</code> or <code>spigot</code>.
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "paper")
|
||||||
|
private String serverSoftware;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Minecraft version to run, e.g. <code>1.21.4</code>. Required.
|
||||||
|
*/
|
||||||
|
@Parameter(required = true)
|
||||||
|
private String mcVersion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimum heap size passed to {@code -Xms}.
|
||||||
|
* Accepts standard JVM memory notation, e.g. <code>512M</code>, <code>1G</code>.
|
||||||
|
* Defaults to <code>512M</code>.
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "512M")
|
||||||
|
private String minMemory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum heap size passed to {@code -Xmx}.
|
||||||
|
* Accepts standard JVM memory notation, e.g. <code>2G</code>, <code>4G</code>.
|
||||||
|
* Defaults to <code>2G</code>.
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "2G")
|
||||||
|
private String maxMemory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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}.
|
||||||
|
*
|
||||||
|
* <p>By setting this to {@code true} you are indicating that you accept the
|
||||||
|
* <a href="https://aka.ms/MinecraftEULA">Minecraft End User License Agreement</a>.</p>
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "false")
|
||||||
|
private boolean acceptEula;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional JVM arguments to pass to the server process.
|
||||||
|
* These are inserted after -Xmx/-Xms and before -jar.
|
||||||
|
*
|
||||||
|
* <pre>{@code
|
||||||
|
* <jvmArgs>
|
||||||
|
* <arg>-XX:+UseG1GC</arg>
|
||||||
|
* <arg>-XX:+ParallelRefProcEnabled</arg>
|
||||||
|
* </jvmArgs>
|
||||||
|
* }</pre>
|
||||||
|
*/
|
||||||
|
@Parameter
|
||||||
|
private List<String> jvmArgs = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to start the server with JDWP remote debugging enabled.
|
||||||
|
* When set to <code>true</code>, the JVM is launched with:
|
||||||
|
* <code>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:{debugPort}</code>.
|
||||||
|
* Attach your IDE's remote debugger to the configured {@code debugPort} to use this feature.
|
||||||
|
* Defaults to <code>false</code>.
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "false")
|
||||||
|
private boolean remoteDebug;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The port the JDWP remote debugger will listen on when {@code remoteDebug} is enabled.
|
||||||
|
* Defaults to <code>5005</code>.
|
||||||
|
*
|
||||||
|
* <pre>{@code
|
||||||
|
* <remoteDebug>true</remoteDebug>
|
||||||
|
* <debugPort>5005</debugPort>
|
||||||
|
* }</pre>
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "5005")
|
||||||
|
private int debugPort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The port the Minecraft server will listen on. Passed to the server via --port.
|
||||||
|
*/
|
||||||
|
@Parameter
|
||||||
|
private Integer port;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||||
|
try {
|
||||||
|
for (var step : getSteps()) {
|
||||||
|
step.run();
|
||||||
|
}
|
||||||
|
} catch (StepExecutionException e) {
|
||||||
|
throw new MojoExecutionException(e.getMessage(), e.getCause());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Step<?>> getSteps() {
|
||||||
|
List<Step<?>> steps = new ArrayList<>();
|
||||||
|
steps.add(new ServerInstallStep(getLog(),
|
||||||
|
new ServerInstallConfig(serverDirectory, pluginJar, serverJarName, serverSoftware, mcVersion, acceptEula)
|
||||||
|
));
|
||||||
|
steps.add(new ServerRunStep(getLog(),
|
||||||
|
new ServerRunStepConfig(minMemory, maxMemory, jvmArgs, remoteDebug, debugPort, port, serverDirectory, serverJarName)
|
||||||
|
));
|
||||||
|
return steps;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.strassburger.mcrun.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public record ServerInstallConfig(File serverDirectory,
|
||||||
|
File pluginJar,
|
||||||
|
String serverJarName,
|
||||||
|
String serverSoftware,
|
||||||
|
String mcVersion,
|
||||||
|
boolean acceptEula
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.strassburger.mcrun.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record ServerRunStepConfig(String minMemory,
|
||||||
|
String maxMemory,
|
||||||
|
List<String> jvmArgs,
|
||||||
|
boolean remoteDebug,
|
||||||
|
int debugPort,
|
||||||
|
Integer port,
|
||||||
|
File serverDirectory,
|
||||||
|
String serverJarName) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package org.strassburger.mcrun.steps;
|
||||||
|
|
||||||
|
import org.apache.maven.plugin.logging.Log;
|
||||||
|
import org.strassburger.mcrun.config.ServerInstallConfig;
|
||||||
|
import org.strassburger.mcrun.downloader.ServerJarDownloadException;
|
||||||
|
import org.strassburger.mcrun.downloader.ServerJarDownloader;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
|
public class ServerInstallStep extends Step<ServerInstallConfig> {
|
||||||
|
public ServerInstallStep(Log log, ServerInstallConfig config) {
|
||||||
|
super(log, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() throws StepExecutionException {
|
||||||
|
copyPlugin();
|
||||||
|
downloadServerJar();
|
||||||
|
acceptEula();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyPlugin() throws StepExecutionException {
|
||||||
|
File pluginsDir = new File(getConfig().serverDirectory(), "plugins");
|
||||||
|
pluginsDir.mkdirs();
|
||||||
|
try {
|
||||||
|
Files.copy(getConfig().pluginJar().toPath(),
|
||||||
|
new File(pluginsDir, getConfig().pluginJar().getName()).toPath(),
|
||||||
|
StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new StepExecutionException("Failed to copy plugin jar file: " + getConfig().pluginJar().getAbsolutePath(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void downloadServerJar() throws StepExecutionException {
|
||||||
|
try {
|
||||||
|
ServerJarDownloader jarDownloader = ServerJarDownloader.forServerSoftware(getConfig().serverSoftware())
|
||||||
|
.withLog(getLog()).withServerDirectory(getConfig().serverDirectory())
|
||||||
|
.withServerJarName(getConfig().serverJarName()).withMcVersion(getConfig().mcVersion())
|
||||||
|
.build();
|
||||||
|
jarDownloader.run();
|
||||||
|
} catch (ServerJarDownloadException e) {
|
||||||
|
throw new StepExecutionException("Failed to download server jar", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void acceptEula() throws StepExecutionException {
|
||||||
|
if (!getConfig().acceptEula()) return;
|
||||||
|
File eula = new File(getConfig().serverDirectory(), "eula.txt");
|
||||||
|
if (eula.exists()) return;
|
||||||
|
try {
|
||||||
|
Files.writeString(eula.toPath(), "eula=true\n");
|
||||||
|
getLog().info("eula.txt created and accepted.");
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new StepExecutionException("Failed to write eula.txt: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package org.strassburger.mcrun.steps;
|
||||||
|
|
||||||
|
import org.apache.maven.plugin.logging.Log;
|
||||||
|
import org.strassburger.mcrun.config.ServerRunStepConfig;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ServerRunStep extends Step<ServerRunStepConfig> {
|
||||||
|
public ServerRunStep(Log log, ServerRunStepConfig config) {
|
||||||
|
super(log, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() throws StepExecutionException {
|
||||||
|
startServerProcess();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> buildCommand() {
|
||||||
|
List<String> cmd = new ArrayList<>();
|
||||||
|
cmd.add("java");
|
||||||
|
cmd.add("-Xmx" + getConfig().maxMemory());
|
||||||
|
cmd.add("-Xms" + getConfig().minMemory());
|
||||||
|
if (getConfig().remoteDebug() && getConfig().debugPort() > 0) {
|
||||||
|
cmd.add(String.format("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:%d", getConfig().debugPort()));
|
||||||
|
}
|
||||||
|
cmd.addAll(getConfig().jvmArgs());
|
||||||
|
cmd.add("-jar");
|
||||||
|
cmd.add(getConfig().serverJarName());
|
||||||
|
cmd.add("--nogui");
|
||||||
|
if (getConfig().port() != null) {
|
||||||
|
cmd.add("--port");
|
||||||
|
cmd.add(String.valueOf(getConfig().port()));
|
||||||
|
}
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startServerProcess() throws StepExecutionException {
|
||||||
|
List<String> command = buildCommand();
|
||||||
|
getLog().info("Starting server with command: " + String.join(" ", command));
|
||||||
|
|
||||||
|
ProcessBuilder pb = new ProcessBuilder(command);
|
||||||
|
pb.directory(getConfig().serverDirectory());
|
||||||
|
pb.inheritIO();
|
||||||
|
Process process;
|
||||||
|
try {
|
||||||
|
process = pb.start();
|
||||||
|
process.waitFor();
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
throw new StepExecutionException("Failed to start server: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.strassburger.mcrun.steps;
|
||||||
|
|
||||||
|
import org.apache.maven.plugin.logging.Log;
|
||||||
|
|
||||||
|
public abstract class Step<T> {
|
||||||
|
private final Log log;
|
||||||
|
private final T config;
|
||||||
|
|
||||||
|
public Step(Log log, T config) {
|
||||||
|
this.log = log;
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void run() throws StepExecutionException;
|
||||||
|
|
||||||
|
protected Log getLog() {
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected T getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.strassburger.mcrun.steps;
|
||||||
|
|
||||||
|
public class StepExecutionException extends RuntimeException {
|
||||||
|
public StepExecutionException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StepExecutionException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user