From 49998a8235ca0eaa56ad66b35bd55fe0bc38c459 Mon Sep 17 00:00:00 2001 From: "Jason P. Leasure" Date: Thu, 16 Jul 2020 19:19:16 -0400 Subject: [PATCH] avoid adding duplicate bundles and fix a typo --- .../ghidra/app/plugin/core/osgi/BundleHost.java | 13 +++++++++++-- .../core/osgi/BundleStatusComponentProvider.java | 8 ++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java index 17a4fcd48a..5b29ece90b 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java @@ -197,13 +197,22 @@ public class BundleHost { * Create new GhidraBundles and add to the list of managed bundles. All GhidraBundles created * with the same {@code enabled} and {@code systemBundle} values. * - * @param bundleFiles a list of bundle files + * @param bundleFileList a list of bundle files * @param enabled if the new bundle should be enabled * @param systemBundle if the new bundle is a system bundle * @return the new bundle objects */ - public Collection add(List bundleFiles, boolean enabled, + public Collection add(List bundleFileList, boolean enabled, boolean systemBundle) { + Set bundleFiles = new HashSet<>(bundleFileList); + Iterator bundleFileIterator = bundleFiles.iterator(); + while (bundleFileIterator.hasNext()) { + ResourceFile bundleFile = bundleFileIterator.next(); + if (fileToBundleMap.containsKey(bundleFile)) { + bundleFileIterator.remove(); + Msg.warn(this, "adding an already managed bundle: " + bundleFile.getAbsolutePath()); + } + } Map newBundleMap = bundleFiles.stream() .collect(Collectors.toUnmodifiableMap(Function.identity(), bundleFile -> createGhidraBundle(BundleHost.this, bundleFile, enabled, diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java index df46dca2b2..95990635b3 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java @@ -51,7 +51,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { static final String BUNDLE_GROUP = "0bundle group"; static final String BUNDLE_LIST_GROUP = "1bundle list group"; - static final String PREFENCE_LAST_SELECTED_BUNDLE = "LastGhidraBundle"; + static final String PREFERENCE_LAST_SELECTED_BUNDLE = "LastGhidraBundle"; private JPanel panel; private LessFreneticGTable bundleStatusTable; @@ -266,14 +266,14 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { } }); } - String lastSelected = Preferences.getProperty(PREFENCE_LAST_SELECTED_BUNDLE); + String lastSelected = Preferences.getProperty(PREFERENCE_LAST_SELECTED_BUNDLE); if (lastSelected != null) { File lastSelectedFile = new File(lastSelected); fileChooser.setSelectedFile(lastSelectedFile); } } else { - String lastSelected = Preferences.getProperty(PREFENCE_LAST_SELECTED_BUNDLE); + String lastSelected = Preferences.getProperty(PREFERENCE_LAST_SELECTED_BUNDLE); if (lastSelected != null) { File lastSelectedFile = new File(lastSelected); fileChooser.setSelectedFile(lastSelectedFile); @@ -283,7 +283,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { List files = fileChooser.getSelectedFiles(); if (!files.isEmpty()) { - Preferences.setProperty(PREFENCE_LAST_SELECTED_BUNDLE, files.get(0).getAbsolutePath()); + Preferences.setProperty(PREFERENCE_LAST_SELECTED_BUNDLE, files.get(0).getAbsolutePath()); List resourceFiles = files.stream().map(ResourceFile::new).collect(Collectors.toUnmodifiableList()); Collection bundles = bundleHost.add(resourceFiles, true, false);