Skip to content

Commit

Permalink
XWIKI-22328: IllegalStateException when installing extension which re…
Browse files Browse the repository at this point in the history
…place an extension installed on several namespace
  • Loading branch information
tmortagne committed Jul 16, 2024
1 parent 5f2e4be commit fd844b5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ private ModifableExtensionPlanNode installExtension(Extension sourceExtension, E

this.progressManager.startStep(this);

// Find all existing versions of the extension
// Find extension colliding with the extension being installed
Set<InstalledExtension> previousExtensions = getReplacedInstalledExtensions(rewrittenExtension, namespace);

this.progressManager.endStep(this);
Expand All @@ -1092,19 +1092,22 @@ private ModifableExtensionPlanNode installExtension(Extension sourceExtension, E
if (namespace == null && previousExtension.getNamespaces() != null) {
for (String previousNamespace : previousExtension.getNamespaces()) {
uninstallExtension(previousExtension, previousNamespace, this.extensionTree, false);
it.remove();

// Remember replaced extension for through the whole job
// Remember replaced extensions through the whole job
this.extensionsCache.addPrevious(previousExtension.getId().getId(), previousNamespace);
}

// This is an uninstall/install situation (and not an upgrade or downgrade), so we remove this
// extension from the previous ones
it.remove();
} else {
uninstallExtension(previousExtension, namespace, this.extensionTree, false);

// Remember replaced extension for through the whole job
// Remember replaced extensions through the whole job
this.extensionsCache.addPrevious(previousExtension.getId().getId(), namespace);
}
} else {
// Remember replaced extension for through the whole job
// Remember replaced extensions through the whole job
this.extensionsCache.addPrevious(previousExtension.getId().getId(), namespace);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,47 @@ void testInstallOnNamespaceThenOnRoot() throws Throwable
assertEquals(0, node.getChildren().size());
}

@Test
void testInstallOnSeveralNamespacesThenOnRoot() throws Throwable
{
// Install 1.0 on namespace1 and namespace2
install(TestResources.REMOTE_UPGRADE10_ID, "namespace1");
install(TestResources.REMOTE_UPGRADE10_ID, "namespace2");

// Move 1.0 on root
ExtensionPlan plan = installPlan(TestResources.REMOTE_UPGRADE10_ID);

assertEquals(3, plan.getTree().size());

Iterator<ExtensionPlanNode> it = plan.getTree().iterator();

ExtensionPlanNode node = it.next();
ExtensionPlanAction action = node.getAction();
assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getExtension().getId());
assertEquals(Action.UNINSTALL, action.getAction());
assertEquals(1, action.getPreviousExtensions().size());
assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getPreviousExtension().getId());
assertEquals("namespace1", action.getNamespace());
assertEquals(0, node.getChildren().size());

node = it.next();
action = node.getAction();
assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getExtension().getId());
assertEquals(Action.UNINSTALL, action.getAction());
assertEquals(1, action.getPreviousExtensions().size());
assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getPreviousExtension().getId());
assertEquals("namespace2", action.getNamespace());
assertEquals(0, node.getChildren().size());

node = it.next();
action = node.getAction();
assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getExtension().getId());
assertEquals(Action.INSTALL, action.getAction());
assertEquals(0, action.getPreviousExtensions().size());
assertNull(action.getNamespace());
assertEquals(0, node.getChildren().size());
}

@Test
void testInstallOnNamespaceThenUnpgradeOnRoot() throws Throwable
{
Expand Down

0 comments on commit fd844b5

Please sign in to comment.