use of org.eclipse.tycho.ReactorProject 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);
}
use of org.eclipse.tycho.ReactorProject in project tycho by eclipse.
the class P2DependencyResolver method getThisReactorProject.
private ReactorProject getThisReactorProject(MavenSession session, MavenProject project, TargetPlatformConfiguration configuration) {
// 'this' project should obey optionalDependencies configuration
final List<TargetEnvironment> environments = configuration.getEnvironments();
final OptionalResolutionAction optionalAction = configuration.getDependencyResolverConfiguration().getOptionalResolutionAction();
Map<String, IDependencyMetadata> dependencyMetadata = getDependencyMetadata(session, project, environments, optionalAction);
final Set<Object> metadata = new LinkedHashSet<>();
final Set<Object> secondaryMetadata = new LinkedHashSet<>();
for (Map.Entry<String, IDependencyMetadata> entry : dependencyMetadata.entrySet()) {
metadata.addAll(entry.getValue().getMetadata(true));
secondaryMetadata.addAll(entry.getValue().getMetadata(false));
}
ReactorProject reactorProjet = new DefaultReactorProject(project) {
@Override
public Set<?> getDependencyMetadata(boolean primary) {
return primary ? metadata : secondaryMetadata;
}
};
return reactorProjet;
}
use of org.eclipse.tycho.ReactorProject 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);
}
}
use of org.eclipse.tycho.ReactorProject in project tycho by eclipse.
the class UpdateSiteAssembler method visitPlugin.
@Override
public void visitPlugin(PluginDescription plugin) {
String bundleId = plugin.getKey().getId();
String version = plugin.getKey().getVersion();
String relPath = PLUGINS_DIR + bundleId + "_" + version + ".jar";
if (archives != null && archives.containsKey(relPath)) {
copyUrl(archives.get(relPath), new File(target, relPath));
return;
}
if (plugin.getLocation() == null) {
throw new IllegalStateException("Unresolved bundle reference " + bundleId + "_" + version);
}
ReactorProject bundleProject = plugin.getMavenProject();
File location = null;
if (bundleProject != null) {
location = bundleProject.getArtifact(plugin.getClassifier());
if (location == null) {
throw new IllegalStateException(bundleProject.getId() + " does not provide an artifact with classifier '" + plugin.getClassifier() + "'");
}
if (location.isDirectory()) {
throw new RuntimeException("Bundle project " + bundleProject.getId() + " artifact is a directory. The build should at least run ``package'' phase.");
}
version = bundleProject.getExpandedVersion();
} else {
location = plugin.getLocation();
}
if (unpackPlugins && isDirectoryShape(plugin, location)) {
// need a directory
File outputJar = getOutputFile(PLUGINS_DIR, bundleId, version, null);
if (location.isDirectory()) {
copyDir(location, outputJar);
} else {
unpackJar(location, outputJar);
}
} else {
// need a jar
File outputJar = getOutputFile(PLUGINS_DIR, bundleId, version, ".jar");
if (location.isDirectory()) {
packDir(location, outputJar);
} else {
copyFile(location, outputJar);
}
}
}
use of org.eclipse.tycho.ReactorProject in project tycho by eclipse.
the class LicenseFeatureHelper method getLicenseFeature.
/**
* Get the license feature jar for feature (or <code>null</code> if it has no license feature).
*
* See {@linkplain http://wiki.eclipse.org/Equinox/p2/License_Mechanism }.
*
* @param feature
* original feature
* @param mavenProject
* original feature project
* @return the license feature jar
*/
public File getLicenseFeature(Feature feature, MavenProject mavenProject) {
String id = feature.getLicenseFeature();
if (id == null) {
return null;
}
ArtifactDescriptor licenseFeature = TychoProjectUtils.getDependencyArtifacts(mavenProject).getArtifact(ArtifactType.TYPE_ECLIPSE_FEATURE, id, feature.getLicenseFeatureVersion());
if (licenseFeature == null) {
throw new IllegalStateException("License feature with id " + id + " is not found among project dependencies");
}
ReactorProject licenseProject = licenseFeature.getMavenProject();
if (licenseProject == null) {
return licenseFeature.getLocation();
}
File artifact = licenseProject.getArtifact();
if (!artifact.isFile()) {
throw new IllegalStateException("At least ''package'' phase need to be executed");
}
return artifact;
}
Aggregations