Skip to content

Commit 2343cae

Browse files
committed
Add provider-friendly methods to extensions
1 parent 2c6f8c0 commit 2343cae

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

gitversion-gradle/changelog-gradle/src/main/java/net/minecraftforge/gitversion/gradle/changelog/ChangelogExtension.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import org.gradle.api.provider.Property;
88
import org.gradle.api.provider.Provider;
9+
import org.gradle.api.provider.ProviderConvertible;
910
import org.gradle.api.publish.maven.MavenPublication;
1011

1112
/// Configuration for the Changelog plugin.
@@ -37,6 +38,15 @@ public sealed interface ChangelogExtension permits ChangelogExtensionInternal {
3738
/// @param marker The start marker for the changelog
3839
void from(Provider<?> marker);
3940

41+
/// Sets the changelog start marker to use when generating the changelog. This can be a tag name or a commit SHA.
42+
///
43+
/// If `null`, the changelog will start from the last merge base commit.
44+
///
45+
/// @param marker The start marker for the changelog
46+
default void from(ProviderConvertible<?> marker) {
47+
this.from(marker.asProvider());
48+
}
49+
4050
/// Sets this project's changelog as an artifact for the given publication.
4151
///
4252
/// @param publication The publication

gitversion-gradle/src/main/groovy/net/minecraftforge/gitversion/gradle/GitVersionExtension.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.gradle.api.file.FileSystemLocation;
99
import org.gradle.api.file.FileSystemLocationProperty;
1010
import org.gradle.api.provider.Provider;
11+
import org.gradle.api.provider.ProviderConvertible;
1112
import org.jetbrains.annotations.NotNullByDefault;
1213
import org.jetbrains.annotations.Nullable;
1314
import org.jetbrains.annotations.UnknownNullability;
@@ -35,9 +36,33 @@ public sealed interface GitVersionExtension permits GitVersionExtensionInternal
3536

3637
String getMCTagOffsetBranch(@UnknownNullability String mcVersion);
3738

38-
String getMCTagOffsetBranch(String mcVersion, String... allowedBranches);
39+
default String getMCTagOffsetBranch(Provider<? extends CharSequence> mcVersion) {
40+
return this.getMCTagOffsetBranch(mcVersion.map(Object::toString).getOrNull());
41+
}
42+
43+
default String getMCTagOffsetBranch(ProviderConvertible<? extends CharSequence> mcVersion) {
44+
return this.getMCTagOffsetBranch(mcVersion.asProvider());
45+
}
46+
47+
String getMCTagOffsetBranch(@UnknownNullability String mcVersion, String... allowedBranches);
48+
49+
default String getMCTagOffsetBranch(Provider<? extends CharSequence> mcVersion, String... allowedBranches) {
50+
return this.getMCTagOffsetBranch(mcVersion.map(Object::toString).getOrNull(), allowedBranches);
51+
}
3952

40-
String getMCTagOffsetBranch(String mcVersion, Collection<String> allowedBranches);
53+
default String getMCTagOffsetBranch(ProviderConvertible<? extends CharSequence> mcVersion, String... allowedBranches) {
54+
return this.getMCTagOffsetBranch(mcVersion.asProvider(), allowedBranches);
55+
}
56+
57+
String getMCTagOffsetBranch(@UnknownNullability String mcVersion, Collection<String> allowedBranches);
58+
59+
default String getMCTagOffsetBranch(Provider<? extends CharSequence> mcVersion, Collection<String> allowedBranches) {
60+
return this.getMCTagOffsetBranch(mcVersion.map(Object::toString).getOrNull(), allowedBranches);
61+
}
62+
63+
default String getMCTagOffsetBranch(ProviderConvertible<? extends CharSequence> mcVersion, Collection<String> allowedBranches) {
64+
return this.getMCTagOffsetBranch(mcVersion.asProvider(), allowedBranches);
65+
}
4166

4267

4368
/* INFO */

gitversion-gradle/src/main/groovy/net/minecraftforge/gitversion/gradle/GitVersionExtensionInternal.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ default String getMCTagOffsetBranch(@UnknownNullability String mcVersion) {
7373
}
7474

7575
@Override
76-
default String getMCTagOffsetBranch(String mcVersion, String... allowedBranches) {
76+
default String getMCTagOffsetBranch(@UnknownNullability String mcVersion, String... allowedBranches) {
7777
return this.getMCTagOffsetBranch(mcVersion, Arrays.asList(allowedBranches));
7878
}
7979

8080
@Override
81-
default String getMCTagOffsetBranch(String mcVersion, Collection<String> allowedBranches) {
81+
default String getMCTagOffsetBranch(@UnknownNullability String mcVersion, Collection<String> allowedBranches) {
82+
if (mcVersion == null || mcVersion.isBlank())
83+
return this.getTagOffsetBranch();
84+
8285
return "%s-%s".formatted(mcVersion, this.getTagOffsetBranch(allowedBranches));
8386
}
8487

0 commit comments

Comments
 (0)