Search in sources :

Example 1 with ArtifactFacade

use of org.eclipse.tycho.p2.facade.internal.ArtifactFacade in project tycho by eclipse.

the class P2MetadataMojo method attachP2Metadata.

protected void attachP2Metadata() throws MojoExecutionException {
    if (!attachP2Metadata || !supportedProjectTypes.contains(project.getPackaging())) {
        return;
    }
    File file = project.getArtifact().getFile();
    if (file == null || !file.canRead()) {
        throw new IllegalStateException();
    }
    File targetDir = new File(project.getBuild().getDirectory());
    ArtifactFacade projectDefaultArtifact = new ArtifactFacade(project.getArtifact());
    try {
        List<IArtifactFacade> artifacts = new ArrayList<>();
        artifacts.add(projectDefaultArtifact);
        for (Artifact attachedArtifact : project.getAttachedArtifacts()) {
            if (attachedArtifact.getFile() != null && (attachedArtifact.getFile().getName().endsWith(".jar") || (attachedArtifact.getFile().getName().endsWith(".zip") && project.getPackaging().equals(ArtifactType.TYPE_INSTALLABLE_UNIT)))) {
                artifacts.add(new ArtifactFacade(attachedArtifact));
            }
        }
        P2Generator p2generator = getService(P2Generator.class);
        Map<String, IP2Artifact> generatedMetadata = p2generator.generateMetadata(artifacts, targetDir);
        if (baselineMode != BaselineMode.disable) {
            generatedMetadata = baselineValidator.validateAndReplace(project, execution, generatedMetadata, baselineRepositories, baselineMode, baselineReplace);
        }
        File contentsXml = new File(targetDir, FILE_NAME_P2_METADATA);
        File artifactsXml = new File(targetDir, FILE_NAME_P2_ARTIFACTS);
        p2generator.persistMetadata(generatedMetadata, contentsXml, artifactsXml);
        projectHelper.attachArtifact(project, EXTENSION_P2_METADATA, CLASSIFIER_P2_METADATA, contentsXml);
        projectHelper.attachArtifact(project, EXTENSION_P2_ARTIFACTS, CLASSIFIER_P2_ARTIFACTS, artifactsXml);
        ReactorProject reactorProject = DefaultReactorProject.adapt(project);
        Set<Object> installableUnits = new LinkedHashSet<>();
        for (Map.Entry<String, IP2Artifact> entry : generatedMetadata.entrySet()) {
            String classifier = entry.getKey();
            IP2Artifact p2artifact = entry.getValue();
            installableUnits.addAll(p2artifact.getInstallableUnits());
            // attach any new classified artifacts, like feature root files for example
            if (classifier != null && !hasAttachedArtifact(project, classifier)) {
                projectHelper.attachArtifact(project, getExtension(p2artifact.getLocation()), classifier, p2artifact.getLocation());
            }
        }
        // TODO 353889 distinguish between dependency resolution seed units ("primary") and other units of the project
        reactorProject.setDependencyMetadata(true, installableUnits);
        reactorProject.setDependencyMetadata(false, Collections.emptySet());
    } catch (IOException e) {
        throw new MojoExecutionException("Could not generate P2 metadata", e);
    }
    File localArtifactsFile = new File(project.getBuild().getDirectory(), FILE_NAME_LOCAL_ARTIFACTS);
    writeArtifactLocations(localArtifactsFile, getAllProjectArtifacts(project));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IArtifactFacade(org.eclipse.tycho.p2.metadata.IArtifactFacade) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) ReactorProject(org.eclipse.tycho.ReactorProject) ArtifactFacade(org.eclipse.tycho.p2.facade.internal.ArtifactFacade) IArtifactFacade(org.eclipse.tycho.p2.metadata.IArtifactFacade) IOException(java.io.IOException) P2Generator(org.eclipse.tycho.p2.metadata.P2Generator) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) Artifact(org.apache.maven.artifact.Artifact) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ArtifactFacade

use of org.eclipse.tycho.p2.facade.internal.ArtifactFacade in project tycho by eclipse.

the class FeatureRootfileArtifactRepositoryTest method assertAttachedArtifact.

private void assertAttachedArtifact(Map<String, IP2Artifact> attachedArtifacts, int expectedSize, String expectedClassifier, String expectedLocationFileName) {
    Assert.assertEquals(1, attachedArtifacts.size());
    IP2Artifact artifactFacade = attachedArtifacts.get(expectedClassifier);
    Assert.assertEquals(artifactFacade.getLocation().getName(), expectedLocationFileName);
}
Also used : IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact)

Example 3 with ArtifactFacade

use of org.eclipse.tycho.p2.facade.internal.ArtifactFacade 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

Artifact (org.apache.maven.artifact.Artifact)2 ArtifactFacade (org.eclipse.tycho.p2.facade.internal.ArtifactFacade)2 IP2Artifact (org.eclipse.tycho.p2.metadata.IP2Artifact)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 ReactorProject (org.eclipse.tycho.ReactorProject)1 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)1 IArtifactFacade (org.eclipse.tycho.p2.metadata.IArtifactFacade)1 P2Generator (org.eclipse.tycho.p2.metadata.P2Generator)1 GAV (org.eclipse.tycho.p2.repository.GAV)1 TychoRepositoryIndex (org.eclipse.tycho.p2.repository.TychoRepositoryIndex)1 PomDependencyCollector (org.eclipse.tycho.p2.target.facade.PomDependencyCollector)1