Skip to content

Commit

Permalink
Clean caches upon deletion of a Target Definition #1246
Browse files Browse the repository at this point in the history
TargetPlatformHelper and TargetPlatformService keep separate caches for
target definition, resulting in a leak of TargetDefinition objects.

The leak happens when TargetDefinition.resolve() caches data in
TargetPlatformHelper.

This also allows to skip the explicit removal of a target selected for
removal from the TargetPlatformHelper's cache in
TargetPlatformPreferencePage.handleRemove() because the removal will
done when the change is applied and TargetPlatformService.deleteTarget()
is then called.

Fixes #1246
  • Loading branch information
basilevs authored and HannesWell committed May 18, 2024
1 parent a42910f commit 145a426
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.PDEPreferencesManager;
import org.eclipse.pde.internal.core.TargetDefinitionManager;
import org.eclipse.pde.internal.core.TargetPlatformHelper;
import org.osgi.service.prefs.BackingStoreException;

/**
Expand Down Expand Up @@ -156,6 +157,7 @@ public void deleteTarget(ITargetHandle handle) throws CoreException {
fExtTargetHandles.remove(((ExternalFileTargetHandle) handle).getLocation());
}
((AbstractTargetHandle) handle).delete();
TargetPlatformHelper.getTargetDefinitionMap().remove(handle);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,22 @@ public void testArguments() throws Exception {

}

/**
* Test for https://github.com/eclipse-pde/eclipse.pde/issues/1246
*/
@Test
public void testDeleteCleansCaches() throws Exception {
ITargetDefinition definition = getNewTarget();
try {
assertFalse(TargetPlatformHelper.getTargetDefinitionMap().containsKey(definition.getHandle()));
definition.resolve(null);
assertTrue(TargetPlatformHelper.getTargetDefinitionMap().containsKey(definition.getHandle()));
} finally {
getTargetService().deleteTarget(definition.getHandle());
assertFalse(TargetPlatformHelper.getTargetDefinitionMap().containsKey(definition.getHandle()));
}
}

/**
* Tests that a single (lower) version of a bundle can be included in the
* target platform.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,6 @@ private void handleRemove() {
}
fRemoved.addAll(selected);
fTargets.removeAll(selected);
for (ITargetDefinition element : selected) {
TargetPlatformHelper.getTargetDefinitionMap().remove(element.getHandle());
}
// Quick hack because the first refresh loses the checkedState, which is being used to bold the active target
fTableViewer.refresh(false);
fTableViewer.refresh(true);
Expand Down

0 comments on commit 145a426

Please sign in to comment.