Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ui/org.eclipse.pde.bnd.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Bundle-Vendor: Eclipse.org
Bundle-Version: 1.2.300.qualifier
Bundle-Localization: plugin
Export-Package: org.eclipse.pde.bnd.ui.autocomplete;version="1.0.0";x-friends:="org.eclipse.pde.ui",
org.eclipse.pde.bnd.ui.model.resolution;version="1.0.0";x-friends:="org.eclipse.pde.ui",
org.eclipse.pde.bnd.ui.plugins;x-internal:=true,
org.eclipse.pde.bnd.ui.preferences;version="1.0.0";x-friends:="org.eclipse.pde.ui",
org.eclipse.pde.bnd.ui.quickfix;version="1.0.0";x-friends:="org.eclipse.pde.ui",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
* Peter Kriens <peter.kriens@aqute.biz> - ongoing enhancements
* Christoph Rueger <chrisrueger@gmail.com> - ongoing enhancements
*******************************************************************************/
package org.eclipse.pde.bnd.ui.tasks;
package org.eclipse.pde.bnd.ui.model.resolution;

import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;

import java.io.File;
import java.util.ArrayList;
Expand All @@ -28,8 +26,9 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import org.eclipse.pde.bnd.ui.model.resolution.RequirementWrapper;
import org.eclipse.core.runtime.IProgressMonitor;
import org.osgi.framework.namespace.PackageNamespace;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
Expand All @@ -45,8 +44,8 @@
public abstract class BndBuilderCapReqLoader implements CapReqLoader {

protected final File file;
private Map<String, List<Capability>> loadCapabilities;
private Map<String, List<RequirementWrapper>> loadRequirements;
private Map<String, Collection<Capability>> loadCapabilities;
private Map<String, Collection<Requirement>> loadRequirements;

public BndBuilderCapReqLoader(File file) {
this.file = file;
Expand Down Expand Up @@ -94,37 +93,33 @@ private void load() throws Exception {
capabilities.addAll(resource.getCapabilities(null));
requirements.addAll(resource.getRequirements(null));
}
loadRequirements = requirements.stream()
.collect(groupingBy(Requirement::getNamespace, mapping(this::toRequirementWrapper, toList())));
loadRequirements = requirements.stream().map(r -> toRequirementWrapper(r))
.collect(groupingBy(Requirement::getNamespace, Collectors.toCollection(ArrayList::new)));
loadCapabilities = capabilities.stream()
.collect(groupingBy(Capability::getNamespace, toList()));
.collect(groupingBy(Capability::getNamespace, Collectors.toCollection(ArrayList::new)));
}

@Override
public Map<String, List<Capability>> loadCapabilities() throws Exception {
public CapReq loadCapReq(IProgressMonitor monitor) throws Exception {
load();
return loadCapabilities;
return new CapReq(loadCapabilities, loadRequirements);
}

@Override
public Map<String, List<RequirementWrapper>> loadRequirements() throws Exception {
load();
return loadRequirements;
}

private RequirementWrapper toRequirementWrapper(Requirement req) {
RequirementWrapper rw = new RequirementWrapper(req);
private Requirement toRequirementWrapper(Requirement req) {
if (req.getNamespace()
.equals(PackageNamespace.PACKAGE_NAMESPACE)) {
String pkgName = (String) req.getAttributes()
.get(PackageNamespace.PACKAGE_NAMESPACE);
try {
rw.requirers = findImportingClasses(pkgName);
List<Clazz> importingClasses = findImportingClasses(pkgName);
if (!importingClasses.isEmpty()) {
return new RequirementWithChildren(req, importingClasses);
}
} catch (Exception e) {
throw Exceptions.duck(e);
}
}
return rw;
return req;
}

private List<Clazz> findImportingClasses(String pkgName) throws Exception {
Expand Down Expand Up @@ -172,4 +167,6 @@ public boolean equals(Object obj) {
return Objects.equals(file, other.file);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Sean Bright <sean@malleable.com> - ongoing enhancements
* BJ Hargrave <bj@hargrave.dev> - ongoing enhancements
*******************************************************************************/
package org.eclipse.pde.bnd.ui.tasks;
package org.eclipse.pde.bnd.ui.model.resolution;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2025 Christoph Läubrich project and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.pde.bnd.ui.model.resolution;

import java.util.Collection;
import java.util.Map;

import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;

public record CapReq(Map<String, Collection<Capability>> capabilities,
Map<String, Collection<Requirement>> requirements) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,17 @@
* Neil Bartlett <njbartlett@gmail.com> - initial API and implementation
* BJ Hargrave <bj@hargrave.dev> - ongoing enhancements
*******************************************************************************/
package org.eclipse.pde.bnd.ui.tasks;
package org.eclipse.pde.bnd.ui.model.resolution;

import java.io.Closeable;
import java.util.List;
import java.util.Map;

import org.eclipse.pde.bnd.ui.model.resolution.RequirementWrapper;
import org.osgi.resource.Capability;
import org.eclipse.core.runtime.IProgressMonitor;

public interface CapReqLoader extends Closeable {

String getShortLabel();

String getLongLabel();

Map<String, List<Capability>> loadCapabilities() throws Exception;

Map<String, List<RequirementWrapper>> loadRequirements() throws Exception;
CapReq loadCapReq(IProgressMonitor monitor) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Neil Bartlett <njbartlett@gmail.com> - initial API and implementation
* BJ Hargrave <bj@hargrave.dev> - ongoing enhancements
*******************************************************************************/
package org.eclipse.pde.bnd.ui.tasks;
package org.eclipse.pde.bnd.ui.model.resolution;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.pde.bnd.ui.tasks;
package org.eclipse.pde.bnd.ui.model.resolution;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.jar.Manifest;

import org.eclipse.pde.bnd.ui.model.resolution.RequirementWrapper;
import org.osgi.resource.Capability;
import org.eclipse.core.runtime.IProgressMonitor;

import aQute.bnd.osgi.resource.ResourceBuilder;

Expand Down Expand Up @@ -56,14 +53,8 @@ public String getLongLabel() {
}

@Override
public Map<String, List<Capability>> loadCapabilities() throws Exception {
loadManifest();
return loadManifest().loadCapabilities();
}

@Override
public Map<String, List<RequirementWrapper>> loadRequirements() throws Exception {
return loadManifest().loadRequirements();
public CapReq loadCapReq(IProgressMonitor monitor) throws Exception {
return loadManifest().loadCapReq(null);
}

private synchronized ResourceCapReqLoader loadManifest() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*******************************************************************************
* Copyright (c) 2025 Christoph Läubrich project and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.pde.bnd.ui.model.resolution;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.osgi.resource.Requirement;
import org.osgi.resource.Resource;

public final class RequirementWithChildren implements Requirement {

private Requirement req;
private Collection<?> children;

public RequirementWithChildren(Requirement req, Collection<?> children) {
this.req = req;
this.children = children == null ? List.of() : List.copyOf(children);
}

@Override
public String getNamespace() {
return req.getNamespace();
}

@Override
public Map<String, String> getDirectives() {
return req.getDirectives();
}

@Override
public Map<String, Object> getAttributes() {
return req.getAttributes();
}

@Override
public Resource getResource() {
return req.getResource();
}

@Override
public boolean equals(Object obj) {
return req.equals(obj);
}

@Override
public int hashCode() {
return req.hashCode();
}

public Collection<?> getChildren() {
return children;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
* Peter Kriens <peter.kriens@aqute.biz> - ongoing enhancements
* Christoph Rueger <chrisrueger@gmail.com> - ongoing enhancements
*******************************************************************************/
package org.eclipse.pde.bnd.ui.tasks;
package org.eclipse.pde.bnd.ui.model.resolution;

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.pde.bnd.ui.ResourceUtils;
import org.eclipse.pde.bnd.ui.model.resolution.RequirementWrapper;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
import org.osgi.resource.Resource;
Expand Down Expand Up @@ -62,8 +63,12 @@ public String getLongLabel() {
}

@Override
public Map<String, List<Capability>> loadCapabilities() throws Exception {
Map<String, List<Capability>> result = new HashMap<>();
public CapReq loadCapReq(IProgressMonitor monitor) throws Exception {
return new CapReq(loadCapabilities(), loadRequirements());
}

private Map<String, Collection<Capability>> loadCapabilities() throws Exception {
Map<String, Collection<Capability>> result = new HashMap<>();

List<Capability> caps = new ArrayList<>(resource.getCapabilities(null));
if (resource instanceof SupportingResource sr) {
Expand All @@ -73,7 +78,7 @@ public Map<String, List<Capability>> loadCapabilities() throws Exception {
}
for (Capability cap : caps) {
String ns = cap.getNamespace();
List<Capability> listForNamespace = result.get(ns);
Collection<Capability> listForNamespace = result.get(ns);
if (listForNamespace == null) {
listForNamespace = new LinkedList<>();
result.put(ns, listForNamespace);
Expand All @@ -84,9 +89,8 @@ public Map<String, List<Capability>> loadCapabilities() throws Exception {
return result;
}

@Override
public Map<String, List<RequirementWrapper>> loadRequirements() throws Exception {
Map<String, List<RequirementWrapper>> result = new HashMap<>();
private Map<String, Collection<Requirement>> loadRequirements() throws Exception {
Map<String, Collection<Requirement>> result = new HashMap<>();

List<Requirement> reqs = new ArrayList<>(resource.getRequirements(null));
if (resource instanceof SupportingResource sr) {
Expand All @@ -96,13 +100,12 @@ public Map<String, List<RequirementWrapper>> loadRequirements() throws Exception
}
for (Requirement req : reqs) {
String ns = req.getNamespace();
List<RequirementWrapper> listForNamespace = result.get(ns);
Collection<Requirement> listForNamespace = result.get(ns);
if (listForNamespace == null) {
listForNamespace = new LinkedList<>();
result.put(ns, listForNamespace);
}
RequirementWrapper wrapper = new RequirementWrapper(req);
listForNamespace.add(wrapper);
listForNamespace.add(req);
}

return result;
Expand Down
Loading
Loading