Skip to content

Commit

Permalink
Show numResolved / numUnresolved in resolution view
Browse files Browse the repository at this point in the history
- First draft to show simple counters to easier spot unresolved requirements.
- reqs resolution := optional are not counted as unresolved.

Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
  • Loading branch information
chrisrueger committed Dec 4, 2023
1 parent 58b8818 commit b7d6b1c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bndtools.model.resolution;

import java.util.Collection;
import java.util.Objects;

import org.osgi.resource.Requirement;

Expand All @@ -11,4 +12,27 @@ public class RequirementWrapper {
public boolean java;
public Collection<? extends Object> 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 + "]";
}

}
36 changes: 35 additions & 1 deletion bndtools.core/src/bndtools/views/resolution/ResolutionView.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public void partActivated(IWorkbenchPart part) {
}
}
};
private Label reqsLabel;

private boolean setLoaders(Set<CapReqLoader> newLoaders) {
Set<CapReqLoader> oldLoaders = loaders;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -479,6 +481,16 @@ public void setInput(Set<CapReqLoader> sourceLoaders, Map<String, List<Capabilit
label = "<no input>";
}
setContentDescription(label);

List<RequirementWrapper> reqs = requirements.values()
.stream()
.flatMap(List::stream)
.toList();

reqsLabel.setText(createReqsViewerLabel(reqs));
reqsLabel.getParent()
.layout();

}
}

Expand All @@ -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<CapReqLoader> getLoadersFromSelection(IStructuredSelection structSel) {
Expand Down

0 comments on commit b7d6b1c

Please sign in to comment.