quick-e2e: Add CopyFileService to handle file copying and update Main class to utilize it

This commit is contained in:
Oliver
2025-03-16 19:23:07 +01:00
parent d925b211fb
commit 2bda8bb7db
3 changed files with 48 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package de.oliver.quicke2e;
import de.oliver.quicke2e.config.Configuration;
import de.oliver.quicke2e.config.Context;
import de.oliver.quicke2e.steps.copyFile.CopyFileService;
import de.oliver.quicke2e.steps.eula.EulaService;
import de.oliver.quicke2e.steps.gradle.GradleService;
import de.oliver.quicke2e.steps.ops.OPsService;
@@ -40,6 +41,11 @@ public class Main {
GradleService gradle = new GradleService();
gradle.runTask(":plugins:fancyholograms:shadowJar");
gradle.runTask(":plugins:fancyvisuals:shadowJar");
CopyFileService copyFile = new CopyFileService();
copyFile.copyFile(context, "plugins/fancyholograms/build/libs", "FancyHolograms-.*\\.jar", "plugins");
copyFile.copyFile(context, "plugins/fancyvisuals/build/libs", "FancyVisuals-.*\\.jar", "plugins");
StartServerService startServer = new StartServerService();
startServer.startServer(context);

View File

@@ -0,0 +1,40 @@
package de.oliver.quicke2e.steps.copyFile;
import de.oliver.quicke2e.config.Context;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Optional;
import java.util.regex.Pattern;
public class CopyFileService {
public void copyFile(Context context, String sourceFolder, String source, String destination) {
String realSource = source;
if (source.contains("*")) {
Pattern pattern = Pattern.compile(source);
try {
Optional<Path> first = Files.walk(Path.of(sourceFolder))
.filter(Files::isRegularFile)
.filter(path -> pattern.matcher(path.getFileName().toString()).matches())
.findFirst();
if (first.isPresent()) {
realSource = first.get().toString();
}
} catch (IOException e) {
e.printStackTrace();
}
}
Path target = context.serverEnvPath().resolve(destination + "/" + Path.of(realSource).getFileName());
try {
Files.copy(Path.of(realSource), target, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -14,7 +14,8 @@ public class GradleService {
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
try {
processBuilder.start();
Process process = processBuilder.start();
process.waitFor();
} catch (Exception e) {
e.printStackTrace();
}