Search in sources :

Example 16 with DependencyArtifacts

use of org.eclipse.tycho.artifacts.DependencyArtifacts in project tycho by eclipse.

the class RepositoryReferenceTool method addTargetPlatformRepository.

/**
 * Restores the p2 metadata view on the module's build target platform that was calculated
 * during the initial dependency resolution (see
 * org.eclipse.tycho.p2.resolver.P2ResolverImpl.toResolutionResult(...)).
 */
private void addTargetPlatformRepository(RepositoryReferences sources, MavenSession session, MavenProject project) throws MojoExecutionException, MojoFailureException {
    try {
        File repositoryLocation = new File(project.getBuild().getDirectory(), "targetPlatformRepository");
        repositoryLocation.mkdirs();
        FileOutputStream stream = new FileOutputStream(new File(repositoryLocation, "content.xml"));
        try {
            MetadataSerializable serializer = osgiServices.getService(MetadataSerializable.class);
            TargetPlatform targetPlatform = TychoProjectUtils.getTargetPlatform(project);
            DependencyResolver resolver = dependencyResolverLocator.lookupDependencyResolver(project);
            TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project);
            DependencyResolverConfiguration resolverConfiguration = configuration.getDependencyResolverConfiguration();
            DependencyArtifacts dependencyArtifacts = resolver.resolveDependencies(session, project, targetPlatform, DefaultReactorProject.adapt(session), resolverConfiguration);
            // this contains dependency-only metadata for 'this' project
            Set<Object> targetPlatformInstallableUnits = new HashSet<>(dependencyArtifacts.getInstallableUnits());
            for (ArtifactDescriptor artifact : dependencyArtifacts.getArtifacts()) {
                ReactorProject otherProject = artifact.getMavenProject();
                if (otherProject == null) {
                    // can't really happen
                    continue;
                }
                File artifactXml = otherProject.getArtifact(RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS);
                if (artifactXml != null && artifactXml.isFile()) {
                    sources.addArtifactRepository(artifactXml.getParentFile());
                }
            }
            serializer.serialize(stream, targetPlatformInstallableUnits);
        } finally {
            stream.close();
        }
        sources.addMetadataRepository(repositoryLocation);
    } catch (IOException e) {
        throw new MojoExecutionException("I/O exception while writing the build target platform to disk", e);
    }
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) ReactorProject(org.eclipse.tycho.ReactorProject) IOException(java.io.IOException) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) DependencyResolverConfiguration(org.eclipse.tycho.core.DependencyResolverConfiguration) DependencyResolver(org.eclipse.tycho.core.DependencyResolver) MetadataSerializable(org.eclipse.tycho.p2.metadata.MetadataSerializable) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) FileOutputStream(java.io.FileOutputStream) TargetPlatform(org.eclipse.tycho.artifacts.TargetPlatform) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)16 File (java.io.File)13 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)8 MavenProject (org.apache.maven.project.MavenProject)5 DependencyResolver (org.eclipse.tycho.core.DependencyResolver)5 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)4 State (org.eclipse.osgi.service.resolver.State)4 ReactorProject (org.eclipse.tycho.ReactorProject)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 ArtifactKey (org.eclipse.tycho.ArtifactKey)3 DependencyResolverConfiguration (org.eclipse.tycho.core.DependencyResolverConfiguration)3 DependencyEntry (org.eclipse.tycho.core.osgitools.DependencyComputer.DependencyEntry)3 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)2 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)2 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)2 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)2 MavenSession (org.apache.maven.execution.MavenSession)2 Dependency (org.apache.maven.model.Dependency)2 LegacySupport (org.apache.maven.plugin.LegacySupport)2 StubArtifactRepository (org.apache.maven.plugin.testing.stubs.StubArtifactRepository)2