use of org.eclipse.tycho.core.shared.TargetEnvironment in project tycho by eclipse.
the class OsgiBundleProject method getImplicitTargetEnvironment.
@Override
public TargetEnvironment getImplicitTargetEnvironment(MavenProject project) {
String filterStr = getManifestValue(EclipsePlatformNamespace.ECLIPSE_PLATFORM_FILTER_HEADER, project);
if (filterStr != null) {
try {
FilterImpl filter = FilterImpl.newInstance(filterStr);
String ws = sn(filter.getPrimaryKeyValue(PlatformPropertiesUtils.OSGI_WS));
String os = sn(filter.getPrimaryKeyValue(PlatformPropertiesUtils.OSGI_OS));
String arch = sn(filter.getPrimaryKeyValue(PlatformPropertiesUtils.OSGI_ARCH));
// validate if os/ws/arch are not null and actually match the filter
if (ws != null && os != null && arch != null) {
Map<String, String> properties = new HashMap<>();
properties.put(PlatformPropertiesUtils.OSGI_WS, ws);
properties.put(PlatformPropertiesUtils.OSGI_OS, os);
properties.put(PlatformPropertiesUtils.OSGI_ARCH, arch);
if (filter.matches(properties)) {
return new TargetEnvironment(os, ws, arch);
}
}
} catch (InvalidSyntaxException e) {
// at least we tried...
}
}
return null;
}
use of org.eclipse.tycho.core.shared.TargetEnvironment in project tycho by eclipse.
the class AbstractArtifactDependencyWalker method matchTargetEnvironment.
private boolean matchTargetEnvironment(PluginRef pluginRef) {
String pluginOs = pluginRef.getOs();
String pluginWs = pluginRef.getWs();
String pluginArch = pluginRef.getArch();
if (environments == null) {
// match all environments be default
return true;
// no target environments, only include environment independent plugins
// return pluginOs == null && pluginWs == null && pluginArch == null;
}
for (TargetEnvironment environment : environments) {
if (environment.match(pluginOs, pluginWs, pluginArch)) {
return true;
}
}
return false;
}
use of org.eclipse.tycho.core.shared.TargetEnvironment in project tycho by eclipse.
the class AbstractTychoProject method getEnvironments.
protected TargetEnvironment[] getEnvironments(MavenProject project, TargetEnvironment environment) {
if (environment != null) {
return new TargetEnvironment[] { environment };
}
TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project);
if (configuration.isImplicitTargetEnvironment()) {
// any
return null;
}
// all specified
List<TargetEnvironment> environments = configuration.getEnvironments();
return environments.toArray(new TargetEnvironment[environments.size()]);
}
use of org.eclipse.tycho.core.shared.TargetEnvironment in project tycho by eclipse.
the class DefaultTargetPlatformConfigurationReader method getTargetPlatformConfiguration.
public TargetPlatformConfiguration getTargetPlatformConfiguration(MavenSession session, MavenProject project) throws BuildFailureException {
TargetPlatformConfiguration result = new TargetPlatformConfiguration();
// Use org.eclipse.tycho:target-platform-configuration/configuration/environment, if provided
Plugin plugin = project.getPlugin("org.eclipse.tycho:target-platform-configuration");
if (plugin != null) {
Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
if (configuration != null) {
if (logger.isDebugEnabled()) {
logger.debug("target-platform-configuration for " + project.toString() + ":\n" + configuration.toString());
}
addTargetEnvironments(result, project, configuration);
setTargetPlatformResolver(result, configuration);
setTarget(result, session, project, configuration);
setPomDependencies(result, configuration);
setAllowConflictingDependencies(result, configuration);
setDisableP2Mirrors(result, configuration);
setExecutionEnvironment(result, configuration);
setExecutionEnvironmentDefault(result, configuration);
setBREEHeaderSelectionPolicy(result, configuration);
setResolveWithEEContraints(result, configuration);
readFilters(result, configuration);
readDependencyResolutionConfiguration(result, configuration);
setIncludePackedArtifacts(result, configuration);
setTargetDefinitionIncludeSources(result, configuration);
}
}
if (result.getEnvironments().isEmpty()) {
TychoProject projectType = projectTypes.get(project.getPackaging());
if (projectType != null) {
TargetEnvironment env = projectType.getImplicitTargetEnvironment(project);
if (env != null) {
if (logger.isDebugEnabled()) {
logger.debug("Implicit target environment for " + project.toString() + ": " + env.toString());
}
result.addEnvironment(env);
}
}
}
if (result.getEnvironments().isEmpty()) {
// applying defaults
logger.warn("No explicit target runtime environment configuration. Build is platform dependent.");
// Otherwise, use project or execution properties, if provided
Properties properties = (Properties) project.getContextValue(TychoConstants.CTX_MERGED_PROPERTIES);
// Otherwise, use current system os/ws/nl/arch
String os = PlatformPropertiesUtils.getOS(properties);
String ws = PlatformPropertiesUtils.getWS(properties);
String arch = PlatformPropertiesUtils.getArch(properties);
result.addEnvironment(new TargetEnvironment(os, ws, arch));
result.setImplicitTargetEnvironment(true);
} else {
result.setImplicitTargetEnvironment(false);
}
return result;
}
use of org.eclipse.tycho.core.shared.TargetEnvironment in project tycho by eclipse.
the class TychoTest method testImplicitTargetEnvironment.
public void testImplicitTargetEnvironment() throws Exception {
File basedir = getBasedir("projects/implicitenvironment/simple");
List<MavenProject> projects = getSortedProjects(basedir);
assertEquals(1, projects.size());
// assertEquals("ambiguous", projects.get(0).getArtifactId());
// assertEquals("none", projects.get(0).getArtifactId());
assertEquals("simple", projects.get(0).getArtifactId());
DefaultTargetPlatformConfigurationReader resolver = lookup(DefaultTargetPlatformConfigurationReader.class);
MavenSession session;
TargetPlatformConfiguration configuration;
List<TargetEnvironment> environments;
// ambiguous
// session = newMavenSession(projects.get(0), projects);
// configuration = resolver.getTargetPlatformConfiguration(session, session.getCurrentProject());
// environments = configuration.getEnvironments();
// assertEquals(0, environments.size());
// none
// session = newMavenSession(projects.get(0), projects);
// configuration = resolver.getTargetPlatformConfiguration(session, session.getCurrentProject());
// environments = configuration.getEnvironments();
// assertEquals(0, environments.size());
// simple
session = newMavenSession(projects.get(0), projects);
configuration = resolver.getTargetPlatformConfiguration(session, session.getCurrentProject());
environments = configuration.getEnvironments();
assertEquals(1, environments.size());
TargetEnvironment env = environments.get(0);
assertEquals("foo", env.getOs());
assertEquals("bar", env.getWs());
assertEquals("munchy", env.getArch());
}
Aggregations