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);
}
}
Aggregations