Return zip
This commit is contained in:
parent
883610878a
commit
ddf8558578
@ -2,17 +2,22 @@ package starter
|
||||
|
||||
import starter.utils.ZipOutput
|
||||
import starter.utils.prettyPrintXml
|
||||
import starter.utils.sanitizeFilename
|
||||
|
||||
class ProjectZip(private val templates: Templates) {
|
||||
|
||||
fun createZip(project: Project, inputs: List<Input>, dependencies: List<Dependency>) {
|
||||
fun createZip(project: Project, inputs: List<Input>, dependencies: List<Dependency>): String {
|
||||
val pom = templates.pom(dependencies, inputs)
|
||||
val prettyPom = prettyPrintXml(pom)
|
||||
|
||||
ZipOutput(project.name).use {
|
||||
val name: String
|
||||
|
||||
ZipOutput(sanitizeFilename(project.name)).use {
|
||||
name = it.name
|
||||
it.write("pom.xml", prettyPom)
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
package starter
|
||||
|
||||
import io.javalin.Javalin
|
||||
import starter.utils.sanitizeFilename
|
||||
import java.io.File
|
||||
|
||||
class Server(
|
||||
private val views: Views,
|
||||
@ -33,10 +35,12 @@ class Server(
|
||||
val basePackage = inputs.find { it.name == "basePackage" }!!.value!!
|
||||
val project = Project(projectName, basePackage)
|
||||
|
||||
projectZip.createZip(project, inputs, deps)
|
||||
TODO()
|
||||
ctx.result("prettyPrintXml(generatedPom)")
|
||||
|
||||
ctx.contentType("text/xml")
|
||||
ctx.header("Content-Disposition", "attachment; filename=\"${sanitizeFilename(projectName)}.zip\"")
|
||||
val zipFile = projectZip.createZip(project, inputs, deps)
|
||||
ctx.result(File(zipFile).readBytes())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
3
src/main/kotlin/starter/utils/PathUtils.kt
Normal file
3
src/main/kotlin/starter/utils/PathUtils.kt
Normal file
@ -0,0 +1,3 @@
|
||||
package starter.utils
|
||||
|
||||
fun sanitizeFilename(inputName: String): String = inputName.replace("[^a-zA-Z0-9-_.]".toRegex(), "_")
|
||||
@ -12,6 +12,8 @@ class ZipOutput(name: String) : AutoCloseable {
|
||||
createNewFile()
|
||||
}
|
||||
private val outputStream = ZipArchiveOutputStream(zipFile.outputStream())
|
||||
val name: String
|
||||
get() = zipFile.name
|
||||
|
||||
fun write(path: String, content: String) {
|
||||
val entry = ZipArchiveEntry(path)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user