Search in sources :

Example 26 with TargetEnvironment

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;
}
Also used : FilterImpl(org.eclipse.osgi.internal.framework.FilterImpl) HashMap(java.util.HashMap) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment)

Example 27 with TargetEnvironment

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;
}
Also used : TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment)

Example 28 with TargetEnvironment

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()]);
}
Also used : TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration)

Example 29 with TargetEnvironment

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;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) TychoProject(org.eclipse.tycho.core.TychoProject) TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment) Properties(java.util.Properties) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) Plugin(org.apache.maven.model.Plugin)

Example 30 with TargetEnvironment

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());
}
Also used : DefaultTargetPlatformConfigurationReader(org.eclipse.tycho.core.resolver.DefaultTargetPlatformConfigurationReader) MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment) File(java.io.File) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration)

Aggregations

TargetEnvironment (org.eclipse.tycho.core.shared.TargetEnvironment)38 Test (org.junit.Test)14 File (java.io.File)10 ArrayList (java.util.ArrayList)6 TargetPlatformConfiguration (org.eclipse.tycho.core.TargetPlatformConfiguration)6 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)3 P2ResolutionResult (org.eclipse.tycho.p2.resolver.facade.P2ResolutionResult)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Properties (java.util.Properties)2 MavenSession (org.apache.maven.execution.MavenSession)2 MavenProject (org.apache.maven.project.MavenProject)2 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)2 ArtifactKey (org.eclipse.tycho.ArtifactKey)2 ReactorProject (org.eclipse.tycho.ReactorProject)2