Search in sources :

Example 1 with OsgiManifest

use of org.eclipse.tycho.core.osgitools.OsgiManifest in project tycho by eclipse.

the class DefaultBundleReaderTest method testLoadManifestFromJar.

public void testLoadManifestFromJar() throws Exception {
    File jar = new File("src/test/resources/bundlereader/jarshape/test.jar");
    OsgiManifest manifest = bundleReader.loadManifest(jar);
    assertEquals("org.eclipse.tycho.test", manifest.getBundleSymbolicName());
}
Also used : OsgiManifest(org.eclipse.tycho.core.osgitools.OsgiManifest) File(java.io.File)

Example 2 with OsgiManifest

use of org.eclipse.tycho.core.osgitools.OsgiManifest in project tycho by eclipse.

the class DefaultEquinoxInstallationFactory method createInstallation.

@Override
public EquinoxInstallation createInstallation(EquinoxInstallationDescription description, File location) {
    Set<String> bundlesToExplode = description.getBundlesToExplode();
    List<File> frameworkExtensions = description.getFrameworkExtensions();
    Map<String, BundleStartLevel> startLevel = description.getBundleStartLevel();
    BundleStartLevel defaultBundleStartLevel = description.getDefaultBundleStartLevel();
    if (defaultBundleStartLevel == null) {
        defaultBundleStartLevel = new BundleStartLevel(null, 4, false);
    }
    Map<ArtifactKey, File> effective = new LinkedHashMap<>();
    for (ArtifactDescriptor artifact : description.getBundles()) {
        ArtifactKey key = artifact.getKey();
        File file = artifact.getLocation();
        OsgiManifest mf = manifestReader.loadManifest(file);
        boolean directoryShape = bundlesToExplode.contains(key.getId()) || mf.isDirectoryShape();
        if (!file.isDirectory() && directoryShape) {
            String filename = key.getId() + "_" + key.getVersion();
            File unpacked = new File(location, "plugins/" + filename);
            unpacked.mkdirs();
            unpack(file, unpacked);
            effective.put(key, unpacked);
        } else {
            effective.put(key, file);
        }
    }
    try {
        location.mkdirs();
        Properties p = new Properties();
        p.putAll(description.getPlatformProperties());
        String newOsgiBundles = toOsgiBundles(effective, startLevel, defaultBundleStartLevel);
        p.setProperty("osgi.bundles", newOsgiBundles);
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=234069
        p.setProperty("osgi.bundlefile.limit", "100");
        // @see SimpleConfiguratorConstants#PROP_KEY_EXCLUSIVE_INSTALLATION
        // p.setProperty("org.eclipse.equinox.simpleconfigurator.exclusiveInstallation", "false");
        p.setProperty("osgi.install.area", "file:" + location.getAbsolutePath().replace('\\', '/'));
        p.setProperty("osgi.configuration.cascaded", "false");
        p.setProperty("osgi.framework", "org.eclipse.osgi");
        p.setProperty("osgi.bundles.defaultStartLevel", String.valueOf(defaultBundleStartLevel.getLevel()));
        // fix osgi.framework
        String url = p.getProperty("osgi.framework");
        if (url != null) {
            File file;
            ArtifactDescriptor desc = description.getBundle(url, null);
            if (desc != null) {
                url = "file:" + desc.getLocation().getAbsolutePath().replace('\\', '/');
            } else if (url.startsWith("file:")) {
                String path = url.substring("file:".length());
                file = new File(path);
                if (!file.isAbsolute()) {
                    file = new File(location, path);
                }
                url = "file:" + file.getAbsolutePath().replace('\\', '/');
            }
        }
        if (url != null) {
            p.setProperty("osgi.framework", url);
        }
        if (!frameworkExtensions.isEmpty()) {
            // see osgi.framework.extensions at http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fruntime-options.html
            Collection<String> bundleNames = unpackFrameworkExtensions(location, frameworkExtensions);
            p.setProperty("osgi.framework", copySystemBundle(description, location));
            p.setProperty("osgi.framework.extensions", StringUtils.join(bundleNames.iterator(), ","));
        }
        if (!description.getDevEntries().isEmpty()) {
            p.put("osgi.dev", createDevProperties(location, description.getDevEntries()));
        }
        File configIni = new File(location, TychoConstants.CONFIG_INI_PATH);
        File configurationLocation = configIni.getParentFile();
        configurationLocation.mkdirs();
        FileOutputStream fos = new FileOutputStream(configIni);
        try {
            p.store(fos, null);
        } finally {
            fos.close();
        }
        return new DefaultEquinoxInstallation(description, location, configurationLocation);
    } catch (IOException e) {
        throw new RuntimeException("Exception creating test eclipse runtime", e);
    }
}
Also used : BundleStartLevel(org.eclipse.sisu.equinox.launching.BundleStartLevel) ArtifactKey(org.eclipse.tycho.ArtifactKey) IOException(java.io.IOException) Properties(java.util.Properties) LinkedHashMap(java.util.LinkedHashMap) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) FileOutputStream(java.io.FileOutputStream) OsgiManifest(org.eclipse.tycho.core.osgitools.OsgiManifest) File(java.io.File)

Example 3 with OsgiManifest

use of org.eclipse.tycho.core.osgitools.OsgiManifest in project tycho by eclipse.

the class DefaultEquinoxInstallationFactory method unpackFrameworkExtensions.

private List<String> unpackFrameworkExtensions(File location, Collection<File> frameworkExtensions) throws IOException {
    List<String> bundleNames = new ArrayList<>();
    for (File bundleFile : frameworkExtensions) {
        OsgiManifest mf = manifestReader.loadManifest(bundleFile);
        bundleNames.add(mf.getBundleSymbolicName());
        File bundleDir = new File(location, "plugins/" + mf.getBundleSymbolicName() + "_" + mf.getBundleVersion());
        if (bundleFile.isFile()) {
            unpack(bundleFile, bundleDir);
        } else {
            FileUtils.copyDirectoryStructure(bundleFile, bundleDir);
        }
    }
    return bundleNames;
}
Also used : ArrayList(java.util.ArrayList) OsgiManifest(org.eclipse.tycho.core.osgitools.OsgiManifest) File(java.io.File)

Example 4 with OsgiManifest

use of org.eclipse.tycho.core.osgitools.OsgiManifest in project tycho by eclipse.

the class DefaultBundleReaderTest method testLoadManifestFromDir.

public void testLoadManifestFromDir() throws Exception {
    File dir = new File("src/test/resources/bundlereader/dirshape");
    OsgiManifest manifest = bundleReader.loadManifest(dir);
    assertEquals("org.eclipse.tycho.test", manifest.getBundleSymbolicName());
}
Also used : OsgiManifest(org.eclipse.tycho.core.osgitools.OsgiManifest) File(java.io.File)

Example 5 with OsgiManifest

use of org.eclipse.tycho.core.osgitools.OsgiManifest in project tycho by eclipse.

the class LocalDependencyResolver method getArtifactKey.

public ArtifactKey getArtifactKey(MavenSession session, File plugin) {
    OsgiManifest mf = manifestReader.loadManifest(plugin);
    ArtifactKey key = mf.toArtifactKey();
    return key;
}
Also used : DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) ArtifactKey(org.eclipse.tycho.ArtifactKey) OsgiManifest(org.eclipse.tycho.core.osgitools.OsgiManifest)

Aggregations

OsgiManifest (org.eclipse.tycho.core.osgitools.OsgiManifest)8 File (java.io.File)7 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)2 ArtifactKey (org.eclipse.tycho.ArtifactKey)2 FileFilter (java.io.FileFilter)1 OutputStream (java.io.OutputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 JarFile (java.util.jar.JarFile)1 Verifier (org.apache.maven.it.Verifier)1 Model (org.apache.maven.model.Model)1 Resource (org.apache.maven.model.Resource)1 BundleStartLevel (org.eclipse.sisu.equinox.launching.BundleStartLevel)1 DefaultArtifactKey (org.eclipse.tycho.DefaultArtifactKey)1 DefaultBundleReader (org.eclipse.tycho.core.osgitools.DefaultBundleReader)1