53
53
import java .nio .file .FileVisitResult ;
54
54
import java .nio .file .Files ;
55
55
import java .nio .file .Path ;
56
- import java .nio .file .Paths ;
57
56
import java .nio .file .SimpleFileVisitor ;
58
57
import java .nio .file .StandardCopyOption ;
59
58
import java .nio .file .attribute .BasicFileAttributes ;
@@ -219,25 +218,25 @@ void execute(Terminal terminal, String pluginId, boolean isBatch, Environment en
219
218
throw new UserException (ExitCodes .USAGE , "plugin id is required" );
220
219
}
221
220
222
- Path pluginZip = download (terminal , pluginId , env .tmpFile (), env . pluginsFile () );
221
+ Path pluginZip = download (terminal , pluginId , env .tmpFile ());
223
222
Path extractedZip = unzip (pluginZip , env .pluginsFile ());
224
223
install (terminal , isBatch , extractedZip , env );
225
224
}
226
225
227
226
/** Downloads the plugin and returns the file it was downloaded to. */
228
- private Path download (Terminal terminal , String pluginId , Path tmpDir , Path pluginsDir ) throws Exception {
227
+ private Path download (Terminal terminal , String pluginId , Path tmpDir ) throws Exception {
229
228
if (OFFICIAL_PLUGINS .contains (pluginId )) {
230
229
final String url = getElasticUrl (terminal , getStagingHash (), Version .CURRENT , pluginId , Platforms .PLATFORM_NAME );
231
230
terminal .println ("-> Downloading " + pluginId + " from elastic" );
232
- return downloadZipAndChecksum (terminal , url , tmpDir , pluginsDir , false );
231
+ return downloadZipAndChecksum (terminal , url , tmpDir , false );
233
232
}
234
233
235
234
// now try as maven coordinates, a valid URL would only have a colon and slash
236
235
String [] coordinates = pluginId .split (":" );
237
236
if (coordinates .length == 3 && pluginId .contains ("/" ) == false && pluginId .startsWith ("file:" ) == false ) {
238
237
String mavenUrl = getMavenUrl (terminal , coordinates , Platforms .PLATFORM_NAME );
239
238
terminal .println ("-> Downloading " + pluginId + " from maven central" );
240
- return downloadZipAndChecksum (terminal , mavenUrl , tmpDir , pluginsDir , true );
239
+ return downloadZipAndChecksum (terminal , mavenUrl , tmpDir , true );
241
240
}
242
241
243
242
// fall back to plain old URL
@@ -251,7 +250,7 @@ private Path download(Terminal terminal, String pluginId, Path tmpDir, Path plug
251
250
throw new UserException (ExitCodes .USAGE , msg );
252
251
}
253
252
terminal .println ("-> Downloading " + URLDecoder .decode (pluginId , "UTF-8" ));
254
- return downloadZip (terminal , pluginId , tmpDir , pluginsDir );
253
+ return downloadZip (terminal , pluginId , tmpDir );
255
254
}
256
255
257
256
// pkg private so tests can override
@@ -325,17 +324,9 @@ private List<String> checkMisspelledPlugin(String pluginId) {
325
324
/** Downloads a zip from the url, into a temp file under the given temp dir. */
326
325
// pkg private for tests
327
326
@ SuppressForbidden (reason = "We use getInputStream to download plugins" )
328
- Path downloadZip (Terminal terminal , String urlString , Path tmpDir , Path pluginsDir ) throws IOException {
327
+ Path downloadZip (Terminal terminal , String urlString , Path tmpDir ) throws IOException {
329
328
terminal .println (VERBOSE , "Retrieving zip from " + urlString );
330
329
URL url = new URL (urlString );
331
- if (url .getProtocol ().equals ("file" )) {
332
- Path pluginsFile = Paths .get (url .getFile ());
333
- if (pluginsFile .startsWith (pluginsDir )) {
334
- throw new IllegalStateException ("Installation failed! " +
335
- "Make sure the plugins directory [" + pluginsDir + "] can not contain the plugin distribution [" +
336
- pluginsFile + "]; move the distribution to an alternate location!" );
337
- }
338
- }
339
330
Path zip = Files .createTempFile (tmpDir , null , ".zip" );
340
331
URLConnection urlConnection = url .openConnection ();
341
332
urlConnection .addRequestProperty ("User-Agent" , "elasticsearch-plugin-installer" );
@@ -384,9 +375,8 @@ public void onProgress(int percent) {
384
375
/** Downloads a zip from the url, as well as a SHA512 (or SHA1) checksum, and checks the checksum. */
385
376
// pkg private for tests
386
377
@ SuppressForbidden (reason = "We use openStream to download plugins" )
387
- private Path downloadZipAndChecksum (Terminal terminal , String urlString , Path tmpDir , Path pluginsDir , boolean allowSha1 )
388
- throws Exception {
389
- Path zip = downloadZip (terminal , urlString , tmpDir , pluginsDir );
378
+ private Path downloadZipAndChecksum (Terminal terminal , String urlString , Path tmpDir , boolean allowSha1 ) throws Exception {
379
+ Path zip = downloadZip (terminal , urlString , tmpDir );
390
380
pathsToDeleteOnShutdown .add (zip );
391
381
String checksumUrlString = urlString + ".sha512" ;
392
382
URL checksumUrl = openUrl (checksumUrlString );
0 commit comments