Skip to content

Commit 3ea175c

Browse files
authored
Display an error if the aggregation is empty (#236)
* Display an error if the aggregation is empty * update apiDump
1 parent a6439ae commit 3ea175c

File tree

6 files changed

+45
-2
lines changed

6 files changed

+45
-2
lines changed

nmcp/api/nmcp.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public abstract class nmcp/LocalRepositoryOptions {
1919
public abstract interface class nmcp/NmcpAggregationExtension {
2020
public abstract fun centralPortal (Lorg/gradle/api/Action;)V
2121
public abstract fun getAllFiles ()Lorg/gradle/api/file/FileCollection;
22+
public abstract fun getAllowEmptyAggregation ()Lorg/gradle/api/provider/Property;
2223
public abstract fun localRepository (Lorg/gradle/api/Action;)V
2324
public abstract fun publishAllProjectsProbablyBreakingProjectIsolation ()V
2425
}

nmcp/src/main/kotlin/nmcp/NmcpAggregationExtension.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package nmcp
22

33
import org.gradle.api.Action
44
import org.gradle.api.file.FileCollection
5+
import org.gradle.api.provider.Property
56

67
interface NmcpAggregationExtension {
78
/**
@@ -37,4 +38,10 @@ interface NmcpAggregationExtension {
3738
* Storage and or AWS S3.
3839
*/
3940
val allFiles: FileCollection
41+
42+
/**
43+
* By default, Nmcp errors if the aggregation is empty.
44+
* Set this to true to allow empty aggregations.
45+
*/
46+
val allowEmptyAggregation: Property<Boolean>
4047
}

nmcp/src/main/kotlin/nmcp/internal/DefaultNmcpAggregationExtension.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.gradle.api.artifacts.result.ArtifactResult
1414
import org.gradle.api.artifacts.result.ResolvedArtifactResult
1515
import org.gradle.api.attributes.Usage
1616
import org.gradle.api.file.ConfigurableFileCollection
17+
import org.gradle.api.provider.Property
1718

1819
@GExtension(
1920
pluginId = "com.gradleup.nmcp.aggregation",
@@ -58,6 +59,12 @@ internal abstract class DefaultNmcpAggregationExtension(private val project: Pro
5859
}
5960
allNames.add(it.name.lowercase())
6061
}
62+
63+
if (!allowEmptyAggregation.orElse(false).get()) {
64+
check(consumerConfiguration.dependencies.isNotEmpty()) {
65+
"Nmcp: the aggregation is empty. This is usually a misconfiguration. If this is intentional, set `allowEmptyAggregation` to true."
66+
}
67+
}
6168
}
6269
}
6370

@@ -90,6 +97,8 @@ internal abstract class DefaultNmcpAggregationExtension(private val project: Pro
9097
}
9198
}
9299
}
100+
101+
abstract override val allowEmptyAggregation: Property<Boolean>
93102
}
94103

95104
private fun isCompatible(artifactResult: ArtifactResult): Boolean {
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import java.io.File
22
import kotlin.test.Test
33
import org.gradle.testkit.runner.GradleRunner
44

5-
class DuplicateNameTest {
5+
class MainTest {
66
@Test
77
fun duplicateName() {
88
val dst = File("build/testProject")
@@ -16,9 +16,26 @@ class DuplicateNameTest {
1616
val result = GradleRunner.create()
1717
.withProjectDir(dst)
1818
.withArguments("nmcpZipAggregation")
19-
.forwardOutput()
2019
.buildAndFail()
2120

2221
assert(result.output.contains("duplicate project name"))
2322
}
23+
24+
@Test
25+
fun emptyAggregation() {
26+
val dst = File("build/testProject")
27+
val src = File("testProjects/empty-aggregation")
28+
29+
dst.deleteRecursively()
30+
dst.mkdirs()
31+
32+
src.copyRecursively(dst, overwrite = true)
33+
34+
val result = GradleRunner.create()
35+
.withProjectDir(dst)
36+
.withArguments("help")
37+
.buildAndFail()
38+
39+
assert(result.output.contains("Nmcp: the aggregation is empty"))
40+
}
2441
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
id("com.gradleup.nmcp.aggregation").version("1.4.2-SNAPSHOT")
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pluginManagement {
2+
listOf(repositories, dependencyResolutionManagement.repositories).forEach {
3+
it.mavenCentral()
4+
it.maven("../../../build/m2")
5+
}
6+
}

0 commit comments

Comments
 (0)