create zip of all dependencies
This commit is contained in:
parent
0f11dfcacc
commit
5aa10f234f
@ -2,12 +2,17 @@ package de.devloop.mavor.servlet;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import de.devloop.mavor.AuthenticatedServlet;
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
@ -26,12 +31,13 @@ public class Download extends AuthenticatedServlet {
|
||||
private static final String PARAMETER_POM = "pom";
|
||||
private static final String PARAMETER_TYPE = "type";
|
||||
|
||||
// TODO: set as property
|
||||
private static final String MAVEN_CMD = "/usr/bin/mvn";
|
||||
private static final String TEMP_DIR = "/home/damage/Temp/mavor";
|
||||
|
||||
@Override
|
||||
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
// implement a lot of checks:
|
||||
// TODO: implement a lot of checks:
|
||||
// NPE, required parameters not given
|
||||
|
||||
String type = req.getParameter(PARAMETER_TYPE);
|
||||
@ -58,6 +64,9 @@ public class Download extends AuthenticatedServlet {
|
||||
req.setAttribute("stderr", executionResult.stderr);
|
||||
req.setAttribute("exitcode", executionResult.exitCode);
|
||||
|
||||
String zipFilename = zipDependencies();
|
||||
req.setAttribute("zipFilename", zipFilename);
|
||||
|
||||
RequestDispatcher view = req.getRequestDispatcher("/download.jsp");
|
||||
view.forward(req, resp);
|
||||
}
|
||||
@ -93,6 +102,33 @@ public class Download extends AuthenticatedServlet {
|
||||
fileWriter.close();
|
||||
}
|
||||
|
||||
private String zipDependencies() throws IOException {
|
||||
File tempDir = new File(TEMP_DIR);
|
||||
File zipFile = File.createTempFile("mavor_", ".zip", tempDir);
|
||||
ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream(zipFile));
|
||||
// TODO: this goes BOOM on parallel use
|
||||
File[] jarFiles = tempDir.listFiles(new FilenameFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return dir.getAbsolutePath().equals(TEMP_DIR) && name.endsWith(".jar");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
for (File jarFile : jarFiles) {
|
||||
FileInputStream jarFileStream = new FileInputStream(jarFile);
|
||||
ZipEntry zipEntry = new ZipEntry(jarFile.getName());
|
||||
zipStream.putNextEntry(zipEntry);
|
||||
zipStream.write(jarFileStream.readAllBytes());
|
||||
zipStream.closeEntry();
|
||||
jarFileStream.close();
|
||||
}
|
||||
|
||||
zipStream.close();
|
||||
return zipFile.getAbsolutePath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads given resource file as a string.
|
||||
*
|
||||
|
@ -3,7 +3,8 @@
|
||||
<html>
|
||||
<body style="background-color:black; color:white">
|
||||
Output:<br/>
|
||||
<pre>${stdout}</pre>
|
||||
<pre>${stdout}</pre><br/>
|
||||
File: ${zipFilename}<br/>
|
||||
<a href="/mavor/logout">logout</a> | <a href="/mavor">back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user