Eclipse equinox implementation of OSGi

  • Bundle
  •  1 package org.osgi.framework;
     2 public interface Bundle extends Comparable<Bundle> {    
     3     int    UNINSTALLED                = 0x00000001;
     4     int    INSTALLED                = 0x00000002;
     5     int    RESOLVED                = 0x00000004;
     6     int    STARTING                = 0x00000008;
     7     int    STOPPING                = 0x00000010;
     8     int    ACTIVE                    = 0x00000020;
     9     int    START_TRANSIENT            = 0x00000001;
    10     int    START_ACTIVATION_POLICY    = 0x00000002;
    11     int    STOP_TRANSIENT            = 0x00000001;
    12     int    SIGNERS_ALL                = 1;
    13     int    SIGNERS_TRUSTED            = 2;
    14     int getState();
    15     voidstart(int options) throws BundleException;
    16     void start() throws BundleException;
    17     voidstop(int options) throws BundleException;
    18     void stop() throws BundleException;
    19     void update(InputStream input) throws BundleException;
    20     void update() throws BundleException;
    21     void uninstall() throws BundleException;
    22     Dictionary<String, String> getHeaders();
    23     long getBundleId();
    24     String getLocation();
    25     ServiceReference<?>[] getRegisteredServices();
    26     ServiceReference<?>[] getServicesInUse();
    27     boolean hasPermission(Object permission);
    28     URL getResource(String name);
    29     Enumeration<String> getEntryPaths(String path);
    30     URL getEntry(String path);
    31     long getLastModified();
    32     Enumeration<URL> findEntries(String path, String filePattern, boolean recurse);
    33     BundleContext getBundleContext();
    34     Map<X509Certificate, List<X509Certificate>> getSignerCertificates(int signersType);
    35     Version getVersion();
    36     <A> A adapt(Class<A> type);
    37     File getDataFile(String filename);
    38 }
  • Framework: also known as Bundle
  •  1 package org.osgi.framework.launch;
     2 
     3 import java.io.InputStream;
     4 import java.net.URL;
     5 import java.util.Enumeration;
     6 import org.osgi.framework.Bundle;
     7 import org.osgi.framework.BundleException;
     8 import org.osgi.framework.Constants;
     9 import org.osgi.framework.FrameworkEvent;
    10 public interface Framework extends Bundle {
    11     void init() throws BundleException;
    12     FrameworkEvent waitForStop(long timeout) throws InterruptedException;
    13     void start() throws BundleException;
    14     void start(int options) throws BundleException;
    15     void stop() throws BundleException;
    16     void stop(int options) throws BundleException;
    17     void uninstall() throws BundleException;
    18     void update() throws BundleException;
    19     void update(InputStream in) throws BundleException;
    20     long getBundleId();
    21     String getLocation();
    22     String getSymbolicName();
    23     Enumeration<String> getEntryPaths(String path);
    24     URL getEntry(String path);
    25     Enumeration<URL> findEntries(String path, String filePattern, boolean recurse);
    26     <A> A adapt(Class<A> type);
    27 }
  • FrameworkFactory
  •  1 package org.osgi.framework.launch;
     2 import java.util.Map;
     3 import org.osgi.framework.Bundle;
     4 /**
     5  * A factory for creating {@link Framework} instances. 
     6  * @ThreadSafe
     7  * @noimplement
     8  * @version $Id: 1684e14aa98a1f6e1ff3e0f3afa2c55982210f72 $
     9  */
    10 public interface FrameworkFactory {
    11     Framework newFramework(Map<String, String> configuration);
    12 }
  • EquinoxLauncher: implement the interface of Framework

Configuration

 

dev.properties

1 #
2 #Wed Sep 11 08:37:19 CST 2013
3 com.dragon.osgi.hello=bin
4 @ignoredot@=true

           config.ini          

1 #Configuration File
2 #Wed Sep 11 08:37:19 CST 2013
3 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
4 osgi.bundles.defaultStartLevel=4
5 osgi.install.area=file\:G\:\\eclipse\\eclipse
6 osgi.framework=file\:G\:/eclipse/eclipse/plugins/org.eclipse.osgi_3.8.0.v20120529-1548.jar
7 osgi.configuration.cascaded=false

 

  •   1 /*******************************************************************************
      2  * Copyright (c) 2006, 2011 Cognos Incorporated, IBM Corporation and others.
      3  * All rights reserved. This program and the accompanying materials
      4  * are made available under the terms of the Eclipse Public License v1.0
      5  * which accompanies this distribution, and is available at
      6  * http://www.eclipse.org/legal/epl-v10.html
      7  * 
      8  *******************************************************************************/
      9 package org.eclipse.osgi.framework.internal.core;
     10 
     11 import java.io.UnsupportedEncodingException;
     12 import java.lang.reflect.Method;
     13 import java.net.URL;
     14 import java.net.URLDecoder;
     15 import java.security.CodeSource;
     16 import java.util.*;
     17 import org.eclipse.core.runtime.internal.adaptor.EclipseAdaptorMsg;
     18 import org.eclipse.osgi.util.NLS;
     19 
     20 /*
     21  * This class should be used in ALL places in the framework implementation to get "system" properties.
     22  * The static methods on this class should be used instead of the System#getProperty, System#setProperty etc methods.
     23  */
     24 public class FrameworkProperties {
     25 
     26     /**@GuardedBy FrameworkProperties.class*/
     27     private static Properties properties;
     28 
     29     // A flag of some sort will have to be supported. 
     30     // Many existing plugins get framework propeties directly from System instead of BundleContext. 
     31     // 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.
     32     private static final String USING_SYSTEM_PROPERTIES_KEY = "osgi.framework.useSystemProperties"; //$NON-NLS-1$
     33     private static final String PROP_FRAMEWORK = "osgi.framework"; //$NON-NLS-1$
     34     private static final String PROP_INSTALL_AREA = "osgi.install.area"; //$NON-NLS-1$
     35 
     36     public static Properties getProperties() {
     37         SecurityManager sm = System.getSecurityManager();
     38         if (sm != null)
     39             sm.checkPropertiesAccess();
     40         return internalGetProperties(null);
     41     }
     42 
     43     public static String getProperty(String key) {
     44         return getProperty(key, null);
     45     }
     46 
     47     public static String getProperty(String key, String defaultValue) {
     48         SecurityManager sm = System.getSecurityManager();
     49         if (sm != null)
     50             sm.checkPropertyAccess(key);
     51         return internalGetProperties(null).getProperty(key, defaultValue);
     52     }
     53 
     54     public static String setProperty(String key, String value) {
     55         SecurityManager sm = System.getSecurityManager();
     56         if (sm != null)
     57             sm.checkPermission(new PropertyPermission(key, "write")); //$NON-NLS-1$
     58         return (String) internalGetProperties(null).put(key, value);
     59     }
     60 
     61     public static String clearProperty(String key) {
     62         SecurityManager sm = System.getSecurityManager();
     63         if (sm != null)
     64             sm.checkPermission(new PropertyPermission(key, "write")); //$NON-NLS-1$
     65         return (String) internalGetProperties(null).remove(key);
     66     }
     67 
     68     private static synchronized Properties internalGetProperties(String usingSystemProperties) {
     69         if (properties == null) {
     70             Properties systemProperties = System.getProperties();
     71             if (usingSystemProperties == null)
     72                 usingSystemProperties = systemProperties.getProperty(USING_SYSTEM_PROPERTIES_KEY);
     73             if (usingSystemProperties == null || usingSystemProperties.equalsIgnoreCase(Boolean.TRUE.toString())) {
     74                 properties = systemProperties;
     75             } else {
     76                 // use systemProperties for a snapshot
     77                 // also see requirements in Bundlecontext.getProperty(...))
     78                 properties = new Properties();
     79                 // snapshot of System properties for uses of getProperties who expect to see framework properties set as System properties
     80                 // we need to do this for all system properties because the properties object is used to back
     81                 // BundleContext#getProperty method which expects all system properties to be available
     82                 synchronized (systemProperties) {
     83                     // bug 360198 - must synchronize on systemProperties to avoid concurrent modification exception
     84                     properties.putAll(systemProperties);
     85                 }
     86             }
     87         }
     88         return properties;
     89     }
     90 
     91     public static synchronized void setProperties(Map<String, String> input) {
     92         if (input == null) {
     93             // just use internal props;  note that this will reuse a previous set of properties if they were set
     94             internalGetProperties("false"); //$NON-NLS-1$
     95             return;
     96         }
     97         properties = null;
     98         Properties toSet = internalGetProperties("false"); //$NON-NLS-1$
     99         for (Iterator<String> keys = input.keySet().iterator(); keys.hasNext();) {
    100             String key = keys.next();
    101             Object value = input.get(key);
    102             if (value instanceof String) {
    103                 toSet.setProperty(key, (String) value);
    104                 continue;
    105             }
    106             value = input.get(key);
    107             if (value != null)
    108                 toSet.put(key, value);
    109             else
    110                 toSet.remove(key);
    111         }
    112     }
    113 
    114     public static synchronized boolean inUse() {
    115         return properties != null;
    116     }
    117 
    118     public static void initializeProperties() {
    119         // initialize some framework properties that must always be set
    120         if (getProperty(PROP_FRAMEWORK) == null || getProperty(PROP_INSTALL_AREA) == null) {
    121             CodeSource cs = FrameworkProperties.class.getProtectionDomain().getCodeSource();
    122             if (cs == null)
    123                 throw new IllegalArgumentException(NLS.bind(EclipseAdaptorMsg.ECLIPSE_STARTUP_PROPS_NOT_SET, PROP_FRAMEWORK + ", " + PROP_INSTALL_AREA)); //$NON-NLS-1$
    124             URL url = cs.getLocation();
    125             // allow props to be preset
    126             if (getProperty(PROP_FRAMEWORK) == null)
    127                 setProperty(PROP_FRAMEWORK, url.toExternalForm());
    128             if (getProperty(PROP_INSTALL_AREA) == null) {
    129                 String filePart = url.getFile();
    130                 setProperty(PROP_INSTALL_AREA, filePart.substring(0, filePart.lastIndexOf('/')));
    131             }
    132         }
    133         // always decode these properties
    134         setProperty(PROP_FRAMEWORK, decode(getProperty(PROP_FRAMEWORK)));
    135         setProperty(PROP_INSTALL_AREA, decode(getProperty(PROP_INSTALL_AREA)));
    136     }
    137 
    138     public static String decode(String urlString) {
    139         //try to use Java 1.4 method if available
    140         try {
    141             Class<? extends URLDecoder> clazz = URLDecoder.class;
    142             Method method = clazz.getDeclaredMethod("decode", new Class[] {String.class, String.class}); //$NON-NLS-1$
    143             //first encode '+' characters, because URLDecoder incorrectly converts 
    144             //them to spaces on certain class library implementations.
    145             if (urlString.indexOf('+') >= 0) {
    146                 int len = urlString.length();
    147                 StringBuffer buf = new StringBuffer(len);
    148                 for (int i = 0; i < len; i++) {
    149                     char c = urlString.charAt(i);
    150                     if (c == '+')
    151                         buf.append("%2B"); //$NON-NLS-1$
    152                     else
    153                         buf.append(c);
    154                 }
    155                 urlString = buf.toString();
    156             }
    157             Object result = method.invoke(null, new Object[] {urlString, "UTF-8"}); //$NON-NLS-1$
    158             if (result != null)
    159                 return (String) result;
    160         } catch (Exception e) {
    161             //JDK 1.4 method not found -- fall through and decode by hand
    162         }
    163         //decode URL by hand
    164         boolean replaced = false;
    165         byte[] encodedBytes = urlString.getBytes();
    166         int encodedLength = encodedBytes.length;
    167         byte[] decodedBytes = new byte[encodedLength];
    168         int decodedLength = 0;
    169         for (int i = 0; i < encodedLength; i++) {
    170             byte b = encodedBytes[i];
    171             if (b == '%') {
    172                 byte enc1 = encodedBytes[++i];
    173                 byte enc2 = encodedBytes[++i];
    174                 b = (byte) ((hexToByte(enc1) << 4) + hexToByte(enc2));
    175                 replaced = true;
    176             }
    177             decodedBytes[decodedLength++] = b;
    178         }
    179         if (!replaced)
    180             return urlString;
    181         try {
    182             return new String(decodedBytes, 0, decodedLength, "UTF-8"); //$NON-NLS-1$
    183         } catch (UnsupportedEncodingException e) {
    184             //use default encoding
    185             return new String(decodedBytes, 0, decodedLength);
    186         }
    187     }
    188 
    189     private static int hexToByte(byte b) {
    190         switch (b) {
    191             case '0' :
    192                 return 0;
    193             case '1' :
    194                 return 1;
    195             case '2' :
    196                 return 2;
    197             case '3' :
    198                 return 3;
    199             case '4' :
    200                 return 4;
    201             case '5' :
    202                 return 5;
    203             case '6' :
    204                 return 6;
    205             case '7' :
    206                 return 7;
    207             case '8' :
    208                 return 8;
    209             case '9' :
    210                 return 9;
    211             case 'A' :
    212             case 'a' :
    213                 return 10;
    214             case 'B' :
    215             case 'b' :
    216                 return 11;
    217             case 'C' :
    218             case 'c' :
    219                 return 12;
    220             case 'D' :
    221             case 'd' :
    222                 return 13;
    223             case 'E' :
    224             case 'e' :
    225                 return 14;
    226             case 'F' :
    227             case 'f' :
    228                 return 15;
    229             default :
    230                 throw new IllegalArgumentException("Switch error decoding URL"); //$NON-NLS-1$
    231         }
    232     }
    233 }
    FrameworkProperties
  •   1 package org.eclipse.osgi.framework.internal.core;
      2 
      3 import java.io.*;
      4 import java.net.URL;
      5 import java.security.*;
      6 import java.security.cert.X509Certificate;
      7 import java.util.*;
      8 import org.eclipse.core.runtime.adaptor.EclipseStarter;
      9 import org.eclipse.osgi.baseadaptor.BaseAdaptor;
     10 import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
     11 import org.osgi.framework.*;
     12 
     13 public class EquinoxLauncher implements org.osgi.framework.launch.Framework {
     14 
     15     private volatile Framework framework;
     16     private volatile Bundle systemBundle;
     17     private final Map<String, String> configuration;
     18     private volatile ConsoleManager consoleMgr = null;
     19 
     20     public EquinoxLauncher(Map<String, String> configuration) {
     21         this.configuration = configuration;
     22     }
     23     public void init() {
     24         checkAdminPermission(AdminPermission.EXECUTE);
     25         if (System.getSecurityManager() == null)
     26             internalInit();
     27         else {
     28             AccessController.doPrivileged(new PrivilegedAction<Object>() {
     29                 public Object run() {
     30                     internalInit();
     31                     return null;
     32                 }
     33             });
     34         }
     35     }
     36     synchronized Framework internalInit() {
     37         if ((getState() & (Bundle.ACTIVE | Bundle.STARTING | Bundle.STOPPING)) != 0)
     38             return framework; // no op
     39 
     40         if (System.getSecurityManager() != null && configuration.get(Constants.FRAMEWORK_SECURITY) != null)
     41             throw new SecurityException("Cannot specify the \"" + Constants.FRAMEWORK_SECURITY + "\" configuration property when a security manager is already installed."); //$NON-NLS-1$ //$NON-NLS-2$
     42 
     43         Framework current = framework;
     44         if (current != null) {
     45             current.close();
     46             framework = null;
     47             systemBundle = null;
     48         }
     49         ClassLoader tccl = Thread.currentThread().getContextClassLoader();
     50         try {
     51             FrameworkProperties.setProperties(configuration);
     52             FrameworkProperties.initializeProperties();
     53             // make sure the active framework thread is used
     54             setEquinoxProperties(configuration);
     55             current = new Framework(new BaseAdaptor(new String[0]));
     56             consoleMgr = ConsoleManager.startConsole(current);
     57             current.launch();
     58             framework = current;
     59             systemBundle = current.systemBundle;
     60         } finally {
     61             ClassLoader currentCCL = Thread.currentThread().getContextClassLoader();
     62             if (currentCCL != tccl)
     63                 Thread.currentThread().setContextClassLoader(tccl);
     64         }
     65         return current;
     66     }
     67     private void setEquinoxProperties(Map<String, String> configuration) {
     68         Object threadBehavior = configuration == null ? null : configuration.get(Framework.PROP_FRAMEWORK_THREAD);
     69         if (threadBehavior == null) {
     70             if (FrameworkProperties.getProperty(Framework.PROP_FRAMEWORK_THREAD) == null)
     71                 FrameworkProperties.setProperty(Framework.PROP_FRAMEWORK_THREAD, Framework.THREAD_NORMAL);
     72         } else {
     73             FrameworkProperties.setProperty(Framework.PROP_FRAMEWORK_THREAD, (String) threadBehavior);
     74         }
     75 
     76         // set the compatibility boot delegation flag to false to get "standard" OSGi behavior WRT boot delegation (bug 344850)
     77         if (FrameworkProperties.getProperty(Constants.OSGI_COMPATIBILITY_BOOTDELEGATION) == null)
     78             FrameworkProperties.setProperty(Constants.OSGI_COMPATIBILITY_BOOTDELEGATION, "false"); //$NON-NLS-1$
     79         // set the support for multiple host to true to get "standard" OSGi behavior (bug 344850)
     80         if (FrameworkProperties.getProperty("osgi.support.multipleHosts") == null) //$NON-NLS-1$
     81             FrameworkProperties.setProperty("osgi.support.multipleHosts", "true"); //$NON-NLS-1$ //$NON-NLS-2$
     82         // first check props we are required to provide reasonable defaults for
     83         Object windowSystem = configuration == null ? null : configuration.get(Constants.FRAMEWORK_WINDOWSYSTEM);
     84         if (windowSystem == null) {
     85             windowSystem = FrameworkProperties.getProperty(EclipseStarter.PROP_WS);
     86             if (windowSystem != null)
     87                 FrameworkProperties.setProperty(Constants.FRAMEWORK_WINDOWSYSTEM, (String) windowSystem);
     88         }
     89         // rest of props can be ignored if the configuration is null
     90         if (configuration == null)
     91             return;
     92         // check each osgi clean property and set the appropriate equinox one
     93         Object clean = configuration.get(Constants.FRAMEWORK_STORAGE_CLEAN);
     94         if (Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT.equals(clean)) {
     95             // remove this so we only clean on first init
     96             configuration.remove(Constants.FRAMEWORK_STORAGE_CLEAN);
     97             FrameworkProperties.setProperty(EclipseStarter.PROP_CLEAN, Boolean.TRUE.toString());
     98         }
     99     }
    100     public FrameworkEvent waitForStop(long timeout) throws InterruptedException {
    101         Framework current = framework;
    102         if (current == null)
    103             return new FrameworkEvent(FrameworkEvent.STOPPED, this, null);
    104         return current.waitForStop(timeout);
    105     }
    106     public Enumeration<URL> findEntries(String path, String filePattern, boolean recurse) {
    107         Bundle current = systemBundle;
    108         if (current == null)
    109             return null;
    110         return current.findEntries(path, filePattern, recurse);
    111     }
    112     public BundleContext getBundleContext() {
    113         Bundle current = systemBundle;
    114         if (current == null)
    115             return null;
    116         return current.getBundleContext();
    117     }
    118     public long getBundleId() {
    119         return 0;
    120     }
    121     public URL getEntry(String path) {
    122         Bundle current = systemBundle;
    123         if (current == null)
    124             return null;
    125         return current.getEntry(path);
    126     }
    127     public Enumeration<String> getEntryPaths(String path) {
    128         Bundle current = systemBundle;
    129         if (current == null)
    130             return null;
    131         return current.getEntryPaths(path);
    132     }
    133     public Dictionary<String, String> getHeaders() {
    134         Bundle current = systemBundle;
    135         if (current == null)
    136             return null;
    137         return current.getHeaders();
    138     }
    139     public Dictionary<String, String> getHeaders(String locale) {
    140         Bundle current = systemBundle;
    141         if (current == null)
    142             return null;
    143         return current.getHeaders(locale);
    144     }
    145     public long getLastModified() {
    146         Bundle current = systemBundle;
    147         if (current == null)
    148             return System.currentTimeMillis();
    149         return current.getLastModified();
    150     }
    151     public String getLocation() {
    152         return Constants.SYSTEM_BUNDLE_LOCATION;
    153     }
    154     public ServiceReference<?>[] getRegisteredServices() {
    155         Bundle current = systemBundle;
    156         if (current == null)
    157             return null;
    158         return current.getRegisteredServices();
    159     }
    160     public URL getResource(String name) {
    161         Bundle current = systemBundle;
    162         if (current == null)
    163             return null;
    164         return current.getResource(name);
    165     }
    166     public Enumeration<URL> getResources(String name) throws IOException {
    167         Bundle current = systemBundle;
    168         if (current == null)
    169             return null;
    170         return current.getResources(name);
    171     }
    172     public ServiceReference<?>[] getServicesInUse() {
    173         Bundle current = systemBundle;
    174         if (current == null)
    175             return null;
    176         return current.getServicesInUse();
    177     }
    178     public int getState() {
    179         Bundle current = systemBundle;
    180         if (current == null)
    181             return Bundle.INSTALLED;
    182         return current.getState();
    183     }
    184     public String getSymbolicName() {
    185         return FrameworkAdaptor.FRAMEWORK_SYMBOLICNAME;
    186     }
    187     public boolean hasPermission(Object permission) {
    188         Bundle current = systemBundle;
    189         if (current == null)
    190             return false;
    191         return current.hasPermission(permission);
    192     }
    193     public Class<?> loadClass(String name) throws ClassNotFoundException {
    194         Bundle current = systemBundle;
    195         if (current == null)
    196             return null;
    197         return current.loadClass(name);
    198     }
    199     public void start(int options) throws BundleException {
    200         start();
    201     }
    202     public void start() throws BundleException {
    203         checkAdminPermission(AdminPermission.EXECUTE);
    204         if (System.getSecurityManager() == null)
    205             internalStart();
    206         else
    207             try {
    208                 AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
    209                     public Object run() {
    210                         internalStart();
    211                         return null;
    212                     }
    213                 });
    214             } catch (PrivilegedActionException e) {
    215                 throw (BundleException) e.getException();
    216             }
    217     }
    218     private void checkAdminPermission(String actions) {
    219         SecurityManager sm = System.getSecurityManager();
    220         if (sm != null)
    221             sm.checkPermission(new AdminPermission(this, actions));
    222     }
    223     void internalStart() {
    224         if (getState() == Bundle.ACTIVE)
    225             return;
    226         Framework current = internalInit();
    227         int level = 1;
    228         try {
    229             level = Integer.parseInt(configuration.get(Constants.FRAMEWORK_BEGINNING_STARTLEVEL));
    230         } catch (Throwable t) {
    231             // do nothing
    232         }
    233         current.startLevelManager.doSetStartLevel(level);
    234     }
    235     public void stop(int options) throws BundleException {
    236         stop();
    237     }
    238     public void stop() throws BundleException {
    239         Bundle current = systemBundle;
    240         if (current == null)
    241             return;
    242         ConsoleManager currentConsole = consoleMgr;
    243         if (currentConsole != null) {
    244             currentConsole.stopConsole();
    245             consoleMgr = null;
    246         }
    247         current.stop();
    248     }
    249     public void uninstall() throws BundleException {
    250         throw new BundleException(Msg.BUNDLE_SYSTEMBUNDLE_UNINSTALL_EXCEPTION, BundleException.INVALID_OPERATION);
    251     }
    252     public void update() throws BundleException {
    253         Bundle current = systemBundle;
    254         if (current == null)
    255             return;
    256         current.update();
    257     }
    258     public void update(InputStream in) throws BundleException {
    259         try {
    260             in.close();
    261         } catch (IOException e) {
    262             // nothing; just being nice
    263         }
    264         update();
    265     }
    266     public Map<X509Certificate, List<X509Certificate>> getSignerCertificates(int signersType) {
    267         Bundle current = systemBundle;
    268         if (current != null)
    269             return current.getSignerCertificates(signersType);
    270         @SuppressWarnings("unchecked")
    271         final Map<X509Certificate, List<X509Certificate>> empty = Collections.EMPTY_MAP;
    272         return empty;
    273     }
    274     public Version getVersion() {
    275         Bundle current = systemBundle;
    276         if (current != null)
    277             return current.getVersion();
    278         return Version.emptyVersion;
    279     }
    280     public <A> A adapt(Class<A> adapterType) {
    281         Bundle current = systemBundle;
    282         if (current != null) {
    283             return current.adapt(adapterType);
    284         }
    285         return null;
    286     }
    287     public int compareTo(Bundle o) {
    288         Bundle current = systemBundle;
    289         if (current != null)
    290             return current.compareTo(o);
    291         throw new IllegalStateException();
    292     }
    293     public File getDataFile(String filename) {
    294         Bundle current = systemBundle;
    295         if (current != null)
    296             return current.getDataFile(filename);
    297         return null;
    298     }
    299 }
    EquinoxLauncher

    Methods in EquixonLauncher

  • 1 public EquinoxLauncher(Map<String, String> configuration) {
    2         this.configuration = configuration;
    3     }
     1 public void init() {
     2         checkAdminPermission(AdminPermission.EXECUTE);
     3         if (System.getSecurityManager() == null)
     4             internalInit();
     5         else {
     6             AccessController.doPrivileged(new PrivilegedAction<Object>() {
     7                 public Object run() {
     8                     internalInit();
     9                     return null;
    10                 }
    11             });
    12         }
    13     }
    14     synchronized Framework internalInit() {
    15         if ((getState() & (Bundle.ACTIVE | Bundle.STARTING | Bundle.STOPPING)) != 0)
    16             return framework; // no op
    17 
    18         if (System.getSecurityManager() != null && configuration.get(Constants.FRAMEWORK_SECURITY) != null)
    19             throw new SecurityException("Cannot specify the \"" + Constants.FRAMEWORK_SECURITY + "\" configuration property when a security manager is already installed."); //$NON-NLS-1$ //$NON-NLS-2$
    20 
    21         Framework current = framework;
    22         if (current != null) {
    23             current.close();
    24             framework = null;
    25             systemBundle = null;
    26         }
    27         ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    28         try {
    29             FrameworkProperties.setProperties(configuration);
    30             FrameworkProperties.initializeProperties();
    31             // make sure the active framework thread is used
    32             setEquinoxProperties(configuration);
    33             current = new Framework(new BaseAdaptor(new String[0]));
    34             consoleMgr = ConsoleManager.startConsole(current);
    35             current.launch();
    36             framework = current;
    37             systemBundle = current.systemBundle;
    38         } finally {
    39             ClassLoader currentCCL = Thread.currentThread().getContextClassLoader();
    40             if (currentCCL != tccl)
    41                 Thread.currentThread().setContextClassLoader(tccl);
    42         }
    43         return current;
    44     }
    1 public static ConsoleManager startConsole(Framework framework) {
    2         ConsoleManager consoleManager = new ConsoleManager(framework, FrameworkProperties.getProperty(PROP_CONSOLE));
    3         consoleManager.startConsole();
    4         return consoleManager;
    5     }
     1 public synchronized void launch() {
     2         /* Return if framework already started */
     3         if (active) {
     4             return;
     5         }
     6         /* mark framework as started */
     7         active = true;
     8         shutdownEvent = new FrameworkEvent[1];
     9         if (THREAD_NORMAL.equals(FrameworkProperties.getProperty(PROP_FRAMEWORK_THREAD, THREAD_NORMAL))) {
    10             Thread fwkThread = new Thread(this, "Framework Active Thread"); //$NON-NLS-1$
    11             fwkThread.setDaemon(false);
    12             fwkThread.start();
    13         }
    14         /* Resume systembundle */
    15         if (Debug.DEBUG_GENERAL) {
    16             Debug.println("Trying to launch framework"); //$NON-NLS-1$
    17         }
    18         systemBundle.resume();
    19         signedContentFactory = new ServiceTracker<SignedContentFactory, SignedContentFactory>(systemBundle.getBundleContext(), SignedContentFactory.class.getName(), null);
    20         signedContentFactory.open();
    21     } 
     1 public void run() {
     2         synchronized (this) {
     3             while (active)
     4                 try {
     5                     this.wait(1000);
     6                 } catch (InterruptedException e) {
     7                     // do nothing
     8                 }
     9         }
    10 }
    1 private void createSystemBundle() {
    2         try {
    3             systemBundle = new InternalSystemBundle(this);
    4             systemBundle.getBundleData().setBundle(systemBundle);
    5         } catch (BundleException e) { // fatal error
    6             e.printStackTrace();
    7             throw new RuntimeException(NLS.bind(Msg.OSGI_SYSTEMBUNDLE_CREATE_EXCEPTION, e.getMessage()), e);
    8         }
    9     }
    1 protected InternalSystemBundle(Framework framework) throws BundleException {
    2         super(framework.adaptor.createSystemBundleData(), framework); // startlevel=0 means framework stopped
    3         Constants.setInternalSymbolicName(bundledata.getSymbolicName());
    4         state = Bundle.RESOLVED;
    5         context = createContext();
    6         fsl = new EquinoxStartLevel();
    7     } 
  • org.eclipse.core.launcher
  • 1 package org.eclipse.core.launcher;
    2 public class Main {
    3     public static void main(String[] args) {
    4         org.eclipse.equinox.launcher.Main.main(args);
    5     }
    6 }
  • org.eclipse.equinox.launcher.Main.java
    • Methods in Main.java
    •  1 public static void main(String[] args) {
       2         int result = 0;
       3         try {
       4             result = new Main().run(args);
       5         } catch (Throwable t) {
       6             // This is *really* unlikely to happen - run() takes care of exceptional situations.
       7             // In case something weird happens, just dump stack - logging is not available at this point
       8             t.printStackTrace();
       9         } finally {
      10             if (!Boolean.getBoolean(PROP_NOSHUTDOWN))
      11                 // make sure we always terminate the VM
      12                 System.exit(result);
      13         }
      14     }
       1     public int run(String[] args) {
       2         int result = 0;
       3         try {
       4             basicRun(args);
       5             String exitCode = System.getProperty(PROP_EXITCODE);
       6             try {
       7                 result = exitCode == null ? 0 : Integer.parseInt(exitCode);
       8             } catch (NumberFormatException e) {
       9                 result = 17;
      10             }
      11         } catch (Throwable e) {
      12             // only log the exceptions if they have not been caught by the 
      13             // EclipseStarter (i.e., if the exitCode is not 13) 
      14             if (!"13".equals(System.getProperty(PROP_EXITCODE))) { //$NON-NLS-1$
      15                 log("Exception launching the Eclipse Platform:"); //$NON-NLS-1$
      16                 log(e);
      17                 String message = "An error has occurred"; //$NON-NLS-1$
      18                 if (logFile == null)
      19                     message += " and could not be logged: \n" + e.getMessage(); //$NON-NLS-1$
      20                 else
      21                     message += ".  See the log file\n" + logFile.getAbsolutePath(); //$NON-NLS-1$
      22                 System.getProperties().put(PROP_EXITDATA, message);
      23             }
      24             // Return "unlucky" 13 as the exit code. The executable will recognize
      25             // this constant and display a message to the user telling them that
      26             // there is information in their log file.
      27             result = 13;
      28         } finally {
      29             // always try putting down the splash screen just in case the application failed to do so
      30             takeDownSplash();
      31             if (bridge != null)
      32                 bridge.uninitialize();
      33         }
      34         // Return an int exit code and ensure the system property is set.
      35         System.getProperties().put(PROP_EXITCODE, Integer.toString(result));
      36         setExitData();
      37         return result;
      38     }
       1     protected void basicRun(String[] args) throws Exception {
       2         System.getProperties().put("eclipse.startTime", Long.toString(System.currentTimeMillis())); //$NON-NLS-1$
       3         commands = args;
       4         String[] passThruArgs = processCommandLine(args);
       5 
       6         if (!debug)
       7             // debug can be specified as system property as well
       8             debug = System.getProperty(PROP_DEBUG) != null;
       9         setupVMProperties();
      10         processConfiguration();
      11 
      12         // need to ensure that getInstallLocation is called at least once to initialize the value.
      13         // Do this AFTER processing the configuration to allow the configuration to set
      14         // the install location.  
      15         getInstallLocation();
      16 
      17         // locate boot plugin (may return -dev mode variations)
      18         URL[] bootPath = getBootPath(bootLocation);
      19 
      20         //Set up the JNI bridge.  We need to know the install location to find the shared library
      21         setupJNI(bootPath);
      22 
      23         //ensure minimum Java version, do this after JNI is set up so that we can write an error message 
      24         //with exitdata if we fail.
      25         if (!checkVersion(System.getProperty("java.version"), System.getProperty(PROP_REQUIRED_JAVA_VERSION))) //$NON-NLS-1$
      26             return;
      27 
      28         // verify configuration location is writable
      29         if (!checkConfigurationLocation(configurationLocation))
      30             return;
      31 
      32         setSecurityPolicy(bootPath);
      33         // splash handling is done here, because the default case needs to know
      34         // the location of the boot plugin we are going to use
      35         handleSplash(bootPath);
      36 
      37         beforeFwkInvocation();
      38         invokeFramework(passThruArgs, bootPath);
      39     }

       

转载于:https://www.cnblogs.com/iiiDragon/p/3313955.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值