From 848ecf9f044aa0bff4224dec5592bc1c4b347545 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sat, 28 Sep 2024 13:02:56 +0200 Subject: [PATCH] [TP] Remove declarations of Exception that are never thrown and clean-up --- .../core/target/IUBundleContainer.java | 13 ++-- .../internal/core/target/P2TargetUtils.java | 50 ++++++------ .../core/target/TargetDefinition.java | 77 ++++++++----------- .../ui/shared/target/EditIUContainerPage.java | 60 +++++---------- .../ui/shared/target/IUContentProvider.java | 23 +++--- .../internal/ui/shared/target/IUFactory.java | 3 +- 6 files changed, 94 insertions(+), 132 deletions(-) diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java index f2f047d4be2..1ac6ab01cdf 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java @@ -265,7 +265,7 @@ protected TargetBundle[] resolveBundles(ITargetDefinition definition, IProgressM private void cacheIUs() throws CoreException { IProfile profile = fSynchronizer.getProfile(); List result = new ArrayList<>(); - MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories, null); + MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories); for (IVersionedId unit : fIUs) { IQuery query = QueryUtil.createIUQuery(unit); addQueryResult(profile, query, unit, result, status); @@ -571,14 +571,13 @@ public boolean isFollowRepositoryReferences() { * Returns the installable units defined by this container * * @return the discovered IUs - * @exception CoreException if unable to retrieve IU's */ - public List getInstallableUnits() throws CoreException { + public List getInstallableUnits() { return fUnits; } /** Returns the declared installable unit identifiers and versions. */ - Collection getUnits() { + Collection getDeclaredUnits() { return Collections.unmodifiableSet(fIUs); } @@ -682,10 +681,10 @@ public String serialize() { } } - IInstallableUnit[] getRootIUs(IProgressMonitor monitor) throws CoreException { + Collection getRootIUs(IProgressMonitor monitor) throws CoreException { IQueryable repos = P2TargetUtils.getQueryableMetadata(getRepositories(), isFollowRepositoryReferences(), monitor); - MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories, null); + MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories); List result = new ArrayList<>(); for (IVersionedId iu : fIUs) { // For versions such as 0.0.0, the IU query may return multiple IUs, so we check which is the latest version @@ -696,7 +695,7 @@ IInstallableUnit[] getRootIUs(IProgressMonitor monitor) throws CoreException { fResolutionStatus = status; throw new CoreException(status); } - return result.toArray(new IInstallableUnit[0]); + return result; } private void addQueryResult(IQueryable queryable, IQuery query, IVersionedId iu, diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java index efbe53a20a4..851196c377d 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java @@ -24,7 +24,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; @@ -503,7 +502,6 @@ private boolean checkProfile(ITargetDefinition target, final IProfile profile) { return false; } } - // ensure environment & NL settings are still the same (else we need a new profile) if (!all && !generateEnvironmentProperties(target).equals(profile.getProperty(IProfile.PROP_ENVIRONMENTS))) { return false; @@ -511,17 +509,13 @@ private boolean checkProfile(ITargetDefinition target, final IProfile profile) { if (!generateNLProperty(target).equals(profile.getProperty(IProfile.PROP_NL))) { return false; } - // check provisioning mode: slice versus plan if (!getProvisionMode().equals(profile.getProperty(PROP_PROVISION_MODE))) { return false; } - - // check that the include source flag matches what the profile represents if (getIncludeSource() != Boolean.parseBoolean(profile.getProperty(PROP_AUTO_INCLUDE_SOURCE))) { return false; } - if (getIncludeConfigurePhase() != Boolean.parseBoolean(profile.getProperty(PROP_INCLUDE_CONFIGURE_PHASE))) { return false; } @@ -530,17 +524,17 @@ private boolean checkProfile(ITargetDefinition target, final IProfile profile) { // still in the profile, we need to recreate (rather than uninstall) IUProfilePropertyQuery propertyQuery = new IUProfilePropertyQuery(PROP_INSTALLED_IU, Boolean.toString(true)); IQueryResult queryResult = profile.query(propertyQuery, null); + ITargetLocation[] containers = target.getTargetLocations(); + if (containers == null) { + return queryResult.isEmpty(); + } Set installedIUs = new HashSet<>(); for (IInstallableUnit unit : queryResult) { installedIUs.add(new NameVersionDescriptor(unit.getId(), unit.getVersion().toString())); } - ITargetLocation[] containers = target.getTargetLocations(); - if (containers == null) { - return installedIUs.isEmpty(); - } for (ITargetLocation container : containers) { if (container instanceof IUBundleContainer bc) { - for (IVersionedId iu : bc.getUnits()) { + for (IVersionedId iu : bc.getDeclaredUnits()) { // if there is something in a container but not in the profile, recreate if (!installedIUs.remove(new NameVersionDescriptor(iu.getId(), iu.getVersion().toString()))) { return false; @@ -951,7 +945,7 @@ static IQueryable getQueryableMetadata(Collection repos, Set seen = new HashSet<>(); List result = new ArrayList<>(repos.size()); List additional = new ArrayList<>(); - MultiStatus repoStatus = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories, null); + MultiStatus repoStatus = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories); for (URI location : repos) { try { IMetadataRepository repository = manager.loadRepository(location, subMonitor.split(1)); @@ -1007,7 +1001,7 @@ private void resolveWithPlanner(ITargetDefinition target, IProfile profile, IPro SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.IUBundleContainer_0, 220); // Get the root IUs for every relevant container in the target definition - IInstallableUnit[] units = getRootIUs(target, subMonitor.split(20)); + Set units = getRootIUs(target, subMonitor.split(20)); // create the provisioning plan IPlanner planner = getPlanner(); @@ -1015,7 +1009,7 @@ private void resolveWithPlanner(ITargetDefinition target, IProfile profile, IPro // first remove everything that was explicitly installed. Then add it back. This has the net effect of // removing everything that is no longer needed. computeRemovals(profile, request, getIncludeSource()); - request.addAll(Arrays.asList(units)); + request.addAll(units); for (IInstallableUnit unit : units) { request.setInstallableUnitProfileProperty(unit, PROP_INSTALLED_IU, Boolean.toString(true)); } @@ -1223,7 +1217,7 @@ private void resolveWithSlicer(ITargetDefinition target, IProfile profile, IProg SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.IUBundleContainer_0, 110); // resolve IUs - IInstallableUnit[] units = getRootIUs(target, subMonitor.split(40)); + Set units = getRootIUs(target, subMonitor.split(40)); Collection repositories = getMetadataRepositories(target); if (repositories.isEmpty()) { @@ -1243,9 +1237,8 @@ private void resolveWithSlicer(ITargetDefinition target, IProfile profile, IProg if (getIncludeSource()) { // Build an IU that represents all the source bundles and slice again to add them in if available IInstallableUnit sourceIU = createSourceIU(queryResult, Version.createOSGi(1, 0, 0)); - IInstallableUnit[] units2 = new IInstallableUnit[units.length + 1]; - System.arraycopy(units, 0, units2, 0, units.length); - units2[units.length] = sourceIU; + List units2 = new ArrayList<>(units); + units2.add(sourceIU); queryResult = slice(units2, allMetadata, target, subMonitor.split(5)); if (queryResult == null || queryResult.isEmpty()) { @@ -1298,7 +1291,9 @@ private void resolveWithSlicer(ITargetDefinition target, IProfile profile, IProg * @return the result of the slice operation * @throws CoreException if a problem occurs during the slice operation that should stop this location from resolving */ - private IQueryResult slice(IInstallableUnit[] units, IQueryable allMetadata, ITargetDefinition definition, IProgressMonitor monitor) throws CoreException { + private IQueryResult slice(Collection units, + IQueryable allMetadata, ITargetDefinition definition, IProgressMonitor monitor) + throws CoreException { SubMonitor subMonitor = SubMonitor.convert(monitor, 100); // slice IUs and all prerequisites PermissiveSlicer slicer = null; @@ -1313,7 +1308,7 @@ private IQueryResult slice(IInstallableUnit[] units, IQueryabl props.put(IProfile.PROP_INSTALL_FEATURES, Boolean.TRUE.toString()); slicer = new PermissiveSlicer(allMetadata, props, true, false, false, true, false); } - IQueryable slice = slicer.slice(Arrays.asList(units), subMonitor.split(50)); + IQueryable slice = slicer.slice(units, subMonitor.split(50)); IStatus sliceStatus = slicer.getStatus(); // If the slicer encounters an error, stop the operation if (sliceStatus.getSeverity() == IStatus.ERROR) { @@ -1454,19 +1449,20 @@ private void findProfileRepos(Set additionalRepos) { * @return the discovered IUs * @exception CoreException if unable to retrieve IU's */ - private IInstallableUnit[] getRootIUs(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException { + private Set getRootIUs(ITargetDefinition definition, IProgressMonitor monitor) + throws CoreException { - HashSet result = new HashSet<>(); ITargetLocation[] containers = definition.getTargetLocations(); if (containers == null) { - return new IInstallableUnit[0]; + return Set.of(); } - SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.IUBundleContainer_0, containers.length * 10); - MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories, null); + SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.IUBundleContainer_0, containers.length); + MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories); + Set result = new HashSet<>(); for (ITargetLocation container : containers) { if (container instanceof IUBundleContainer iuContainer) { try { - Collections.addAll(result, iuContainer.getRootIUs(subMonitor.split(10))); + result.addAll(iuContainer.getRootIUs(subMonitor.split(1))); } catch (CoreException e) { status.add(e.getStatus()); } @@ -1475,7 +1471,7 @@ private IInstallableUnit[] getRootIUs(ITargetDefinition definition, IProgressMon if (!status.isOK()) { throw new CoreException(status); } - return result.toArray(new IInstallableUnit[result.size()]); + return result; } /** diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetDefinition.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetDefinition.java index 5b56dc08f10..e7ac5cad7ee 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetDefinition.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetDefinition.java @@ -24,12 +24,12 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -372,7 +372,7 @@ public IStatus resolve(IProgressMonitor monitor) { fResolutionStatus = null; SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.TargetDefinition_1, targetLocations.length * 100); try { - MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.TargetDefinition_2, null); + MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.TargetDefinition_2); Map> synchronizers = new HashMap<>(); // clear all previous maps P2TargetUtils.fgTargetArtifactRepo.clear(); @@ -396,17 +396,17 @@ public IStatus resolve(IProgressMonitor monitor) { List delayedLocations = synchronizers.values().stream().flatMap(Collection::stream) .toList(); subMonitor.setWorkRemaining(synchronizers.size() * 100 + delayedLocations.size()); - for (Entry> entry : synchronizers.entrySet()) { + synchronizers.forEach((synchronizer, locations) -> { subMonitor.checkCanceled(); try { - entry.getKey().synchronize(this, subMonitor.split(100)); - entry.getValue().stream().map(loc -> loc.getStatus()).filter(Objects::nonNull) - .filter(s -> !s.isOK()).forEach(status::add); + synchronizer.synchronize(this, subMonitor.split(100)); + locations.stream().map(ITargetLocation::getStatus).filter(s -> s != null && !s.isOK()) + .forEach(status::add); } catch (CoreException e) { PDECore.log(e.getStatus()); status.add(e.getStatus()); } - } + }); for (ITargetLocation location : delayedLocations) { subMonitor.checkCanceled(); IStatus s = location.resolve(this, subMonitor.split(1)); @@ -450,7 +450,7 @@ public IStatus getStatus() { ITargetLocation[] containers = getTargetLocations(); if (containers != null) { // Check if the containers have any resolution problems - MultiStatus result = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.TargetDefinition_5, null); + MultiStatus result = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.TargetDefinition_5); for (ITargetLocation container : containers) { IStatus containerStatus = container.getStatus(); if (containerStatus != null && !containerStatus.isOK()) { @@ -827,7 +827,7 @@ public void setImplicitDependencies(NameVersionDescriptor[] bundles) { } fImplicit = bundles; if (fRoot != null && bundles != null && bundles.length > 0) { - Element implicitDependenciesElement = TargetDefinitionDocumentTools.getChildElement(fRoot, + Element implicitDependencies = TargetDefinitionDocumentTools.getChildElement(fRoot, TargetDefinitionPersistenceHelper.IMPLICIT); List descriptorElements = new ArrayList<>(); for (NameVersionDescriptor descriptor : bundles) { @@ -839,9 +839,7 @@ public void setImplicitDependencies(NameVersionDescriptor[] bundles) { descriptorElements.add(plugin); } - TargetDefinitionDocumentTools.updateElements(implicitDependenciesElement, null, descriptorElements, - (Element o1, Element o2) -> o1.getAttribute(TargetDefinitionPersistenceHelper.ATTR_ID) - .compareTo(o2.getAttribute(TargetDefinitionPersistenceHelper.ATTR_ID))); + TargetDefinitionDocumentTools.updateElements(implicitDependencies, null, descriptorElements, BY_ATTR_ID); } else { removeElement(TargetDefinitionPersistenceHelper.IMPLICIT); } @@ -1205,10 +1203,9 @@ private void serializeBundleContainers(ITargetLocation[] targetLocations, Elemen NodeList nodes = containersElement.getChildNodes(); for (int j = 0; j < nodes.getLength(); j++) { - Node node = nodes.item(j); - if (node instanceof Element element - && node.getNodeName().equalsIgnoreCase(TargetDefinitionPersistenceHelper.LOCATION)) { - String type = (element).getAttribute(TargetDefinitionPersistenceHelper.ATTR_LOCATION_TYPE); + if (nodes.item(j) instanceof Element element + && element.getNodeName().equalsIgnoreCase(TargetDefinitionPersistenceHelper.LOCATION)) { + String type = element.getAttribute(TargetDefinitionPersistenceHelper.ATTR_LOCATION_TYPE); switch (type) { case IUBundleContainer.TYPE: oldIUContainers.add(element); @@ -1252,13 +1249,15 @@ private void updateContainerElements(Element containersElement, List ol .compareTo(o2.getAttribute(TargetDefinitionPersistenceHelper.ATTR_LOCATION_PATH)); int idCompare = 0; if (o1 instanceof FeatureBundleContainer) { - idCompare = o1.getAttribute(TargetDefinitionPersistenceHelper.ATTR_ID) - .compareTo(o2.getAttribute(TargetDefinitionPersistenceHelper.ATTR_ID)); + idCompare = BY_ATTR_ID.compare(o1, o2); } return typeCompare == 0 && pathCompare == 0 && idCompare == 0 ? 0 : 1; }); } + private static final Comparator BY_ATTR_ID = Comparator + .comparing(o -> o.getAttribute(TargetDefinitionPersistenceHelper.ATTR_ID)); + private void updateIUContainerElements(Element containersElement, List oldContainers, List newContainers) { Map> oldContainersByRepo = new HashMap<>(); @@ -1268,18 +1267,15 @@ private void updateIUContainerElements(Element containersElement, List List units = new ArrayList<>(); String repoURL = null; for (int i = 0; i < nodes.getLength(); i++) { - Node node = nodes.item(i); - if (node instanceof Element) { + if (nodes.item(i) instanceof Element element) { if (repoURL == null - && node.getNodeName().equalsIgnoreCase(TargetDefinitionPersistenceHelper.REPOSITORY)) { - repoURL = ((Element) node).getAttribute(TargetDefinitionPersistenceHelper.LOCATION); - if (!oldContainersByRepo.containsKey(repoURL)) { - oldContainersByRepo.put(repoURL, new ArrayList<>()); - } - oldContainersByRepo.get(repoURL).add(container); - } else if (node.getNodeName() + && element.getNodeName().equalsIgnoreCase(TargetDefinitionPersistenceHelper.REPOSITORY)) { + repoURL = element.getAttribute(TargetDefinitionPersistenceHelper.LOCATION); + + oldContainersByRepo.computeIfAbsent(repoURL, u -> new ArrayList<>()).add(container); + } else if (element.getNodeName() .equalsIgnoreCase(TargetDefinitionPersistenceHelper.INSTALLABLE_UNIT)) { - units.add((Element) node); + units.add(element); } } } @@ -1295,14 +1291,13 @@ private void updateIUContainerElements(Element containersElement, List List units = new ArrayList<>(); String repoURL = null; for (int i = 0; i < nodes.getLength(); i++) { - Node node = nodes.item(i); - if (node instanceof Element) { + if (nodes.item(i) instanceof Element element) { if (repoURL == null - && node.getNodeName().equalsIgnoreCase(TargetDefinitionPersistenceHelper.REPOSITORY)) { - repoURL = ((Element) node).getAttribute(TargetDefinitionPersistenceHelper.LOCATION); - } else if (node.getNodeName() + && element.getNodeName().equalsIgnoreCase(TargetDefinitionPersistenceHelper.REPOSITORY)) { + repoURL = element.getAttribute(TargetDefinitionPersistenceHelper.LOCATION); + } else if (element.getNodeName() .equalsIgnoreCase(TargetDefinitionPersistenceHelper.INSTALLABLE_UNIT)) { - units.add((Element) node); + units.add(element); } } } @@ -1310,9 +1305,7 @@ private void updateIUContainerElements(Element containersElement, List if (oldContainersByRepo.containsKey(repoURL)) { Element oldContainer = oldContainersByRepo.get(repoURL).get(0); TargetDefinitionDocumentTools.updateElements(oldContainer, oldUnitsByContainer.get(oldContainer), - units, - (Element o1, Element o2) -> o1.getAttribute(TargetDefinitionPersistenceHelper.ATTR_ID) - .compareTo(o2.getAttribute(TargetDefinitionPersistenceHelper.ATTR_ID))); + units, BY_ATTR_ID); if (oldContainersByRepo.get(repoURL).size() == 1) { oldContainersByRepo.remove(repoURL); } else { @@ -1325,8 +1318,8 @@ private void updateIUContainerElements(Element containersElement, List } } - for (Entry> entry : oldContainersByRepo.entrySet()) { - entry.getValue().forEach(TargetDefinitionDocumentTools::removeChildAndWhitespace); + for (List containers : oldContainersByRepo.values()) { + containers.forEach(TargetDefinitionDocumentTools::removeChildAndWhitespace); } } @@ -1351,8 +1344,6 @@ private void serializeBundles(Element parent, NameVersionDescriptor[] bundles) { bundlElements.add(includedBundle); } } - TargetDefinitionDocumentTools.updateElements(parent, null, bundlElements, - (Element o1, Element o2) -> o1.getAttribute(TargetDefinitionPersistenceHelper.ATTR_ID) - .compareTo(o2.getAttribute(TargetDefinitionPersistenceHelper.ATTR_ID))); - } + TargetDefinitionDocumentTools.updateElements(parent, null, bundlElements, BY_ATTR_ID); } +} diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/EditIUContainerPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/EditIUContainerPage.java index 08231286683..3dc0f6f519e 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/EditIUContainerPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/EditIUContainerPage.java @@ -213,18 +213,10 @@ private void createRepositoryComboArea(final Composite parent) { } private void refreshAvailableIUArea(final Composite parent) { - try { - if (fEditContainer == null || fEditContainer.getInstallableUnits().isEmpty()) { - return; - } - } catch (CoreException e) { - PDEPlugin.log(e); - } - - if (refreshThread != null && refreshThread.isAlive()) { + if (fEditContainer == null || fEditContainer.getInstallableUnits().isEmpty() + || (refreshThread != null && refreshThread.isAlive())) { return; } - refreshThread = new Thread(() -> { try { final AtomicBoolean loaded = new AtomicBoolean(false); @@ -244,13 +236,9 @@ private void refreshAvailableIUArea(final Composite parent) { @SuppressWarnings("restriction") final String pendingLabel = org.eclipse.ui.internal.progress.ProgressMessages.PendingUpdateAdapter_PendingLabel; if (children.length > 0 && !children[0].getText().equals(pendingLabel)) { - try { - fAvailableIUGroup.getCheckboxTreeViewer().expandAll(); - fAvailableIUGroup.setChecked(fEditContainer.getInstallableUnits().toArray()); - fAvailableIUGroup.getCheckboxTreeViewer().collapseAll(); - } catch (CoreException e) { - PDEPlugin.log(e); - } + fAvailableIUGroup.getCheckboxTreeViewer().expandAll(); + fAvailableIUGroup.setChecked(fEditContainer.getInstallableUnits().toArray()); + fAvailableIUGroup.getCheckboxTreeViewer().collapseAll(); loaded.set(true); } }); @@ -271,8 +259,9 @@ private void refreshAvailableIUArea(final Composite parent) { */ private void createAvailableIUArea(Composite parent) { int filterConstant = AvailableIUGroup.AVAILABLE_NONE; - if (!profileUI.getPolicy().getRepositoriesVisible()) + if (!profileUI.getPolicy().getRepositoriesVisible()) { filterConstant = AvailableIUGroup.AVAILABLE_ALL; + } fAvailableIUGroup = new AvailableIUGroup(profileUI, parent, parent.getFont(), fQueryContext, null, filterConstant); fAvailableIUGroup.getCheckboxTreeViewer().addCheckStateListener(event -> { IInstallableUnit[] units = fAvailableIUGroup.getCheckedLeafIUs(); @@ -619,28 +608,21 @@ private void restoreWidgetState() { // If we are editing a bundle check any installable units if (fEditContainer != null) { - try { - // TODO This code does not do a good job, selecting, revealing, and collapsing all - // Only able to check items if we don't have categories - fQueryContext.setViewType(org.eclipse.equinox.internal.p2.ui.query.IUViewQueryContext.AVAILABLE_VIEW_FLAT); - fAvailableIUGroup.updateAvailableViewState(); - fAvailableIUGroup.setChecked(fEditContainer.getInstallableUnits().toArray()); - // Make sure view is back in proper state - updateViewContext(); - IInstallableUnit[] units = fAvailableIUGroup.getCheckedLeafIUs(); - if (units.length > 0) { - fAvailableIUGroup.getCheckboxTreeViewer().setSelection(new StructuredSelection(units[0]), true); - String msg = units.length == 1 ? Messages.EditIUContainerPage_itemSelected - : Messages.EditIUContainerPage_itemsSelected; - fSelectionCount.setText(NLS.bind(msg, Integer.toString(units.length))); - } else { - fSelectionCount.setText(NLS.bind(Messages.EditIUContainerPage_itemsSelected, Integer.toString(0))); - } - fAvailableIUGroup.getCheckboxTreeViewer().collapseAll(); - - } catch (CoreException e) { - PDEPlugin.log(e); + // TODO This code does not do a good job, selecting, revealing, and collapsing all + // Only able to check items if we don't have categories + fQueryContext.setViewType(org.eclipse.equinox.internal.p2.ui.query.IUViewQueryContext.AVAILABLE_VIEW_FLAT); + fAvailableIUGroup.updateAvailableViewState(); + fAvailableIUGroup.setChecked(fEditContainer.getInstallableUnits().toArray()); + // Make sure view is back in proper state + updateViewContext(); + IInstallableUnit[] units = fAvailableIUGroup.getCheckedLeafIUs(); + if (units.length > 0) { + fAvailableIUGroup.getCheckboxTreeViewer().setSelection(new StructuredSelection(units[0]), true); } + String msg = units.length == 1 ? Messages.EditIUContainerPage_itemSelected + : Messages.EditIUContainerPage_itemsSelected; + fSelectionCount.setText(NLS.bind(msg, units.length)); + fAvailableIUGroup.getCheckboxTreeViewer().collapseAll(); } } } \ No newline at end of file diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/IUContentProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/IUContentProvider.java index 1ca876ecd77..6a7017a052c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/IUContentProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/IUContentProvider.java @@ -14,9 +14,8 @@ *******************************************************************************/ package org.eclipse.pde.internal.ui.shared.target; -import java.util.List; +import java.util.Collection; -import org.eclipse.core.runtime.CoreException; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.pde.core.target.ITargetDefinition; @@ -37,19 +36,15 @@ public Object[] getElements(Object inputElement) { public Object[] getChildren(Object parentElement) { IUBundleContainer location = (IUBundleContainer) parentElement; if (location.isResolved()) { - try { - // if this is a bundle container then we must be sure that all bundle containers are - // happy since they all share the same profile. - ITargetDefinition target = location.getTarget(); - if (target == null || !P2TargetUtils.isResolved(target)) { - return new Object[0]; - } - List units = location.getInstallableUnits(); - // Wrap the units so that they remember their parent container - return units.stream().map(unit -> new IUWrapper(unit, location)).toArray(); - } catch (CoreException e) { - return new Object[] {e.getStatus()}; + // if this is a bundle container we must be sure that all bundle + // containers are happy since they all share the same profile. + ITargetDefinition target = location.getTarget(); + if (target == null || !P2TargetUtils.isResolved(target)) { + return new Object[0]; } + Collection units = location.getInstallableUnits(); + // Wrap the units so that they remember their parent container + return units.stream().map(unit -> new IUWrapper(unit, location)).toArray(); } return new Object[0]; } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/IUFactory.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/IUFactory.java index 883ea07727d..cb5768ffb08 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/IUFactory.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/IUFactory.java @@ -15,7 +15,6 @@ package org.eclipse.pde.internal.ui.shared.target; import java.net.URI; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -118,7 +117,7 @@ public IStatus update(ITargetDefinition target, TreePath[] treePaths, IProgressM SubMonitor subMonitor = SubMonitor.convert(monitor, containers.size() + wrappers.size()); for (IUBundleContainer container : containers) { try { - IUBundleContainer update = container.update(Collections.emptySet(), subMonitor.split(1)); + IUBundleContainer update = container.update(Set.of(), subMonitor.split(1)); updatedContainer.put(container, update); } catch (CoreException e) { return e.getStatus();