Commit 563ec8c2 authored by Evan W. Patton's avatar Evan W. Patton

Make extension deletion robust to package name collisions

If a project contained multiple extensions sharing the same package
name, deleting one extension would also remove the other extensions
sharing that package name. This generally shouldn't happen going
forward because extension bundles automatically group extensions by
package name (which is why this logic is in place), but it didn't
handle the case where old extensions were in the same package.

This commit groups extensions by the components.json file that defines
them, and only deletes those extensions that are siblings by the
components.json file, rather than blanket-deleting extensions solely
by package name.

Fixes #910

Change-Id: I26a5db29a3919033fd50f2a2d65c6f805513ae2c
parent 3274ac6e
...@@ -80,6 +80,8 @@ public final class YaProjectEditor extends ProjectEditor implements ProjectChang ...@@ -80,6 +80,8 @@ public final class YaProjectEditor extends ProjectEditor implements ProjectChang
// Mapping of package names to extensions defined by the package (n > 1) // Mapping of package names to extensions defined by the package (n > 1)
private final Map<String, Set<String>> externalCollections = new HashMap<>(); private final Map<String, Set<String>> externalCollections = new HashMap<>();
private final Map<String, String> extensionToNodeName = new HashMap<>();
private final Map<String, Set<String>> extensionsInNode = new HashMap<>();
// Number of external component descriptors loaded since there is no longer a 1-1 correspondence // Number of external component descriptors loaded since there is no longer a 1-1 correspondence
private volatile int numExternalComponentsLoaded = 0; private volatile int numExternalComponentsLoaded = 0;
...@@ -494,6 +496,13 @@ public final class YaProjectEditor extends ProjectEditor implements ProjectChang ...@@ -494,6 +496,13 @@ public final class YaProjectEditor extends ProjectEditor implements ProjectChang
externalCollections.put(packageName, new HashSet<String>()); externalCollections.put(packageName, new HashSet<String>());
} }
externalCollections.get(packageName).add(name); externalCollections.get(packageName).add(name);
if (!extensionsInNode.containsKey(fileId)) {
extensionsInNode.put(fileId, new HashSet<String>());
}
extensionsInNode.get(fileId).add(name);
extensionToNodeName.put(name, fileId);
name = packageName; name = packageName;
if (!externalComponents.contains(name)) { if (!externalComponents.contains(name)) {
externalComponents.add(name); externalComponents.add(name);
...@@ -618,6 +627,8 @@ public final class YaProjectEditor extends ProjectEditor implements ProjectChang ...@@ -618,6 +627,8 @@ public final class YaProjectEditor extends ProjectEditor implements ProjectChang
COMPONENT_DATABASE.addComponentDatabaseListener(this); COMPONENT_DATABASE.addComponentDatabaseListener(this);
COMPONENT_DATABASE.resetDatabase(); COMPONENT_DATABASE.resetDatabase();
externalComponents.clear(); externalComponents.clear();
extensionsInNode.clear();
extensionToNodeName.clear();
numExternalComponentsLoaded = 0; numExternalComponentsLoaded = 0;
} }
...@@ -658,10 +669,9 @@ public final class YaProjectEditor extends ProjectEditor implements ProjectChang ...@@ -658,10 +669,9 @@ public final class YaProjectEditor extends ProjectEditor implements ProjectChang
Set<String> removedTypes = new HashSet<>(componentTypes); Set<String> removedTypes = new HashSet<>(componentTypes);
// aggregate types in the same package // aggregate types in the same package
for (String type : removedTypes) { for (String type : removedTypes) {
String packageName = COMPONENT_DATABASE.getComponentType(type); Set<String> siblings = extensionsInNode.get(extensionToNodeName.get(COMPONENT_DATABASE.getComponentType(type)));
packageName = packageName.substring(0, packageName.lastIndexOf('.')); if (siblings != null) {
if (externalCollections.containsKey(packageName)) { for (String siblingType : siblings) {
for (String siblingType : externalCollections.get(packageName)) {
String siblingName = siblingType.substring(siblingType.lastIndexOf('.') + 1); String siblingName = siblingType.substring(siblingType.lastIndexOf('.') + 1);
if (!removedTypes.contains(siblingName)) { if (!removedTypes.contains(siblingName)) {
componentTypes.add(siblingName); componentTypes.add(siblingName);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment