diff --git a/src/main/java/de/devloop/mavor/servlet/Download.java b/src/main/java/de/devloop/mavor/servlet/Download.java index b6368e2..5973b73 100644 --- a/src/main/java/de/devloop/mavor/servlet/Download.java +++ b/src/main/java/de/devloop/mavor/servlet/Download.java @@ -31,11 +31,14 @@ public class Download extends AuthenticatedServlet { private static final String PARAMETER_VERSION = "version"; private static final String PARAMETER_POM = "pom"; private static final String PARAMETER_TYPE = "type"; + private static final String PARAMETER_ZIP = "zip"; // TODO: set as property private static final String MAVEN_CMD = "/usr/bin/mvn"; private static final String TEMP_DIR = "/home/damage/Temp/mavor"; + private File tempDir = new File(TEMP_DIR); + @Override protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO: implement a lot of checks: @@ -50,6 +53,13 @@ public class Download extends AuthenticatedServlet { generatePomXmlByArtifact(site, groupId, artifactId, version); } else if (type.equals("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 { throw new ServletException("Unknown download type: " + type); } @@ -96,7 +106,7 @@ public class Download extends AuthenticatedServlet { } private void writePomXml(String pomXml) throws IOException { - File pomXmlFile = new File(TEMP_DIR + "/pom.xml"); + File pomXmlFile = new File(tempDir, "pom.xml"); pomXmlFile.delete(); FileWriter fileWriter = new FileWriter(pomXmlFile); fileWriter.write(pomXml); @@ -104,7 +114,6 @@ public class Download extends AuthenticatedServlet { } private String zipDependencies() throws IOException { - File tempDir = new File(TEMP_DIR); File zipFile = new File(tempDir, "mavor_" + UUID.randomUUID() + ".zip"); ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream(zipFile)); // TODO: this goes BOOM on parallel use diff --git a/src/main/webapp/download.jsp b/src/main/webapp/download.jsp index 514611a..d7a6cd7 100644 --- a/src/main/webapp/download.jsp +++ b/src/main/webapp/download.jsp @@ -4,7 +4,7 @@
Output:${stdout}