1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Use redirect.

This commit is contained in:
Cedric Beust 2015-11-10 13:54:57 -08:00
parent ae7511be25
commit e3eff30fa6
4 changed files with 31 additions and 13 deletions

Binary file not shown.

View file

@ -1 +1 @@
kobalt.version=0.244 kobalt.version=0.245

View file

@ -73,7 +73,7 @@ public class Main {
} }
private static final String downloadUrl(String version) { private static final String downloadUrl(String version) {
return "https://github.com/cbeust/kobalt/releases/download/" + version + "/kobalt-" + version + ".zip"; return "http://beust.com/kobalt/kobalt-" + version + ".zip";
} }
private void initWrapperFile(String version) throws IOException { private void initWrapperFile(String version) throws IOException {
@ -90,8 +90,12 @@ public class Main {
return wrapperProperties.getProperty(PROPERTY_VERSION); return wrapperProperties.getProperty(PROPERTY_VERSION);
} }
private String getWrapperDownloadUrl() { private String getWrapperDownloadUrl(String version) {
return wrapperProperties.getProperty(PROPERTY_DOWNLOAD_URL); String result = wrapperProperties.getProperty(PROPERTY_DOWNLOAD_URL);
if (result == null) {
result = downloadUrl(version);
}
return result;
} }
private boolean isWindows() { private boolean isWindows() {
@ -112,7 +116,7 @@ public class Main {
Path kobaltJarFile = Paths.get(zipOutputDir, Path kobaltJarFile = Paths.get(zipOutputDir,
getWrapperDir().getPath() + "/" + FILE_NAME + "-" + getWrapperVersion() + ".jar"); getWrapperDir().getPath() + "/" + FILE_NAME + "-" + getWrapperVersion() + ".jar");
if (! Files.exists(localZipFile) || ! Files.exists(kobaltJarFile)) { if (! Files.exists(localZipFile) || ! Files.exists(kobaltJarFile)) {
download(localZipFile.toFile()); download(localZipFile.toFile(), version);
} }
// //
@ -144,7 +148,7 @@ public class Main {
error("Couldn't open zip file " + localZipFile + ": " + e.getMessage()); error("Couldn't open zip file " + localZipFile + ": " + e.getMessage());
error("The file is probably corrupt, downloading it again"); error("The file is probably corrupt, downloading it again");
Files.delete(localZipFile); Files.delete(localZipFile);
download(localZipFile.toFile()); download(localZipFile.toFile(), version);
} }
} }
@ -173,12 +177,26 @@ public class Main {
private static final String[] FILES = new String[] { KOBALTW, "kobalt/wrapper/" + FILE_NAME + "-wrapper.jar" }; private static final String[] FILES = new String[] { KOBALTW, "kobalt/wrapper/" + FILE_NAME + "-wrapper.jar" };
private void download(File file) throws IOException { private void download(File file, String version) throws IOException {
String fileUrl = getWrapperDownloadUrl(); String fileUrl = getWrapperDownloadUrl(version);
URL url = new URL(fileUrl); log(2, "Downloading " + fileUrl);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
int responseCode = httpConn.getResponseCode(); boolean done = false;
HttpURLConnection httpConn = null;
int responseCode = 0;
URL url = null;
while (! done) {
url = new URL(fileUrl);
httpConn = (HttpURLConnection) url.openConnection();
responseCode = httpConn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_MOVED_TEMP ||
responseCode == HttpURLConnection.HTTP_MOVED_PERM) {
fileUrl = httpConn.getHeaderField("Location");
} else {
done = true;
}
}
// always check HTTP response code first // always check HTTP response code first
if (responseCode == HttpURLConnection.HTTP_OK) { if (responseCode == HttpURLConnection.HTTP_OK) {
@ -191,7 +209,7 @@ public class Main {
// extracts file name from header field // extracts file name from header field
int index = disposition.indexOf("filename="); int index = disposition.indexOf("filename=");
if (index > 0) { if (index > 0) {
fileName = disposition.substring(index + 10, disposition.length() - 1); fileName = disposition.substring(index + 9, disposition.length());
} }
} else { } else {
// extracts file name from URL // extracts file name from URL

View file

@ -1,2 +1,2 @@
kobalt.version=0.244 kobalt.version=0.245