Skip to content

Commit 564cea3

Browse files
Recursive result
1 parent db91100 commit 564cea3

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/main/java/org/hydev/mcpm/client/uninstall/UninstallResult.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
package org.hydev.mcpm.client.uninstall;
22

3+
import java.util.HashMap;
4+
import java.util.Map;
5+
36
/**
47
* Result for uninstalling
58
*
9+
* @param state State of uninstall
10+
* @param dependencies States for uninstall dependencies
611
* @author Anushka (https://github.com/aanushkasharma)
712
* @since 2022-11-27
813
*/
9-
public record UninstallResult(State state)
10-
{
14+
public record UninstallResult(State state, Map<String, State> dependencies) {
15+
public UninstallResult(State state) {
16+
this(state, new HashMap<>());
17+
}
18+
1119
public enum State {
20+
NOT_FOUND,
1221
FAILED_TO_DELETE,
1322
SUCCESS
1423
}

src/main/java/org/hydev/mcpm/client/uninstall/Uninstaller.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
import java.io.File;
99

10-
import static org.hydev.mcpm.client.uninstall.UninstallResult.State.FAILED_TO_DELETE;
11-
import static org.hydev.mcpm.client.uninstall.UninstallResult.State.SUCCESS;
10+
import static org.hydev.mcpm.client.uninstall.UninstallResult.State.*;
1211

1312

1413
/**
@@ -28,7 +27,7 @@ public Uninstaller(PluginTracker tracker, UnloadBoundary unloader, LocalJarBound
2827
}
2928

3029
@Override
31-
public UninstallResult uninstall(UninstallInput input) throws PluginNotFoundException {
30+
public UninstallResult uninstall(UninstallInput input) {
3231
// 1. Unload plugin
3332
// This will throw PluginNotFoundException if the plugin isn't loaded. If it is loaded,
3433
// this will return the jar of the currently loaded plugin, which is the most precise.
@@ -46,7 +45,12 @@ public UninstallResult uninstall(UninstallInput input) throws PluginNotFoundExce
4645
if (jar == null) {
4746
// This will throw PluginNotFoundException when a plugin of the name in the file system
4847
// could not be found.
49-
jar = jarFinder.findJar(input.name());
48+
try {
49+
jar = jarFinder.findJar(input.name());
50+
}
51+
catch (PluginNotFoundException e) {
52+
return new UninstallResult(NOT_FOUND);
53+
}
5054
}
5155

5256
// 3. Delete plugin jar
@@ -56,18 +60,24 @@ public UninstallResult uninstall(UninstallInput input) throws PluginNotFoundExce
5660

5761
// 4. Remove manually installed flag from the tracker
5862
tracker.removeEntry(input.name());
63+
var result = new UninstallResult(SUCCESS);
5964

6065
// 5. Remove orphan dependencies
6166
if (input.recursive()) {
6267
var orphans = tracker.listOrphanPlugins(false);
6368
for (var orphan : orphans) {
64-
try {
65-
uninstall(new UninstallInput(orphan, true));
69+
var rec = uninstall(new UninstallInput(orphan, true));
70+
71+
// Recursive result
72+
result.dependencies().put(orphan, rec.state());
73+
for (var pair : rec.dependencies().entrySet()) {
74+
if (!result.dependencies().containsKey(pair.getKey())) {
75+
result.dependencies().put(pair.getKey(), pair.getValue());
76+
}
6677
}
67-
catch (PluginNotFoundException ignored) { }
6878
}
6979
}
7080

71-
return new UninstallResult(SUCCESS);
81+
return result;
7282
}
7383
}

0 commit comments

Comments
 (0)