e.printStackTrace();
}
}
public void downloadAndExtract(String name) throws IOException {
HttpDownloadHelper downloadHelper = new HttpDownloadHelper();
File pluginFile = new File(url + "/" + name + "/elasticsearch-" + name + "-" + Version.number() + ".zip");
boolean downloaded = false;
String filterZipName = null;
if (!pluginFile.exists()) {
pluginFile = new File(url + "/elasticsearch-" + name + "-" + Version.number() + ".zip");
if (!pluginFile.exists()) {
pluginFile = new File(environment.pluginsFile(), name + ".zip");
if (url != null) {
URL pluginUrl = new URL(url);
System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
try {
downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
downloaded = true;
} catch (IOException e) {
// ignore
}
} else {
url = "http://elasticsearch.googlecode.com/svn/plugins";
}
if (!downloaded) {
if (name.indexOf('/') != -1) {
// github repo
String[] elements = name.split("/");
String userName = elements[0];
String repoName = elements[1];
String version = null;
if (elements.length > 2) {
version = elements[2];
}
filterZipName = userName + "-" + repoName;
// the installation file should not include the userName, just the repoName
name = repoName;
if (name.startsWith("elasticsearch-")) {
// remove elasticsearch- prefix
name = name.substring("elasticsearch-".length());
} else if (name.startsWith("es-")) {
// remove es- prefix
name = name.substring("es-".length());
}
pluginFile = new File(environment.pluginsFile(), name + ".zip");
if (version == null) {
// try with ES version from downloads
URL pluginUrl = new URL("https://github.com/downloads/" + userName + "/" + repoName + "/" + repoName + "-" + Version.number() + ".zip");
System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
try {
downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
downloaded = true;
} catch (IOException e) {
// try a tag with ES version
pluginUrl = new URL("https://github.com/" + userName + "/" + repoName + "/zipball/v" + Version.number());
System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
try {
downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
downloaded = true;
} catch (IOException e1) {
// download master
pluginUrl = new URL("https://github.com/" + userName + "/" + repoName + "/zipball/master");
System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
try {
downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
downloaded = true;
} catch (IOException e2) {
// ignore
}
}
}
} else {
// download explicit version
URL pluginUrl = new URL("https://github.com/downloads/" + userName + "/" + repoName + "/" + repoName + "-" + version + ".zip");
System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
try {
downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
downloaded = true;
} catch (IOException e) {
// try a tag with ES version
pluginUrl = new URL("https://github.com/" + userName + "/" + repoName + "/zipball/v" + version);
System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
try {
downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
downloaded = true;
} catch (IOException e1) {
// ignore
}
}
}
} else {
URL pluginUrl = new URL(url + "/" + name + "/elasticsearch-" + name + "-" + Version.number() + ".zip");
System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
try {
downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
downloaded = true;
} catch (IOException e) {
// ignore
}
}