Skip to content

Commit

Permalink
Use fallback maven if maven.ic2.player.to is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
glowredman committed Sep 21, 2023
1 parent 007638e commit 8f838cb
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -600,15 +600,7 @@ repositories {
}
maven {
name = "ic2"
url = "https://maven.ic2.player.to/"
metadataSources {
mavenPom()
artifact()
}
}
maven {
name = "ic2-mirror"
url = "https://maven2.ic2.player.to/"
url = getURL("https://maven.ic2.player.to/", "https://maven2.ic2.player.to/")
metadataSources {
mavenPom()
artifact()
Expand Down Expand Up @@ -1576,6 +1568,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'
Expand Down

0 comments on commit 8f838cb

Please sign in to comment.