cleanup system
This commit is contained in:
parent
4c9676773f
commit
a5cf24366e
@ -49,14 +49,15 @@ public class DownloadJars extends AuthenticatedServlet {
|
|||||||
// NPE, required parameters not given
|
// NPE, required parameters not given
|
||||||
|
|
||||||
String type = req.getParameter(PARAMETER_TYPE);
|
String type = req.getParameter(PARAMETER_TYPE);
|
||||||
|
File pomXmlFile;
|
||||||
if (type.equals("artifact")) {
|
if (type.equals("artifact")) {
|
||||||
String site = req.getParameter(PARAMETER_SITE);
|
String site = req.getParameter(PARAMETER_SITE);
|
||||||
String groupId = req.getParameter(PARAMETER_GROUP_ID);
|
String groupId = req.getParameter(PARAMETER_GROUP_ID);
|
||||||
String artifactId = req.getParameter(PARAMETER_ARTIFACT_ID);
|
String artifactId = req.getParameter(PARAMETER_ARTIFACT_ID);
|
||||||
String version = req.getParameter(PARAMETER_VERSION);
|
String version = req.getParameter(PARAMETER_VERSION);
|
||||||
generatePomXmlByArtifact(site, groupId, artifactId, version);
|
pomXmlFile = generatePomXmlByArtifact(site, groupId, artifactId, version);
|
||||||
} else if (type.equals("pom")) {
|
} else if (type.equals("pom")) {
|
||||||
writePomXml(req.getParameter(PARAMETER_POM));
|
pomXmlFile = writePomXml(req.getParameter(PARAMETER_POM));
|
||||||
} else {
|
} else {
|
||||||
throw new ServletException("Unknown download type: " + type);
|
throw new ServletException("Unknown download type: " + type);
|
||||||
}
|
}
|
||||||
@ -66,6 +67,8 @@ public class DownloadJars extends AuthenticatedServlet {
|
|||||||
executionResult = executeMaven();
|
executionResult = executeMaven();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new ServletException("Running maven failed", e);
|
throw new ServletException("Running maven failed", e);
|
||||||
|
} finally {
|
||||||
|
pomXmlFile.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
req.setAttribute("stdout", executionResult.stdout);
|
req.setAttribute("stdout", executionResult.stdout);
|
||||||
@ -92,22 +95,24 @@ public class DownloadJars extends AuthenticatedServlet {
|
|||||||
return executionResult;
|
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");
|
String pomXml = getResourceFileAsString("pomstub.xml");
|
||||||
pomXml = pomXml.replace("{site-id}", "foo");
|
pomXml = pomXml.replace("{site-id}", "foo");
|
||||||
pomXml = pomXml.replace("{site-url}", site);
|
pomXml = pomXml.replace("{site-url}", site);
|
||||||
pomXml = pomXml.replace("{group-id}", groupId);
|
pomXml = pomXml.replace("{group-id}", groupId);
|
||||||
pomXml = pomXml.replace("{artifact-id}", artifactId);
|
pomXml = pomXml.replace("{artifact-id}", artifactId);
|
||||||
pomXml = pomXml.replace("{version}", version);
|
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");
|
File pomXmlFile = new File(tempDir, "pom.xml");
|
||||||
pomXmlFile.delete();
|
pomXmlFile.delete();
|
||||||
FileWriter fileWriter = new FileWriter(pomXmlFile);
|
FileWriter fileWriter = new FileWriter(pomXmlFile);
|
||||||
fileWriter.write(pomXml);
|
fileWriter.write(pomXml);
|
||||||
fileWriter.close();
|
fileWriter.close();
|
||||||
|
|
||||||
|
return pomXmlFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String zipDependencies() throws IOException {
|
private String zipDependencies() throws IOException {
|
||||||
@ -134,6 +139,7 @@ public class DownloadJars extends AuthenticatedServlet {
|
|||||||
zipStream.write(jarFileStream.readAllBytes());
|
zipStream.write(jarFileStream.readAllBytes());
|
||||||
zipStream.closeEntry();
|
zipStream.closeEntry();
|
||||||
jarFileStream.close();
|
jarFileStream.close();
|
||||||
|
jarFile.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
zipStream.close();
|
zipStream.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user