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> <updated>1779565206518</updated>
<workItem from="1779565207730" duration="57000" /> <workItem from="1779565207730" duration="57000" />
<workItem from="1779565274563" duration="632000" /> <workItem from="1779565274563" duration="632000" />
<workItem from="1779565913273" duration="7278000" /> <workItem from="1779565913273" duration="7503000" />
</task> </task>
<servers /> <servers />
</component> </component>
@@ -94,8 +94,13 @@ public class RunServerMojo extends AbstractMojo {
@Override @Override
public void execute() throws MojoExecutionException, MojoFailureException { 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"); File pluginsDir = new File(serverDirectory, "plugins");
pluginsDir.mkdirs(); pluginsDir.mkdirs();
try { try {
@@ -105,7 +110,9 @@ public class RunServerMojo extends AbstractMojo {
} catch (IOException e) { } catch (IOException e) {
throw new MojoExecutionException("Failed to copy plugin jar file: " + pluginJar.getAbsolutePath(), e); throw new MojoExecutionException("Failed to copy plugin jar file: " + pluginJar.getAbsolutePath(), e);
} }
}
private void downloadServerJar() throws MojoExecutionException {
try { try {
ServerJarDownloader jarDownloader = ServerJarDownloader.forServerSoftware(serverSoftware) ServerJarDownloader jarDownloader = ServerJarDownloader.forServerSoftware(serverSoftware)
.withLog(getLog()).withServerDirectory(serverDirectory) .withLog(getLog()).withServerDirectory(serverDirectory)
@@ -115,25 +122,16 @@ public class RunServerMojo extends AbstractMojo {
} catch (ServerJarDownloadException e) { } catch (ServerJarDownloadException e) {
throw new MojoExecutionException("Failed to download server jar", e); throw new MojoExecutionException("Failed to download server jar", e);
} }
}
if (acceptEula) acceptEula(); private void acceptEula() throws MojoExecutionException {
File eula = new File(serverDirectory, "eula.txt");
List<String> command = buildCommand(); if (eula.exists()) return;
getLog().info("Starting server with command: " + String.join(" ", command));
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(serverDirectory);
pb.inheritIO();
Process process;
try { try {
process = pb.start(); Files.writeString(eula.toPath(), "eula=true\n");
getLog().info("eula.txt created and accepted.");
} catch (IOException e) { } catch (IOException e) {
throw new MojoExecutionException("Failed to start server: " + e.getMessage(), e); throw new MojoExecutionException("Failed to write eula.txt: " + e.getMessage(), e);
}
try {
process.waitFor();
} catch (InterruptedException e) {
throw new MojoExecutionException("Failed to start server: " + e.getMessage(), e);
} }
} }
@@ -153,14 +151,19 @@ public class RunServerMojo extends AbstractMojo {
return cmd; return cmd;
} }
private void acceptEula() throws MojoExecutionException { private void startServerProcess() throws MojoExecutionException {
File eula = new File(serverDirectory, "eula.txt"); List<String> command = buildCommand();
if (eula.exists()) return; getLog().info("Starting server with command: " + String.join(" ", command));
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(serverDirectory);
pb.inheritIO();
Process process;
try { try {
Files.writeString(eula.toPath(), "eula=true\n"); process = pb.start();
getLog().info("eula.txt created and accepted."); process.waitFor();
} catch (IOException e) { } catch (IOException | InterruptedException e) {
throw new MojoExecutionException("Failed to write eula.txt: " + e.getMessage(), e); throw new MojoExecutionException("Failed to start server: " + e.getMessage(), e);
} }
} }
} }