Skip to content

Commit

Permalink
Provide a tycho workspace reader
Browse files Browse the repository at this point in the history
Fixes #585
  • Loading branch information
laeubi committed Jun 12, 2022
1 parent ebacb7f commit 5811cb1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</developer>
</developers>
<prerequisites>
<maven>3.6.3</maven>
<maven>3.8.6</maven>
</prerequisites>

<groupId>org.eclipse.tycho</groupId>
Expand All @@ -84,7 +84,7 @@
<jxpathVersion>1.3</jxpathVersion>
<pluginToolsVersion>3.6.4</pluginToolsVersion>
<jgit-version>6.1.0.202203080745-r</jgit-version>
<maven-version>3.8.5</maven-version>
<maven-version>3.8.6</maven-version>
<!-- NOTE: when updating surefire version, double-check Import-Package statements generated by bnd-maven-plugin and possibly adapt instructions in various bnd.bnd files -->
<!-- Stick to 3.0.0-M5 because of https://github.com/eclipse/tycho/issues/879 / https://issues.apache.org/jira/projects/SUREFIRE/issues/SUREFIRE-2072 -->
<surefire-version>3.0.0-M5</surefire-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.repository.WorkspaceReader;
import org.eclipse.aether.repository.WorkspaceRepository;
import org.eclipse.sisu.equinox.EquinoxServiceFactory;
import org.eclipse.tycho.ArtifactDescriptor;
import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.MavenDependencyDescriptor;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.artifacts.DependencyArtifacts;
import org.eclipse.tycho.core.osgitools.DefaultReactorProject;
import org.eclipse.tycho.core.utils.TychoProjectUtils;
import org.eclipse.tycho.p2.resolver.facade.P2ResolverFactory;

@Component(role = WorkspaceReader.class, hint = "TychoWorkspaceReader")
public class TychoWorkspaceReader implements WorkspaceReader {
Expand All @@ -30,8 +41,13 @@ public class TychoWorkspaceReader implements WorkspaceReader {
@Requirement
private LegacySupport legacySupport;

@Requirement
private EquinoxServiceFactory equinox;

@Requirement
private Logger logger;

public TychoWorkspaceReader() {
System.out.println("Hello from TychoWorkspaceReader!");
//TODO this requires https://issues.apache.org/jira/browse/MNG-7400
repository = new WorkspaceRepository("tycho", null);
}
Expand All @@ -44,10 +60,35 @@ public WorkspaceRepository getRepository() {
@Override
public File findArtifact(Artifact artifact) {
if ("pom".equals(artifact.getExtension())) {
//TODO we have not a pom yet but we probably want to generate one, otherwise maven tries to download
//it from the repository and would not find it resulting in
//[WARNING] The POM for org.eclipse.equinox:org.eclipse.equinox.preferences:jar:3.9.0.v20210726-0943 is missing,
// no dependency information available
return null;
}
MavenProject currentProject = legacySupport.getSession().getCurrentProject();
System.out.println("TychoWorkspaceReader: findArtifact(" + artifact + ") " + currentProject);
ReactorProject reactorProject = DefaultReactorProject.adapt(currentProject);

Optional<DependencyArtifacts> dependencyMetadata = TychoProjectUtils
.getOptionalDependencyArtifacts(reactorProject);
if (dependencyMetadata.isPresent()) {
P2ResolverFactory factory = this.equinox.getService(P2ResolverFactory.class);
logger.debug("Attempt to resolve " + artifact + " for project " + currentProject + " ...");
for (ArtifactDescriptor descriptor : dependencyMetadata.get().getArtifacts()) {
MavenDependencyDescriptor dependencyDescriptor = factory.resolveDependencyDescriptor(descriptor);
if (dependencyDescriptor != null) {
if (dependencyDescriptor.getGroupId().equals(artifact.getGroupId())
&& dependencyDescriptor.getArtifactId().equals(artifact.getArtifactId())) {
ArtifactKey artifactKey = descriptor.getKey();
if (dependencyDescriptor.getVersion().equals(artifact.getVersion())
|| artifactKey.getVersion().equals(artifact.getVersion())) {
//we have a match!
return descriptor.getLocation(true);
}
}
}
}
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.TychoConstants;
Expand Down Expand Up @@ -42,6 +43,12 @@ public static DependencyArtifacts getDependencyArtifacts(ReactorProject project)
return resolvedDependencies;
}

public static Optional<DependencyArtifacts> getOptionalDependencyArtifacts(ReactorProject project) {
DependencyArtifacts resolvedDependencies = (DependencyArtifacts) project
.getContextValue(TychoConstants.CTX_DEPENDENCY_ARTIFACTS);
return Optional.ofNullable(resolvedDependencies);
}

/**
* Returns the {@link TargetPlatformConfiguration} instance associated with the given project.
*
Expand Down

0 comments on commit 5811cb1

Please sign in to comment.