Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nmcp/api/nmcp.api
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public abstract class nmcp/LocalRepositoryOptions {
public abstract interface class nmcp/NmcpAggregationExtension {
public abstract fun centralPortal (Lorg/gradle/api/Action;)V
public abstract fun getAllFiles ()Lorg/gradle/api/file/FileCollection;
public abstract fun getAllowEmptyAggregation ()Lorg/gradle/api/provider/Property;
public abstract fun localRepository (Lorg/gradle/api/Action;)V
public abstract fun publishAllProjectsProbablyBreakingProjectIsolation ()V
}
Expand Down
7 changes: 7 additions & 0 deletions nmcp/src/main/kotlin/nmcp/NmcpAggregationExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nmcp

import org.gradle.api.Action
import org.gradle.api.file.FileCollection
import org.gradle.api.provider.Property

interface NmcpAggregationExtension {
/**
Expand Down Expand Up @@ -37,4 +38,10 @@ interface NmcpAggregationExtension {
* Storage and or AWS S3.
*/
val allFiles: FileCollection

/**
* By default, Nmcp errors if the aggregation is empty.
* Set this to true to allow empty aggregations.
*/
val allowEmptyAggregation: Property<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.gradle.api.artifacts.result.ArtifactResult
import org.gradle.api.artifacts.result.ResolvedArtifactResult
import org.gradle.api.attributes.Usage
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.provider.Property

@GExtension(
pluginId = "com.gradleup.nmcp.aggregation",
Expand Down Expand Up @@ -58,6 +59,12 @@ internal abstract class DefaultNmcpAggregationExtension(private val project: Pro
}
allNames.add(it.name.lowercase())
}

if (!allowEmptyAggregation.orElse(false).get()) {
check(consumerConfiguration.dependencies.isNotEmpty()) {
"Nmcp: the aggregation is empty. This is usually a misconfiguration. If this is intentional, set `allowEmptyAggregation` to true."
}
}
}
}

Expand Down Expand Up @@ -90,6 +97,8 @@ internal abstract class DefaultNmcpAggregationExtension(private val project: Pro
}
}
}

abstract override val allowEmptyAggregation: Property<Boolean>
}

private fun isCompatible(artifactResult: ArtifactResult): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import java.io.File
import kotlin.test.Test
import org.gradle.testkit.runner.GradleRunner

class DuplicateNameTest {
class MainTest {
@Test
fun duplicateName() {
val dst = File("build/testProject")
Expand All @@ -16,9 +16,26 @@ class DuplicateNameTest {
val result = GradleRunner.create()
.withProjectDir(dst)
.withArguments("nmcpZipAggregation")
.forwardOutput()
.buildAndFail()

assert(result.output.contains("duplicate project name"))
}

@Test
fun emptyAggregation() {
val dst = File("build/testProject")
val src = File("testProjects/empty-aggregation")

dst.deleteRecursively()
dst.mkdirs()

src.copyRecursively(dst, overwrite = true)

val result = GradleRunner.create()
.withProjectDir(dst)
.withArguments("help")
.buildAndFail()

assert(result.output.contains("Nmcp: the aggregation is empty"))
}
}
3 changes: 3 additions & 0 deletions nmcp/testProjects/empty-aggregation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("com.gradleup.nmcp.aggregation").version("1.4.2-SNAPSHOT")
}
6 changes: 6 additions & 0 deletions nmcp/testProjects/empty-aggregation/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pluginManagement {
listOf(repositories, dependencyResolutionManagement.repositories).forEach {
it.mavenCentral()
it.maven("../../../build/m2")
}
}