Skip to content

Commit

Permalink
Support gradle versions api url customization (#807)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcel Sebek <marcel.sebek@deutsche-boerse.com>
  • Loading branch information
sebek64 and marcel-sebek-dbag committed Sep 7, 2023
1 parent 610f5b2 commit 6be5c69
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ The default is `release-candidate`. The value can be changed as shown below:
dependencyUpdates.gradleReleaseChannel="current"
```

#### Gradle Versions Api Base URL

The `gradleVersionsApiBaseUrl` task property provides an option for customization of the Gradle versions service URL.
If not specified, the default value https://services.gradle.org/versions/ is used.
The customization can be useful in restricted environments without direct internet access and proxy availability.

#### Constraints

If you use constraints, for example to define a BOM using the [`java-platform`](https://docs.gradle.org/current/userguide/java_platform_plugin.html)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class DependencyUpdates @JvmOverloads constructor(
val outputDir: String,
val reportfileName: String?,
val checkForGradleUpdate: Boolean,
val gradleVersionsApiBaseUrl: String,
val gradleReleaseChannel: String,
val checkConstraints: Boolean = false,
val checkBuildEnvironmentConstraints: Boolean = false,
Expand Down Expand Up @@ -107,7 +108,7 @@ class DependencyUpdates @JvmOverloads constructor(
val upgradeVersions = toMap(versions.upgrade)

// Check for Gradle updates.
val gradleUpdateChecker = GradleUpdateChecker(checkForGradleUpdate)
val gradleUpdateChecker = GradleUpdateChecker(checkForGradleUpdate, gradleVersionsApiBaseUrl)

return DependencyUpdatesReporter(
project, revision, outputFormatterArgument, outputDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ open class DependencyUpdatesTask : DefaultTask() { // tasks can't be final
@Input
var checkForGradleUpdate: Boolean = true

@Input
var gradleVersionsApiBaseUrl: String = "https://services.gradle.org/versions/"

@Input
var checkConstraints: Boolean = false

Expand Down Expand Up @@ -128,7 +131,7 @@ open class DependencyUpdatesTask : DefaultTask() { // tasks can't be final
}
val evaluator = DependencyUpdates(
project, resolutionStrategyAction, revision,
outputFormatter(), outputDir, reportfileName, checkForGradleUpdate,
outputFormatter(), outputDir, reportfileName, checkForGradleUpdate, gradleVersionsApiBaseUrl,
gradleReleaseChannel, checkConstraints, checkBuildEnvironmentConstraints,
filterConfigurations
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import java.util.concurrent.TimeUnit
*/
class GradleUpdateChecker(
val enabled: Boolean = true,
private val gradleVersionsApiBaseUrl: String,
) {

init {
if (enabled) {
fetch()
fetch(gradleVersionsApiBaseUrl)
}
}

Expand Down Expand Up @@ -84,7 +85,6 @@ class GradleUpdateChecker(
private val cacheMap = EnumMap<GradleReleaseChannel, ReleaseStatus>(
GradleReleaseChannel::class.java
)
private const val API_BASE_URL = "https://services.gradle.org/versions/"
private const val CLIENT_TIME_OUT = 15_000L
private val client: OkHttpClient = OkHttpClient.Builder()
.connectTimeout(CLIENT_TIME_OUT, TimeUnit.SECONDS)
Expand All @@ -95,17 +95,17 @@ class GradleUpdateChecker(
.addLast(KotlinJsonAdapterFactory())
.build()

/** Represents the XML from [API_BASE_URL] */
/** Represents the XML from [gradleVersionsApiBaseUrl] */
private class VersionSite {
var version: String? = null
}

private fun fetch() {
private fun fetch(gradleVersionsApiBaseUrl: String) {
for (it in GradleReleaseChannel.values()) {
try {
client.newCall(
Request.Builder()
.url(API_BASE_URL + it.id)
.url(gradleVersionsApiBaseUrl + it.id)
.build()
).execute().use { response ->
response.body?.source()?.let { body ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ final class DependencyUpdatesSpec extends Specification {
}

when:
def reporter = evaluate(project, 'milestone', 'plain', 'build', null, null, true, CURRENT.id)
def reporter = evaluate(project, 'milestone', 'plain', 'build', null, null, true, "", CURRENT.id)
reporter.write()

then:
Expand Down Expand Up @@ -619,7 +619,7 @@ final class DependencyUpdatesSpec extends Specification {
addRepositoryTo(project)

when:
def reporter = evaluate(project, 'milestone', null, 'build', null,null, false, RELEASE_CANDIDATE.id, {config -> config.name.equals("upgradesFound")})
def reporter = evaluate(project, 'milestone', null, 'build', null,null, false, "", RELEASE_CANDIDATE.id, {config -> config.name.equals("upgradesFound")})
reporter.write()

then:
Expand All @@ -645,10 +645,10 @@ final class DependencyUpdatesSpec extends Specification {

private static def evaluate(project, revision = 'milestone', outputFormatter = null,
outputDir = 'build', resolutionStrategy = null, reportfileName = null,
checkForGradleUpdate = true, gradleReleaseChannel = RELEASE_CANDIDATE.id,
checkForGradleUpdate = true, gradleVersionsApiBaseUrl = "", gradleReleaseChannel = RELEASE_CANDIDATE.id,
configurationFilter = { true }) {
new DependencyUpdates(project, resolutionStrategy, revision, buildOutputFormatter(outputFormatter), outputDir,
reportfileName, checkForGradleUpdate, gradleReleaseChannel, false, false, configurationFilter).run()
reportfileName, checkForGradleUpdate, gradleVersionsApiBaseUrl, gradleReleaseChannel, false, false, configurationFilter).run()
}

private static OutputFormatterArgument buildOutputFormatter(outputFormatter) {
Expand Down

0 comments on commit 6be5c69

Please sign in to comment.