Skip to content

Commit 6ce5ac7

Browse files
committed
More sister methods for #getPublishingForgeMaven
1 parent 22ef5c0 commit 6ce5ac7

File tree

2 files changed

+169
-5
lines changed

2 files changed

+169
-5
lines changed

src/main/groovy/net/minecraftforge/gradleutils/GradleUtilsExtension.java

Lines changed: 140 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.gradle.api.file.Directory;
1111
import org.gradle.api.provider.Provider;
1212

13+
import java.io.File;
14+
1315
/// Contains various utilities for working with Gradle scripts.
1416
///
1517
/// [Projects][org.gradle.api.Project] that apply GradleUtils are given [GradleUtilsExtensionForProject].
@@ -72,7 +74,7 @@ public sealed interface GradleUtilsExtension permits GradleUtilsExtensionInterna
7274
///
7375
/// @return The closure
7476
default Action<MavenArtifactRepository> getPublishingForgeMaven() {
75-
return getPublishingForgeMaven("https://maven.minecraftforge.net/releases");
77+
return getPublishingForgeMaven(Constants.FORGE_MAVEN_RELEASE);
7678
}
7779

7880
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
@@ -117,5 +119,141 @@ default Action<MavenArtifactRepository> getPublishingForgeMaven() {
117119
/// @param fallbackPublishingEndpoint The fallback URL for the release repository
118120
/// @param defaultFolder The default folder if the required maven information is not set
119121
/// @return The closure
120-
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint, Provider<? extends Directory> defaultFolder);
122+
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint, Object defaultFolder);
123+
124+
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
125+
/// publishing block.
126+
///
127+
/// **Important:** The following environment variables must be set for this to work:
128+
/// - `MAVEN_USER`: Containing the username to use for authentication
129+
/// - `MAVEN_PASSWORD`: Containing the password to use for authentication
130+
///
131+
/// The following environment variables are optional:
132+
/// - `MAVEN_URL(_RELEASE)`: Containing the URL to use for the release repository
133+
/// - Please note that since Forge does not have a snapshot repository, snapshot maven publishing via GradleUtils is
134+
/// no longer supported as of 3.0.0.
135+
///
136+
/// If the required environment variables are not present, the output Maven will be set to the given default folder.
137+
///
138+
/// If the `MAVEN_URL_RELEASE` variable is not set, the Forge releases repository will be used
139+
/// (`https://maven.minecraftforge.net/releases`).
140+
///
141+
/// @param defaultFolder The default folder if the required maven information is not set
142+
/// @return The closure
143+
default Action<MavenArtifactRepository> getPublishingForgeMaven(File defaultFolder) {
144+
return this.getPublishingForgeMaven(Constants.FORGE_MAVEN_RELEASE, defaultFolder);
145+
}
146+
147+
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
148+
/// publishing block.
149+
/// **Important:** The following environment variables must be set for this to work:
150+
/// - `MAVEN_USER`: Containing the username to use for authentication
151+
/// - `MAVEN_PASSWORD`: Containing the password to use for authentication
152+
///
153+
/// The following environment variables are optional:
154+
/// - `MAVEN_URL(_RELEASE)`: Containing the URL to use for the release repository
155+
/// - Please note that since Forge does not have a snapshot repository, snapshot maven publishing via GradleUtils is
156+
/// no longer supported as of 3.0.0.
157+
///
158+
/// If the required environment variables are not present, the output Maven will be set to the given default
159+
/// folder.
160+
///
161+
/// If the `MAVEN_URL(_RELEASE)` variable is not set, the passed in fallback URL will be used for the release
162+
/// repository.
163+
///
164+
/// @param fallbackPublishingEndpoint The fallback URL for the release repository
165+
/// @param defaultFolder The default folder if the required maven information is not set
166+
/// @return The closure
167+
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint, File defaultFolder);
168+
169+
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
170+
/// publishing block.
171+
///
172+
/// **Important:** The following environment variables must be set for this to work:
173+
/// - `MAVEN_USER`: Containing the username to use for authentication
174+
/// - `MAVEN_PASSWORD`: Containing the password to use for authentication
175+
///
176+
/// The following environment variables are optional:
177+
/// - `MAVEN_URL(_RELEASE)`: Containing the URL to use for the release repository
178+
/// - Please note that since Forge does not have a snapshot repository, snapshot maven publishing via GradleUtils is
179+
/// no longer supported as of 3.0.0.
180+
///
181+
/// If the required environment variables are not present, the output Maven will be set to the given default folder.
182+
///
183+
/// If the `MAVEN_URL_RELEASE` variable is not set, the Forge releases repository will be used
184+
/// (`https://maven.minecraftforge.net/releases`).
185+
///
186+
/// @param defaultFolder The default folder if the required maven information is not set
187+
/// @return The closure
188+
default Action<MavenArtifactRepository> getPublishingForgeMaven(Directory defaultFolder) {
189+
return this.getPublishingForgeMaven(Constants.FORGE_MAVEN_RELEASE, defaultFolder);
190+
}
191+
192+
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
193+
/// publishing block.
194+
/// **Important:** The following environment variables must be set for this to work:
195+
/// - `MAVEN_USER`: Containing the username to use for authentication
196+
/// - `MAVEN_PASSWORD`: Containing the password to use for authentication
197+
///
198+
/// The following environment variables are optional:
199+
/// - `MAVEN_URL(_RELEASE)`: Containing the URL to use for the release repository
200+
/// - Please note that since Forge does not have a snapshot repository, snapshot maven publishing via GradleUtils is
201+
/// no longer supported as of 3.0.0.
202+
///
203+
/// If the required environment variables are not present, the output Maven will be set to the given default
204+
/// folder.
205+
///
206+
/// If the `MAVEN_URL(_RELEASE)` variable is not set, the passed in fallback URL will be used for the release
207+
/// repository.
208+
///
209+
/// @param fallbackPublishingEndpoint The fallback URL for the release repository
210+
/// @param defaultFolder The default folder if the required maven information is not set
211+
/// @return The closure
212+
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint, Directory defaultFolder);
213+
214+
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
215+
/// publishing block.
216+
///
217+
/// **Important:** The following environment variables must be set for this to work:
218+
/// - `MAVEN_USER`: Containing the username to use for authentication
219+
/// - `MAVEN_PASSWORD`: Containing the password to use for authentication
220+
///
221+
/// The following environment variables are optional:
222+
/// - `MAVEN_URL(_RELEASE)`: Containing the URL to use for the release repository
223+
/// - Please note that since Forge does not have a snapshot repository, snapshot maven publishing via GradleUtils is
224+
/// no longer supported as of 3.0.0.
225+
///
226+
/// If the required environment variables are not present, the output Maven will be set to the given default folder.
227+
///
228+
/// If the `MAVEN_URL_RELEASE` variable is not set, the Forge releases repository will be used
229+
/// (`https://maven.minecraftforge.net/releases`).
230+
///
231+
/// @param defaultFolder The default folder if the required maven information is not set
232+
/// @return The closure
233+
default Action<MavenArtifactRepository> getPublishingForgeMaven(Provider<?> defaultFolder) {
234+
return this.getPublishingForgeMaven(Constants.FORGE_MAVEN_RELEASE, defaultFolder);
235+
}
236+
237+
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
238+
/// publishing block.
239+
/// **Important:** The following environment variables must be set for this to work:
240+
/// - `MAVEN_USER`: Containing the username to use for authentication
241+
/// - `MAVEN_PASSWORD`: Containing the password to use for authentication
242+
///
243+
/// The following environment variables are optional:
244+
/// - `MAVEN_URL(_RELEASE)`: Containing the URL to use for the release repository
245+
/// - Please note that since Forge does not have a snapshot repository, snapshot maven publishing via GradleUtils is
246+
/// no longer supported as of 3.0.0.
247+
///
248+
/// If the required environment variables are not present, the output Maven will be set to the given default
249+
/// folder.
250+
///
251+
/// If the `MAVEN_URL(_RELEASE)` variable is not set, the passed in fallback URL will be used for the release
252+
/// repository.
253+
///
254+
/// @param fallbackPublishingEndpoint The fallback URL for the release repository
255+
/// @param defaultFolder The default folder if the required maven information is not set
256+
/// @return The closure
257+
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint, Provider<?> defaultFolder);
258+
121259
}

src/main/groovy/net/minecraftforge/gradleutils/GradleUtilsExtensionImpl.groovy

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import static net.minecraftforge.gradleutils.GradleUtilsPlugin.LOGGER
3737

3838
@Inject
3939
GradleUtilsExtensionImpl() {
40-
this.rootDirectory = this.objects.directoryProperty().fileValue(this.buildLayout.rootDirectory)
40+
this.rootDirectory = this.objects.directoryProperty().fileValue(this.buildLayout.rootDirectory)\
4141

4242
this.mavenUser = this.objects.property(String).value(this.providers.environmentVariable('MAVEN_USER')).tap(SharedUtil.finalizeProperty())
4343
this.mavenPassword = this.objects.property(String).value(this.providers.environmentVariable('MAVEN_PASSWORD')).tap(SharedUtil.finalizeProperty())
@@ -50,7 +50,33 @@ import static net.minecraftforge.gradleutils.GradleUtilsPlugin.LOGGER
5050
}
5151

5252
@Override
53-
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint, Provider<? extends Directory> defaultFolder) {
53+
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint, Object defaultFolder) {
54+
this.getPublishingForgeMaven(fallbackPublishingEndpoint, this.providers.provider { defaultFolder })
55+
}
56+
57+
@Override
58+
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint, File defaultFolder) {
59+
this.getPublishingForgeMavenInternal(fallbackPublishingEndpoint, this.providers.provider { defaultFolder })
60+
}
61+
62+
@Override
63+
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint, Directory defaultFolder) {
64+
this.getPublishingForgeMavenInternal(fallbackPublishingEndpoint, this.providers.provider { defaultFolder.asFile.absoluteFile })
65+
}
66+
67+
@Override
68+
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint, Provider<?> defaultFolder) {
69+
this.getPublishingForgeMavenInternal(fallbackPublishingEndpoint, defaultFolder.map {
70+
if (it instanceof Directory)
71+
it.asFile
72+
else if (it instanceof File)
73+
it
74+
else
75+
this.rootDirectory.files(it).singleFile
76+
}.map(File.&getAbsoluteFile))
77+
}
78+
79+
private Action<MavenArtifactRepository> getPublishingForgeMavenInternal(String fallbackPublishingEndpoint, Provider<? extends File> defaultFolder) {
5480
{ MavenArtifactRepository repo ->
5581
repo.name = 'forge'
5682

@@ -67,7 +93,7 @@ import static net.minecraftforge.gradleutils.GradleUtilsPlugin.LOGGER
6793
}
6894
} else {
6995
LOGGER.info('Forge publishing credentials not found, using local folder')
70-
repo.url = defaultFolder.get().asFile.absoluteFile.toURI()
96+
repo.url = defaultFolder.get().absoluteFile.toURI()
7197
}
7298
}
7399
}

0 commit comments

Comments
 (0)