Use fallback maven if maven.ic2.player.to is unavailable (#218)

* Use fallback maven if maven.ic2.player.to is unavailable

* Add sugested change

Co-authored-by: Raven Szewczyk <git@eigenraven.me>

* Use `content` instead of `filter`

Co-authored-by: Raven Szewczyk <git@eigenraven.me>

---------

Co-authored-by: Raven Szewczyk <git@eigenraven.me>
This commit is contained in:
glowredmanandRaven Szewczyk authored and GitHub committed 2023-09-21 21:04:58 +02:00
1 parent 007638e1b7
commit 0398e2e0e8
1 file changed
+22 -8
+22 -8
View File
@@ -600,15 +600,10 @@ repositories {
}
maven {
name = "ic2"
url = "https://maven.ic2.player.to/"
metadataSources {
mavenPom()
artifact()
url = getURL("https://maven.ic2.player.to/", "https://maven2.ic2.player.to/")
content {
includeGroup "net.industrial-craft"
}
}
maven {
name = "ic2-mirror"
url = "https://maven2.ic2.player.to/"
metadataSources {
mavenPom()
artifact()
@@ -1576,6 +1571,25 @@ def getSecondaryArtifacts() {
return secondaryArtifacts
}
def getURL(String main, String fallback) {
return pingURL(main, 10000) ? main : fallback
}
// credit: https://stackoverflow.com/a/3584332
def pingURL(String url, int timeout) {
url = url.replaceFirst("^https", "http") // Otherwise an exception may be thrown on invalid SSL certificates.
try {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection()
connection.setConnectTimeout(timeout)
connection.setReadTimeout(timeout)
connection.setRequestMethod("HEAD")
int responseCode = connection.getResponseCode()
return 200 <= responseCode && responseCode <= 399
} catch (IOException ignored) {
return false
}
}
// For easier scripting of things that require variables defined earlier in the buildscript
if (file('addon.late.gradle.kts').exists()) {
apply from: 'addon.late.gradle.kts'