Search in sources :

Example 1 with BundleConfiguration

use of org.eclipse.tycho.model.BundleConfiguration in project tycho by eclipse.

the class WorkspaceTychoOsgiRuntimeLocator method addProduct.

public boolean addProduct(EquinoxRuntimeDescription result, Artifact pom) throws MavenExecutionException {
    ProductConfiguration product;
    try {
        product = ProductConfiguration.read(new File(pom.getFile().getParentFile(), pom.getArtifactId() + ".product"));
    } catch (IOException e) {
        return false;
    }
    // the above fails with IOException if .product file is not available or can't be read
    // we get here only when we have valid product instance
    Set<String> missing = new LinkedHashSet<>();
    for (PluginRef pluginRef : product.getPlugins()) {
        DevBundleInfo bundleInfo = workspaceState.getBundleInfo(pluginRef.getId(), pluginRef.getVersion());
        if (bundleInfo != null) {
            addBundle(result, bundleInfo);
        } else {
            missing.add(pluginRef.toString());
        }
    }
    if (!missing.isEmpty()) {
        throw new MavenExecutionException("Inconsistent m2e-tycho workspace state, missing bundles: " + missing.toString(), (Throwable) null);
    }
    Map<String, BundleConfiguration> bundleConfigurations = product.getPluginConfiguration();
    if (bundleConfigurations != null) {
        for (BundleConfiguration bundleConfiguration : bundleConfigurations.values()) {
            result.addBundleStartLevel(bundleConfiguration.getId(), bundleConfiguration.getStartLevel(), bundleConfiguration.isAutoStart());
        }
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenExecutionException(org.apache.maven.MavenExecutionException) BundleConfiguration(org.eclipse.tycho.model.BundleConfiguration) ProductConfiguration(org.eclipse.tycho.model.ProductConfiguration) DevBundleInfo(org.eclipse.tycho.dev.DevBundleInfo) PluginRef(org.eclipse.tycho.model.PluginRef) IOException(java.io.IOException) File(java.io.File)

Example 2 with BundleConfiguration

use of org.eclipse.tycho.model.BundleConfiguration in project tycho by eclipse.

the class ProductConfigurationTest method testProductConfigurationParseWithStartLevel.

@Test
public void testProductConfigurationParseWithStartLevel() throws Exception {
    ProductConfiguration config = ProductConfiguration.read(getClass().getResourceAsStream("/product/MyProduct.product"));
    Map<String, BundleConfiguration> bundles = config.getPluginConfiguration();
    // <plugin id="org.eclipse.core.contenttype" autoStart="true" startLevel="1" />
    BundleConfiguration contentType = bundles.get("org.eclipse.core.contenttype");
    Assert.assertNotNull(contentType);
    Assert.assertTrue(contentType.isAutoStart());
    Assert.assertEquals(1, contentType.getStartLevel());
    // <plugin id="HeadlessProduct" autoStart="false" startLevel="2" />
    BundleConfiguration headlessProduct = bundles.get("HeadlessProduct");
    Assert.assertNotNull(headlessProduct);
    Assert.assertFalse(headlessProduct.isAutoStart());
    Assert.assertEquals(2, headlessProduct.getStartLevel());
}
Also used : BundleConfiguration(org.eclipse.tycho.model.BundleConfiguration) ProductConfiguration(org.eclipse.tycho.model.ProductConfiguration) Test(org.junit.Test)

Example 3 with BundleConfiguration

use of org.eclipse.tycho.model.BundleConfiguration in project tycho by eclipse.

the class ProductExportMojo method generateOSGiBundles.

private void generateOSGiBundles(Properties props, TargetEnvironment environment) throws MojoFailureException {
    Map<String, BundleConfiguration> bundlesToStart = productConfiguration.getPluginConfiguration();
    if (bundlesToStart == null) {
        bundlesToStart = new HashMap<>();
        // This is the wellknown set of bundles for Eclipse based application for 3.3 and 3.4 without p2
        // 
        bundlesToStart.put(// 
        "org.eclipse.equinox.common", new BundleConfiguration("org.eclipse.equinox.common", 2, true));
        // 
        bundlesToStart.put(// 
        "org.eclipse.core.runtime", new BundleConfiguration("org.eclipse.core.runtime", -1, true));
    }
    Map<String, PluginDescription> bundles = new LinkedHashMap<>(getBundles(environment));
    StringBuilder osgiBundles = new StringBuilder();
    for (PluginDescription plugin : bundles.values()) {
        String bundleId = plugin.getKey().getId();
        // starts
        if ("org.eclipse.osgi".equals(bundleId)) {
            continue;
        }
        if (osgiBundles.length() > 0) {
            osgiBundles.append(',');
        }
        osgiBundles.append(bundleId);
        BundleConfiguration startup = bundlesToStart.get(bundleId);
        if (startup != null) {
            osgiBundles.append('@');
            if (startup.getStartLevel() > 0) {
                osgiBundles.append(startup.getStartLevel());
            }
            if (startup.isAutoStart()) {
                if (startup.getStartLevel() > 0) {
                    osgiBundles.append(':');
                }
                osgiBundles.append("start");
            }
        }
    }
    setPropertyIfNotNull(props, "osgi.bundles", osgiBundles.toString());
}
Also used : BundleConfiguration(org.eclipse.tycho.model.BundleConfiguration) PluginDescription(org.eclipse.tycho.core.PluginDescription) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

BundleConfiguration (org.eclipse.tycho.model.BundleConfiguration)3 ProductConfiguration (org.eclipse.tycho.model.ProductConfiguration)2 File (java.io.File)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 MavenExecutionException (org.apache.maven.MavenExecutionException)1 PluginDescription (org.eclipse.tycho.core.PluginDescription)1 DevBundleInfo (org.eclipse.tycho.dev.DevBundleInfo)1 PluginRef (org.eclipse.tycho.model.PluginRef)1 Test (org.junit.Test)1