use of org.eclipse.tycho.core.DependencyResolver in project tycho by eclipse.
the class TestMojo method createEclipseInstallation.
private EquinoxInstallation createEclipseInstallation() throws MojoExecutionException {
DependencyResolver platformResolver = dependencyResolverLocator.lookupDependencyResolver(project);
final List<Dependency> extraDependencies = getExtraDependencies();
List<ReactorProject> reactorProjects = getReactorProjects();
final DependencyResolverConfiguration resolverConfiguration = new DependencyResolverConfiguration() {
@Override
public OptionalResolutionAction getOptionalResolutionAction() {
return OptionalResolutionAction.IGNORE;
}
@Override
public List<Dependency> getExtraRequirements() {
return extraDependencies;
}
};
DependencyArtifacts testRuntimeArtifacts = platformResolver.resolveDependencies(session, project, null, reactorProjects, resolverConfiguration);
if (testRuntimeArtifacts == null) {
throw new MojoExecutionException("Cannot determinate build target platform location -- not executing tests");
}
work.mkdirs();
EquinoxInstallationDescription testRuntime = new DefaultEquinoxInstallationDescription();
testRuntime.setDefaultBundleStartLevel(defaultStartLevel);
testRuntime.addBundlesToExplode(getBundlesToExplode());
testRuntime.addFrameworkExtensions(getFrameworkExtensions());
if (bundleStartLevel != null) {
for (BundleStartLevel level : bundleStartLevel) {
testRuntime.addBundleStartLevel(level);
}
}
TestFrameworkProvider provider = providerHelper.selectProvider(getProjectType().getClasspath(project), getMergedProviderProperties(), providerHint);
createSurefireProperties(provider);
for (ArtifactDescriptor artifact : testRuntimeArtifacts.getArtifacts(ArtifactType.TYPE_ECLIPSE_PLUGIN)) {
// note that this project is added as directory structure rooted at project basedir.
// project classes and test-classes are added via dev.properties file (see #createDevProperties())
// all other projects are added as bundle jars.
ReactorProject otherProject = artifact.getMavenProject();
if (otherProject != null) {
if (otherProject.sameProject(project)) {
testRuntime.addBundle(artifact.getKey(), project.getBasedir());
continue;
}
File file = otherProject.getArtifact(artifact.getClassifier());
if (file != null) {
testRuntime.addBundle(artifact.getKey(), file);
continue;
}
}
testRuntime.addBundle(artifact);
}
Set<Artifact> testFrameworkBundles = providerHelper.filterTestFrameworkBundles(provider, pluginArtifacts);
for (Artifact artifact : testFrameworkBundles) {
DevBundleInfo devInfo = workspaceState.getBundleInfo(session, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), project.getPluginArtifactRepositories());
if (devInfo != null) {
testRuntime.addBundle(devInfo.getArtifactKey(), devInfo.getLocation(), true);
testRuntime.addDevEntries(devInfo.getSymbolicName(), devInfo.getDevEntries());
} else {
File bundleLocation = artifact.getFile();
ArtifactKey bundleArtifactKey = getBundleArtifactKey(bundleLocation);
testRuntime.addBundle(bundleArtifactKey, bundleLocation, true);
}
}
testRuntime.addDevEntries(getTestBundleSymbolicName(), getBuildOutputDirectories());
reportsDirectory.mkdirs();
return installationFactory.createInstallation(testRuntime, work);
}
use of org.eclipse.tycho.core.DependencyResolver in project tycho by eclipse.
the class DefaultDependencyResolverFactory method lookupDependencyResolver.
public DependencyResolver lookupDependencyResolver(MavenProject project) {
Properties properties = (Properties) project.getContextValue(TychoConstants.CTX_MERGED_PROPERTIES);
TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project);
String property = properties.getProperty("tycho.targetPlatform");
DependencyResolver resolver;
if (property != null) {
logger.warn("-Dtycho.targetPlatform is deprecated and WILL be removed in the next Tycho version.");
File location = new File(property);
if (!location.exists() || !location.isDirectory()) {
throw new RuntimeException("Invalid target platform location: " + property);
}
try {
resolver = container.lookup(DependencyResolver.class, LocalDependencyResolver.ROLE_HINT);
} catch (ComponentLookupException e) {
throw new RuntimeException("Could not instantiate required component", e);
}
try {
((LocalDependencyResolver) resolver).setLocation(new File(property));
} catch (IOException e) {
throw new RuntimeException("Could not create target platform", e);
}
return resolver;
}
String resolverRole = configuration.getTargetPlatformResolver();
if (resolverRole == null) {
resolverRole = DEFAULT_RESOLVER_HINT;
}
try {
resolver = container.lookup(DependencyResolver.class, resolverRole);
} catch (ComponentLookupException e) {
throw new RuntimeException("Could not instantiate required component", e);
}
return resolver;
}
use of org.eclipse.tycho.core.DependencyResolver in project tycho by eclipse.
the class DefaultTychoResolver method setupProject.
@Override
public void setupProject(MavenSession session, MavenProject project, ReactorProject reactorProject) {
AbstractTychoProject dr = (AbstractTychoProject) projectTypes.get(project.getPackaging());
if (dr == null) {
return;
}
// skip if setup was already done
if (project.getContextValue(TychoConstants.CTX_MERGED_PROPERTIES) != null) {
return;
}
// generic Eclipse/OSGi metadata
dr.setupProject(session, project);
// p2 metadata
Properties properties = new Properties();
properties.putAll(project.getProperties());
// session wins
properties.putAll(session.getSystemProperties());
properties.putAll(session.getUserProperties());
project.setContextValue(TychoConstants.CTX_MERGED_PROPERTIES, properties);
setTychoEnvironmentProperties(properties, project);
TargetPlatformConfiguration configuration = configurationReader.getTargetPlatformConfiguration(session, project);
project.setContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION, configuration);
ExecutionEnvironmentConfiguration eeConfiguration = new ExecutionEnvironmentConfigurationImpl(logger, !configuration.isResolveWithEEConstraints());
dr.readExecutionEnvironmentConfiguration(project, eeConfiguration);
project.setContextValue(TychoConstants.CTX_EXECUTION_ENVIRONMENT_CONFIGURATION, eeConfiguration);
DependencyResolver resolver = dependencyResolverLocator.lookupDependencyResolver(project);
resolver.setupProjects(session, project, reactorProject);
}
use of org.eclipse.tycho.core.DependencyResolver in project tycho by eclipse.
the class DefaultTychoResolver method resolveProject.
@Override
public void resolveProject(MavenSession session, MavenProject project, List<ReactorProject> reactorProjects) {
AbstractTychoProject dr = (AbstractTychoProject) projectTypes.get(project.getPackaging());
if (dr == null) {
return;
}
DependencyResolver resolver = dependencyResolverLocator.lookupDependencyResolver(project);
logger.info("Computing target platform for " + project);
TargetPlatform preliminaryTargetPlatform = resolver.computePreliminaryTargetPlatform(session, project, reactorProjects);
TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project);
DependencyResolverConfiguration resolverConfiguration = configuration.getDependencyResolverConfiguration();
logger.info("Resolving dependencies of " + project);
DependencyArtifacts dependencyArtifacts = resolver.resolveDependencies(session, project, preliminaryTargetPlatform, reactorProjects, resolverConfiguration);
if (logger.isDebugEnabled() && DebugUtils.isDebugEnabled(session, project)) {
StringBuilder sb = new StringBuilder();
sb.append("Resolved target platform for ").append(project).append("\n");
dependencyArtifacts.toDebugString(sb, " ");
logger.debug(sb.toString());
}
dr.setDependencyArtifacts(session, project, dependencyArtifacts);
logger.info("Resolving class path of " + project);
dr.resolveClassPath(session, project);
resolver.injectDependenciesIntoMavenModel(project, dr, dependencyArtifacts, logger);
if (logger.isDebugEnabled() && DebugUtils.isDebugEnabled(session, project)) {
StringBuilder sb = new StringBuilder();
sb.append("Injected dependencies for ").append(project.toString()).append("\n");
for (Dependency dependency : project.getDependencies()) {
sb.append(" ").append(dependency.toString());
}
logger.debug(sb.toString());
}
}
use of org.eclipse.tycho.core.DependencyResolver 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