64
64
import java .io .BufferedReader ;
65
65
import java .io .ByteArrayInputStream ;
66
66
import java .io .ByteArrayOutputStream ;
67
+ import java .io .FileNotFoundException ;
67
68
import java .io .IOException ;
68
69
import java .io .InputStream ;
69
70
import java .io .StringReader ;
93
94
import java .security .NoSuchProviderException ;
94
95
import java .util .ArrayList ;
95
96
import java .util .Arrays ;
97
+ import java .util .Collections ;
96
98
import java .util .Date ;
97
99
import java .util .HashSet ;
98
100
import java .util .List ;
@@ -280,9 +282,17 @@ void installPlugin(String pluginUrl, Path home) throws Exception {
280
282
installPlugin (pluginUrl , home , skipJarHellCommand );
281
283
}
282
284
285
+ void installPlugins (final List <String > pluginUrls , final Path home ) throws Exception {
286
+ installPlugins (pluginUrls , home , skipJarHellCommand );
287
+ }
288
+
283
289
void installPlugin (String pluginUrl , Path home , InstallPluginCommand command ) throws Exception {
284
- Environment env = TestEnvironment .newEnvironment (Settings .builder ().put ("path.home" , home ).build ());
285
- command .execute (terminal , pluginUrl , false , env );
290
+ installPlugins (pluginUrl == null ? Collections .emptyList () : Collections .singletonList (pluginUrl ), home , command );
291
+ }
292
+
293
+ void installPlugins (final List <String > pluginUrls , final Path home , final InstallPluginCommand command ) throws Exception {
294
+ final Environment env = TestEnvironment .newEnvironment (Settings .builder ().put ("path.home" , home ).build ());
295
+ command .execute (terminal , pluginUrls , false , env );
286
296
}
287
297
288
298
void assertPlugin (String name , Path original , Environment env ) throws IOException {
@@ -382,7 +392,7 @@ void assertInstallCleaned(Environment env) throws IOException {
382
392
public void testMissingPluginId () throws IOException {
383
393
final Tuple <Path , Environment > env = createEnv (fs , temp );
384
394
final UserException e = expectThrows (UserException .class , () -> installPlugin (null , env .v1 ()));
385
- assertTrue (e .getMessage (), e .getMessage ().contains ("plugin id is required" ));
395
+ assertTrue (e .getMessage (), e .getMessage ().contains ("at least one plugin id is required" ));
386
396
}
387
397
388
398
public void testSomethingWorks () throws Exception {
@@ -393,6 +403,38 @@ public void testSomethingWorks() throws Exception {
393
403
assertPlugin ("fake" , pluginDir , env .v2 ());
394
404
}
395
405
406
+ public void testMultipleWorks () throws Exception {
407
+ Tuple <Path , Environment > env = createEnv (fs , temp );
408
+ Path pluginDir = createPluginDir (temp );
409
+ String fake1PluginZip = createPluginUrl ("fake1" , pluginDir );
410
+ String fake2PluginZip = createPluginUrl ("fake2" , pluginDir );
411
+ installPlugins (Arrays .asList (fake1PluginZip , fake2PluginZip ), env .v1 ());
412
+ assertPlugin ("fake1" , pluginDir , env .v2 ());
413
+ assertPlugin ("fake2" , pluginDir , env .v2 ());
414
+ }
415
+
416
+ public void testDuplicateInstall () throws Exception {
417
+ Tuple <Path , Environment > env = createEnv (fs , temp );
418
+ Path pluginDir = createPluginDir (temp );
419
+ String pluginZip = createPluginUrl ("fake" , pluginDir );
420
+ final UserException e = expectThrows (UserException .class , () -> installPlugins (Arrays .asList (pluginZip , pluginZip ), env .v1 ()));
421
+ assertThat (e , hasToString (containsString ("duplicate plugin id [" + pluginZip + "]" )));
422
+ }
423
+
424
+ public void testTransaction () throws Exception {
425
+ Tuple <Path , Environment > env = createEnv (fs , temp );
426
+ Path pluginDir = createPluginDir (temp );
427
+ String pluginZip = createPluginUrl ("fake" , pluginDir );
428
+ final FileNotFoundException e = expectThrows (
429
+ FileNotFoundException .class ,
430
+ () -> installPlugins (Arrays .asList (pluginZip , pluginZip + "does-not-exist" ), env .v1 ()));
431
+ assertThat (e , hasToString (containsString ("does-not-exist" )));
432
+ final Path fakeInstallPath = env .v2 ().pluginsFile ().resolve ("fake" );
433
+ // fake should have been removed when the file not found exception occurred
434
+ assertFalse (Files .exists (fakeInstallPath ));
435
+ assertInstallCleaned (env .v2 ());
436
+ }
437
+
396
438
public void testInstallFailsIfPreviouslyRemovedPluginFailed () throws Exception {
397
439
Tuple <Path , Environment > env = createEnv (fs , temp );
398
440
Path pluginDir = createPluginDir (temp );
@@ -769,7 +811,8 @@ Build.Flavor buildFlavor() {
769
811
};
770
812
771
813
final Environment environment = createEnv (fs , temp ).v2 ();
772
- final T exception = expectThrows (clazz , () -> flavorCommand .execute (terminal , "x-pack" , false , environment ));
814
+ final T exception =
815
+ expectThrows (clazz , () -> flavorCommand .execute (terminal , Collections .singletonList ("x-pack" ), false , environment ));
773
816
assertThat (exception , hasToString (containsString (expectedMessage )));
774
817
}
775
818
@@ -830,7 +873,7 @@ private void installPlugin(MockTerminal terminal, boolean isBatch) throws Except
830
873
writePluginSecurityPolicy (pluginDir , "setFactory" );
831
874
}
832
875
String pluginZip = createPlugin ("fake" , pluginDir ).toUri ().toURL ().toString ();
833
- skipJarHellCommand .execute (terminal , pluginZip , isBatch , env .v2 ());
876
+ skipJarHellCommand .execute (terminal , Collections . singletonList ( pluginZip ) , isBatch , env .v2 ());
834
877
}
835
878
836
879
void assertInstallPluginFromUrl (
0 commit comments