forked from typedb/typedb-dependencies
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated version of assemble_maven rewritten in Kotlin (typedb#293)
## What is the goal of this PR? Rewrite `assemble_maven` in Kotlin in order for us to understand it better and improve its maintability/readability. ## What are the changes implemented in this PR? Implement `assemble_maven` in `@graknlabs_bazel_distribution//maven:new_rules.bzl`
- Loading branch information
Showing
7 changed files
with
643 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import picocli.CommandLine | ||
import picocli.CommandLine.Command | ||
import picocli.CommandLine.Option | ||
import java.io.BufferedInputStream | ||
import java.io.BufferedOutputStream | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
import java.util.* | ||
import java.util.concurrent.Callable | ||
import java.util.zip.ZipEntry | ||
import java.util.zip.ZipFile | ||
import java.util.zip.ZipOutputStream | ||
import kotlin.system.exitProcess | ||
|
||
|
||
@Command(name = "jar-assembler", mixinStandardHelpOptions = true) | ||
class JarAssembler : Callable<Unit> { | ||
|
||
@Option(names = ["--output"], required = true) | ||
lateinit var output_file: File | ||
|
||
@Option(names = ["--prefix"]) | ||
lateinit var prefix: String | ||
|
||
@Option(names = ["--group-id"]) | ||
var groupId = "" | ||
|
||
@Option(names = ["--artifact-id"]) | ||
var artifactId = "" | ||
|
||
@Option(names = ["--pom-file"]) | ||
var pomFile: File? = null | ||
|
||
@Option(names = ["--jars"], split = ";") | ||
lateinit var jars: Array<File> | ||
|
||
val entryNames = mutableSetOf<String>() | ||
|
||
override fun call() { | ||
ZipOutputStream(BufferedOutputStream(FileOutputStream(output_file))).use { out -> | ||
if (pomFile != null) { | ||
val pomFileEntry = ZipEntry("META-INF/maven/${groupId}/${artifactId}/pom.xml") | ||
out.putNextEntry(pomFileEntry) | ||
out.write(pomFile!!.readBytes()) | ||
} | ||
for (jar in jars) { | ||
ZipFile(jar).use { jarZip -> | ||
jarZip.entries().asSequence().forEach { entry -> | ||
if (entry.name.contains("META-INF")) { | ||
return@forEach | ||
} | ||
if (entryNames.contains(entry.name)) { | ||
return@forEach | ||
} | ||
entryNames.add(entry.name) | ||
BufferedInputStream(jarZip.getInputStream(entry)).use { inputStream -> | ||
val newEntry = ZipEntry(prefix + entry.name) | ||
out.putNextEntry(newEntry) | ||
inputStream.copyTo(out, 1024) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun main(args: Array<String>): Unit = exitProcess(CommandLine(JarAssembler()).execute(*args)) |
Oops, something went wrong.