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
// 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, 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
private volatile int numExternalComponentsLoaded = 0;
......@@ -494,6 +496,13 @@ public final class YaProjectEditor extends ProjectEditor implements ProjectChang
externalCollections.put(packageName, new HashSet<String>());
}
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;
if (!externalComponents.contains(name)) {
externalComponents.add(name);
......@@ -618,6 +627,8 @@ public final class YaProjectEditor extends ProjectEditor implements ProjectChang
COMPONENT_DATABASE.addComponentDatabaseListener(this);
COMPONENT_DATABASE.resetDatabase();
externalComponents.clear();
extensionsInNode.clear();
extensionToNodeName.clear();
numExternalComponentsLoaded = 0;
}
......@@ -658,10 +669,9 @@ public final class YaProjectEditor extends ProjectEditor implements ProjectChang
Set<String> removedTypes = new HashSet<>(componentTypes);
// aggregate types in the same package
for (String type : removedTypes) {
String packageName = COMPONENT_DATABASE.getComponentType(type);
packageName = packageName.substring(0, packageName.lastIndexOf('.'));
if (externalCollections.containsKey(packageName)) {
for (String siblingType : externalCollections.get(packageName)) {
Set<String> siblings = extensionsInNode.get(extensionToNodeName.get(COMPONENT_DATABASE.getComponentType(type)));
if (siblings != null) {
for (String siblingType : siblings) {
String siblingName = siblingType.substring(siblingType.lastIndexOf('.') + 1);
if (!removedTypes.contains(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