Skip to content

Commit

Permalink
Merge pull request #6 from Liftric/chore/update_dependencies
Browse files Browse the repository at this point in the history
chore: update dependencies & gradle
  • Loading branch information
nvima authored Aug 9, 2024
2 parents cb45b12 + 9cc76b3 commit 7654f55
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Cache
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v2.4.2
- name: Validate
run: ./gradlew check validatePlugins --continue
2 changes: 1 addition & 1 deletion .github/workflows/publish-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Cache
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v2.4.2
- name: Validate
run: ./gradlew check validatePlugins --continue
- name: Publish
Expand Down
31 changes: 17 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import io.gitlab.arturbosch.detekt.Detekt

@Suppress("DSL_SCOPE_VIOLATION") // IntelliJ incorrectly marks libs as not callable
plugins {
`kotlin-dsl`
`maven-publish`
Expand All @@ -18,7 +19,6 @@ dependencies {
implementation(libs.aws.ecs)
implementation(libs.aws.codeartifact)
implementation(libs.aws.sts)
testImplementation(libs.junit)
}

ktlint {
Expand Down Expand Up @@ -62,29 +62,32 @@ tasks.withType<DependencyUpdatesTask> {
}
}

group = "com.liftric.code.artifact.repository"
version = with(versioning.info) {
if (branch == "HEAD" && dirty.not()) {
tag
} else {
full
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}

group = "com.liftric.code.artifact.repository"
version =
with(versioning.info) {
if (branch == "HEAD" && dirty.not()) {
tag
} else {
full
}
}

gradlePlugin {
website.set("https://github.com/Liftric/code-artifact-repository-plugin")
vcsUrl.set("https://github.com/Liftric/code-artifact-repository-plugin")
plugins {
create("CodeArtifactRepositoryPlugin") {
id = "com.liftric.code-artifact-repository-plugin"
displayName = "code-artifact-repository-plugin"
description = "Apply AWS CodeArtifact repositories"
implementationClass = "com.liftric.code.artifact.repository.CodeArtifactRepositoryPlugin"
tags.set(listOf("aws", "codeartifact", "maven", "repository"))
}
}
}

pluginBundle {
website = "https://github.com/Liftric/code-artifact-repository-plugin"
vcsUrl = "https://github.com/Liftric/code-artifact-repository-plugin"
description = "Gradle plugin to apply AWS CodeArtifact repositories"
tags = listOf("aws", "codeartifact", "maven", "repository")
}
18 changes: 8 additions & 10 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
[versions]
aws = "2.17.224"
detekt = "1.20.0"
junit = "4.13.2"
kotlin = "1.7.0"
ktlint-gradle = "10.3.0"
plugin-publish = "1.0.0"
version-catalog-update = "0.5.1"
version-check = "0.42.0"
versioning = "3.0.0"
aws = "2.26.31"
detekt = "1.23.6"
kotlin = "2.0.10"
ktlint-gradle = "12.1.1"
plugin-publish = "1.2.1"
version-catalog-update = "0.8.4"
version-check = "0.51.0"
versioning = "3.1.0"

[libraries]
aws-codeartifact = { module = "software.amazon.awssdk:codeartifact", version.ref = "aws" }
aws-ecs = { module = "software.amazon.awssdk:ecs", version.ref = "aws" }
aws-sts = { module = "software.amazon.awssdk:sts", version.ref = "aws" }
junit = { module = "junit:junit", version.ref = "junit" }

[plugins]
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-rc-3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
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 7654f55

Please sign in to comment.