fix(gui): don't init already loaded plugins while collecting options (#2727)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package jadx.gui.utils.plugins;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import jadx.api.JadxArgs;
|
||||
import jadx.api.JadxDecompiler;
|
||||
@@ -27,12 +27,13 @@ public class CollectPlugins {
|
||||
}
|
||||
|
||||
public CloseablePlugins build() {
|
||||
SortedSet<PluginContext> allPlugins = new TreeSet<>();
|
||||
mainWindow.getWrapper().getCurrentDecompiler()
|
||||
.ifPresent(decompiler -> allPlugins.addAll(decompiler.getPluginManager().getResolvedPluginContexts()));
|
||||
|
||||
// collect and init not loaded plugins in new temp context
|
||||
Runnable closeable = null;
|
||||
Optional<JadxDecompiler> currentDecompiler = mainWindow.getWrapper().getCurrentDecompiler();
|
||||
if (currentDecompiler.isPresent()) {
|
||||
JadxDecompiler decompiler = currentDecompiler.get();
|
||||
SortedSet<PluginContext> plugins = decompiler.getPluginManager().getResolvedPluginContexts();
|
||||
return new CloseablePlugins(new ArrayList<>(plugins), null);
|
||||
}
|
||||
// collect and init plugins in new temp context
|
||||
JadxArgs jadxArgs = mainWindow.getSettings().toJadxArgs();
|
||||
jadxArgs.setFilesGetter(JadxFilesGetter.INSTANCE);
|
||||
try (JadxDecompiler decompiler = new JadxDecompiler(jadxArgs)) {
|
||||
@@ -44,18 +45,10 @@ public class CollectPlugins {
|
||||
pluginContext.setAppContext(appContext);
|
||||
});
|
||||
pluginManager.load(new JadxExternalPluginsLoader());
|
||||
SortedSet<PluginContext> missingPlugins = new TreeSet<>();
|
||||
for (PluginContext context : pluginManager.getAllPluginContexts()) {
|
||||
if (!allPlugins.contains(context)) {
|
||||
missingPlugins.add(context);
|
||||
}
|
||||
}
|
||||
if (!missingPlugins.isEmpty()) {
|
||||
pluginManager.init(missingPlugins);
|
||||
allPlugins.addAll(missingPlugins);
|
||||
closeable = () -> pluginManager.unload(missingPlugins);
|
||||
}
|
||||
SortedSet<PluginContext> allPlugins = pluginManager.getAllPluginContexts();
|
||||
pluginManager.init(allPlugins);
|
||||
Runnable closeable = () -> pluginManager.unload(allPlugins);
|
||||
return new CloseablePlugins(new ArrayList<>(allPlugins), closeable);
|
||||
}
|
||||
return new CloseablePlugins(new ArrayList<>(allPlugins), closeable);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-10
@@ -31,7 +31,7 @@ public class JadxExternalPluginsLoader implements JadxPluginLoader {
|
||||
public List<JadxPlugin> load() {
|
||||
close();
|
||||
long start = System.currentTimeMillis();
|
||||
Map<Class<? extends JadxPlugin>, JadxPlugin> map = new HashMap<>();
|
||||
Map<String, JadxPlugin> map = new HashMap<>();
|
||||
loadFromClsLoader(map, thisClassLoader());
|
||||
loadInstalledPlugins(map);
|
||||
|
||||
@@ -45,7 +45,7 @@ public class JadxExternalPluginsLoader implements JadxPluginLoader {
|
||||
}
|
||||
|
||||
public JadxPlugin loadFromJar(Path jar) {
|
||||
Map<Class<? extends JadxPlugin>, JadxPlugin> map = new HashMap<>();
|
||||
Map<String, JadxPlugin> map = new HashMap<>();
|
||||
loadFromJar(map, jar);
|
||||
int loaded = map.size();
|
||||
if (loaded == 0) {
|
||||
@@ -59,22 +59,26 @@ public class JadxExternalPluginsLoader implements JadxPluginLoader {
|
||||
|
||||
}
|
||||
|
||||
private void loadFromClsLoader(Map<Class<? extends JadxPlugin>, JadxPlugin> map, ClassLoader classLoader) {
|
||||
ServiceLoader.load(JadxPlugin.class, classLoader)
|
||||
.stream()
|
||||
.filter(p -> p.type().getClassLoader() == classLoader)
|
||||
.filter(p -> !map.containsKey(p.type()))
|
||||
.forEach(p -> map.put(p.type(), p.get()));
|
||||
private void loadFromClsLoader(Map<String, JadxPlugin> map, ClassLoader classLoader) {
|
||||
ServiceLoader<JadxPlugin> serviceLoader = ServiceLoader.load(JadxPlugin.class, classLoader);
|
||||
for (ServiceLoader.Provider<JadxPlugin> provider : serviceLoader.stream().collect(Collectors.toList())) {
|
||||
Class<? extends JadxPlugin> pluginClass = provider.type();
|
||||
String clsName = pluginClass.getName();
|
||||
if (!map.containsKey(clsName)
|
||||
&& pluginClass.getClassLoader() == classLoader) {
|
||||
map.put(clsName, provider.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadInstalledPlugins(Map<Class<? extends JadxPlugin>, JadxPlugin> map) {
|
||||
private void loadInstalledPlugins(Map<String, JadxPlugin> map) {
|
||||
List<Path> jars = JadxPluginsTools.getInstance().getEnabledPluginJars();
|
||||
for (Path jar : jars) {
|
||||
loadFromJar(map, jar);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadFromJar(Map<Class<? extends JadxPlugin>, JadxPlugin> map, Path jar) {
|
||||
private void loadFromJar(Map<String, JadxPlugin> map, Path jar) {
|
||||
try {
|
||||
File jarFile = jar.toFile();
|
||||
String clsLoaderName = JADX_PLUGIN_CLASSLOADER_PREFIX + jarFile.getName();
|
||||
|
||||
Reference in New Issue
Block a user