use of org.eclipse.sisu.equinox.embedder.EquinoxLifecycleListener 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);
}
}
Aggregations