-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
918 additions
and
290 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
55 changes: 33 additions & 22 deletions
55
deployer/src/main/kotlin/io/deepmedia/tools/deployer/ConfigureSigning.kt
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 |
---|---|---|
@@ -1,37 +1,48 @@ | ||
package io.deepmedia.tools.deployer | ||
|
||
import io.deepmedia.tools.deployer.model.AbstractDeploySpec | ||
import io.deepmedia.tools.deployer.model.Component | ||
import org.gradle.api.Project | ||
import org.gradle.api.logging.LogLevel | ||
import org.gradle.api.publish.PublishingExtension | ||
import org.gradle.api.publish.maven.MavenPublication | ||
import org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal | ||
import org.gradle.kotlin.dsl.get | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.gradle.kotlin.dsl.withType | ||
import org.gradle.plugins.signing.Sign | ||
import org.gradle.plugins.signing.SigningExtension | ||
import org.gradle.plugins.signing.signatory.pgp.PgpSignatory | ||
import org.gradle.security.internal.pgp.BaseInMemoryPgpSignatoryProvider | ||
|
||
/** | ||
* Note: with respect to official docs, we do the extra step of fetching the signatory | ||
* (which [SigningExtension] generates after [SigningExtension.useInMemoryPgpKeys]) and pass that again | ||
* to the task using [Sign.setSignatory]. | ||
* | ||
* This may be helpful in case different key-password pairs are defined for different publications, | ||
* which our API allows, while the [SigningExtension] is a project-wide item. There's the risk that | ||
* at execution time, all tasks use the last key-value pair which is not what we want. | ||
*/ | ||
internal fun Project.configureSigning( | ||
spec: AbstractDeploySpec<*>, | ||
info: Pair<String, String>, | ||
maven: MavenPublication, | ||
log: Logger | ||
): Sign? { | ||
// Configure signing if present | ||
val signInfo = spec.resolveSigning(this) | ||
if (signInfo != null) { | ||
log { "configureSigning: signing MavenPublication ${maven.name}" } | ||
val ext = extensions.getByType(SigningExtension::class) | ||
val (key, password) = signInfo | ||
ext.useInMemoryPgpKeys(key, password) | ||
try { | ||
return ext.sign(maven).single() | ||
} catch (e: Throwable) { | ||
logger.log( | ||
LogLevel.WARN, "Two or more specs share the same MavenPublication under the hood! " + | ||
"Only one of the signatures will be used, and other configuration parameters " + | ||
"might be conflicting as well. Location: ${log.prefix} [${e.message}]") | ||
} | ||
): Sign { | ||
log { "configureSigning: signing MavenPublication ${maven.name}" } | ||
|
||
// If this publication is shared between specs, there's a chance that the sign task already exists. | ||
// Note that we have no way of verifying whether that spec used the same key-password pair, so we warn. | ||
val previous = tasks.withType<Sign>().findByName("sign${maven.name.capitalized()}") | ||
if (previous != null) { | ||
logger.log( | ||
LogLevel.WARN, "Two or more specs share the same MavenPublication under the hood! " + | ||
"Only one of the signatures will be used, and other configuration parameters " + | ||
"might be conflicting too. Location: ${log.prefix}") | ||
return previous | ||
} | ||
|
||
val ext = extensions.getByType(SigningExtension::class) | ||
ext.useInMemoryPgpKeys(info.first, info.second) | ||
val signatory = ext.signatory | ||
return ext.sign(maven).single().apply { | ||
setSignatory(signatory) | ||
} | ||
return null | ||
} |
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
Oops, something went wrong.