Search in sources :

Example 6 with PomDependencyCollector

use of org.eclipse.tycho.p2.target.facade.PomDependencyCollector in project tycho by eclipse.

the class P2DependencyResolver method collectPomDependencies.

private PomDependencyCollector collectPomDependencies(MavenProject project, List<ReactorProject> reactorProjects, MavenSession session) {
    Set<String> projectIds = new HashSet<>();
    for (ReactorProject p : reactorProjects) {
        String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion());
        projectIds.add(key);
    }
    ArrayList<String> scopes = new ArrayList<>();
    scopes.add(Artifact.SCOPE_COMPILE);
    Collection<Artifact> artifacts;
    try {
        artifacts = projectDependenciesResolver.resolve(project, scopes, session);
    } catch (MultipleArtifactsNotFoundException e) {
        Collection<Artifact> missing = new HashSet<>(e.getMissingArtifacts());
        for (Iterator<Artifact> it = missing.iterator(); it.hasNext(); ) {
            Artifact a = it.next();
            String key = ArtifactUtils.key(a.getGroupId(), a.getArtifactId(), a.getBaseVersion());
            if (projectIds.contains(key)) {
                it.remove();
            }
        }
        if (!missing.isEmpty()) {
            throw new RuntimeException("Could not resolve project dependencies", e);
        }
        artifacts = e.getResolvedArtifacts();
        artifacts.removeAll(e.getMissingArtifacts());
    } catch (AbstractArtifactResolutionException e) {
        throw new RuntimeException("Could not resolve project dependencies", e);
    }
    List<Artifact> externalArtifacts = new ArrayList<>(artifacts.size());
    for (Artifact artifact : artifacts) {
        String key = ArtifactUtils.key(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());
        if (projectIds.contains(key)) {
            // resolved to an older snapshot from the repo, we only want the current project in the reactor
            continue;
        }
        externalArtifacts.add(artifact);
    }
    PomDependencyProcessor pomDependencyProcessor = new PomDependencyProcessor(session, repositorySystem, resolverFactory, equinox.getService(LocalRepositoryP2Indices.class), getLogger());
    return pomDependencyProcessor.collectPomDependencies(project, externalArtifacts);
}
Also used : AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ReactorProject(org.eclipse.tycho.ReactorProject) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) ArrayList(java.util.ArrayList) MultipleArtifactsNotFoundException(org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException) Artifact(org.apache.maven.artifact.Artifact) AttachedArtifact(org.eclipse.tycho.p2.facade.internal.AttachedArtifact) LocalRepositoryP2Indices(org.eclipse.tycho.p2.repository.LocalRepositoryP2Indices) Iterator(java.util.Iterator) Collection(java.util.Collection) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 7 with PomDependencyCollector

use of org.eclipse.tycho.p2.target.facade.PomDependencyCollector in project tycho by eclipse.

the class PomDependencyProcessor method collectPomDependencies.

PomDependencyCollector collectPomDependencies(MavenProject project, Collection<Artifact> transitivePomDependencies) {
    final TychoRepositoryIndex p2ArtifactsInLocalRepo = localRepoIndices.getArtifactsIndex();
    PomDependencyCollector result = resolverFactory.newPomDependencyCollector();
    result.setProjectLocation(project.getBasedir());
    for (Artifact artifact : transitivePomDependencies) {
        if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
            // ignore
            continue;
        }
        P2DataArtifacts p2Data = new P2DataArtifacts(artifact);
        p2Data.resolve(session, project.getRemoteArtifactRepositories());
        if (p2Data.p2MetadataXml.isAvailable() && p2Data.p2ArtifactsXml.isAvailable()) {
            /*
                 * The POM dependency has (probably) been built by Tycho, so we can re-use the
                 * existing p2 data in the target platform. The data is stored in the attached
                 * artifacts p2metadata.xml and p2artifacts.xml, which are now present in the local
                 * Maven repository.
                 */
            if (logger.isDebugEnabled()) {
                logger.debug("P2TargetPlatformResolver: Using existing metadata of " + artifact.toString());
            }
            result.addArtifactWithExistingMetadata(new ArtifactFacade(artifact), new ArtifactFacade(p2Data.p2MetadataXml.artifact));
            /*
                 * Since the p2artifacts.xml exists on disk, we can add the artifact to the (global)
                 * p2 artifact repository view of local Maven repository. Then, the artifact is
                 * available in the build.
                 */
            // TODO this should happen in resolution context
            p2ArtifactsInLocalRepo.addGav(new GAV(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()));
        } else if (!p2Data.p2MetadataXml.isAvailable() && !p2Data.p2ArtifactsXml.isAvailable()) {
            /*
                 * The POM dependency has not been built by Tycho. If the dependency is a bundle,
                 * run the p2 bundle publisher on it and add the result to the resolution context.
                 */
            if (logger.isDebugEnabled()) {
                logger.debug("P2resolver.addMavenArtifact " + artifact.toString());
            }
            result.publishAndAddArtifactIfBundleArtifact(new ArtifactFacade(artifact));
        } else {
            failDueToPartialP2Data(artifact, p2Data);
        }
    }
    return result;
}
Also used : PomDependencyCollector(org.eclipse.tycho.p2.target.facade.PomDependencyCollector) TychoRepositoryIndex(org.eclipse.tycho.p2.repository.TychoRepositoryIndex) ArtifactFacade(org.eclipse.tycho.p2.facade.internal.ArtifactFacade) GAV(org.eclipse.tycho.p2.repository.GAV) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

PomDependencyCollector (org.eclipse.tycho.p2.target.facade.PomDependencyCollector)4 Artifact (org.apache.maven.artifact.Artifact)2 TargetPlatformFilter (org.eclipse.tycho.artifacts.TargetPlatformFilter)2 Test (org.junit.Test)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 AbstractArtifactResolutionException (org.apache.maven.artifact.resolver.AbstractArtifactResolutionException)1 MultipleArtifactsNotFoundException (org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException)1 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)1 ReactorProject (org.eclipse.tycho.ReactorProject)1 ReactorProjectIdentities (org.eclipse.tycho.ReactorProjectIdentities)1 TargetPlatform (org.eclipse.tycho.artifacts.TargetPlatform)1 TargetPlatformConfiguration (org.eclipse.tycho.core.TargetPlatformConfiguration)1 ExecutionEnvironmentConfiguration (org.eclipse.tycho.core.ee.shared.ExecutionEnvironmentConfiguration)1 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)1