Search in sources :

Example 1 with EquinoxRuntimeDescription

use of org.eclipse.sisu.equinox.embedder.EquinoxRuntimeLocator.EquinoxRuntimeDescription in project tycho by eclipse.

the class DefaultEquinoxEmbedder method doStart.

protected void doStart() throws Exception {
    final List<File> installationLocations = new ArrayList<>();
    final List<File> bundleLocations = new ArrayList<>();
    final List<String> extraSystemPackages = new ArrayList<>();
    final Map<String, String> platformProperties = new LinkedHashMap<>();
    equinoxLocator.locateRuntime(new EquinoxRuntimeDescription() {

        @Override
        public void addExtraSystemPackage(String systemPackage) {
            if (systemPackage == null || systemPackage.length() == 0) {
                throw new IllegalArgumentException();
            }
            extraSystemPackages.add(systemPackage);
        }

        @Override
        public void addPlatformProperty(String property, String value) {
            if (property == null || property.length() == 0) {
                throw new IllegalArgumentException();
            }
            platformProperties.put(property, value);
        }

        @Override
        public void addInstallation(File location) {
            if (location == null || !location.isDirectory() || !new File(location, "plugins").isDirectory()) {
                throw new IllegalArgumentException();
            }
            if (!installationLocations.isEmpty()) {
                // allow only one installation for now
                throw new IllegalStateException();
            }
            installationLocations.add(location);
        }

        @Override
        public void addBundle(File location) {
            if (location == null || !location.exists()) {
                throw new IllegalArgumentException();
            }
            if (!isFrameworkBundle(location)) {
                bundleLocations.add(location);
            }
        }

        @Override
        public void addBundleStartLevel(String id, int level, boolean autostart) {
        // TODO do we need to autostart?
        }
    });
    if (installationLocations.isEmpty() && !platformProperties.containsKey("osgi.install.area")) {
        throw new RuntimeException("Equinox runtime location is missing or invalid");
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("osgi.framework.useSystemProperties", "false");
    final StringBuilder bundles = new StringBuilder();
    if (!installationLocations.isEmpty()) {
        File frameworkDir = installationLocations.get(0);
        String frameworkLocation = frameworkDir.getAbsolutePath();
        platformProperties.put("osgi.install.area", frameworkLocation);
        platformProperties.put("osgi.syspath", frameworkLocation + "/plugins");
        platformProperties.put("osgi.configuration.area", copyToTempFolder(new File(frameworkDir, "configuration")));
        // platformProperties.put( "eclipse.p2.data.area", dataArea.getAbsolutePath() );
        addBundlesDir(bundles, new File(frameworkDir, "plugins").listFiles(), false);
    }
    for (File location : bundleLocations) {
        if (bundles.length() > 0) {
            bundles.append(',');
        }
        bundles.append(getReferenceUrl(location));
    }
    platformProperties.put("osgi.bundles", bundles.toString());
    // this tells framework to use our classloader as parent, so it can see classes that we see
    platformProperties.put("osgi.parentClassloader", "fwk");
    if (extraSystemPackages.size() > 0) {
        StringBuilder sb = new StringBuilder();
        for (String pkg : extraSystemPackages) {
            if (sb.length() > 0) {
                sb.append(',');
            }
            sb.append(pkg);
        }
        // make the system bundle export the given packages and load them from the parent class loader
        platformProperties.put("org.osgi.framework.system.packages.extra", sb.toString());
    }
    // debug
    // properties.put( "osgi.console", "" );
    // properties.put( "osgi.debug", "" );
    // properties.put( "eclipse.consoleLog", "true" );
    // TODO switch to org.eclipse.osgi.launch.Equinox
    // EclipseStarter is not helping here
    EclipseStarter.setInitialProperties(platformProperties);
    EclipseStarter.startup(getNonFrameworkArgs(), null);
    frameworkContext = EclipseStarter.getSystemBundleContext();
    activateBundlesInWorkingOrder();
    for (EquinoxLifecycleListener listener : lifecycleListeners.values()) {
        listener.afterFrameworkStarted(this);
    }
}
Also used : ArrayList(java.util.ArrayList) EquinoxLifecycleListener(org.eclipse.sisu.equinox.embedder.EquinoxLifecycleListener) LinkedHashMap(java.util.LinkedHashMap) EquinoxRuntimeDescription(org.eclipse.sisu.equinox.embedder.EquinoxRuntimeLocator.EquinoxRuntimeDescription) File(java.io.File)

Example 2 with EquinoxRuntimeDescription

use of org.eclipse.sisu.equinox.embedder.EquinoxRuntimeLocator.EquinoxRuntimeDescription in project tycho by eclipse.

the class P2ApplicationLauncher method execute.

public int execute(int forkedProcessTimeoutInSeconds) {
    try {
        File installationFolder = newTemporaryFolder();
        try {
            final EquinoxInstallationDescription description = new DefaultEquinoxInstallationDescription();
            runtimeLocator.locateRuntime(new EquinoxRuntimeDescription() {

                @Override
                public void addPlatformProperty(String property, String value) {
                    description.addPlatformProperty(property, value);
                }

                @Override
                public void addInstallation(File location) {
                    for (File file : new File(location, "plugins").listFiles()) {
                        P2ApplicationLauncher.this.addBundle(description, file);
                    }
                }

                @Override
                public void addExtraSystemPackage(String systemPackages) {
                }

                @Override
                public void addBundle(File location) {
                    P2ApplicationLauncher.this.addBundle(description, location);
                }

                @Override
                public void addBundleStartLevel(String id, int level, boolean autostart) {
                    description.addBundleStartLevel(new BundleStartLevel(id, level, autostart));
                }
            });
            EquinoxInstallation installation = installationFactory.createInstallation(description, installationFolder);
            EquinoxLaunchConfiguration launchConfiguration = new EquinoxLaunchConfiguration(installation);
            launchConfiguration.setWorkingDirectory(workingDirectory);
            launchConfiguration.addProgramArguments("-configuration", installation.getConfigurationLocation().getAbsolutePath());
            if (logger.isDebugEnabled()) {
                launchConfiguration.addProgramArguments("-debug", "-consoleLog");
                launchConfiguration.addProgramArguments("-console");
            }
            // application and application arguments
            launchConfiguration.addProgramArguments("-nosplash", "-application", applicationName);
            launchConfiguration.addProgramArguments(args.toArray(new String[args.size()]));
            return launcher.execute(launchConfiguration, forkedProcessTimeoutInSeconds);
        } finally {
            try {
                FileUtils.deleteDirectory(installationFolder);
            } catch (IOException e) {
                // this may happen if child process did not close all file handles
                logger.warn("Failed to delete temp folder " + installationFolder);
            }
        }
    } catch (Exception e) {
        // TODO better exception?
        throw new RuntimeException(e);
    }
}
Also used : BundleStartLevel(org.eclipse.sisu.equinox.launching.BundleStartLevel) IOException(java.io.IOException) EquinoxInstallation(org.eclipse.sisu.equinox.launching.EquinoxInstallation) IOException(java.io.IOException) EquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription) DefaultEquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription) EquinoxRuntimeDescription(org.eclipse.sisu.equinox.embedder.EquinoxRuntimeLocator.EquinoxRuntimeDescription) DefaultEquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription) File(java.io.File)

Aggregations

File (java.io.File)2 EquinoxRuntimeDescription (org.eclipse.sisu.equinox.embedder.EquinoxRuntimeLocator.EquinoxRuntimeDescription)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 EquinoxLifecycleListener (org.eclipse.sisu.equinox.embedder.EquinoxLifecycleListener)1 BundleStartLevel (org.eclipse.sisu.equinox.launching.BundleStartLevel)1 DefaultEquinoxInstallationDescription (org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription)1 EquinoxInstallation (org.eclipse.sisu.equinox.launching.EquinoxInstallation)1 EquinoxInstallationDescription (org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription)1