Skip to content

Commit

Permalink
Use the MavenBundleResolver to resolve JUnit Bundles from TargetPlatfrom
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jul 19, 2023
1 parent d3aeec7 commit 7ddb1b4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.function.Supplier;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -54,8 +55,8 @@
import org.eclipse.tycho.PackagingType;
import org.eclipse.tycho.PlatformPropertiesUtils;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.ResolvedArtifactKey;
import org.eclipse.tycho.TargetEnvironment;
import org.eclipse.tycho.TargetPlatform;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.core.ArtifactDependencyVisitor;
import org.eclipse.tycho.core.ArtifactDependencyWalker;
Expand All @@ -70,14 +71,12 @@
import org.eclipse.tycho.core.osgitools.project.BuildOutputJar;
import org.eclipse.tycho.core.osgitools.project.EclipsePluginProject;
import org.eclipse.tycho.core.osgitools.project.EclipsePluginProjectImpl;
import org.eclipse.tycho.core.resolver.P2ResolutionResult;
import org.eclipse.tycho.core.resolver.P2ResolutionResult.Entry;
import org.eclipse.tycho.core.resolver.P2Resolver;
import org.eclipse.tycho.core.resolver.P2ResolverFactory;
import org.eclipse.tycho.core.utils.TychoProjectUtils;
import org.eclipse.tycho.model.Feature;
import org.eclipse.tycho.model.ProductConfiguration;
import org.eclipse.tycho.model.UpdateSite;
import org.eclipse.tycho.model.classpath.JUnitBundle;
import org.eclipse.tycho.model.classpath.JUnitClasspathContainerEntry;
import org.eclipse.tycho.model.classpath.LibraryClasspathEntry;
import org.eclipse.tycho.model.classpath.ProjectClasspathEntry;
Expand Down Expand Up @@ -114,6 +113,9 @@ public class OsgiBundleProject extends AbstractTychoProject implements BundlePro
@Requirement
private BuildPropertiesParser buildPropertiesParser;

@Requirement
private MavenBundleResolver mavenBundleResolver;

@Override
public ArtifactDependencyWalker getDependencyWalker(ReactorProject project) {
final DependencyArtifacts artifacts = getDependencyArtifacts(project);
Expand Down Expand Up @@ -263,18 +265,15 @@ private Collection<ClasspathEntry> computeExtraTestClasspath(ReactorProject reac
for (ProjectClasspathEntry cpe : entries) {
if (cpe instanceof JUnitClasspathContainerEntry junit) {
logger.info("Resolving JUnit " + junit.getJUnitSegment() + " classpath container");
P2Resolver resolver = resolverFactory
.createResolver(Collections.singletonList(TargetEnvironment.getRunningEnvironment()));
TargetPlatform tp = TychoProjectUtils.getTargetPlatform(reactorProject);
Collection<P2ResolutionResult> result = resolver
.resolveArtifactDependencies(tp, ClasspathReader.asMaven(junit.getArtifacts())).values();
for (P2ResolutionResult resolutionResult : result) {
for (Entry entry : resolutionResult.getArtifacts()) {
logger.debug("Resolved " + entry.getId() + "::" + entry.getVersion());
File location = entry.getLocation(true);
list.add(new DefaultClasspathEntry(null, entry, Collections.singletonList(location),

for (JUnitBundle junitBundle : junit.getArtifacts()) {
Optional<ResolvedArtifactKey> mavenBundle = mavenBundleResolver.resolveMavenBundle(
reactorProject.adapt(MavenProject.class), reactorProject.adapt(MavenSession.class),
ClasspathReader.toMaven(junitBundle));
mavenBundle.ifPresent(key -> {
list.add(new DefaultClasspathEntry(key,
Collections.singletonList(new DefaultAccessRule("**/*", false))));
}
});
}
}
}
Expand Down Expand Up @@ -318,6 +317,9 @@ private void removeDuplicateTestCompileRoot(File sourceFolder, List<String> test

@Override
public EclipsePluginProject getEclipsePluginProject(ReactorProject otherProject) {
if (otherProject == null) {
return null;
}
EclipsePluginProjectImpl pdeProject = (EclipsePluginProjectImpl) otherProject
.getContextValue(CTX_ECLIPSE_PLUGIN_PROJECT);
if (pdeProject == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public static org.eclipse.tycho.ArtifactKey toTychoArtifact(IInstallableUnit uni

// p2 artifacts

public static IArtifactKey toP2BundleArtifactKey(org.eclipse.tycho.ArtifactKey artifact) {
return createP2ArtifactKey(PublisherHelper.OSGI_BUNDLE_CLASSIFIER, artifact);
}

public static IArtifactKey toP2FeatureArtifactKey(org.eclipse.tycho.ArtifactKey artifact) {
return createP2ArtifactKey(PublisherHelper.ECLIPSE_FEATURE_CLASSIFIER, artifact);
}

public static IArtifactKey toP2ArtifactKey(org.eclipse.tycho.ArtifactKey artifact) {
if (TYPE_ECLIPSE_PLUGIN.equals(artifact.getType()) || TYPE_BUNDLE_FRAGMENT.equals(artifact.getType())) {
return createP2ArtifactKey(PublisherHelper.OSGI_BUNDLE_CLASSIFIER, artifact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,19 @@ public final void saveLocalMavenRepository() {

@Override
public File getArtifactLocation(org.eclipse.tycho.ArtifactKey artifact) {
IArtifactKey p2Artifact = ArtifactTypeHelper.toP2ArtifactKey(artifact);
if (p2Artifact != null) {
return artifacts.getArtifactFile(p2Artifact);
if (ArtifactType.TYPE_INSTALLABLE_UNIT.equals(artifact.getType())) {
//it might be a bundle or a feature...
File bundleFile = artifacts.getArtifactFile(ArtifactTypeHelper.toP2BundleArtifactKey(artifact));
if (bundleFile != null) {
return bundleFile;
}
//the try it as a feature
return artifacts.getArtifactFile(ArtifactTypeHelper.toP2FeatureArtifactKey(artifact));
} else {
IArtifactKey p2Artifact = ArtifactTypeHelper.toP2ArtifactKey(artifact);
if (p2Artifact != null) {
return artifacts.getArtifactFile(p2Artifact);
}
}
return null;
}
Expand Down

0 comments on commit 7ddb1b4

Please sign in to comment.