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