|
@@ -226,7 +226,7 @@ class InstallPluginCommand extends EnvironmentAwareCommand {
|
|
|
handleInstallXPack(buildFlavor());
|
|
|
}
|
|
|
|
|
|
- Path pluginZip = download(terminal, pluginId, env.tmpFile());
|
|
|
+ Path pluginZip = download(terminal, pluginId, env.tmpFile(), isBatch);
|
|
|
Path extractedZip = unzip(pluginZip, env.pluginsFile());
|
|
|
install(terminal, isBatch, extractedZip, env);
|
|
|
}
|
|
@@ -249,11 +249,11 @@ class InstallPluginCommand extends EnvironmentAwareCommand {
|
|
|
}
|
|
|
|
|
|
/** Downloads the plugin and returns the file it was downloaded to. */
|
|
|
- private Path download(Terminal terminal, String pluginId, Path tmpDir) throws Exception {
|
|
|
+ private Path download(Terminal terminal, String pluginId, Path tmpDir, boolean isBatch) throws Exception {
|
|
|
if (OFFICIAL_PLUGINS.contains(pluginId)) {
|
|
|
final String url = getElasticUrl(terminal, getStagingHash(), Version.CURRENT, isSnapshot(), pluginId, Platforms.PLATFORM_NAME);
|
|
|
terminal.println("-> Downloading " + pluginId + " from elastic");
|
|
|
- return downloadAndValidate(terminal, url, tmpDir, true);
|
|
|
+ return downloadAndValidate(terminal, url, tmpDir, true, isBatch);
|
|
|
}
|
|
|
|
|
|
// now try as maven coordinates, a valid URL would only have a colon and slash
|
|
@@ -261,7 +261,7 @@ class InstallPluginCommand extends EnvironmentAwareCommand {
|
|
|
if (coordinates.length == 3 && pluginId.contains("/") == false && pluginId.startsWith("file:") == false) {
|
|
|
String mavenUrl = getMavenUrl(terminal, coordinates, Platforms.PLATFORM_NAME);
|
|
|
terminal.println("-> Downloading " + pluginId + " from maven central");
|
|
|
- return downloadAndValidate(terminal, mavenUrl, tmpDir, false);
|
|
|
+ return downloadAndValidate(terminal, mavenUrl, tmpDir, false, isBatch);
|
|
|
}
|
|
|
|
|
|
// fall back to plain old URL
|
|
@@ -275,7 +275,7 @@ class InstallPluginCommand extends EnvironmentAwareCommand {
|
|
|
throw new UserException(ExitCodes.USAGE, msg);
|
|
|
}
|
|
|
terminal.println("-> Downloading " + URLDecoder.decode(pluginId, "UTF-8"));
|
|
|
- return downloadZip(terminal, pluginId, tmpDir);
|
|
|
+ return downloadZip(terminal, pluginId, tmpDir, isBatch);
|
|
|
}
|
|
|
|
|
|
// pkg private so tests can override
|
|
@@ -370,14 +370,14 @@ class InstallPluginCommand extends EnvironmentAwareCommand {
|
|
|
/** Downloads a zip from the url, into a temp file under the given temp dir. */
|
|
|
// pkg private for tests
|
|
|
@SuppressForbidden(reason = "We use getInputStream to download plugins")
|
|
|
- Path downloadZip(Terminal terminal, String urlString, Path tmpDir) throws IOException {
|
|
|
+ Path downloadZip(Terminal terminal, String urlString, Path tmpDir, boolean isBatch) throws IOException {
|
|
|
terminal.println(VERBOSE, "Retrieving zip from " + urlString);
|
|
|
URL url = new URL(urlString);
|
|
|
Path zip = Files.createTempFile(tmpDir, null, ".zip");
|
|
|
URLConnection urlConnection = url.openConnection();
|
|
|
urlConnection.addRequestProperty("User-Agent", "elasticsearch-plugin-installer");
|
|
|
- int contentLength = urlConnection.getContentLength();
|
|
|
- try (InputStream in = new TerminalProgressInputStream(urlConnection.getInputStream(), contentLength, terminal)) {
|
|
|
+ try (InputStream in = isBatch ? urlConnection.getInputStream() :
|
|
|
+ new TerminalProgressInputStream(urlConnection.getInputStream(),urlConnection.getContentLength(),terminal)) {
|
|
|
// must overwrite since creating the temp file above actually created the file
|
|
|
Files.copy(in, zip, StandardCopyOption.REPLACE_EXISTING);
|
|
|
}
|
|
@@ -440,17 +440,18 @@ class InstallPluginCommand extends EnvironmentAwareCommand {
|
|
|
* @param urlString the URL of the plugin ZIP
|
|
|
* @param tmpDir a temporary directory to write downloaded files to
|
|
|
* @param officialPlugin true if the plugin is an official plugin
|
|
|
+ * @param isBatch true if the install is running in batch mode
|
|
|
* @return the path to the downloaded plugin ZIP
|
|
|
* @throws IOException if an I/O exception occurs download or reading files and resources
|
|
|
* @throws PGPException if an exception occurs verifying the downloaded ZIP signature
|
|
|
* @throws UserException if checksum validation fails
|
|
|
*/
|
|
|
private Path downloadAndValidate(
|
|
|
- final Terminal terminal,
|
|
|
- final String urlString,
|
|
|
- final Path tmpDir,
|
|
|
- final boolean officialPlugin) throws IOException, PGPException, UserException {
|
|
|
- Path zip = downloadZip(terminal, urlString, tmpDir);
|
|
|
+ final Terminal terminal,
|
|
|
+ final String urlString,
|
|
|
+ final Path tmpDir,
|
|
|
+ final boolean officialPlugin, boolean isBatch) throws IOException, PGPException, UserException {
|
|
|
+ Path zip = downloadZip(terminal, urlString, tmpDir, isBatch);
|
|
|
pathsToDeleteOnShutdown.add(zip);
|
|
|
String checksumUrlString = urlString + ".sha512";
|
|
|
URL checksumUrl = openUrl(checksumUrlString);
|