cleanup system

This commit is contained in:
damage 2024-12-23 11:04:05 +01:00
parent 4c9676773f
commit a5cf24366e

View File

@ -49,14 +49,15 @@ public class DownloadJars extends AuthenticatedServlet {
// NPE, required parameters not given
String type = req.getParameter(PARAMETER_TYPE);
File pomXmlFile;
if (type.equals("artifact")) {
String site = req.getParameter(PARAMETER_SITE);
String groupId = req.getParameter(PARAMETER_GROUP_ID);
String artifactId = req.getParameter(PARAMETER_ARTIFACT_ID);
String version = req.getParameter(PARAMETER_VERSION);
generatePomXmlByArtifact(site, groupId, artifactId, version);
pomXmlFile = generatePomXmlByArtifact(site, groupId, artifactId, version);
} else if (type.equals("pom")) {
writePomXml(req.getParameter(PARAMETER_POM));
pomXmlFile = writePomXml(req.getParameter(PARAMETER_POM));
} else {
throw new ServletException("Unknown download type: " + type);
}
@ -66,6 +67,8 @@ public class DownloadJars extends AuthenticatedServlet {
executionResult = executeMaven();
} catch (InterruptedException e) {
throw new ServletException("Running maven failed", e);
} finally {
pomXmlFile.delete();
}
req.setAttribute("stdout", executionResult.stdout);
@ -92,22 +95,24 @@ public class DownloadJars extends AuthenticatedServlet {
return executionResult;
}
private void generatePomXmlByArtifact(String site, String groupId, String artifactId, String version) throws IOException {
private File generatePomXmlByArtifact(String site, String groupId, String artifactId, String version) throws IOException {
String pomXml = getResourceFileAsString("pomstub.xml");
pomXml = pomXml.replace("{site-id}", "foo");
pomXml = pomXml.replace("{site-url}", site);
pomXml = pomXml.replace("{group-id}", groupId);
pomXml = pomXml.replace("{artifact-id}", artifactId);
pomXml = pomXml.replace("{version}", version);
writePomXml(pomXml);
return writePomXml(pomXml);
}
private void writePomXml(String pomXml) throws IOException {
private File writePomXml(String pomXml) throws IOException {
File pomXmlFile = new File(tempDir, "pom.xml");
pomXmlFile.delete();
FileWriter fileWriter = new FileWriter(pomXmlFile);
fileWriter.write(pomXml);
fileWriter.close();
return pomXmlFile;
}
private String zipDependencies() throws IOException {
@ -134,6 +139,7 @@ public class DownloadJars extends AuthenticatedServlet {
zipStream.write(jarFileStream.readAllBytes());
zipStream.closeEntry();
jarFileStream.close();
jarFile.delete();
}
zipStream.close();