Skip to content

Commit

Permalink
Fixes #36 Misplaced Signing Key
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverspryn committed Mar 28, 2024
1 parent ee6eaeb commit 1c06740
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class EnvironmentVariableDelegate(
/**
* Gets an environment variable in one of two ways:
* ```kotlin
* val JAVA_HOME: String by envVar() // Fetches the environment variable named "JAVA_HOME"
* val javaHome: String by envVar("JAVA_HOME") // Fetches the environment variable named "JAVA_HOME"
* val JAVA_HOME by envVar() // Fetches the environment variable named "JAVA_HOME" as a String
* val javaHome by envVar("JAVA_HOME") // Fetches the environment variable named "JAVA_HOME" as a String
* ```
*
* @param variableName The name of the environment variable to fetch. If
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,28 @@ import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
import org.gradle.api.Project

class GradlePropertyDelegate<T>(
class GradlePropertyDelegate(
private val project: Project,
private val variableName: String? = null
) : ReadOnlyProperty<Any?, T> {
@Suppress("UNCHECKED_CAST")
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
) : ReadOnlyProperty<Any?, String> {
override fun getValue(thisRef: Any?, property: KProperty<*>): String {
val nameToUse = variableName ?: property.name
val outcome = project.findProperty(nameToUse) as T

if (outcome == null) {
throw IllegalStateException("Gradle property variable '$nameToUse' is not set.")
} else {
return outcome
}
val outcome = project.findProperty(nameToUse) as String?
return outcome ?: ""
}
}

/**
* Gets a Gradle property in one of two ways:
* ```kotlin
* val propertyName: String by propertyValue() // Fetches the value of "propertyName" in gradle.properties
* val property: String by propertyValue("propertyName") // Fetches the value of "propertyName" in gradle.properties
* val propertyName by propertyValue() // Fetches the Gradle Property value of "propertyName" as a String
* val property by propertyValue("propertyName") // Fetches the Gradle Property value of "propertyName" as a String
* ```
*
* @param propertyName The name of the property to fetch. If `null`, the
* name of the Kotlin variable will be used.
* @return The value of the Gradle property.
* @throws IllegalStateException If the Gradle property is not set.
* @return The value of the Gradle property or an empty string if it is
* not set.
*/
fun <T> Project.propertyValue(propertyName: String? = null) =
GradlePropertyDelegate<T>(this, propertyName)
fun Project.propertyValue(propertyName: String? = null) =
GradlePropertyDelegate(this, propertyName)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.oliverspryn.gradle.plugin
import com.android.build.api.dsl.LibraryExtension
import com.oliverspryn.gradle.BuildConfig
import com.oliverspryn.gradle.CentralRepositoryConfig
import com.oliverspryn.gradle.delegate.envVar
import com.oliverspryn.gradle.delegate.propertyValue
import com.oliverspryn.gradle.extension.plugins
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand Down Expand Up @@ -101,8 +101,8 @@ class CentralRepositoryConventionPlugin : Plugin<Project> {
}

extensions.configure<SigningExtension> {
val gpgSigningKey: String by envVar("GPG_SIGNING_KEY")
val gpgSigningKeyPassword: String by envVar("GPG_SIGNING_KEY_PASSWORD")
val gpgSigningKey by propertyValue("GPG_SIGNING_KEY")
val gpgSigningKeyPassword by propertyValue("GPG_SIGNING_KEY_PASSWORD")

useInMemoryPgpKeys(gpgSigningKey, gpgSigningKeyPassword)
sign(extensions.getByType<PublishingExtension>().publications[CentralRepositoryConfig.LIBRARY_NAME])
Expand Down

0 comments on commit 1c06740

Please sign in to comment.