mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
.asc signing for Maven publication.
This commit is contained in:
parent
6b017d17e6
commit
93746240d1
2 changed files with 72 additions and 9 deletions
57
src/main/kotlin/com/beust/kobalt/maven/Gpg.kt
Normal file
57
src/main/kotlin/com/beust/kobalt/maven/Gpg.kt
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package com.beust.kobalt.maven
|
||||||
|
|
||||||
|
import com.beust.kobalt.misc.log
|
||||||
|
import com.google.inject.Singleton
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class Gpg {
|
||||||
|
val COMMANDS = listOf("gpg", "gpg2")
|
||||||
|
|
||||||
|
fun findGpgCommand() : String? {
|
||||||
|
val path = System.getenv("PATH")
|
||||||
|
if (path != null) {
|
||||||
|
path.split(File.pathSeparator).forEach { dir ->
|
||||||
|
COMMANDS.map { File(dir, it) }.firstOrNull { it.exists() }?.let {
|
||||||
|
return it.absolutePath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the .asc files
|
||||||
|
*/
|
||||||
|
fun runGpg(files: List<File>) : List<File> {
|
||||||
|
val result = arrayListOf<File>()
|
||||||
|
val gpg = findGpgCommand()
|
||||||
|
if (gpg != null) {
|
||||||
|
val directory = files.get(0).parentFile.absoluteFile
|
||||||
|
files.forEach { file ->
|
||||||
|
with(File(directory, file.absolutePath + ".asc")) {
|
||||||
|
delete()
|
||||||
|
result.add(this)
|
||||||
|
}
|
||||||
|
val allArgs = arrayListOf<String>()
|
||||||
|
allArgs.add(gpg)
|
||||||
|
allArgs.add("-ab")
|
||||||
|
allArgs.add(file.absolutePath)
|
||||||
|
|
||||||
|
val pb = ProcessBuilder(allArgs)
|
||||||
|
pb.directory(directory)
|
||||||
|
pb.inheritIO()
|
||||||
|
log(1, "Signing files: " + allArgs.join(" "))
|
||||||
|
val process = pb.start()
|
||||||
|
val errorCode = process.waitFor()
|
||||||
|
if (errorCode != 0) {
|
||||||
|
throw KobaltException("Couldn't sign file $file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return files.map { File(it.absolutePath + ".asc") }
|
||||||
|
} else {
|
||||||
|
throw KobaltException("Couldn't find the command, is it installed and in your PATH?")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package com.beust.kobalt.plugin.publish
|
||||||
import com.beust.klaxon.*
|
import com.beust.klaxon.*
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.internal.TaskResult
|
import com.beust.kobalt.internal.TaskResult
|
||||||
|
import com.beust.kobalt.maven.Gpg
|
||||||
import com.beust.kobalt.maven.Http
|
import com.beust.kobalt.maven.Http
|
||||||
import com.beust.kobalt.maven.KobaltException
|
import com.beust.kobalt.maven.KobaltException
|
||||||
import com.beust.kobalt.maven.Md5
|
import com.beust.kobalt.maven.Md5
|
||||||
|
@ -43,7 +44,7 @@ open public class UnauthenticatedJCenterApi @Inject constructor(open val http: H
|
||||||
|
|
||||||
public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val username: String?,
|
public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val username: String?,
|
||||||
@Nullable @Assisted("password") val password: String?,
|
@Nullable @Assisted("password") val password: String?,
|
||||||
override val http: Http) : UnauthenticatedJCenterApi(http) {
|
override val http: Http, val gpg: Gpg) : UnauthenticatedJCenterApi(http) {
|
||||||
|
|
||||||
interface IFactory {
|
interface IFactory {
|
||||||
fun create(@Nullable @Assisted("username") username: String?,
|
fun create(@Nullable @Assisted("username") username: String?,
|
||||||
|
@ -88,24 +89,29 @@ public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val
|
||||||
.join("/")
|
.join("/")
|
||||||
}
|
}
|
||||||
|
|
||||||
return upload(files, configuration, fileToPath, true)
|
return upload(files, configuration, fileToPath, generateMd5 = true, generateAsc = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uploadFile(file: File, url: String, configuration: JCenterConfiguration, generateMd5: Boolean = false) =
|
fun uploadFile(file: File, url: String, configuration: JCenterConfiguration, generateMd5: Boolean = false,
|
||||||
upload(arrayListOf(file), configuration, {
|
generateAsc: Boolean = false) =
|
||||||
f: File -> "${UnauthenticatedJCenterApi.BINTRAY_URL_API_CONTENT}/$username/generic/$url"
|
upload(arrayListOf(file), configuration, {
|
||||||
}, generateMd5)
|
f: File -> "${UnauthenticatedJCenterApi.BINTRAY_URL_API_CONTENT}/$username/generic/$url"},
|
||||||
|
generateMd5, generateAsc)
|
||||||
|
|
||||||
private fun upload(files: List<File>, configuration : JCenterConfiguration?, fileToPath: (File) -> String,
|
private fun upload(files: List<File>, configuration : JCenterConfiguration?, fileToPath: (File) -> String,
|
||||||
generateMd5: Boolean = false) : TaskResult {
|
generateMd5: Boolean = false, generateAsc: Boolean) : TaskResult {
|
||||||
val successes = arrayListOf<File>()
|
val successes = arrayListOf<File>()
|
||||||
val failures = hashMapOf<File, String>()
|
val failures = hashMapOf<File, String>()
|
||||||
val filesToUpload = arrayListOf<File>()
|
val filesToUpload = arrayListOf<File>()
|
||||||
files.forEach {
|
|
||||||
|
|
||||||
// Create the md5 for this file
|
if (generateAsc) {
|
||||||
|
// Create the .asc files
|
||||||
|
filesToUpload.addAll(gpg.runGpg(files))
|
||||||
|
}
|
||||||
|
files.forEach {
|
||||||
filesToUpload.add(it)
|
filesToUpload.add(it)
|
||||||
if (generateMd5) {
|
if (generateMd5) {
|
||||||
|
// Create and upload the md5 for this file
|
||||||
with(File(it.absolutePath)) {
|
with(File(it.absolutePath)) {
|
||||||
val md5: String = Md5.toMd5(this)
|
val md5: String = Md5.toMd5(this)
|
||||||
val md5File = File(absolutePath + ".md5")
|
val md5File = File(absolutePath + ".md5")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue