|
78 | 78 | import java.util.Collections;
|
79 | 79 | import java.util.HashMap;
|
80 | 80 | import java.util.HashSet;
|
| 81 | +import java.util.LinkedHashMap; |
81 | 82 | import java.util.List;
|
82 | 83 | import java.util.Locale;
|
83 | 84 | import java.util.Map;
|
@@ -230,32 +231,47 @@ void execute(Terminal terminal, List<String> pluginIds, boolean isBatch, Environ
|
230 | 231 | }
|
231 | 232 | }
|
232 | 233 |
|
233 |
| - final List<Path> deleteOnFailure = new ArrayList<>(); |
234 |
| - final Set<PluginInfo> pluginInfos = new HashSet<>(); |
| 234 | + final Map<String, List<Path>> deleteOnFailures = new LinkedHashMap<>(); |
235 | 235 | for (final String pluginId : pluginIds) {
|
| 236 | + terminal.println("-> Installing " + pluginId); |
236 | 237 | try {
|
237 | 238 | if ("x-pack".equals(pluginId)) {
|
238 | 239 | handleInstallXPack(buildFlavor());
|
239 | 240 | }
|
240 | 241 |
|
| 242 | + final List<Path> deleteOnFailure = new ArrayList<>(); |
| 243 | + deleteOnFailures.put(pluginId, deleteOnFailure); |
| 244 | + |
241 | 245 | final Path pluginZip = download(terminal, pluginId, env.tmpFile(), isBatch);
|
242 | 246 | final Path extractedZip = unzip(pluginZip, env.pluginsFile());
|
243 | 247 | deleteOnFailure.add(extractedZip);
|
244 | 248 | final PluginInfo pluginInfo = installPlugin(terminal, isBatch, extractedZip, env, deleteOnFailure);
|
245 |
| - pluginInfos.add(pluginInfo); |
| 249 | + terminal.println("-> Installed " + pluginInfo.getName()); |
| 250 | + // swap the entry by plugin id for one with the installed plugin name, it gives a cleaner error message for URL installs |
| 251 | + deleteOnFailures.remove(pluginId); |
| 252 | + deleteOnFailures.put(pluginInfo.getName(), deleteOnFailure); |
246 | 253 | } catch (final Exception installProblem) {
|
247 |
| - try { |
248 |
| - IOUtils.rm(deleteOnFailure.toArray(new Path[0])); |
249 |
| - } catch (final IOException exceptionWhileRemovingFiles) { |
250 |
| - installProblem.addSuppressed(exceptionWhileRemovingFiles); |
| 254 | + terminal.println("-> Failed installing " + pluginId); |
| 255 | + for (final Map.Entry<String, List<Path>> deleteOnFailureEntry : deleteOnFailures.entrySet()) { |
| 256 | + terminal.println("-> Rolling back " + deleteOnFailureEntry.getKey()); |
| 257 | + boolean success = false; |
| 258 | + try { |
| 259 | + IOUtils.rm(deleteOnFailureEntry.getValue().toArray(new Path[0])); |
| 260 | + success = true; |
| 261 | + } catch (final IOException exceptionWhileRemovingFiles) { |
| 262 | + final Exception exception = new Exception( |
| 263 | + "failed rolling back installation of [" + deleteOnFailureEntry.getKey() + "]", |
| 264 | + exceptionWhileRemovingFiles); |
| 265 | + installProblem.addSuppressed(exception); |
| 266 | + terminal.println("-> Failed rolling back " + deleteOnFailureEntry.getKey()); |
| 267 | + } |
| 268 | + if (success) { |
| 269 | + terminal.println("-> Rolled back " + deleteOnFailureEntry.getKey()); |
| 270 | + } |
251 | 271 | }
|
252 | 272 | throw installProblem;
|
253 | 273 | }
|
254 | 274 | }
|
255 |
| - |
256 |
| - for (final PluginInfo pluginInfo : pluginInfos) { |
257 |
| - terminal.println("-> Installed " + pluginInfo.getName()); |
258 |
| - } |
259 | 275 | }
|
260 | 276 |
|
261 | 277 | Build.Flavor buildFlavor() {
|
|
0 commit comments