Eclipse equinox implementation of OSGi
- Bundle
package org.osgi.framework;
public interface Bundle extends Comparable<Bundle> {
int UNINSTALLED = 0x00000001;
int INSTALLED = 0x00000002;
int RESOLVED = 0x00000004;
int STARTING = 0x00000008;
int STOPPING = 0x00000010;
int ACTIVE = 0x00000020;
int START_TRANSIENT = 0x00000001;
int START_ACTIVATION_POLICY = 0x00000002;
int STOP_TRANSIENT = 0x00000001;
int SIGNERS_ALL = ;
int SIGNERS_TRUSTED = ;
int getState();
voidstart(int options) throws BundleException;
void start() throws BundleException;
voidstop(int options) throws BundleException;
void stop() throws BundleException;
void update(InputStream input) throws BundleException;
void update() throws BundleException;
void uninstall() throws BundleException;
Dictionary<String, String> getHeaders();
long getBundleId();
String getLocation();
ServiceReference<?>[] getRegisteredServices();
ServiceReference<?>[] getServicesInUse();
boolean hasPermission(Object permission);
URL getResource(String name);
Enumeration<String> getEntryPaths(String path);
URL getEntry(String path);
long getLastModified();
Enumeration<URL> findEntries(String path, String filePattern, boolean recurse);
BundleContext getBundleContext();
Map<X509Certificate, List<X509Certificate>> getSignerCertificates(int signersType);
Version getVersion();
<A> A adapt(Class<A> type);
File getDataFile(String filename);
}- Framework: also known as Bundle
package org.osgi.framework.launch; import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkEvent;
public interface Framework extends Bundle {
void init() throws BundleException;
FrameworkEvent waitForStop(long timeout) throws InterruptedException;
void start() throws BundleException;
void start(int options) throws BundleException;
void stop() throws BundleException;
void stop(int options) throws BundleException;
void uninstall() throws BundleException;
void update() throws BundleException;
void update(InputStream in) throws BundleException;
long getBundleId();
String getLocation();
String getSymbolicName();
Enumeration<String> getEntryPaths(String path);
URL getEntry(String path);
Enumeration<URL> findEntries(String path, String filePattern, boolean recurse);
<A> A adapt(Class<A> type);
}- FrameworkFactory
package org.osgi.framework.launch;
import java.util.Map;
import org.osgi.framework.Bundle;
/**
* A factory for creating {@link Framework} instances.
* @ThreadSafe
* @noimplement
* @version $Id: 1684e14aa98a1f6e1ff3e0f3afa2c55982210f72 $
*/
public interface FrameworkFactory {
Framework newFramework(Map<String, String> configuration);
}- EquinoxLauncher: implement the interface of Framework
Configuration
dev.properties
#
#Wed Sep 11 08:37:19 CST 2013
com.dragon.osgi.hello=bin
@ignoredot@=true
config.ini
#Configuration File
#Wed Sep 11 08:37:19 CST 2013
osgi.bundles=reference\:file\:G\:/eclipse/eclipse/plugins/org.apache.felix.gogo.runtime_0.8.0.v201108120515.jar@start,reference\:file\:G\:/eclipse/eclipse/plugins/org.apache.felix.gogo.shell_0.8.0.v201110170705.jar@start,reference\:file\:G\:/eclipse/eclipse/plugins/org.apache.felix.gogo.command_0.8.0.v201108120515.jar@start,reference\:file\:G\:/eclipse/Workspace/com.dragon.osgi.hello@start,reference\:file\:G\:/eclipse/eclipse/plugins/org.eclipse.equinox.console_1.0.0.v20120522-1841.jar@start
osgi.bundles.defaultStartLevel=4
osgi.install.area=file\:G\:\\eclipse\\eclipse
osgi.framework=file\:G\:/eclipse/eclipse/plugins/org.eclipse.osgi_3.8.0.v20120529-1548.jar
osgi.configuration.cascaded=false
/*******************************************************************************
* Copyright (c) 2006, 2011 Cognos Incorporated, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package org.eclipse.osgi.framework.internal.core; import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLDecoder;
import java.security.CodeSource;
import java.util.*;
import org.eclipse.core.runtime.internal.adaptor.EclipseAdaptorMsg;
import org.eclipse.osgi.util.NLS; /*
* This class should be used in ALL places in the framework implementation to get "system" properties.
* The static methods on this class should be used instead of the System#getProperty, System#setProperty etc methods.
*/
public class FrameworkProperties { /**@GuardedBy FrameworkProperties.class*/
private static Properties properties; // A flag of some sort will have to be supported.
// Many existing plugins get framework propeties directly from System instead of BundleContext.
// Note that the OSGi TCK is one example where this property MUST be set to false because many TCK bundles set and read system properties.
private static final String USING_SYSTEM_PROPERTIES_KEY = "osgi.framework.useSystemProperties"; //$NON-NLS-1$
private static final String PROP_FRAMEWORK = "osgi.framework"; //$NON-NLS-1$
private static final String PROP_INSTALL_AREA = "osgi.install.area"; //$NON-NLS-1$ public static Properties getProperties() {
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPropertiesAccess();
return internalGetProperties(null);
} public static String getProperty(String key) {
return getProperty(key, null);
} public static String getProperty(String key, String defaultValue) {
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPropertyAccess(key);
return internalGetProperties(null).getProperty(key, defaultValue);
} public static String setProperty(String key, String value) {
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPermission(new PropertyPermission(key, "write")); //$NON-NLS-1$
return (String) internalGetProperties(null).put(key, value);
} public static String clearProperty(String key) {
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPermission(new PropertyPermission(key, "write")); //$NON-NLS-1$
return (String) internalGetProperties(null).remove(key);
} private static synchronized Properties internalGetProperties(String usingSystemProperties) {
if (properties == null) {
Properties systemProperties = System.getProperties();
if (usingSystemProperties == null)
usingSystemProperties = systemProperties.getProperty(USING_SYSTEM_PROPERTIES_KEY);
if (usingSystemProperties == null || usingSystemProperties.equalsIgnoreCase(Boolean.TRUE.toString())) {
properties = systemProperties;
} else {
// use systemProperties for a snapshot
// also see requirements in Bundlecontext.getProperty(...))
properties = new Properties();
// snapshot of System properties for uses of getProperties who expect to see framework properties set as System properties
// we need to do this for all system properties because the properties object is used to back
// BundleContext#getProperty method which expects all system properties to be available
synchronized (systemProperties) {
// bug 360198 - must synchronize on systemProperties to avoid concurrent modification exception
properties.putAll(systemProperties);
}
}
}
return properties;
} public static synchronized void setProperties(Map<String, String> input) {
if (input == null) {
// just use internal props; note that this will reuse a previous set of properties if they were set
internalGetProperties("false"); //$NON-NLS-1$
return;
}
properties = null;
Properties toSet = internalGetProperties("false"); //$NON-NLS-1$
for (Iterator<String> keys = input.keySet().iterator(); keys.hasNext();) {
String key = keys.next();
Object value = input.get(key);
if (value instanceof String) {
toSet.setProperty(key, (String) value);
continue;
}
value = input.get(key);
if (value != null)
toSet.put(key, value);
else
toSet.remove(key);
}
} public static synchronized boolean inUse() {
return properties != null;
} public static void initializeProperties() {
// initialize some framework properties that must always be set
if (getProperty(PROP_FRAMEWORK) == null || getProperty(PROP_INSTALL_AREA) == null) {
CodeSource cs = FrameworkProperties.class.getProtectionDomain().getCodeSource();
if (cs == null)
throw new IllegalArgumentException(NLS.bind(EclipseAdaptorMsg.ECLIPSE_STARTUP_PROPS_NOT_SET, PROP_FRAMEWORK + ", " + PROP_INSTALL_AREA)); //$NON-NLS-1$
URL url = cs.getLocation();
// allow props to be preset
if (getProperty(PROP_FRAMEWORK) == null)
setProperty(PROP_FRAMEWORK, url.toExternalForm());
if (getProperty(PROP_INSTALL_AREA) == null) {
String filePart = url.getFile();
setProperty(PROP_INSTALL_AREA, filePart.substring(0, filePart.lastIndexOf('/')));
}
}
// always decode these properties
setProperty(PROP_FRAMEWORK, decode(getProperty(PROP_FRAMEWORK)));
setProperty(PROP_INSTALL_AREA, decode(getProperty(PROP_INSTALL_AREA)));
} public static String decode(String urlString) {
//try to use Java 1.4 method if available
try {
Class<? extends URLDecoder> clazz = URLDecoder.class;
Method method = clazz.getDeclaredMethod("decode", new Class[] {String.class, String.class}); //$NON-NLS-1$
//first encode '+' characters, because URLDecoder incorrectly converts
//them to spaces on certain class library implementations.
if (urlString.indexOf('+') >= 0) {
int len = urlString.length();
StringBuffer buf = new StringBuffer(len);
for (int i = 0; i < len; i++) {
char c = urlString.charAt(i);
if (c == '+')
buf.append("%2B"); //$NON-NLS-1$
else
buf.append(c);
}
urlString = buf.toString();
}
Object result = method.invoke(null, new Object[] {urlString, "UTF-8"}); //$NON-NLS-1$
if (result != null)
return (String) result;
} catch (Exception e) {
//JDK 1.4 method not found -- fall through and decode by hand
}
//decode URL by hand
boolean replaced = false;
byte[] encodedBytes = urlString.getBytes();
int encodedLength = encodedBytes.length;
byte[] decodedBytes = new byte[encodedLength];
int decodedLength = 0;
for (int i = 0; i < encodedLength; i++) {
byte b = encodedBytes[i];
if (b == '%') {
byte enc1 = encodedBytes[++i];
byte enc2 = encodedBytes[++i];
b = (byte) ((hexToByte(enc1) << 4) + hexToByte(enc2));
replaced = true;
}
decodedBytes[decodedLength++] = b;
}
if (!replaced)
return urlString;
try {
return new String(decodedBytes, 0, decodedLength, "UTF-8"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
//use default encoding
return new String(decodedBytes, 0, decodedLength);
}
} private static int hexToByte(byte b) {
switch (b) {
case '0' :
return 0;
case '1' :
return 1;
case '2' :
return 2;
case '3' :
return 3;
case '4' :
return 4;
case '5' :
return 5;
case '6' :
return 6;
case '7' :
return 7;
case '8' :
return 8;
case '9' :
return 9;
case 'A' :
case 'a' :
return 10;
case 'B' :
case 'b' :
return 11;
case 'C' :
case 'c' :
return 12;
case 'D' :
case 'd' :
return 13;
case 'E' :
case 'e' :
return 14;
case 'F' :
case 'f' :
return 15;
default :
throw new IllegalArgumentException("Switch error decoding URL"); //$NON-NLS-1$
}
}
}FrameworkProperties
package org.eclipse.osgi.framework.internal.core; import java.io.*;
import java.net.URL;
import java.security.*;
import java.security.cert.X509Certificate;
import java.util.*;
import org.eclipse.core.runtime.adaptor.EclipseStarter;
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
import org.osgi.framework.*; public class EquinoxLauncher implements org.osgi.framework.launch.Framework { private volatile Framework framework;
private volatile Bundle systemBundle;
private final Map<String, String> configuration;
private volatile ConsoleManager consoleMgr = null; public EquinoxLauncher(Map<String, String> configuration) {
this.configuration = configuration;
}
public void init() {
checkAdminPermission(AdminPermission.EXECUTE);
if (System.getSecurityManager() == null)
internalInit();
else {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
internalInit();
return null;
}
});
}
}
synchronized Framework internalInit() {
if ((getState() & (Bundle.ACTIVE | Bundle.STARTING | Bundle.STOPPING)) != 0)
return framework; // no op if (System.getSecurityManager() != null && configuration.get(Constants.FRAMEWORK_SECURITY) != null)
throw new SecurityException("Cannot specify the \"" + Constants.FRAMEWORK_SECURITY + "\" configuration property when a security manager is already installed."); //$NON-NLS-1$ //$NON-NLS-2$ Framework current = framework;
if (current != null) {
current.close();
framework = null;
systemBundle = null;
}
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
FrameworkProperties.setProperties(configuration);
FrameworkProperties.initializeProperties();
// make sure the active framework thread is used
setEquinoxProperties(configuration);
current = new Framework(new BaseAdaptor(new String[0]));
consoleMgr = ConsoleManager.startConsole(current);
current.launch();
framework = current;
systemBundle = current.systemBundle;
} finally {
ClassLoader currentCCL = Thread.currentThread().getContextClassLoader();
if (currentCCL != tccl)
Thread.currentThread().setContextClassLoader(tccl);
}
return current;
}
private void setEquinoxProperties(Map<String, String> configuration) {
Object threadBehavior = configuration == null ? null : configuration.get(Framework.PROP_FRAMEWORK_THREAD);
if (threadBehavior == null) {
if (FrameworkProperties.getProperty(Framework.PROP_FRAMEWORK_THREAD) == null)
FrameworkProperties.setProperty(Framework.PROP_FRAMEWORK_THREAD, Framework.THREAD_NORMAL);
} else {
FrameworkProperties.setProperty(Framework.PROP_FRAMEWORK_THREAD, (String) threadBehavior);
} // set the compatibility boot delegation flag to false to get "standard" OSGi behavior WRT boot delegation (bug 344850)
if (FrameworkProperties.getProperty(Constants.OSGI_COMPATIBILITY_BOOTDELEGATION) == null)
FrameworkProperties.setProperty(Constants.OSGI_COMPATIBILITY_BOOTDELEGATION, "false"); //$NON-NLS-1$
// set the support for multiple host to true to get "standard" OSGi behavior (bug 344850)
if (FrameworkProperties.getProperty("osgi.support.multipleHosts") == null) //$NON-NLS-1$
FrameworkProperties.setProperty("osgi.support.multipleHosts", "true"); //$NON-NLS-1$ //$NON-NLS-2$
// first check props we are required to provide reasonable defaults for
Object windowSystem = configuration == null ? null : configuration.get(Constants.FRAMEWORK_WINDOWSYSTEM);
if (windowSystem == null) {
windowSystem = FrameworkProperties.getProperty(EclipseStarter.PROP_WS);
if (windowSystem != null)
FrameworkProperties.setProperty(Constants.FRAMEWORK_WINDOWSYSTEM, (String) windowSystem);
}
// rest of props can be ignored if the configuration is null
if (configuration == null)
return;
// check each osgi clean property and set the appropriate equinox one
Object clean = configuration.get(Constants.FRAMEWORK_STORAGE_CLEAN);
if (Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT.equals(clean)) {
// remove this so we only clean on first init
configuration.remove(Constants.FRAMEWORK_STORAGE_CLEAN);
FrameworkProperties.setProperty(EclipseStarter.PROP_CLEAN, Boolean.TRUE.toString());
}
}
public FrameworkEvent waitForStop(long timeout) throws InterruptedException {
Framework current = framework;
if (current == null)
return new FrameworkEvent(FrameworkEvent.STOPPED, this, null);
return current.waitForStop(timeout);
}
public Enumeration<URL> findEntries(String path, String filePattern, boolean recurse) {
Bundle current = systemBundle;
if (current == null)
return null;
return current.findEntries(path, filePattern, recurse);
}
public BundleContext getBundleContext() {
Bundle current = systemBundle;
if (current == null)
return null;
return current.getBundleContext();
}
public long getBundleId() {
return 0;
}
public URL getEntry(String path) {
Bundle current = systemBundle;
if (current == null)
return null;
return current.getEntry(path);
}
public Enumeration<String> getEntryPaths(String path) {
Bundle current = systemBundle;
if (current == null)
return null;
return current.getEntryPaths(path);
}
public Dictionary<String, String> getHeaders() {
Bundle current = systemBundle;
if (current == null)
return null;
return current.getHeaders();
}
public Dictionary<String, String> getHeaders(String locale) {
Bundle current = systemBundle;
if (current == null)
return null;
return current.getHeaders(locale);
}
public long getLastModified() {
Bundle current = systemBundle;
if (current == null)
return System.currentTimeMillis();
return current.getLastModified();
}
public String getLocation() {
return Constants.SYSTEM_BUNDLE_LOCATION;
}
public ServiceReference<?>[] getRegisteredServices() {
Bundle current = systemBundle;
if (current == null)
return null;
return current.getRegisteredServices();
}
public URL getResource(String name) {
Bundle current = systemBundle;
if (current == null)
return null;
return current.getResource(name);
}
public Enumeration<URL> getResources(String name) throws IOException {
Bundle current = systemBundle;
if (current == null)
return null;
return current.getResources(name);
}
public ServiceReference<?>[] getServicesInUse() {
Bundle current = systemBundle;
if (current == null)
return null;
return current.getServicesInUse();
}
public int getState() {
Bundle current = systemBundle;
if (current == null)
return Bundle.INSTALLED;
return current.getState();
}
public String getSymbolicName() {
return FrameworkAdaptor.FRAMEWORK_SYMBOLICNAME;
}
public boolean hasPermission(Object permission) {
Bundle current = systemBundle;
if (current == null)
return false;
return current.hasPermission(permission);
}
public Class<?> loadClass(String name) throws ClassNotFoundException {
Bundle current = systemBundle;
if (current == null)
return null;
return current.loadClass(name);
}
public void start(int options) throws BundleException {
start();
}
public void start() throws BundleException {
checkAdminPermission(AdminPermission.EXECUTE);
if (System.getSecurityManager() == null)
internalStart();
else
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
public Object run() {
internalStart();
return null;
}
});
} catch (PrivilegedActionException e) {
throw (BundleException) e.getException();
}
}
private void checkAdminPermission(String actions) {
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPermission(new AdminPermission(this, actions));
}
void internalStart() {
if (getState() == Bundle.ACTIVE)
return;
Framework current = internalInit();
int level = 1;
try {
level = Integer.parseInt(configuration.get(Constants.FRAMEWORK_BEGINNING_STARTLEVEL));
} catch (Throwable t) {
// do nothing
}
current.startLevelManager.doSetStartLevel(level);
}
public void stop(int options) throws BundleException {
stop();
}
public void stop() throws BundleException {
Bundle current = systemBundle;
if (current == null)
return;
ConsoleManager currentConsole = consoleMgr;
if (currentConsole != null) {
currentConsole.stopConsole();
consoleMgr = null;
}
current.stop();
}
public void uninstall() throws BundleException {
throw new BundleException(Msg.BUNDLE_SYSTEMBUNDLE_UNINSTALL_EXCEPTION, BundleException.INVALID_OPERATION);
}
public void update() throws BundleException {
Bundle current = systemBundle;
if (current == null)
return;
current.update();
}
public void update(InputStream in) throws BundleException {
try {
in.close();
} catch (IOException e) {
// nothing; just being nice
}
update();
}
public Map<X509Certificate, List<X509Certificate>> getSignerCertificates(int signersType) {
Bundle current = systemBundle;
if (current != null)
return current.getSignerCertificates(signersType);
@SuppressWarnings("unchecked")
final Map<X509Certificate, List<X509Certificate>> empty = Collections.EMPTY_MAP;
return empty;
}
public Version getVersion() {
Bundle current = systemBundle;
if (current != null)
return current.getVersion();
return Version.emptyVersion;
}
public <A> A adapt(Class<A> adapterType) {
Bundle current = systemBundle;
if (current != null) {
return current.adapt(adapterType);
}
return null;
}
public int compareTo(Bundle o) {
Bundle current = systemBundle;
if (current != null)
return current.compareTo(o);
throw new IllegalStateException();
}
public File getDataFile(String filename) {
Bundle current = systemBundle;
if (current != null)
return current.getDataFile(filename);
return null;
}
}EquinoxLauncher
Methods in EquixonLauncher
public EquinoxLauncher(Map<String, String> configuration) {
this.configuration = configuration;
}public void init() {
checkAdminPermission(AdminPermission.EXECUTE);
if (System.getSecurityManager() == null)
internalInit();
else {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
internalInit();
return null;
}
});
}
}
synchronized Framework internalInit() {
if ((getState() & (Bundle.ACTIVE | Bundle.STARTING | Bundle.STOPPING)) != 0)
return framework; // no op if (System.getSecurityManager() != null && configuration.get(Constants.FRAMEWORK_SECURITY) != null)
throw new SecurityException("Cannot specify the \"" + Constants.FRAMEWORK_SECURITY + "\" configuration property when a security manager is already installed."); //$NON-NLS-1$ //$NON-NLS-2$ Framework current = framework;
if (current != null) {
current.close();
framework = null;
systemBundle = null;
}
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
FrameworkProperties.setProperties(configuration);
FrameworkProperties.initializeProperties();
// make sure the active framework thread is used
setEquinoxProperties(configuration);
current = new Framework(new BaseAdaptor(new String[0]));
consoleMgr = ConsoleManager.startConsole(current);
current.launch();
framework = current;
systemBundle = current.systemBundle;
} finally {
ClassLoader currentCCL = Thread.currentThread().getContextClassLoader();
if (currentCCL != tccl)
Thread.currentThread().setContextClassLoader(tccl);
}
return current;
}public static ConsoleManager startConsole(Framework framework) {
ConsoleManager consoleManager = new ConsoleManager(framework, FrameworkProperties.getProperty(PROP_CONSOLE));
consoleManager.startConsole();
return consoleManager;
}public synchronized void launch() {
/* Return if framework already started */
if (active) {
return;
}
/* mark framework as started */
active = true;
shutdownEvent = new FrameworkEvent[1];
if (THREAD_NORMAL.equals(FrameworkProperties.getProperty(PROP_FRAMEWORK_THREAD, THREAD_NORMAL))) {
Thread fwkThread = new Thread(this, "Framework Active Thread"); //$NON-NLS-1$
fwkThread.setDaemon(false);
fwkThread.start();
}
/* Resume systembundle */
if (Debug.DEBUG_GENERAL) {
Debug.println("Trying to launch framework"); //$NON-NLS-1$
}
systemBundle.resume();
signedContentFactory = new ServiceTracker<SignedContentFactory, SignedContentFactory>(systemBundle.getBundleContext(), SignedContentFactory.class.getName(), null);
signedContentFactory.open();
}public void run() {
synchronized (this) {
while (active)
try {
this.wait(1000);
} catch (InterruptedException e) {
// do nothing
}
}
}private void createSystemBundle() {
try {
systemBundle = new InternalSystemBundle(this);
systemBundle.getBundleData().setBundle(systemBundle);
} catch (BundleException e) { // fatal error
e.printStackTrace();
throw new RuntimeException(NLS.bind(Msg.OSGI_SYSTEMBUNDLE_CREATE_EXCEPTION, e.getMessage()), e);
}
}protected InternalSystemBundle(Framework framework) throws BundleException {
super(framework.adaptor.createSystemBundleData(), framework); // startlevel=0 means framework stopped
Constants.setInternalSymbolicName(bundledata.getSymbolicName());
state = Bundle.RESOLVED;
context = createContext();
fsl = new EquinoxStartLevel();
}- org.eclipse.core.launcher
package org.eclipse.core.launcher;
public class Main {
public static void main(String[] args) {
org.eclipse.equinox.launcher.Main.main(args);
}
}- org.eclipse.equinox.launcher.Main.java
- Methods in Main.java
public static void main(String[] args) {
int result = 0;
try {
result = new Main().run(args);
} catch (Throwable t) {
// This is *really* unlikely to happen - run() takes care of exceptional situations.
// In case something weird happens, just dump stack - logging is not available at this point
t.printStackTrace();
} finally {
if (!Boolean.getBoolean(PROP_NOSHUTDOWN))
// make sure we always terminate the VM
System.exit(result);
}
}public int run(String[] args) {
int result = 0;
try {
basicRun(args);
String exitCode = System.getProperty(PROP_EXITCODE);
try {
result = exitCode == null ? 0 : Integer.parseInt(exitCode);
} catch (NumberFormatException e) {
result = 17;
}
} catch (Throwable e) {
// only log the exceptions if they have not been caught by the
// EclipseStarter (i.e., if the exitCode is not 13)
if (!"13".equals(System.getProperty(PROP_EXITCODE))) { //$NON-NLS-1$
log("Exception launching the Eclipse Platform:"); //$NON-NLS-1$
log(e);
String message = "An error has occurred"; //$NON-NLS-1$
if (logFile == null)
message += " and could not be logged: \n" + e.getMessage(); //$NON-NLS-1$
else
message += ". See the log file\n" + logFile.getAbsolutePath(); //$NON-NLS-1$
System.getProperties().put(PROP_EXITDATA, message);
}
// Return "unlucky" 13 as the exit code. The executable will recognize
// this constant and display a message to the user telling them that
// there is information in their log file.
result = 13;
} finally {
// always try putting down the splash screen just in case the application failed to do so
takeDownSplash();
if (bridge != null)
bridge.uninitialize();
}
// Return an int exit code and ensure the system property is set.
System.getProperties().put(PROP_EXITCODE, Integer.toString(result));
setExitData();
return result;
}protected void basicRun(String[] args) throws Exception {
System.getProperties().put("eclipse.startTime", Long.toString(System.currentTimeMillis())); //$NON-NLS-1$
commands = args;
String[] passThruArgs = processCommandLine(args); if (!debug)
// debug can be specified as system property as well
debug = System.getProperty(PROP_DEBUG) != null;
setupVMProperties();
processConfiguration(); // need to ensure that getInstallLocation is called at least once to initialize the value.
// Do this AFTER processing the configuration to allow the configuration to set
// the install location.
getInstallLocation(); // locate boot plugin (may return -dev mode variations)
URL[] bootPath = getBootPath(bootLocation); //Set up the JNI bridge. We need to know the install location to find the shared library
setupJNI(bootPath); //ensure minimum Java version, do this after JNI is set up so that we can write an error message
//with exitdata if we fail.
if (!checkVersion(System.getProperty("java.version"), System.getProperty(PROP_REQUIRED_JAVA_VERSION))) //$NON-NLS-1$
return; // verify configuration location is writable
if (!checkConfigurationLocation(configurationLocation))
return; setSecurityPolicy(bootPath);
// splash handling is done here, because the default case needs to know
// the location of the boot plugin we are going to use
handleSplash(bootPath); beforeFwkInvocation();
invokeFramework(passThruArgs, bootPath);
}
Eclipse equinox implementation of OSGi的更多相关文章
- Eclipse Equinox DS(Declarative Service)
Equinox DS's METE-INF/MANIFEST.MF Manifest-Version: 1.0 Lazy-ManifestFilter: (Service-Component=*) B ...
- OSGiBundle出现 Could not find bundle: org.eclipse.equinox.console的解决方案
按照网上教程创建OSGI HelloWorld实例配置run configuration时出现Could not find bundle: org.eclipse.equinox.console 和C ...
- 解决:“Workbench has not been created yet” error in eclipse plugin programming”,OSGI启动控制台报错问题
项目中使用了OSGI的框架,最近被问到OSGI框架是什么,自己表示几乎没什么认识,于是想自己手动搭建一个OSGI小例子试一试 于是在搭建过程中遇到了下面的问题:项目启动很慢而且控制台也报了很多异常出来 ...
- OSGI企业应用开发(三)Eclipse中搭建Equinox运行环境
上篇文章介绍了如何在Eclipse中搭建Felix的运行环境,我们需要將Bundle发布到Felix框架的bundle目录下,Felix框架启动时才会自动加载这些Bundle,否则需要在Felix框架 ...
- 基于Equinox构建OSGi项目
几种OSGi框架 Several independently implemented OSGi frameworks exist today, including four that are avai ...
- Eclipse插件开发之基础篇(4) OSGi框架
转载出处:http://www.cnblogs.com/liuzhuo. 1. 什么是OSGi框架 OSGi(Open Service Gateway Initiative)框架是运行在JavaVM环 ...
- 基于 Equinox 的 OSGi Console 的研究和探索
自定制 OSGi Console 进行组建和服务生命周期管理模块化编程的好处已经很好地被理解了约 40 年,但在 OSGi 之前,开发人员不得不自己发明模块化设计和系统.随着软件应用体系结构的不断发展 ...
- OSGI在Eclipse中执行-console出错的问题
在Eclipse中安装osgi插件后,执行出现异常:
- 《深入理解OSGi:Equinox原理、应用与最佳实践》笔记_2_建立开发环境
本文对应书本5.1.3的内容 书本中通过CVS下载的源码 但是笔者实践的时候发现无法下载...地址已经失效了(也许是笔者的失误输错地址所致) 可以用git下载 地址是: http://git.ecli ...
随机推荐
- 4.jQuery和DOM 对象之间的相互转换
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- html基础知识,整理
# HMTL 基础知识 ###查看网页源代码吗 ``` ctrl + u``` ###dom元素 一个标签即代表一个dom元素 ###dom元素属性 ``` <p id ="first ...
- copy模拟
1.copy是浅复制,只复制一层:而deepcopy是所有层都复制,适用于lis嵌套listt的复制.两都均是函数.
- C++_类和动态内存分配5-使用指向对象的指针
再探new和delete new为创建的每一个对象的名称字符串分配存储空间,这是在构造函数中进行的: 析构函数使用delete来释放这些内存. 字符串是一个字符数组,所以析构函数使用的是带中括号的de ...
- [JLOI2015]管道连接(斯坦纳树)
[Luogu3264] 原题解 多个频道,每个频道的关键点要求相互联通 详见代码,非常巧妙 #include<cstdio> #include<iostream> #inclu ...
- 【算法笔记】B1024 科学计数法
1024 科学计数法 (20 分) 科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位, ...
- Codeforces - 570D 离散DFS序 特殊的子树统计 (暴力出奇迹)
题意:给定一棵树,树上每个节点有对应的字符,多次询问在\(u\)子树的深度为\(d\)的所有节点上的字符任意组合能否凑成一个回文串 把dfs序存储在一个二维线性表中,一个维度记录字符另一个维度记录深度 ...
- HDU - 2203 KMP水题
循环移位的套路操作就是一份折开变两份 /*H E A D*/ void match(){ int n=strlen(T+1); int m=strlen(P+1); int j=0; rep(i,1, ...
- [转] CSS3垂直手风琴折叠菜单
[From] http://www.html5tricks.com/css3-ver-accordion-menu.html 之前我们已经分享过很多关于手风琴菜单了,有水平方向的,也有垂直方向的.今天 ...
- 初用msui.js
MSui,基于 Framework7 开发,组件功能使用Zepto库提供.定位轻量级的ui库 简单的使用MSui组件只需要引入所提供的CDN则可 <link rel="styleshe ...