Skip to content

Commit

Permalink
Merge pull request #5710 from pkriens/feature/resolution-view
Browse files Browse the repository at this point in the history
  • Loading branch information
pkriens committed Jun 29, 2023
2 parents 5690551 + b177454 commit 5dcc87a
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 63 deletions.
22 changes: 22 additions & 0 deletions biz.aQute.bndlib/src/aQute/bnd/build/model/EE.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
import java.util.TreeSet;

import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
import org.osgi.resource.Resource;

import aQute.bnd.exceptions.Exceptions;
import aQute.bnd.header.Attrs;
import aQute.bnd.header.Parameters;
import aQute.bnd.osgi.Analyzer;
import aQute.bnd.osgi.Processor;
import aQute.bnd.osgi.resource.FilterParser;
import aQute.bnd.osgi.resource.FilterParser.Expression;
import aQute.bnd.osgi.resource.ResourceBuilder;
import aQute.bnd.version.Version;
import aQute.lib.utf8properties.UTF8Properties;

Expand Down Expand Up @@ -84,6 +87,7 @@ public enum EE {
private transient Parameters packages = null;
private transient Parameters modules = null;

private Resource resource;
/**
* For use by JavaSE_9 and later.
*/
Expand Down Expand Up @@ -338,4 +342,22 @@ public static EE getEEFromReleaseVersion(int releaseVersion) {
public static SortedSet<EE> all() {
return all;
}

/**
* Return a list of capabilities associated with this EE
*/
public Resource getResource() {
if (resource != null)
return resource;

ResourceBuilder rb = new ResourceBuilder();
getPackages()
.forEach((k, v) -> {
String name = Processor.removeDuplicateMarker(k);
rb.addExportPackage(name, v);
});

rb.addEE(this);
return resource = rb.build();
}
}
2 changes: 2 additions & 0 deletions bndtools.core/icons.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ icons.service=icons/service.png
icons.capreq=icons/connections.png

# Java Things
icons.java=icons/java.png
icons.jar=icons/jar.gif
icons.multijar=icons/multijar.gif
icons.class=icons/class.gif
icons.interface=icons/interface.gif
icons.package=icons/package.gif
icons.packages=icons/packages.gif
icons.projects=icons/projects.gif
icons.osgi.ee=icons/java.png

# Bnd Things
icons.bndrun=icons/bndrun.gif
Expand Down
Binary file modified bndtools.core/resources/unprocessed/icons/java.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class RequirementWrapper {

public Requirement requirement;
public boolean resolved;
public boolean java;
public Collection<? extends Object> requirers;

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void update(ViewerCell cell) {
cell.setImage(icon);

StyledString label = getLabel(rw.requirement);
if (rw.resolved)
if (rw.resolved || rw.java)
label.setStyle(0, label.length(), resolved);

cell.setText(label.getString());
Expand Down Expand Up @@ -71,6 +71,12 @@ public String getToolTipText(Object element) {
StringBuilder buf = new StringBuilder();
if (rw.resolved)
buf.append("RESOLVED:\n");
if (rw.java)
buf.append("JAVA:\n");

buf.append("FROM: ")
.append(req.getResource())
.append("\n");

Resource r = rw.requirement.getResource();
if (r instanceof SupportingResource sr) {
Expand Down Expand Up @@ -100,6 +106,8 @@ public String getToolTipText(Object element) {
.append(" := ")
.append(directive.getValue());

Resource resource = req.getResource();

return buf.toString();
}

Expand Down
30 changes: 24 additions & 6 deletions bndtools.core/src/bndtools/tasks/AnalyseBundleResolutionJob.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bndtools.tasks;

import static java.util.Collections.emptyList;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -18,6 +20,7 @@
import org.osgi.resource.Capability;
import org.osgi.resource.Namespace;

import aQute.bnd.build.model.EE;
import aQute.bnd.osgi.resource.ResourceUtils;
import aQute.lib.io.IO;
import bndtools.model.resolution.RequirementWrapper;
Expand All @@ -30,10 +33,16 @@ public class AnalyseBundleResolutionJob extends Job {

private Map<String, List<RequirementWrapper>> requirements;
private Map<String, List<Capability>> capabilities;
private EE ee;

public AnalyseBundleResolutionJob(String name, Set<? extends CapReqLoader> loaders) {
this(name, loaders, null);
}

public AnalyseBundleResolutionJob(String name, Set<? extends CapReqLoader> loaders, EE ee) {
super(name);
this.loaders = loaders;
this.ee = ee;
}

private static <K, V> void mergeMaps(Map<K, List<V>> from, Map<K, List<V>> into) {
Expand All @@ -53,6 +62,8 @@ private static <K, V> void mergeMaps(Map<K, List<V>> from, Map<K, List<V>> into)
@Override
protected IStatus run(IProgressMonitor monitor) {
try {


// Load all the capabilities and requirements
Map<String, List<Capability>> allCaps = new HashMap<>();
Map<String, List<RequirementWrapper>> allReqs = new HashMap<>();
Expand All @@ -72,13 +83,14 @@ protected IStatus run(IProgressMonitor monitor) {

// Check for resolved requirements
for (String namespace : allReqs.keySet()) {
List<RequirementWrapper> rws = allReqs.get(namespace);
List<Capability> candidates = allCaps.get(namespace);
List<RequirementWrapper> rws = allReqs.getOrDefault(namespace, emptyList());
List<Capability> candidates = allCaps.getOrDefault(namespace, emptyList());

if (candidates == null)
continue;
List<Capability> javaCandidates = ee == null ? emptyList()
: ee.getResource()
.getCapabilities(namespace);

for (RequirementWrapper rw : rws) {
outer: for (RequirementWrapper rw : rws) {
String filterDirective = rw.requirement.getDirectives()
.get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
if (filterDirective == null) {
Expand All @@ -88,7 +100,13 @@ protected IStatus run(IProgressMonitor monitor) {
for (Capability cand : candidates) {
if (predicate.test(cand)) {
rw.resolved = true;
break;
continue outer;
}
}
for (Capability cand : javaCandidates) {
if (predicate.test(cand)) {
rw.java = true;
continue outer;
}
}
}
Expand Down
Loading

0 comments on commit 5dcc87a

Please sign in to comment.