Clean up execute method

This commit is contained in:
2026-05-23 23:57:51 +02:00
parent dd9d263a07
commit 1f2f611977
2 changed files with 28 additions and 25 deletions
+1 -1
View File
@@ -54,7 +54,7 @@
<updated>1779565206518</updated>
<workItem from="1779565207730" duration="57000" />
<workItem from="1779565274563" duration="632000" />
<workItem from="1779565913273" duration="7278000" />
<workItem from="1779565913273" duration="7503000" />
</task>
<servers />
</component>
@@ -94,8 +94,13 @@ public class RunServerMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Server directory: " + serverDirectory.getAbsolutePath());
copyPlugin();
downloadServerJar();
if (acceptEula) acceptEula();
startServerProcess();
}
private void copyPlugin() throws MojoExecutionException {
File pluginsDir = new File(serverDirectory, "plugins");
pluginsDir.mkdirs();
try {
@@ -105,7 +110,9 @@ public class RunServerMojo extends AbstractMojo {
} 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)
@@ -115,25 +122,16 @@ public class RunServerMojo extends AbstractMojo {
} catch (ServerJarDownloadException e) {
throw new MojoExecutionException("Failed to download server jar", e);
}
}
if (acceptEula) acceptEula();
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;
private void acceptEula() throws MojoExecutionException {
File eula = new File(serverDirectory, "eula.txt");
if (eula.exists()) return;
try {
process = pb.start();
Files.writeString(eula.toPath(), "eula=true\n");
getLog().info("eula.txt created and accepted.");
} catch (IOException e) {
throw new MojoExecutionException("Failed to start server: " + e.getMessage(), e);
}
try {
process.waitFor();
} catch (InterruptedException e) {
throw new MojoExecutionException("Failed to start server: " + e.getMessage(), e);
throw new MojoExecutionException("Failed to write eula.txt: " + e.getMessage(), e);
}
}
@@ -153,14 +151,19 @@ public class RunServerMojo extends AbstractMojo {
return cmd;
}
private void acceptEula() throws MojoExecutionException {
File eula = new File(serverDirectory, "eula.txt");
if (eula.exists()) return;
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 {
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);
process = pb.start();
process.waitFor();
} catch (IOException | InterruptedException e) {
throw new MojoExecutionException("Failed to start server: " + e.getMessage(), e);
}
}
}