diff --git a/bndtools.core/src/bndtools/model/resolution/RequirementWrapper.java b/bndtools.core/src/bndtools/model/resolution/RequirementWrapper.java index 90bf18931d..4a32864c7e 100644 --- a/bndtools.core/src/bndtools/model/resolution/RequirementWrapper.java +++ b/bndtools.core/src/bndtools/model/resolution/RequirementWrapper.java @@ -1,6 +1,7 @@ package bndtools.model.resolution; import java.util.Collection; +import java.util.Objects; import org.osgi.resource.Requirement; @@ -11,4 +12,27 @@ public class RequirementWrapper { public boolean java; public Collection requirers; + @Override + public int hashCode() { + return Objects.hash(java, requirement, requirers, resolved); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RequirementWrapper other = (RequirementWrapper) obj; + return java == other.java && Objects.equals(requirement, other.requirement) + && Objects.equals(requirers, other.requirers) && resolved == other.resolved; + } + + @Override + public String toString() { + return "RequirementWrapper [resolved=" + resolved + ", java=" + java + ", requirement=" + requirement + "]"; + } + } diff --git a/bndtools.core/src/bndtools/views/resolution/ResolutionView.java b/bndtools.core/src/bndtools/views/resolution/ResolutionView.java index 21d9f72f84..a1464cb499 100644 --- a/bndtools.core/src/bndtools/views/resolution/ResolutionView.java +++ b/bndtools.core/src/bndtools/views/resolution/ResolutionView.java @@ -165,6 +165,7 @@ public void partActivated(IWorkbenchPart part) { } } }; + private Label reqsLabel; private boolean setLoaders(Set newLoaders) { Set oldLoaders = loaders; @@ -205,7 +206,8 @@ public void createPartControl(Composite parent) { reqsLayout.marginHeight = 0; reqsLayout.verticalSpacing = 2; reqsPanel.setLayout(reqsLayout); - new Label(reqsPanel, SWT.NONE).setText("Requirements:"); + reqsLabel = new Label(reqsPanel, SWT.NONE); + reqsLabel.setText("Requirements:"); reqsTree = new Tree(reqsPanel, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER); reqsTree.setHeaderVisible(false); reqsTree.setLinesVisible(false); @@ -479,6 +481,16 @@ public void setInput(Set sourceLoaders, Map reqs = requirements.values() + .stream() + .flatMap(List::stream) + .toList(); + + reqsLabel.setText(createReqsViewerLabel(reqs)); + reqsLabel.getParent() + .layout(); + } } @@ -496,6 +508,28 @@ public void selectionChanged(IWorkbenchPart part, ISelection selection) { outOfDate = true; } } + + } + + private String createReqsViewerLabel(List list) { + int numReqsResolved = 0; + int numReqsUnresolved = 0; + for (Object element : list) { + if (element instanceof RequirementWrapper reqWrapper) { + if (reqWrapper.resolved) { + numReqsResolved++; + } else { + String resolution = reqWrapper.requirement.getDirectives() + .get("resolution"); + if (resolution != null && !"optional".equals(resolution)) { + // unresolved are only which are not optional + numReqsUnresolved++; + } + } + } + } + + return "Requirements: Resolved: " + numReqsResolved + " Unresolved: " + numReqsUnresolved; } private Set getLoadersFromSelection(IStructuredSelection structSel) {