Skip to content

Commit

Permalink
Rename ociDependencies extension -> ociImageDependencies
Browse files Browse the repository at this point in the history
Rename image dependency collector -> runtime
Rename imageScope(String) dependency collector -> runtimeScope(String)
  • Loading branch information
SgtSilvio committed Mar 23, 2024
1 parent a4464a5 commit e352386
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 58 deletions.
4 changes: 2 additions & 2 deletions examples/java-app-groovy-dsl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ testing {
implementation(libs.testcontainers)
implementation(libs.gradleOci.junitJupiter)
}
ociDependencies.forTestSuite(it) {
image.add(project).tag("latest")
ociImageDependencies.forTestSuite(it) {
runtime.add(project).tag("latest")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/java-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ testing {
implementation(libs.testcontainers)
implementation(libs.gradleOci.junitJupiter)
}
ociDependencies {
image(project).tag("latest")
ociImageDependencies {
runtime(project).tag("latest")
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.sgtsilvio.gradle.oci

import io.github.sgtsilvio.gradle.oci.attributes.DISTRIBUTION_TYPE_ATTRIBUTE
import io.github.sgtsilvio.gradle.oci.dsl.OciDependenciesExtension
import io.github.sgtsilvio.gradle.oci.dsl.OciExtension
import io.github.sgtsilvio.gradle.oci.dsl.OciImageDependenciesExtension
import io.github.sgtsilvio.gradle.oci.internal.concatCamelCase
import io.github.sgtsilvio.gradle.oci.internal.dsl.OciDependenciesExtensionImpl
import io.github.sgtsilvio.gradle.oci.internal.dsl.OciExtensionImpl
import io.github.sgtsilvio.gradle.oci.internal.dsl.OciImageDependenciesExtensionImpl
import io.github.sgtsilvio.gradle.oci.internal.mainToEmpty
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -23,9 +23,9 @@ class OciPlugin : Plugin<Project> {
val extension = project.extensions.create(OciExtension::class, EXTENSION_NAME, OciExtensionImpl::class)
registerPushTasks(project, extension)
project.extensions.create(
OciDependenciesExtension::class,
DEPENDENCIES_EXTENSION_NAME,
OciDependenciesExtensionImpl::class,
OciImageDependenciesExtension::class,
IMAGE_DEPENDENCIES_EXTENSION_NAME,
OciImageDependenciesExtensionImpl::class,
extension,
)
}
Expand All @@ -48,5 +48,5 @@ class OciPlugin : Plugin<Project> {
}

const val EXTENSION_NAME = "oci"
const val DEPENDENCIES_EXTENSION_NAME = "ociDependencies"
const val IMAGE_DEPENDENCIES_EXTENSION_NAME = "ociImageDependencies"
const val TASK_GROUP_NAME = "oci"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.sgtsilvio.gradle.oci.dsl

import org.gradle.api.Action
import org.gradle.api.plugins.jvm.JvmTestSuite
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.testing.Test

/**
* @author Silvio Giebl
*/
interface OciImageDependenciesExtension : DependencyConstraintFactories {

fun forTestSuite(testSuite: JvmTestSuite): OciImageDependenciesForRuntime

fun forTestSuite(testSuite: JvmTestSuite, action: Action<in OciImageDependenciesForRuntime>) =
action.execute(forTestSuite(testSuite))

fun forTest(testTask: TaskProvider<Test>): OciImageDependenciesForRuntime

fun forTest(testTask: TaskProvider<Test>, action: Action<in OciImageDependenciesForRuntime>) =
action.execute(forTest(testTask))

// dsl syntactic sugar

val JvmTestSuite.runtime get() = forTestSuite(this).runtime

fun JvmTestSuite.runtimeScope(scope: String) = forTestSuite(this).runtimeScope(scope)

// no dsl syntactic sugar for Test because is should not be used inside a lazy task configuration
}

interface OciImageDependenciesForRuntime : DependencyConstraintFactories {

val runtime: ResolvableOciImageDependencies

fun runtimeScope(scope: String): ResolvableOciImageDependencies
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package io.github.sgtsilvio.gradle.oci.internal.dsl

import io.github.sgtsilvio.gradle.oci.OciRegistryDataTask
import io.github.sgtsilvio.gradle.oci.TASK_GROUP_NAME
import io.github.sgtsilvio.gradle.oci.dsl.OciDependencies
import io.github.sgtsilvio.gradle.oci.dsl.OciDependenciesExtension
import io.github.sgtsilvio.gradle.oci.dsl.OciExtension
import io.github.sgtsilvio.gradle.oci.dsl.OciImageDependenciesExtension
import io.github.sgtsilvio.gradle.oci.dsl.OciImageDependenciesForRuntime
import io.github.sgtsilvio.gradle.oci.dsl.ResolvableOciImageDependencies
import io.github.sgtsilvio.gradle.oci.internal.concatCamelCase
import org.gradle.api.artifacts.dsl.DependencyConstraintHandler
Expand All @@ -22,16 +22,16 @@ import javax.inject.Inject
/**
* @author Silvio Giebl
*/
internal abstract class OciDependenciesExtensionImpl @Inject constructor(
internal abstract class OciImageDependenciesExtensionImpl @Inject constructor(
private val oci: OciExtension,
private val objectFactory: ObjectFactory,
private val taskContainer: TaskContainer,
private val projectLayout: ProjectLayout,
dependencyConstraintHandler: DependencyConstraintHandler,
) : DependencyConstraintFactoriesImpl(dependencyConstraintHandler), OciDependenciesExtension {
) : DependencyConstraintFactoriesImpl(dependencyConstraintHandler), OciImageDependenciesExtension {

private val testSuiteDependencies = HashMap<String, OciDependenciesImpl>()
private val testDependencies = HashMap<String, OciDependenciesImpl>()
private val testSuiteDependencies = HashMap<String, OciImageDependenciesForRuntimeImpl>()
private val testDependencies = HashMap<String, OciImageDependenciesForRuntimeImpl>()

final override fun forTestSuite(testSuite: JvmTestSuite) = testSuiteDependencies.getOrPut(testSuite.name) {
val testSuiteName = testSuite.name
Expand All @@ -45,7 +45,7 @@ internal abstract class OciDependenciesExtensionImpl @Inject constructor(
jvmArgumentProviders += OciTestArgumentProvider(objectFactory, registryDataTask)
}
}
objectFactory.newInstance<OciDependenciesImpl>(testSuiteName, registryDataTask, oci)
objectFactory.newInstance<OciImageDependenciesForRuntimeImpl>(testSuiteName, registryDataTask, oci)
}

final override fun forTest(testTask: TaskProvider<Test>) = testDependencies.getOrPut(testTask.name) {
Expand All @@ -58,22 +58,22 @@ internal abstract class OciDependenciesExtensionImpl @Inject constructor(
testTask {
jvmArgumentProviders += OciTestArgumentProvider(objectFactory, registryDataTask)
}
objectFactory.newInstance<OciDependenciesImpl>(testTaskName, registryDataTask, oci)
objectFactory.newInstance<OciImageDependenciesForRuntimeImpl>(testTaskName, registryDataTask, oci)
}
}

internal abstract class OciDependenciesImpl @Inject constructor(
internal abstract class OciImageDependenciesForRuntimeImpl @Inject constructor(
private val name: String,
private val registryDataTask: TaskProvider<OciRegistryDataTask>,
private val oci: OciExtension,
dependencyConstraintHandler: DependencyConstraintHandler,
) : DependencyConstraintFactoriesImpl(dependencyConstraintHandler), OciDependencies {
) : DependencyConstraintFactoriesImpl(dependencyConstraintHandler), OciImageDependenciesForRuntime {

private val scopes = HashMap<String, ResolvableOciImageDependencies>()

final override val image = imageScope("")
final override val runtime = runtimeScope("")

final override fun imageScope(scope: String): ResolvableOciImageDependencies = scopes.getOrPut(scope) {
final override fun runtimeScope(scope: String): ResolvableOciImageDependencies = scopes.getOrPut(scope) {
val imageDependencies = oci.imageDependencies.create(name.concatCamelCase(scope))
registryDataTask {
from(imageDependencies)
Expand Down

0 comments on commit e352386

Please sign in to comment.