Skip to content

Commit

Permalink
Fix artifact conflicts for built-in tasks (#31)
Browse files Browse the repository at this point in the history
* Put built-in tasks in their own folder

* Don't run actions on plugin markers
  • Loading branch information
natario1 authored Dec 29, 2024
1 parent e88c8e4 commit fb9d312
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.deepmedia.tools.deployer.inference

import io.deepmedia.tools.deployer.isKotlinProject
import io.deepmedia.tools.deployer.model.Component
import io.deepmedia.tools.deployer.model.DeploySpec
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
Expand All @@ -27,11 +26,11 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
*/
internal class AndroidInference(private val componentNames: List<String>) : Inference {

override fun inferComponents(project: Project, spec: DeploySpec, create: (Component.() -> Unit) -> Component) {
override fun inferComponents(project: Project, spec: DeploySpec, create: InferenceComponentFactory) {
project.plugins.withId("com.android.library") {
val kotlin = if (project.isKotlinProject) project.kotlinExtension else null
componentNames.forEach { componentName ->
create {
create(true) {
fromSoftwareComponent(componentName)

packaging.set("aar")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.gradle.plugin.devel.GradlePluginDevelopmentExtension
*/
internal class GradlePluginInference : Inference {

override fun inferComponents(project: Project, spec: DeploySpec, create: (Component.() -> Unit) -> Component) {
override fun inferComponents(project: Project, spec: DeploySpec, create: InferenceComponentFactory) {
project.plugins.withId("java-gradle-plugin") {
val gradlePlugin = project.extensions.getByType<GradlePluginDevelopmentExtension>()
project.whenEvaluated {
Expand All @@ -27,13 +27,13 @@ internal class GradlePluginInference : Inference {
}
}

private fun inferComponents(project: Project, spec: DeploySpec, gradlePlugins: GradlePluginDevelopmentExtension, create: (Component.() -> Unit) -> Component) {
val mainComponent = create {
private fun inferComponents(project: Project, spec: DeploySpec, gradlePlugins: GradlePluginDevelopmentExtension, create: InferenceComponentFactory) {
val mainComponent = create(true) {
fromMavenPublication("pluginMaven", clone = true)
packaging.set("jar")
}
gradlePlugins.plugins.all {
create {
create(false) {
fromGradlePluginDeclaration(this@all, mainComponent, clone = true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import io.deepmedia.tools.deployer.model.Component
import io.deepmedia.tools.deployer.model.DeploySpec
import org.gradle.api.Project


internal typealias InferenceComponentFactory = (runUserAction: Boolean, configure: Component.() -> Unit) -> Component

internal interface Inference {
fun inferComponents(
project: Project,
spec: DeploySpec,
create: (Component.() -> Unit) -> Component
create: InferenceComponentFactory
)
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package io.deepmedia.tools.deployer.inference

import io.deepmedia.tools.deployer.model.Component
import io.deepmedia.tools.deployer.model.DeploySpec
import org.gradle.api.Project

/**
* Unused, replaced with Component.fromJava() instead.
*/
internal class JavaInference : Inference {
override fun inferComponents(project: Project, spec: DeploySpec, create: (Component.() -> Unit) -> Component) {
override fun inferComponents(project: Project, spec: DeploySpec, create: InferenceComponentFactory) {
project.plugins.withId("java") {
create {
create(true) {
fromSoftwareComponent("java")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.deepmedia.tools.deployer.inference

import io.deepmedia.tools.deployer.model.Component
import io.deepmedia.tools.deployer.model.DeploySpec
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
Expand All @@ -18,13 +17,13 @@ internal class KotlinInference : Inference {
"org.jetbrains.kotlin.multiplatform"
)

private fun inferComponent(target: KotlinTarget, multiplatform: Boolean, create: (Component.() -> Unit) -> Component) {
private fun inferComponent(target: KotlinTarget, multiplatform: Boolean, create: InferenceComponentFactory) {
if (target is KotlinAndroidTarget) {
// Should use AndroidInference!
return
}
if (target is KotlinOnlyTarget<*>) {
create {
create(true) {
fromKotlinTarget(target)
if (multiplatform && target.platformType != KotlinPlatformType.common) {
artifactId.set { "$it-${target.name.lowercase()}" }
Expand All @@ -35,7 +34,7 @@ internal class KotlinInference : Inference {
}
}

override fun inferComponents(project: Project, spec: DeploySpec, create: (Component.() -> Unit) -> Component) {
override fun inferComponents(project: Project, spec: DeploySpec, create: InferenceComponentFactory) {
pluginIds.forEach { pluginId ->
project.plugins.withId(pluginId) {
val kotlin = project.kotlinExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ open class Content @Inject constructor(private val objects: ObjectFactory) : Com
inherit.finalizeValue() // fixes 'components'
inferenceData.finalizeValue()
inferenceData.get().forEach {
it.inference.inferComponents(project, spec) { configure ->
it.inference.inferComponents(project, spec) { runUserAction, configure ->
component {
configure()
it.action.execute(this)
if (runUserAction) it.action.execute(this)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal val MavenArtifact.isDocsJar get() = classifier == "javadoc" && extensio

internal val Project.makeEmptyDocsJar get() = tasks.maybeRegister<Jar>("makeEmptyDocsJar") {
archiveClassifier.set("javadoc")
destinationDirectory.set(layout.buildDirectory.dir("deployer").get().dir("builtins").dir("emptyDocs"))
}

/* private val Project.makeAutoDocsJar: TaskProvider<Jar> get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ internal val MavenArtifact.isSourcesJar get() = classifier == "sources" && exten

internal val Project.makeEmptySourcesJar get() = tasks.maybeRegister<Jar>("makeEmptySourcesJar") {
archiveClassifier.set("sources")
destinationDirectory.set(layout.buildDirectory.dir("deployer").get().dir("builtins").dir("emptySources"))
}

internal val Project.makeKotlinSourcesJar: TaskProvider<Jar> get() = tasks.maybeRegister("makeKotlinSourcesJar") {
archiveClassifier.set("sources")
destinationDirectory.set(layout.buildDirectory.dir("deployer").get().dir("builtins").dir("kotlinSources"))

val kotlin = project.kotlinExtension
kotlin.sourceSets.all {
val sourceSet = this
Expand All @@ -34,6 +37,8 @@ internal val Project.makeKotlinSourcesJar: TaskProvider<Jar> get() = tasks.maybe

internal val Project.makeJavaSourcesJar: TaskProvider<Jar> get() = tasks.maybeRegister("makeJavaSourcesJar") {
archiveClassifier.set("sources")
destinationDirectory.set(layout.buildDirectory.dir("deployer").get().dir("builtins").dir("javaSources"))

val java = project.extensions.getByType<JavaPluginExtension>()
from(java.sourceSets["main"].allSource)
}

0 comments on commit fb9d312

Please sign in to comment.