29
29
import org .elasticsearch .cli .ExitCodes ;
30
30
import org .elasticsearch .cli .SettingCommand ;
31
31
import org .elasticsearch .cli .Terminal ;
32
- import org .elasticsearch .cli .UserError ;
32
+ import org .elasticsearch .cli .UserException ;
33
33
import org .elasticsearch .common .collect .Tuple ;
34
34
import org .elasticsearch .common .hash .MessageDigests ;
35
35
import org .elasticsearch .common .io .FileSystemUtils ;
@@ -188,7 +188,7 @@ protected void execute(Terminal terminal, OptionSet options, Map<String, String>
188
188
// TODO: in jopt-simple 5.0 we can enforce a min/max number of positional args
189
189
List <String > args = arguments .values (options );
190
190
if (args .size () != 1 ) {
191
- throw new UserError (ExitCodes .USAGE , "Must supply a single plugin id argument" );
191
+ throw new UserException (ExitCodes .USAGE , "Must supply a single plugin id argument" );
192
192
}
193
193
String pluginId = args .get (0 );
194
194
boolean isBatch = options .has (batchOption ) || System .console () == null ;
@@ -250,7 +250,7 @@ private Path download(Terminal terminal, String pluginId, Path tmpDir) throws Ex
250
250
if (plugins .isEmpty () == false ) {
251
251
msg += ", did you mean " + (plugins .size () == 1 ? "[" + plugins .get (0 ) + "]" : "any of " + plugins .toString ()) + "?" ;
252
252
}
253
- throw new UserError (ExitCodes .USAGE , msg );
253
+ throw new UserException (ExitCodes .USAGE , msg );
254
254
}
255
255
terminal .println ("-> Downloading " + URLDecoder .decode (pluginId , "UTF-8" ));
256
256
return downloadZip (terminal , pluginId , tmpDir );
@@ -328,20 +328,20 @@ private Path downloadZipAndChecksum(Terminal terminal, String urlString, Path tm
328
328
BufferedReader checksumReader = new BufferedReader (new InputStreamReader (in , StandardCharsets .UTF_8 ));
329
329
expectedChecksum = checksumReader .readLine ();
330
330
if (checksumReader .readLine () != null ) {
331
- throw new UserError (ExitCodes .IO_ERROR , "Invalid checksum file at " + checksumUrl );
331
+ throw new UserException (ExitCodes .IO_ERROR , "Invalid checksum file at " + checksumUrl );
332
332
}
333
333
}
334
334
335
335
byte [] zipbytes = Files .readAllBytes (zip );
336
336
String gotChecksum = MessageDigests .toHexString (MessageDigests .sha1 ().digest (zipbytes ));
337
337
if (expectedChecksum .equals (gotChecksum ) == false ) {
338
- throw new UserError (ExitCodes .IO_ERROR , "SHA1 mismatch, expected " + expectedChecksum + " but got " + gotChecksum );
338
+ throw new UserException (ExitCodes .IO_ERROR , "SHA1 mismatch, expected " + expectedChecksum + " but got " + gotChecksum );
339
339
}
340
340
341
341
return zip ;
342
342
}
343
343
344
- private Path unzip (Path zip , Path pluginsDir ) throws IOException , UserError {
344
+ private Path unzip (Path zip , Path pluginsDir ) throws IOException , UserException {
345
345
// unzip plugin to a staging temp dir
346
346
347
347
final Path target = stagingDirectory (pluginsDir );
@@ -386,7 +386,7 @@ private Path unzip(Path zip, Path pluginsDir) throws IOException, UserError {
386
386
Files .delete (zip );
387
387
if (hasEsDir == false ) {
388
388
IOUtils .rm (target );
389
- throw new UserError (ExitCodes .DATA_ERROR , "`elasticsearch` directory is missing in the plugin zip" );
389
+ throw new UserException (ExitCodes .DATA_ERROR , "`elasticsearch` directory is missing in the plugin zip" );
390
390
}
391
391
return target ;
392
392
}
@@ -425,7 +425,7 @@ private PluginInfo verify(Terminal terminal, Path pluginRoot, boolean isBatch, E
425
425
// don't let luser install plugin as a module...
426
426
// they might be unavoidably in maven central and are packaged up the same way)
427
427
if (MODULES .contains (info .getName ())) {
428
- throw new UserError (ExitCodes .USAGE , "plugin '" + info .getName () + "' cannot be installed like this, it is a system module" );
428
+ throw new UserException (ExitCodes .USAGE , "plugin '" + info .getName () + "' cannot be installed like this, it is a system module" );
429
429
}
430
430
431
431
// check for jar hell before any copying
@@ -475,7 +475,7 @@ private void install(Terminal terminal, boolean isBatch, Path tmpRoot, Environme
475
475
476
476
final Path destination = env .pluginsFile ().resolve (info .getName ());
477
477
if (Files .exists (destination )) {
478
- throw new UserError (
478
+ throw new UserException (
479
479
ExitCodes .USAGE ,
480
480
"plugin directory " + destination .toAbsolutePath () +
481
481
" already exists. To update the plugin, uninstall it first using 'remove " + info .getName () + "' command" );
@@ -520,15 +520,15 @@ private void install(Terminal terminal, boolean isBatch, Path tmpRoot, Environme
520
520
/** Copies the files from {@code tmpBinDir} into {@code destBinDir}, along with permissions from dest dirs parent. */
521
521
private void installBin (PluginInfo info , Path tmpBinDir , Path destBinDir ) throws Exception {
522
522
if (Files .isDirectory (tmpBinDir ) == false ) {
523
- throw new UserError (ExitCodes .IO_ERROR , "bin in plugin " + info .getName () + " is not a directory" );
523
+ throw new UserException (ExitCodes .IO_ERROR , "bin in plugin " + info .getName () + " is not a directory" );
524
524
}
525
525
Files .createDirectory (destBinDir );
526
526
setFileAttributes (destBinDir , DIR_AND_EXECUTABLE_PERMS );
527
527
528
528
try (DirectoryStream <Path > stream = Files .newDirectoryStream (tmpBinDir )) {
529
529
for (Path srcFile : stream ) {
530
530
if (Files .isDirectory (srcFile )) {
531
- throw new UserError (
531
+ throw new UserException (
532
532
ExitCodes .DATA_ERROR ,
533
533
"Directories not allowed in bin dir for plugin " + info .getName () + ", found " + srcFile .getFileName ());
534
534
}
@@ -547,7 +547,7 @@ private void installBin(PluginInfo info, Path tmpBinDir, Path destBinDir) throws
547
547
*/
548
548
private void installConfig (PluginInfo info , Path tmpConfigDir , Path destConfigDir ) throws Exception {
549
549
if (Files .isDirectory (tmpConfigDir ) == false ) {
550
- throw new UserError (ExitCodes .IO_ERROR , "config in plugin " + info .getName () + " is not a directory" );
550
+ throw new UserException (ExitCodes .IO_ERROR , "config in plugin " + info .getName () + " is not a directory" );
551
551
}
552
552
553
553
Files .createDirectories (destConfigDir );
@@ -563,7 +563,7 @@ private void installConfig(PluginInfo info, Path tmpConfigDir, Path destConfigDi
563
563
try (DirectoryStream <Path > stream = Files .newDirectoryStream (tmpConfigDir )) {
564
564
for (Path srcFile : stream ) {
565
565
if (Files .isDirectory (srcFile )) {
566
- throw new UserError (ExitCodes .DATA_ERROR , "Directories not allowed in config dir for plugin " + info .getName ());
566
+ throw new UserException (ExitCodes .DATA_ERROR , "Directories not allowed in config dir for plugin " + info .getName ());
567
567
}
568
568
569
569
Path destFile = destConfigDir .resolve (tmpConfigDir .relativize (srcFile ));
0 commit comments