Search in sources :

Example 1 with AttachedArtifact

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

the class P2DependencyResolver method getDependencyMetadata.

protected Map<String, IDependencyMetadata> getDependencyMetadata(final MavenSession session, final MavenProject project, final List<TargetEnvironment> environments, final OptionalResolutionAction optionalAction) {
    final Map<String, IDependencyMetadata> metadata = new LinkedHashMap<>();
    metadata.put(null, generator.generateMetadata(new AttachedArtifact(project, project.getBasedir(), null), environments, optionalAction));
    // let external providers contribute additional metadata
    try {
        pluginRealmHelper.execute(session, project, new Runnable() {

            @Override
            public void run() {
                try {
                    for (P2MetadataProvider provider : plexus.lookupList(P2MetadataProvider.class)) {
                        Map<String, IDependencyMetadata> providedMetadata = provider.getDependencyMetadata(session, project, null, optionalAction);
                        if (providedMetadata != null) {
                            metadata.putAll(providedMetadata);
                        }
                    }
                } catch (ComponentLookupException e) {
                // have not found anything
                }
            }
        }, new PluginFilter() {

            @Override
            public boolean accept(PluginDescriptor descriptor) {
                return isTychoP2Plugin(descriptor);
            }
        });
    } catch (MavenExecutionException e) {
        throw new RuntimeException(e);
    }
    return metadata;
}
Also used : PluginFilter(org.eclipse.tycho.core.maven.utils.PluginRealmHelper.PluginFilter) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) LinkedHashMap(java.util.LinkedHashMap) AttachedArtifact(org.eclipse.tycho.p2.facade.internal.AttachedArtifact) PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MavenExecutionException(org.apache.maven.MavenExecutionException) IDependencyMetadata(org.eclipse.tycho.p2.metadata.IDependencyMetadata) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with AttachedArtifact

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

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

the class P2MetadataMojo method getAllProjectArtifacts.

/**
 * Returns a map from classifiers to artifact files of the given project. The classifier
 * <code>null</code> is mapped to the project's main artifact.
 */
private static Map<String, File> getAllProjectArtifacts(MavenProject project) {
    Map<String, File> artifacts = new HashMap<>();
    Artifact mainArtifact = project.getArtifact();
    if (mainArtifact != null) {
        artifacts.put(null, mainArtifact.getFile());
    }
    for (Artifact attachedArtifact : project.getAttachedArtifacts()) {
        artifacts.put(attachedArtifact.getClassifier(), attachedArtifact.getFile());
    }
    return artifacts;
}
Also used : HashMap(java.util.HashMap) File(java.io.File) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

HashMap (java.util.HashMap)3 File (java.io.File)2 Map (java.util.Map)2 Artifact (org.apache.maven.artifact.Artifact)2 IP2Artifact (org.eclipse.tycho.p2.metadata.IP2Artifact)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 MavenExecutionException (org.apache.maven.MavenExecutionException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)1 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)1 ReactorProject (org.eclipse.tycho.ReactorProject)1 PluginFilter (org.eclipse.tycho.core.maven.utils.PluginRealmHelper.PluginFilter)1 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)1 ArtifactFacade (org.eclipse.tycho.p2.facade.internal.ArtifactFacade)1 AttachedArtifact (org.eclipse.tycho.p2.facade.internal.AttachedArtifact)1 IArtifactFacade (org.eclipse.tycho.p2.metadata.IArtifactFacade)1 IDependencyMetadata (org.eclipse.tycho.p2.metadata.IDependencyMetadata)1