Skip to content

Commit

Permalink
Consider the BND Buildpath/Testpath as extra items in the container
Browse files Browse the repository at this point in the history
Currently we rely on the Manifest to discover all required items but
that do not work for items that are not referenced inside the manifest.

This handles the BND Buildpath/Testpath as if it was part of the
traditional Secondary Dependencies.

Fix #777
  • Loading branch information
laeubi committed Nov 4, 2023
1 parent 9c2e301 commit f0b5a30
Showing 1 changed file with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.eclipse.pde.internal.core.bnd.BndProjectManager;
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;

import aQute.bnd.build.Container;
import aQute.bnd.build.Project;

public class RequiredPluginsClasspathContainer extends PDEClasspathContainer implements IClasspathContainer {
Expand Down Expand Up @@ -204,6 +205,7 @@ private List<IClasspathEntry> computePluginEntriesByModel() {
if (fBuild != null) {
addSecondaryDependencies(desc, added, entries);
}
addBndClasspath(desc, added, entries);

// add Import-Package
// sort by symbolicName_version to get a consistent order
Expand All @@ -229,6 +231,22 @@ private List<IClasspathEntry> computePluginEntriesByModel() {
return entries;
}

private void addBndClasspath(BundleDescription desc, Set<BundleDescription> added, List<IClasspathEntry> entries) {
try {
Optional<Project> bndProject = BndProjectManager.getBndProject(project);
if (bndProject.isPresent()) {
for (Container container : bndProject.get().getBuildpath()) {
addExtraModel(desc, added, entries, container.getBundleSymbolicName());
}
for (Container container : bndProject.get().getTestpath()) {
addExtraModel(desc, added, entries, container.getBundleSymbolicName());
}
}
} catch (Exception e) {
PDECore.logException(e, "Can't set classpath from bnd!"); //$NON-NLS-1$
}
}

/**
* Return the list of {@link IClasspathContributor}s provided by the
* <code>org.eclipse.pde.core.pluginClasspathContributors</code> extension point.
Expand Down Expand Up @@ -538,24 +556,30 @@ private void addSecondaryDependencies(BundleDescription desc, Set<BundleDescript
if (entry != null) {
String[] tokens = entry.getTokens();
for (String pluginId : tokens) {
// Get PluginModelBase first to resolve system.bundle entry if it exists
IPluginModelBase model = PluginRegistry.findModel(pluginId);
if (model != null) {
BundleDescription bundleDesc = model.getBundleDescription();
if (added.contains(bundleDesc)) {
continue;
}
Map<BundleDescription, List<Rule>> rules = new HashMap<>();
findExportedPackages(bundleDesc, desc, rules);
addDependency(bundleDesc, added, rules, entries, true);
}
// Get PluginModelBase first to resolve system.bundle entry
// if it exists
addExtraModel(desc, added, entries, pluginId);
}
}
} catch (CoreException e) {
return;
}
}

private void addExtraModel(BundleDescription desc, Set<BundleDescription> added, List<IClasspathEntry> entries,
String pluginId) throws CoreException {
IPluginModelBase model = PluginRegistry.findModel(pluginId);
if (model != null) {
BundleDescription bundleDesc = model.getBundleDescription();
if (added.contains(bundleDesc)) {
return;
}
Map<BundleDescription, List<Rule>> rules = new HashMap<>();
findExportedPackages(bundleDesc, desc, rules);
addDependency(bundleDesc, added, rules, entries, true);
}
}

protected final void findExportedPackages(BundleDescription desc, BundleDescription projectDesc,
Map<BundleDescription, List<Rule>> map) {
if (desc != null) {
Expand All @@ -572,7 +596,8 @@ protected final void findExportedPackages(BundleDescription desc, BundleDescript
}
map.put(bdesc, rules);

// Look at re-exported Require-Bundles for any other exported packages
// Look at re-exported Require-Bundles for any other exported
// packages
BundleSpecification[] requiredBundles = bdesc.getRequiredBundles();
for (BundleSpecification requiredBundle : requiredBundles) {
if (requiredBundle.isExported()) {
Expand Down

0 comments on commit f0b5a30

Please sign in to comment.