Skip to content

Commit

Permalink
fix: resolve ktlint formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Mirwald committed Aug 8, 2024
1 parent a6a2a22 commit 5e46a8e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class CodeArtifact {
AwsBasicCredentials.create(
accessKeyId.get(),
secretAccessKey.get(),
)
),
).resolveCredentials()
}
} else {
Expand All @@ -55,7 +55,7 @@ abstract class CodeArtifact {
AwsBasicCredentials.create(
accessKeyId.get(),
secretAccessKey.get(),
)
),
).resolveCredentials()
}
} else {
Expand Down Expand Up @@ -83,7 +83,7 @@ abstract class CodeArtifact {
internal fun repositoryEndpointResponse(
domain: String,
repository: String,
format: String = "maven"
format: String = "maven",
): GetRepositoryEndpointResponse {
return client.getRepositoryEndpoint {
it.domain(domain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ package com.liftric.code.artifact.repository
import org.gradle.api.plugins.ExtensionContainer

abstract class CodeArtifactRepositoryExtension(private val extensionContainer: ExtensionContainer) : CodeArtifact() {
fun additional(name: String, block: CodeArtifact.() -> Unit) {
fun additional(
name: String,
block: CodeArtifact.() -> Unit,
) {
if (name.isEmpty()) error("Empty domain is not supported!")
store[name] = extensionContainer.create(
"${name}${CodeArtifactRepositoryPlugin.extensionName}",
CodeArtifactRepositoryExtension::class.java,
extensionContainer
).apply {
block.invoke(this)
region.convention(this@CodeArtifactRepositoryExtension.region)
profile.convention(this@CodeArtifactRepositoryExtension.profile)
accessKeyId.convention(this@CodeArtifactRepositoryExtension.accessKeyId)
secretAccessKey.convention(this@CodeArtifactRepositoryExtension.secretAccessKey)
tokenExpiresIn.convention(this@CodeArtifactRepositoryExtension.tokenExpiresIn)
}
store[name] =
extensionContainer.create(
"${name}${CodeArtifactRepositoryPlugin.EXTENSION_NAME}",
CodeArtifactRepositoryExtension::class.java,
extensionContainer,
).apply {
block.invoke(this)
region.convention(this@CodeArtifactRepositoryExtension.region)
profile.convention(this@CodeArtifactRepositoryExtension.profile)
accessKeyId.convention(this@CodeArtifactRepositoryExtension.accessKeyId)
secretAccessKey.convention(this@CodeArtifactRepositoryExtension.secretAccessKey)
tokenExpiresIn.convention(this@CodeArtifactRepositoryExtension.tokenExpiresIn)
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,68 @@ abstract class CodeArtifactRepositoryPlugin : Plugin<Any> {
override fun apply(scope: Any) {
when (scope) {
is Settings -> {
scope.extensions.create(extensionName, CodeArtifactRepositoryExtension::class.java, scope.extensions)
scope.extensions.create(EXTENSION_NAME, CodeArtifactRepositoryExtension::class.java, scope.extensions)
.also {
CodeArtifactRepositoryExtension.store[""] = it
}
}

is Project -> {
scope.extensions.create(extensionName, CodeArtifactRepositoryExtension::class.java, scope.extensions)
scope.extensions.create(EXTENSION_NAME, CodeArtifactRepositoryExtension::class.java, scope.extensions)
.also {
CodeArtifactRepositoryExtension.store[""] = it
}
}

is Gradle -> {
scope.beforeSettings {
extensions.create(extensionName, CodeArtifactRepositoryExtension::class.java, extensions)
.also {
CodeArtifactRepositoryExtension.store[""] = it
}
extensions.create(EXTENSION_NAME, CodeArtifactRepositoryExtension::class.java, extensions).also {
CodeArtifactRepositoryExtension.store[""] = it
}
}
}

else -> {
throw GradleException("Should only get applied on Settings or Project")
}
}
}

companion object {
const val extensionName = "CodeArtifactRepository"
const val EXTENSION_NAME = "CodeArtifactRepository"
}
}

inline fun Settings.codeArtifactRepository(configure: CodeArtifactRepositoryExtension.() -> Unit) {
extensions.getByName<CodeArtifactRepositoryExtension>(CodeArtifactRepositoryPlugin.extensionName).configure()
extensions.getByName<CodeArtifactRepositoryExtension>(CodeArtifactRepositoryPlugin.EXTENSION_NAME).configure()
}

inline fun Project.codeArtifactRepository(configure: CodeArtifactRepositoryExtension.() -> Unit) {
extensions.getByName<CodeArtifactRepositoryExtension>(CodeArtifactRepositoryPlugin.extensionName).configure()
extensions.getByName<CodeArtifactRepositoryExtension>(CodeArtifactRepositoryPlugin.EXTENSION_NAME).configure()
}

inline fun Gradle.codeArtifactRepository(crossinline configure: CodeArtifactRepositoryExtension.() -> Unit) {
settingsEvaluated {
extensions.getByName<CodeArtifactRepositoryExtension>(CodeArtifactRepositoryPlugin.extensionName).configure()
extensions.getByName<CodeArtifactRepositoryExtension>(CodeArtifactRepositoryPlugin.EXTENSION_NAME).configure()
}
}

/**
* Use the default CodeArtifact config (and therefore extension)
*/
fun RepositoryHandler.codeArtifact(domain: String, repository: String): MavenArtifactRepository =
codeArtifact("", domain, repository)
fun RepositoryHandler.codeArtifact(
domain: String,
repository: String,
): MavenArtifactRepository = codeArtifact("", domain, repository)

/**
* Use CodeArtifact by additional name
*/
fun RepositoryHandler.codeArtifact(additionalName: String, domain: String, repository: String) = maven {
fun RepositoryHandler.codeArtifact(
additionalName: String,
domain: String,
repository: String,
) = maven {
CodeArtifactRepositoryExtension.store[additionalName]?.let {
name = listOf(additionalName, domain, repository).joinToString("") { it.capitalized() }
url = URI.create(it.repositoryEndpointResponse(domain, repository).repositoryEndpoint())
Expand All @@ -89,18 +97,25 @@ fun codeArtifactToken(domain: String): String = codeArtifactToken("", domain)
/**
* If you need the plain endpoint uri
*/
fun codeArtifactUri(domain: String, repository: String, format: String): URI =
codeArtifactUri("", domain, repository, format)
fun codeArtifactUri(
domain: String,
repository: String,
format: String,
): URI = codeArtifactUri("", domain, repository, format)

/**
* If you need the plain token
*
* @param additionalName this is the name (prefix) of the codeArtifactRepository configuration. Use an empty string to use
* the default extension
*/
fun codeArtifactToken(additionalName: String, domain: String): String {
val settings = CodeArtifactRepositoryExtension.store[additionalName]
?: throw GradleException("didn't find CodeArtifactRepositoryExtension with the name: $")
fun codeArtifactToken(
additionalName: String,
domain: String,
): String {
val settings =
CodeArtifactRepositoryExtension.store[additionalName]
?: throw GradleException("didn't find CodeArtifactRepositoryExtension with the name: $")
return settings.authorizationTokenResponse(domain).authorizationToken()
}

Expand All @@ -110,8 +125,14 @@ fun codeArtifactToken(additionalName: String, domain: String): String {
* @param additionalName this is the name (prefix) of the codeArtifactRepository configuration. Use an empty string to use
* the default extension
*/
fun codeArtifactUri(additionalName: String, domain: String, repository: String, format: String): URI {
val settings = CodeArtifactRepositoryExtension.store[additionalName]
?: throw GradleException("didn't find CodeArtifactRepositoryExtension with the name: $")
fun codeArtifactUri(
additionalName: String,
domain: String,
repository: String,
format: String,
): URI {
val settings =
CodeArtifactRepositoryExtension.store[additionalName]
?: throw GradleException("didn't find CodeArtifactRepositoryExtension with the name: $")
return settings.repositoryEndpointResponse(domain, repository, format).repositoryEndpoint().let { URI.create(it) }
}

0 comments on commit 5e46a8e

Please sign in to comment.