Skip to content

Commit 3389587

Browse files
committed
Replace BuildDependencyCollector by DependencyManager
This reduces logically duplicated code.
1 parent 514eaae commit 3389587

5 files changed

Lines changed: 55 additions & 95 deletions

File tree

apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/ApiBaseline.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2007, 2024 IBM Corporation and others.
2+
* Copyright (c) 2007, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -72,7 +72,7 @@
7272
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
7373
import org.eclipse.pde.api.tools.internal.provisional.model.IApiElement;
7474
import org.eclipse.pde.api.tools.internal.util.Util;
75-
import org.eclipse.pde.internal.core.BuildDependencyCollector;
75+
import org.eclipse.pde.internal.core.ClasspathComputer;
7676
import org.eclipse.pde.internal.core.TargetPlatformHelper;
7777
import org.osgi.framework.Constants;
7878
import org.osgi.framework.Version;
@@ -876,7 +876,7 @@ public IApiComponent[] getPrerequisiteComponents(IApiComponent[] components) thr
876876
bundles.add(bundleComponent.getBundleDescription());
877877
}
878878
}
879-
Collection<BundleDescription> dependencies = BuildDependencyCollector.collectBuildRelevantDependencies(bundles);
879+
Collection<BundleDescription> dependencies = ClasspathComputer.collectBuildRelevantDependencies(bundles);
880880
return dependencies.stream().map(bundle -> {
881881
String id = bundle.getSymbolicName();
882882
Version version = bundle.getVersion();

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/BuildDependencyCollector.java

Lines changed: 0 additions & 88 deletions
This file was deleted.

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathComputer.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2005, 2022 IBM Corporation and others.
2+
* Copyright (c) 2005, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,13 +15,15 @@
1515

1616
import java.util.ArrayList;
1717
import java.util.Arrays;
18+
import java.util.Collection;
1819
import java.util.Collections;
1920
import java.util.HashMap;
2021
import java.util.Iterator;
2122
import java.util.LinkedHashMap;
2223
import java.util.List;
2324
import java.util.Map;
2425
import java.util.Map.Entry;
26+
import java.util.Set;
2527
import java.util.regex.Pattern;
2628
import java.util.stream.Collectors;
2729
import java.util.stream.Stream;
@@ -52,6 +54,9 @@
5254
import org.eclipse.pde.internal.core.project.PDEProject;
5355
import org.eclipse.pde.internal.core.util.CoreUtility;
5456
import org.eclipse.team.core.RepositoryProvider;
57+
import org.osgi.framework.namespace.BundleNamespace;
58+
import org.osgi.framework.namespace.HostNamespace;
59+
import org.osgi.framework.namespace.PackageNamespace;
5560

5661
public class ClasspathComputer {
5762

@@ -161,6 +166,21 @@ private static void addSourceAndLibraries(Map<String, IPath> sourceLibraryMap, C
161166
}
162167
}
163168

169+
private static final Set<String> BUILD_RELEVANT_NAMESPACES = Set.of( //
170+
BundleNamespace.BUNDLE_NAMESPACE, // Require-Bundle
171+
PackageNamespace.PACKAGE_NAMESPACE, // Import-Package
172+
HostNamespace.HOST_NAMESPACE // Fragment-Host
173+
);
174+
175+
/**
176+
* Returns all transitive dependencies that are relevant for building
177+
* {@code roots}, including {@code roots} themselves.
178+
*/
179+
public static Collection<BundleDescription> collectBuildRelevantDependencies(Collection<BundleDescription> roots) {
180+
return DependencyManager.findRequirementsClosure(roots, BUILD_RELEVANT_NAMESPACES,
181+
DependencyManager.Options.INCLUDE_OPTIONAL_DEPENDENCIES);
182+
}
183+
164184
public static boolean hasTestPluginName(IProject project) {
165185
String pattern = PDECore.getDefault().getPreferencesManager().getString(ICoreConstants.TEST_PLUGIN_PATTERN);
166186
return pattern != null && !pattern.isEmpty() && Pattern.compile(pattern).matcher(project.getName()).find();

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/DependencyManager.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2005, 2022 IBM Corporation and others.
2+
* Copyright (c) 2005, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -41,6 +41,7 @@
4141
import org.osgi.framework.wiring.BundleRevision;
4242
import org.osgi.framework.wiring.BundleWire;
4343
import org.osgi.framework.wiring.BundleWiring;
44+
import org.osgi.resource.Namespace;
4445
import org.osgi.resource.Resource;
4546

4647
/**
@@ -175,6 +176,32 @@ public static Set<BundleDescription> getDependencies(Collection<IPluginModelBase
175176
*/
176177
public static Set<BundleDescription> findRequirementsClosure(Collection<BundleDescription> bundles,
177178
Options... options) {
179+
return findRequirementsClosure(bundles, Set.of(), options);
180+
}
181+
182+
/**
183+
* Returns a {@link Set} of bundle descriptions of the given
184+
* {@link IPluginModelBase}s and all of their required dependencies of the
185+
* given OSGi-Wiring {@link Namespace}s.
186+
* <p>
187+
* The set includes the descriptions of the given bundle descriptions as
188+
* well as all transitively computed explicit and optional (if requested)
189+
* dependencies. So it is the self-contained closure for all required
190+
* dependencies of the given set of plug-ins.
191+
* </p>
192+
*
193+
* @param bundles
194+
* the collection of {@link BundleDescription}s to compute
195+
* dependencies for.
196+
* @param namespaces
197+
* the set of OSGi wiring name-spaces whose required wires are
198+
* considered. If empty all name-spaces are considered.
199+
* @param options
200+
* the specified {@link Options} for computing the closure
201+
* @return a set of bundle descriptions
202+
*/
203+
public static Set<BundleDescription> findRequirementsClosure(Collection<BundleDescription> bundles,
204+
Set<String> namespaces, Options... options) {
178205

179206
Set<Options> optionSet = Set.of(options);
180207
boolean includeOptional = optionSet.contains(Options.INCLUDE_OPTIONAL_DEPENDENCIES);
@@ -234,7 +261,8 @@ public static Set<BundleDescription> findRequirementsClosure(Collection<BundleDe
234261
}
235262
}
236263

237-
List<BundleWire> requiredWires = wiring.getRequiredWires(null);
264+
Iterable<BundleWire> requiredWires = namespaces.isEmpty() ? wiring.getRequiredWires(null)
265+
: namespaces.stream().map(wiring::getRequiredWires).flatMap(List::stream)::iterator;
238266
for (BundleWire wire : requiredWires) {
239267
BundleRevision declaringBundle = wire.getRequirement().getRevision();
240268
if (declaringBundle != bundle && !closure.contains(declaringBundle)) {

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/DynamicPluginProjectReferences.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public List<IProject> getDependentProjects(IBuildConfiguration buildConfiguratio
4444
if (model != null) {
4545
BundleDescription bundle = model.getBundleDescription();
4646
if (bundle != null) {
47-
return BuildDependencyCollector.collectBuildRelevantDependencies(Set.of(bundle)).stream()
47+
return ClasspathComputer.collectBuildRelevantDependencies(Set.of(bundle)).stream()
4848
.map(b -> (org.osgi.resource.Resource) b) //
4949
.filter(dependency -> dependency != bundle).map(PluginRegistry::findModel)
5050
.map(IPluginModelBase::getUnderlyingResource).filter(Objects::nonNull)

0 commit comments

Comments
 (0)