download zip file
This commit is contained in:
parent
36473592ad
commit
97324e4647
@ -31,11 +31,14 @@ public class Download extends AuthenticatedServlet {
|
|||||||
private static final String PARAMETER_VERSION = "version";
|
private static final String PARAMETER_VERSION = "version";
|
||||||
private static final String PARAMETER_POM = "pom";
|
private static final String PARAMETER_POM = "pom";
|
||||||
private static final String PARAMETER_TYPE = "type";
|
private static final String PARAMETER_TYPE = "type";
|
||||||
|
private static final String PARAMETER_ZIP = "zip";
|
||||||
|
|
||||||
// TODO: set as property
|
// TODO: set as property
|
||||||
private static final String MAVEN_CMD = "/usr/bin/mvn";
|
private static final String MAVEN_CMD = "/usr/bin/mvn";
|
||||||
private static final String TEMP_DIR = "/home/damage/Temp/mavor";
|
private static final String TEMP_DIR = "/home/damage/Temp/mavor";
|
||||||
|
|
||||||
|
private File tempDir = new File(TEMP_DIR);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
// TODO: implement a lot of checks:
|
// TODO: implement a lot of checks:
|
||||||
@ -50,6 +53,13 @@ public class Download extends AuthenticatedServlet {
|
|||||||
generatePomXmlByArtifact(site, groupId, artifactId, version);
|
generatePomXmlByArtifact(site, groupId, artifactId, version);
|
||||||
} else if (type.equals("pom")) {
|
} else if (type.equals("pom")) {
|
||||||
writePomXml(req.getParameter(PARAMETER_POM));
|
writePomXml(req.getParameter(PARAMETER_POM));
|
||||||
|
} else if (type.equals("zip")) {
|
||||||
|
String zipFilename = req.getParameter(PARAMETER_ZIP);
|
||||||
|
File zipFile = new File(tempDir, zipFilename);
|
||||||
|
resp.setContentType("application/zip");
|
||||||
|
FileInputStream fileInputStream = new FileInputStream(zipFile);
|
||||||
|
fileInputStream.transferTo(resp.getOutputStream());
|
||||||
|
fileInputStream.close();
|
||||||
} else {
|
} else {
|
||||||
throw new ServletException("Unknown download type: " + type);
|
throw new ServletException("Unknown download type: " + type);
|
||||||
}
|
}
|
||||||
@ -96,7 +106,7 @@ public class Download extends AuthenticatedServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void writePomXml(String pomXml) throws IOException {
|
private void writePomXml(String pomXml) throws IOException {
|
||||||
File pomXmlFile = new File(TEMP_DIR + "/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);
|
||||||
@ -104,7 +114,6 @@ public class Download extends AuthenticatedServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String zipDependencies() throws IOException {
|
private String zipDependencies() throws IOException {
|
||||||
File tempDir = new File(TEMP_DIR);
|
|
||||||
File zipFile = new File(tempDir, "mavor_" + UUID.randomUUID() + ".zip");
|
File zipFile = new File(tempDir, "mavor_" + UUID.randomUUID() + ".zip");
|
||||||
ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream(zipFile));
|
ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream(zipFile));
|
||||||
// TODO: this goes BOOM on parallel use
|
// TODO: this goes BOOM on parallel use
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<body style="background-color:black; color:white">
|
<body style="background-color:black; color:white">
|
||||||
Output:<br/>
|
Output:<br/>
|
||||||
<pre>${stdout}</pre><br/>
|
<pre>${stdout}</pre><br/>
|
||||||
File: ${zipFilename}<br/>
|
File: <a href="/mavor/download?type=zip&file=${zipFilename}">${zipFilename}</a><br/>
|
||||||
<a href="/mavor/logout">logout</a> | <a href="/mavor">back</a>
|
<a href="/mavor/logout">logout</a> | <a href="/mavor">back</a>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user