org.eclipse.osgi_3.7.2.v20120110-1415

  found = true;
        }
        if (args[(i - 1)].equalsIgnoreCase("-arch"))
        {
          FrameworkProperties.setProperty("osgi.arch", arg);
          found = true;
        }
        if (args[(i - 1)].equalsIgnoreCase("-nl"))
        {
          FrameworkProperties.setProperty("osgi.nl", arg);
          found = true;
        }
        if (args[(i - 1)].equalsIgnoreCase("-nlExtensions"))
        {
          FrameworkProperties.setProperty("osgi.nl.extensions", arg);
          found = true;
        }
        if (found)
        {
          configArgs[(configArgIndex++)] = (i - 1);
          configArgs[(configArgIndex++)] = i;
        }
      }
    }
    if (configArgIndex == 0)
    {
      EclipseEnvironmentInfo.setFrameworkArgs(new String[0]);
      EclipseEnvironmentInfo.setAppArgs(args);
      return args;
    }
    String[] appArgs = new String[args.length - configArgIndex];
    String[] frameworkArgs = new String[configArgIndex];
    configArgIndex = 0;
    int j = 0;
    int k = 0;
    for (int i = 0; i < args.length; i++) {
      if (i == configArgs[configArgIndex])
      {
        frameworkArgs[(k++)] = args[i];
        configArgIndex++;
      }
      else
      {
        appArgs[(j++)] = args[i];
      }
    }
    EclipseEnvironmentInfo.setFrameworkArgs(frameworkArgs);
    EclipseEnvironmentInfo.setAppArgs(appArgs);
    return appArgs;
  }
  
  private static String[] getArrayFromList(String prop, String separator)
  {
    return ManifestElement.getArrayFromList(prop, separator);
  }
  
  protected static String getSysPath()
  {
    String result = FrameworkProperties.getProperty("osgi.syspath");
    if (result != null) {
      return result;
    }
    result = getSysPathFromURL(FrameworkProperties.getProperty("osgi.framework"));
    if (result == null) {
      result = getSysPathFromCodeSource();
    }
    if (result == null) {
      throw new IllegalStateException("Can not find the system path.");
    }
    if (Character.isUpperCase(result.charAt(0)))
    {
      char[] chars = result.toCharArray();
      chars[0] = Character.toLowerCase(chars[0]);
      result = new String(chars);
    }
    FrameworkProperties.setProperty("osgi.syspath", result);
    return result;
  }
  
  private static String getSysPathFromURL(String urlSpec)
  {
    if (urlSpec == null) {
      return null;
    }
    URL url = LocationHelper.buildURL(urlSpec, false);
    if (url == null) {
      return null;
    }
    File fwkFile = new File(url.getFile());
    fwkFile = new File(fwkFile.getAbsolutePath());
    fwkFile = new File(fwkFile.getParent());
    return fwkFile.getAbsolutePath();
  }
  
  private static String getSysPathFromCodeSource()
  {
    ProtectionDomain pd = EclipseStarter.class.getProtectionDomain();
    if (pd == null) {
      return null;
    }
    CodeSource cs = pd.getCodeSource();
    if (cs == null) {
      return null;
    }
    URL url = cs.getLocation();
    if (url == null) {
      return null;
    }
    String result = url.getFile();
    if (result.endsWith(".jar"))
    {
      result = result.substring(0, result.lastIndexOf('/'));
      if ("folder".equals(FrameworkProperties.getProperty("osgi.framework.shape"))) {
        result = result.substring(0, result.lastIndexOf('/'));
      }
    }
    else
    {
      if (result.endsWith("/")) {
        result = result.substring(0, result.length() - 1);
      }
      result = result.substring(0, result.lastIndexOf('/'));
      result = result.substring(0, result.lastIndexOf('/'));
    }
    return result;
  }
  
  private static Bundle[] getCurrentBundles(boolean includeInitial)
  {
    Bundle[] installed = context.getBundles();
    List<Bundle> initial = new ArrayList();
    for (int i = 0; i < installed.length; i++)
    {
      Bundle bundle = installed[i];
      if (bundle.getLocation().startsWith("initial@"))
      {
        if (includeInitial) {
          initial.add(bundle);
        }
      }
      else if ((!includeInitial) && (bundle.getBundleId() != 0L)) {
        initial.add(bundle);
      }
    }
    return (Bundle[])initial.toArray(new Bundle[initial.size()]);
  }
  
  private static Bundle getBundleByLocation(String location, Bundle[] bundles)
  {
    for (int i = 0; i < bundles.length; i++)
    {
      Bundle bundle = bundles[i];
      if (location.equalsIgnoreCase(bundle.getLocation())) {
        return bundle;
      }
    }
    return null;
  }
  
  private static void uninstallBundles(Bundle[] curInitBundles, InitialBundle[] newInitBundles, List<Bundle> toRefresh)
  {
    for (int i = 0; i < curInitBundles.length; i++)
    {
      boolean found = false;
      for (int j = 0; j < newInitBundles.length; j++) {
        if (curInitBundles[i].getLocation().equalsIgnoreCase(locationString))
        {
          found = true;
          break;
        }
      }
      if (!found) {
        try
        {
          curInitBundles[i].uninstall();
          toRefresh.add(curInitBundles[i]);
        }
        catch (BundleException e)
        {
          FrameworkLogEntry entry = new FrameworkLogEntry("org.eclipse.osgi", 4, 0, NLS.bind(EclipseAdaptorMsg.ECLIPSE_STARTUP_FAILED_UNINSTALL, curInitBundles[i].getLocation()), 0, e, null);
          log.log(entry);
        }
      }
    }
  }
  
  /* Error */
  private static void installBundles(InitialBundle[] initialBundles, Bundle[] curInitBundles, List<Bundle> startBundles, List<Bundle> lazyActivationBundles, List<Bundle> toRefresh)
  {
    // Byte code:
    //   0: getstatic 1287	org/eclipse/core/runtime/adaptor/EclipseStarter:context	Lorg/osgi/framework/BundleContext;
    //   3: getstatic 1274	org/eclipse/core/runtime/adaptor/EclipseStarter:class$1	Ljava/lang/Class;
    //   6: dup
    //   7: ifnonnull +29 -> 36
    //   10: pop
    //   11: ldc_w 722
    //   14: invokestatic 1333	java/lang/Class:forName	(Ljava/lang/String;)Ljava/lang/Class;
    //   17: dup
    //   18: putstatic 1274	org/eclipse/core/runtime/adaptor/EclipseStarter:class$1	Ljava/lang/Class;
    //   21: goto +15 -> 36
    //   24: new 755	java/lang/NoClassDefFoundError
    //   27: dup_x1
    //   28: swap
    //   29: invokevirtual 1371	java/lang/Throwable:getMessage	()Ljava/lang/String;
    //   32: invokespecial 1343	java/lang/NoClassDefFoundError:<init>	(Ljava/lang/String;)V
    //   35: athrow
    //   36: invokevirtual 1331	java/lang/Class:getName	()Ljava/lang/String;
    //   39: invokeinterface 1551 2 0
    //   44: astore 5
    //   46: aconst_null
    //   47: astore 6
    //   49: aload 5
    //   51: ifnull +18 -> 69
    //   54: getstatic 1287	org/eclipse/core/runtime/adaptor/EclipseStarter:context	Lorg/osgi/framework/BundleContext;
    //   57: aload 5
    //   59: invokeinterface 1550 2 0
    //   64: checkcast 822	org/osgi/service/startlevel/StartLevel
    //   67: astore 6
    //   69: iconst_0
    //   70: istore 7
    //   72: goto +329 -> 401
    //   75: aload_0
    //   76: iload 7
    //   78: aaload
    //   79: getfield 1293	org/eclipse/core/runtime/adaptor/EclipseStarter$InitialBundle:locationString	Ljava/lang/String;
    //   82: aload_1
    //   83: invokestatic 1440	org/eclipse/core/runtime/adaptor/EclipseStarter:getBundleByLocation	(Ljava/lang/String;[Lorg/osgi/framework/Bundle;)Lorg/osgi/framework/Bundle;
    //   86: astore 8
    //   88: aload 8
    //   90: ifnonnull +132 -> 222
    //   93: aload_0
    //   94: iload 7
    //   96: aaload
    //   97: getfield 1294	org/eclipse/core/runtime/adaptor/EclipseStarter$InitialBundle:location	Ljava/net/URL;
    //   100: invokevirtual 1375	java/net/URL:openStream	()Ljava/io/InputStream;
    //   103: astore 9
    //   105: getstatic 1287	org/eclipse/core/runtime/adaptor/EclipseStarter:context	Lorg/osgi/framework/BundleContext;
    //   108: aload_0
    //   109: iload 7
    //   111: aaload
    //   112: getfield 1293	org/eclipse/core/runtime/adaptor/EclipseStarter$InitialBundle:locationString	Ljava/lang/String;
    //   115: aload 9
    //   117: invokeinterface 1552 3 0
    //   122: astore 8
    //   124: goto +71 -> 195
    //   127: astore 10
    //   129: aload 10
    //   131: instanceof 797
    //   134: ifeq +11 -> 145
    //   137: aload 10
    //   139: checkcast 797	org/eclipse/osgi/framework/adaptor/StatusException
    //   142: goto +4 -> 146
    //   145: aconst_null
    //   146: astore 11
    //   148: aload 11
    //   150: ifnull +42 -> 192
    //   153: aload 11
    //   155: invokeinterface 1517 1 0
    //   160: iconst_1
    //   161: if_icmpne +31 -> 192
    //   164: aload 11
    //   166: invokeinterface 1518 1 0
    //   171: instanceof 817
    //   174: ifeq +18 -> 192
    //   177: aload 11
    //   179: invokeinterface 1518 1 0
    //   184: checkcast 817	org/osgi/framework/Bundle
    //   187: astore 8
    //   189: goto +6 -> 195
    //   192: aload 10
    //   194: athrow
    //   195: aload_0
    //   196: iload 7
    //   198: aaload
    //   199: getfield 1292	org/eclipse/core/runtime/adaptor/EclipseStarter$InitialBundle:start	Z
    //   202: ifne +20 -> 222
    //   205: aload 8
    //   207: invokestatic 1417	org/eclipse/core/runtime/adaptor/EclipseStarter:hasLazyActivationPolicy	(Lorg/osgi/framework/Bundle;)Z
    //   210: ifeq +12 -> 222
    //   213: aload_3
    //   214: aload 8
    //   216: invokeinterface 1500 2 0
    //   221: pop
    //   222: aload 8
    //   224: invokeinterface 1535 1 0
    //   229: iconst_1
    //   230: iand
    //   231: ifne +34 -> 265
    //   234: aload_0
    //   235: iload 7
    //   237: aaload
    //   238: getfield 1291	org/eclipse/core/runtime/adaptor/EclipseStarter$InitialBundle:level	I
    //   241: iflt +24 -> 265
    //   244: aload 6
    //   246: ifnull +19 -> 265
    //   249: aload 6
    //   251: aload 8
    //   253: aload_0
    //   254: iload 7
    //   256: aaload
    //   257: getfield 1291	org/eclipse/core/runtime/adaptor/EclipseStarter$InitialBundle:level	I
    //   260: invokeinterface 1559 3 0
    //   265: aload_0
    //   266: iload 7
    //   268: aaload
    //   269: getfield 1292	org/eclipse/core/runtime/adaptor/EclipseStarter$InitialBundle:start	Z
    //   272: ifeq +12 -> 284
    //   275: aload_2
    //   276: aload 8
    //   278: invokeinterface 1500 2 0
    //   283: pop
    //   284: aload 8
    //   286: invokeinterface 1535 1 0
    //   291: iconst_2
    //   292: iand
    //   293: ifeq +105 -> 398
    //   296: aload 4
    //   298: aload 8
    //   300: invokeinterface 1500 2 0
    //   305: pop
    //   306: goto +92 -> 398
    //   309: astore 9
    //   311: new 804	org/eclipse/osgi/framework/log/FrameworkLogEntry
    //   314: dup
    //   315: ldc_w 718
    //   318: iconst_4
    //   319: iconst_0
    //   320: getstatic 1302	org/eclipse/core/runtime/internal/adaptor/EclipseAdaptorMsg:ECLIPSE_STARTUP_FAILED_INSTALL	Ljava/lang/String;
    //   323: aload_0
    //   324: iload 7
    //   326: aaload
    //   327: getfield 1294	org/eclipse/core/runtime/adaptor/EclipseStarter$InitialBundle:location	Ljava/net/URL;
    //   330: invokestatic 1487	org/eclipse/osgi/util/NLS:bind	(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
    //   333: iconst_0
    //   334: aload 9
    //   336: aconst_null
    //   337: invokespecial 1477	org/eclipse/osgi/framework/log/FrameworkLogEntry:<init>	(Ljava/lang/String;IILjava/lang/String;ILjava/lang/Throwable;[Lorg/eclipse/osgi/framework/log/FrameworkLogEntry;)V
    //   340: astore 10
    //   342: getstatic 1286	org/eclipse/core/runtime/adaptor/EclipseStarter:log	Lorg/eclipse/osgi/framework/log/FrameworkLog;
    //   345: aload 10
    //   347: invokeinterface 1520 2 0
    //   352: goto +46 -> 398
    //   355: astore 9
    //   357: new 804	org/eclipse/osgi/framework/log/FrameworkLogEntry
    //   360: dup
    //   361: ldc_w 718
    //   364: iconst_4
    //   365: iconst_0
    //   366: getstatic 1302	org/eclipse/core/runtime/internal/adaptor/EclipseAdaptorMsg:ECLIPSE_STARTUP_FAILED_INSTALL	Ljava/lang/String;
    //   369: aload_0
    //   370: iload 7
    //   372: aaload
    //   373: getfield 1294	org/eclipse/core/runtime/adaptor/EclipseStarter$InitialBundle:location	Ljava/net/URL;
    //   376: invokestatic 1487	org/eclipse/osgi/util/NLS:bind	(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
    //   379: iconst_0
    //   380: aload 9
    //   382: aconst_null
    //   383: invokespecial 1477	org/eclipse/osgi/framework/log/FrameworkLogEntry:<init>	(Ljava/lang/String;IILjava/lang/String;ILjava/lang/Throwable;[Lorg/eclipse/osgi/framework/log/FrameworkLogEntry;)V
    //   386: astore 10
    //   388: getstatic 1286	org/eclipse/core/runtime/adaptor/EclipseStarter:log	Lorg/eclipse/osgi/framework/log/FrameworkLog;
    //   391: aload 10
    //   393: invokeinterface 1520 2 0
    //   398: iinc 7 1
    //   401: iload 7
    //   403: aload_0
    //   404: arraylength
    //   405: if_icmplt -330 -> 75
    //   408: goto +24 -> 432
    //   411: astore 12
    //   413: aload 5
    //   415: ifnull +14 -> 429
    //   418: getstatic 1287	org/eclipse/core/runtime/adaptor/EclipseStarter:context	Lorg/osgi/framework/BundleContext;
    //   421: aload 5
    //   423: invokeinterface 1549 2 0
    //   428: pop
    //   429: aload 12
    //   431: athrow
    //   432: aload 5
    //   434: ifnull +14 -> 448
    //   437: getstatic 1287	org/eclipse/core/runtime/adaptor/EclipseStarter:context	Lorg/osgi/framework/BundleContext;
    //   440: aload 5
    //   442: invokeinterface 1549 2 0
    //   447: pop
    //   448: return
    // Line number table:
    //   Java source line #1014	-> byte code offset #0
    //   Java source line #1015	-> byte code offset #46
    //   Java source line #1016	-> byte code offset #49
    //   Java source line #1017	-> byte code offset #54
    //   Java source line #1019	-> byte code offset #69
    //   Java source line #1020	-> byte code offset #75
    //   Java source line #1023	-> byte code offset #88
    //   Java source line #1024	-> byte code offset #93
    //   Java source line #1026	-> byte code offset #105
    //   Java source line #1027	-> byte code offset #127
    //   Java source line #1028	-> byte code offset #129
    //   Java source line #1029	-> byte code offset #148
    //   Java source line #1030	-> byte code offset #177
    //   Java source line #1032	-> byte code offset #192
    //   Java source line #1035	-> byte code offset #195
    //   Java source line #1036	-> byte code offset #213
    //   Java source line #1040	-> byte code offset #222
    //   Java source line #1041	-> byte code offset #249
    //   Java source line #1043	-> byte code offset #265
    //   Java source line #1044	-> byte code offset #275
    //   Java source line #1046	-> byte code offset #284
    //   Java source line #1047	-> byte code offset #296
    //   Java source line #1048	-> byte code offset #309
    //   Java source line #1049	-> byte code offset #311
    //   Java source line #1050	-> byte code offset #342
    //   Java source line #1051	-> byte code offset #355
    //   Java source line #1052	-> byte code offset #357
    //   Java source line #1053	-> byte code offset #388
    //   Java source line #1019	-> byte code offset #398
    //   Java source line #1056	-> byte code offset #411
    //   Java source line #1057	-> byte code offset #413
    //   Java source line #1058	-> byte code offset #418
    //   Java source line #1059	-> byte code offset #429
    //   Java source line #1057	-> byte code offset #432
    //   Java source line #1058	-> byte code offset #437
    //   Java source line #1060	-> byte code offset #448
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	449	0	initialBundles	InitialBundle[]
    //   0	449	1	curInitBundles	Bundle[]
    //   0	449	2	startBundles	List<Bundle>
    //   0	449	3	lazyActivationBundles	List<Bundle>
    //   0	449	4	toRefresh	List<Bundle>
    //   44	397	5	reference	ServiceReference<?>
    //   47	203	6	startService	StartLevel
    //   70	332	7	i	int
    //   86	213	8	osgiBundle	Bundle
    //   103	13	9	in	java.io.InputStream
    //   309	26	9	e	BundleException
    //   355	26	9	e	IOException
    //   127	66	10	e	BundleException
    //   340	6	10	entry	FrameworkLogEntry
    //   386	6	10	entry	FrameworkLogEntry
    //   146	32	11	status	org.eclipse.osgi.framework.adaptor.StatusException
    //   411	19	12	localObject	Object
    //   24	1	17	localClassNotFoundException	ClassNotFoundException
    // Exception table:
    //   from	to	target	type
    //   11	17	24	java/lang/ClassNotFoundException
    //   105	124	127	org/osgi/framework/BundleException
    //   88	306	309	org/osgi/framework/BundleException
    //   88	306	355	java/io/IOException
    //   69	411	411	finally
  }
  
  private static boolean hasLazyActivationPolicy(Bundle target)
  {
    Dictionary<String, String> headers = target.getHeaders("");
    
    String fragmentHost = (String)headers.get("Fragment-Host");
    if (fragmentHost != null) {
      return false;
    }
    String activationPolicy = (String)headers.get("Bundle-ActivationPolicy");
    try
    {
      if (activationPolicy != null)
      {
        ManifestElement[] elements = ManifestElement.parseHeader("Bundle-ActivationPolicy", activationPolicy);
        if ((elements != null) && (elements.length > 0)) {
          if ("lazy".equals(elements[0].getValue())) {
            return true;
          }
        }
      }
      else
      {
        String eclipseLazyStart = (String)headers.get("Eclipse-LazyStart");
        if (eclipseLazyStart == null) {
          eclipseLazyStart = (String)headers.get("Eclipse-AutoStart");
        }
        ManifestElement[] elements = ManifestElement.parseHeader("Eclipse-LazyStart", eclipseLazyStart);
        if ((elements != null) && (elements.length > 0))
        {
          if ("true".equals(elements[0].getValue())) {
            return true;
          }
          if (elements[0].getDirective("exceptions") != null) {
            return true;
          }
        }
      }
    }
    catch (BundleException localBundleException) {}
    return false;
  }
  
  private static void startBundles(Bundle[] startBundles, Bundle[] lazyBundles)
  {
    for (int i = 0; i < startBundles.length; i++) {
      startBundle(startBundles[i], 0);
    }
    for (int i = 0; i < lazyBundles.length; i++) {
      startBundle(lazyBundles[i], 2);
    }
  }
  
  private static void startBundle(Bundle bundle, int options)
  {
    try
    {
      bundle.start(options);
    }
    catch (BundleException e)
    {
      if ((bundle.getState() & 0x4) != 0)
      {
        FrameworkLogEntry entry = new FrameworkLogEntry("org.eclipse.osgi", 4, 0, NLS.bind(EclipseAdaptorMsg.ECLIPSE_STARTUP_FAILED_START, bundle.getLocation()), 0, e, null);
        log.log(entry);
      }
    }
  }
  
  private static void loadConfigurationInfo()
  {
    Location configArea = LocationManager.getConfigurationLocation();
    if (configArea == null) {
      return;
    }
    URL location = null;
    try
    {
      location = new URL(configArea.getURL().toExternalForm() + "config.ini");
    }
    catch (MalformedURLException localMalformedURLException) {}
    mergeProperties(FrameworkProperties.getProperties(), loadProperties(location));
  }
  
  /* Error */
  private static Properties loadProperties(URL location)
  {
    // Byte code:
    //   0: new 780	java/util/Properties
    //   3: dup
    //   4: invokespecial 1396	java/util/Properties:<init>	()V
    //   7: astore_1
    //   8: aload_0
    //   9: ifnonnull +5 -> 14
    //   12: aload_1
    //   13: areturn
    //   14: aload_0
    //   15: invokevirtual 1375	java/net/URL:openStream	()Ljava/io/InputStream;
    //   18: astore_2
    //   19: aload_1
    //   20: aload_2
    //   21: invokevirtual 1397	java/util/Properties:load	(Ljava/io/InputStream;)V
    //   24: goto +10 -> 34
    //   27: astore_3
    //   28: aload_2
    //   29: invokevirtual 1325	java/io/InputStream:close	()V
    //   32: aload_3
    //   33: athrow
    //   34: aload_2
    //   35: invokevirtual 1325	java/io/InputStream:close	()V
    //   38: goto +4 -> 42
    //   41: pop
    //   42: aload_1
    //   43: areturn
    // Line number table:
    //   Java source line #1135	-> byte code offset #0
    //   Java source line #1136	-> byte code offset #8
    //   Java source line #1137	-> byte code offset #12
    //   Java source line #1139	-> byte code offset #14
    //   Java source line #1141	-> byte code offset #19
    //   Java source line #1142	-> byte code offset #27
    //   Java source line #1143	-> byte code offset #28
    //   Java source line #1144	-> byte code offset #32
    //   Java source line #1143	-> byte code offset #34
    //   Java source line #1145	-> byte code offset #41
    //   Java source line #1149	-> byte code offset #42
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	44	0	location	URL
    //   7	36	1	result	Properties
    //   18	17	2	in	java.io.InputStream
    //   27	6	3	localObject	Object
    //   41	1	4	localIOException	IOException
    // Exception table:
    //   from	to	target	type
    //   19	27	27	finally
    //   14	38	41	java/io/IOException
  }
  
  private static URL makeRelative(URL base, URL location)
    throws MalformedURLException
  {
    if (base == null) {
      return location;
    }
    if (!"file".equals(base.getProtocol())) {
      return location;
    }
    if (!location.getProtocol().equals("reference")) {
      return location;
    }
    URL nonReferenceLocation = new URL(location.getPath());
    if (!base.getProtocol().equals(nonReferenceLocation.getProtocol())) {
      return location;
    }
    File locationPath = new File(nonReferenceLocation.getPath());
    if (!locationPath.isAbsolute()) {
      return location;
    }
    File relativePath = makeRelative(new File(base.getPath()), locationPath);
    String urlPath = relativePath.getPath();
    if (File.separatorChar != '/') {
      urlPath = urlPath.replace(File.separatorChar, '/');
    }
    if (nonReferenceLocation.getPath().endsWith("/")) {
      urlPath = urlPath + '/';
    }
    URL relativeURL = new URL(base.getProtocol(), base.getHost(), base.getPort(), urlPath);
    
    relativeURL = new URL("reference:" + relativeURL.toExternalForm());
    return relativeURL;
  }
  
  private static File makeRelative(File base, File location)
  {
    if (!location.isAbsolute()) {
      return location;
    }
    File relative = new File(new FilePath(base).makeRelative(new FilePath(location)));
    return relative;
  }
  
  private static void mergeProperties(Properties destination, Properties source)
  {
    for (Enumeration<?> e = source.keys(); e.hasMoreElements();)
    {
      String key = (String)e.nextElement();
      String value = source.getProperty(key);
      if (destination.getProperty(key) == null) {
        destination.setProperty(key, value);
      }
    }
  }
  
  private static void setStartLevel(int value)
  {
    ServiceReference<?> reference = context.getServiceReference(StartLevel.class.getName());
    StartLevel startLevel = reference != null ? (StartLevel)context.getService(reference) : null;
    if (startLevel == null) {
      return;
    }
    Semaphore semaphore = new Semaphore(0);
    StartupEventListener listener = new StartupEventListener(semaphore, 8);
    context.addFrameworkListener(listener);
    context.addBundleListener(listener);
    startLevel.setStartLevel(value);
    context.ungetService(reference);
    updateSplash(semaphore, listener);
  }
  
  /* Error */
  private static void updateSplash(Semaphore semaphore, StartupEventListener listener)
  {
    // Byte code:
    //   0: new 823	org/osgi/util/tracker/ServiceTracker
    //   3: dup
    //   4: getstatic 1287	org/eclipse/core/runtime/adaptor/EclipseStarter:context	Lorg/osgi/framework/BundleContext;
    //   7: getstatic 1276	org/eclipse/core/runtime/adaptor/EclipseStarter:class$3	Ljava/lang/Class;
    //   10: dup
    //   11: ifnonnull +29 -> 40
    //   14: pop
    //   15: ldc_w 720
    //   18: invokestatic 1333	java/lang/Class:forName	(Ljava/lang/String;)Ljava/lang/Class;
    //   21: dup
    //   22: putstatic 1276	org/eclipse/core/runtime/adaptor/EclipseStarter:class$3	Ljava/lang/Class;
    //   25: goto +15 -> 40
    //   28: new 755	java/lang/NoClassDefFoundError
    //   31: dup_x1
    //   32: swap
    //   33: invokevirtual 1371	java/lang/Throwable:getMessage	()Ljava/lang/String;
    //   36: invokespecial 1343	java/lang/NoClassDefFoundError:<init>	(Ljava/lang/String;)V
    //   39: athrow
    //   40: invokevirtual 1331	java/lang/Class:getName	()Ljava/lang/String;
    //   43: aconst_null
    //   44: invokespecial 1491	org/osgi/util/tracker/ServiceTracker:<init>	(Lorg/osgi/framework/BundleContext;Ljava/lang/String;Lorg/osgi/util/tracker/ServiceTrackerCustomizer;)V
    //   47: astore_2
    //   48: aload_2
    //   49: invokevirtual 1489	org/osgi/util/tracker/ServiceTracker:open	()V
    //   52: aload_2
    //   53: invokevirtual 1490	org/osgi/util/tracker/ServiceTracker:getService	()Ljava/lang/Object;
    //   56: checkcast 814	org/eclipse/osgi/service/runnable/StartupMonitor
    //   59: astore_3
    //   60: aload_3
    //   61: ifnull +13 -> 74
    //   64: aload_3
    //   65: invokeinterface 1534 1 0
    //   70: goto +4 -> 74
    //   73: pop
    //   74: aload_0
    //   75: ldc2_w 675
    //   78: invokevirtual 1460	org/eclipse/core/runtime/internal/adaptor/Semaphore:acquire	(J)Z
    //   81: ifeq -29 -> 52
    //   84: goto +34 -> 118
    //   87: astore 4
    //   89: aload_1
    //   90: ifnull +21 -> 111
    //   93: getstatic 1287	org/eclipse/core/runtime/adaptor/EclipseStarter:context	Lorg/osgi/framework/BundleContext;
    //   96: aload_1
    //   97: invokeinterface 1548 2 0
    //   102: getstatic 1287	org/eclipse/core/runtime/adaptor/EclipseStarter:context	Lorg/osgi/framework/BundleContext;
    //   105: aload_1
    //   106: invokeinterface 1546 2 0
    //   111: aload_2
    //   112: invokevirtual 1488	org/osgi/util/tracker/ServiceTracker:close	()V
    //   115: aload 4
    //   117: athrow
    //   118: aload_1
    //   119: ifnull +21 -> 140
    //   122: getstatic 1287	org/eclipse/core/runtime/adaptor/EclipseStarter:context	Lorg/osgi/framework/BundleContext;
    //   125: aload_1
    //   126: invokeinterface 1548 2 0
    //   131: getstatic 1287	org/eclipse/core/runtime/adaptor/EclipseStarter:context	Lorg/osgi/framework/BundleContext;
    //   134: aload_1
    //   135: invokeinterface 1546 2 0
    //   140: aload_2
    //   141: invokevirtual 1488	org/osgi/util/tracker/ServiceTracker:close	()V
    //   144: return
    // Line number table:
    //   Java source line #1238	-> byte code offset #0
    //   Java source line #1239	-> byte code offset #48
    //   Java source line #1242	-> byte code offset #52
    //   Java source line #1243	-> byte code offset #60
    //   Java source line #1245	-> byte code offset #64
    //   Java source line #1246	-> byte code offset #73
    //   Java source line #1251	-> byte code offset #74
    //   Java source line #1252	-> byte code offset #84
    //   Java source line #1255	-> byte code offset #87
    //   Java source line #1256	-> byte code offset #89
    //   Java source line #1257	-> byte code offset #93
    //   Java source line #1258	-> byte code offset #102
    //   Java source line #1260	-> byte code offset #111
    //   Java source line #1261	-> byte code offset #115
    //   Java source line #1256	-> byte code offset #118
    //   Java source line #1257	-> byte code offset #122
    //   Java source line #1258	-> byte code offset #131
    //   Java source line #1260	-> byte code offset #140
    //   Java source line #1262	-> byte code offset #144
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	145	0	semaphore	Semaphore
    //   0	145	1	listener	StartupEventListener
    //   47	94	2	monitorTracker	org.osgi.util.tracker.ServiceTracker<StartupMonitor, StartupMonitor>
    //   59	6	3	monitor	StartupMonitor
    //   87	29	4	localObject	Object
    //   28	1	5	localClassNotFoundException	ClassNotFoundException
    //   73	1	6	localThrowable	Throwable
    // Exception table:
    //   from	to	target	type
    //   15	21	28	java/lang/ClassNotFoundException
    //   64	70	73	java/lang/Throwable
    //   52	87	87	finally
  }
  
  static class StartupEventListener
    implements SynchronousBundleListener, FrameworkListener
  {
    private final Semaphore semaphore;
    private final int frameworkEventType;
    
    public StartupEventListener(Semaphore semaphore, int frameworkEventType)
    {
      this.semaphore = semaphore;
      this.frameworkEventType = frameworkEventType;
    }
    
    public void bundleChanged(BundleEvent event)
    {
      if ((event.getBundle().getBundleId() == 0L) && (event.getType() == 256)) {
        semaphore.release();
      }
    }
    
    public void frameworkEvent(FrameworkEvent event)
    {
      if (event.getType() == frameworkEventType) {
        semaphore.release();
      }
    }
  }
  
  private static String searchFor(String target, String start)
  {
    String[] candidates = (String[])searchCandidates.get(start);
    if (candidates == null)
    {
      File startFile = new File(start);
      if ((!startFile.exists()) && (start.indexOf('%') >= 0))
      {
        String decodePath = FrameworkProperties.decode(start);
        File f = new File(decodePath);
        if (f.exists()) {
          startFile = f;
        }
      }
      candidates = startFile.list();
      if (candidates != null) {
        searchCandidates.put(start, candidates);
      }
    }
    if (candidates == null) {
      return null;
    }
    String result = null;
    Object[] maxVersion = (Object[])null;
    for (int i = 0; i < candidates.length; i++)
    {
      String candidateName = candidates[i];
      if (candidateName.startsWith(target))
      {
        boolean simpleJar = false;
        char versionSep = candidateName.length() > target.length() ? candidateName.charAt(target.length()) : '\000';
        if ((candidateName.length() > target.length()) && (versionSep != '_') && (versionSep != '-'))
        {
          if ((candidateName.length() == 4 + target.length()) && (candidateName.endsWith(".jar"))) {
            simpleJar = true;
          }
        }
        else
        {
          String version = (candidateName.length() > target.length() + 1) && ((versionSep == '_') || (versionSep == '-')) ? candidateName.substring(target.length() + 1) : "";
          Object[] currentVersion = getVersionElements(version);
          if ((currentVersion != null) && (compareVersion(maxVersion, currentVersion) < 0))
          {
            File candidate = new File(start, candidateName);
            if ((!simpleJar) || (candidate.isFile()))
            {
              result = candidate.getAbsolutePath();
              maxVersion = currentVersion;
            }
          }
        }
      }
    }
    if (result == null) {
      return null;
    }
    return result.replace(File.separatorChar, '/') + "/";
  }
  
  private static Object[] getVersionElements(String version)
  {
    Object[] result = { new Integer(-1), new Integer(-1), new Integer(-1), "" };
    StringTokenizer t = new StringTokenizer(version, ".");
    for (int i = 0; (t.hasMoreTokens()) && (i < 4); i++)
    {
      String token = t.nextToken();
      if (i < 3)
      {
        try
        {
          result[i] = new Integer(token);
        }
        catch (Exception localException)
        {
          if (i != 0) {
            break;
          }
        }
        return null;
      }
      else
      {
        result[i] = token;
      }
    }
    return result;
  }
  
  private static int compareVersion(Object[] left, Object[] right)
  {
    if (left == null) {
      return -1;
    }
    int result = ((Integer)left[0]).compareTo((Integer)right[0]);
    if (result != 0) {
      return result;
    }
    result = ((Integer)left[1]).compareTo((Integer)right[1]);
    if (result != 0) {
      return result;
    }
    result = ((Integer)left[2]).compareTo((Integer)right[2]);
    if (result != 0) {
      return result;
    }
    return ((String)left[3]).compareTo((String)right[3]);
  }
  
  private static void finalizeProperties()
  {
    if ((FrameworkProperties.getProperty("osgi.dev") != null) && (FrameworkProperties.getProperty("osgi.checkConfiguration") == null)) {
      FrameworkProperties.setProperty("osgi.checkConfiguration", "true");
    }
  }
  
  private static class InitialBundle
  {
    public final String locationString;
    public final URL location;
    public final int level;
    public final boolean start;
    
    InitialBundle(String locationString, URL location, int level, boolean start)
    {
      this.locationString = locationString;
      this.location = location;
      this.level = level;
      this.start = start;
    }
  }
  
  public static void setInitialProperties(Map<String, String> initialProperties)
  {
    if ((initialProperties == null) || (initialProperties.isEmpty())) {
      return;
    }
    for (Iterator localIterator = initialProperties.entrySet().iterator(); localIterator.hasNext();)
    {
      Map.Entry<String, String> entry = (Map.Entry)localIterator.next();
      if (entry.getValue() != null) {
        FrameworkProperties.setProperty((String)entry.getKey(), (String)entry.getValue());
      } else {
        FrameworkProperties.clearProperty((String)entry.getKey());
      }
    }
  }
  
  public static BundleContext getSystemBundleContext()
  {
    if ((context == null) || (!running)) {
      return null;
    }
    return context.getBundle().getBundleContext();
  }
  
  private static boolean isForcedRestart()
  {
    return Boolean.valueOf(FrameworkProperties.getProperty("osgi.forcedRestart")).booleanValue();
  }
  
  static void internalAddFrameworkShutdownHandler(Runnable handler)
  {
    if (running) {
      throw new IllegalStateException(EclipseAdaptorMsg.ECLIPSE_STARTUP_ALREADY_RUNNING);
    }
    if (shutdownHandlers == null) {
      shutdownHandlers = new ArrayList();
    }
    shutdownHandlers.add(handler);
  }
  
  static void internalRemoveFrameworkShutdownHandler(Runnable handler)
  {
    if (running) {
      throw new IllegalStateException(EclipseAdaptorMsg.ECLIPSE_STARTUP_ALREADY_RUNNING);
    }
    if (shutdownHandlers != null) {
      shutdownHandlers.remove(handler);
    }
  }
  
  private static void registerFrameworkShutdownHandlers()
  {
    if (shutdownHandlers == null) {
      return;
    }
    Bundle systemBundle = context.getBundle();
    for (Iterator<Runnable> it = shutdownHandlers.iterator(); it.hasNext();)
    {
      final Runnable handler = (Runnable)it.next();
      BundleListener listener = new BundleListener()
      {
        public void bundleChanged(BundleEvent event)
        {
          if ((event.getBundle() == EclipseStarter.this) && (event.getType() == 4)) {
            handler.run();
          }
        }
      };
      context.addBundleListener(listener);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.core.runtime.adaptor.EclipseStarter
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.core.runtime.adaptor;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import org.eclipse.core.runtime.internal.adaptor.BasicLocation;
import org.eclipse.core.runtime.internal.adaptor.EclipseEnvironmentInfo;
import org.eclipse.core.runtime.internal.adaptor.LocationHelper;
import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
import org.eclipse.osgi.internal.baseadaptor.AdaptorUtil;
import org.eclipse.osgi.service.datalocation.Location;

public class LocationManager
{
  private static Location installLocation = null;
  private static Location configurationLocation = null;
  private static Location userLocation = null;
  private static Location instanceLocation = null;
  private static Location eclipseHomeLocation = null;
  public static final String READ_ONLY_AREA_SUFFIX = ".readOnly";
  public static final String PROP_INSTALL_AREA = "osgi.install.area";
  public static final String PROP_CONFIG_AREA = "osgi.configuration.area";
  public static final String PROP_CONFIG_AREA_DEFAULT = "osgi.configuration.area.default";
  public static final String PROP_SHARED_CONFIG_AREA = "osgi.sharedConfiguration.area";
  public static final String PROP_INSTANCE_AREA = "osgi.instance.area";
  public static final String PROP_INSTANCE_AREA_DEFAULT = "osgi.instance.area.default";
  public static final String PROP_USER_AREA = "osgi.user.area";
  public static final String PROP_USER_AREA_DEFAULT = "osgi.user.area.default";
  public static final String PROP_MANIFEST_CACHE = "osgi.manifest.cache";
  public static final String PROP_USER_HOME = "user.home";
  public static final String PROP_USER_DIR = "user.dir";
  public static final String PROP_HOME_LOCATION_AREA = "eclipse.home.location";
  static final String PROP_LAUNCHER = "eclipse.launcher";
  public static final String BUNDLES_DIR = "bundles";
  public static final String STATE_FILE = ".state";
  public static final String LAZY_FILE = ".lazy";
  public static final String BUNDLE_DATA_FILE = ".bundledata";
  public static final String MANIFESTS_DIR = "manifests";
  public static final String CONFIG_FILE = "config.ini";
  public static final String ECLIPSE_PROPERTIES = "eclipse.properties";
  private static final String ECLIPSE = "eclipse";
  private static final String PRODUCT_SITE_MARKER = ".eclipseproduct";
  private static final String PRODUCT_SITE_ID = "id";
  private static final String PRODUCT_SITE_VERSION = "version";
  private static final String CONFIG_DIR = "configuration";
  private static final String NONE = "@none";
  private static final String NO_DEFAULT = "@noDefault";
  private static final String USER_HOME = "@user.home";
  private static final String USER_DIR = "@user.dir";
  private static final String INSTANCE_DATA_AREA_PREFIX = ".metadata/.plugins/";
  
  public static URL buildURL(String spec, boolean trailingSlash)
  {
    return LocationHelper.buildURL(spec, trailingSlash);
  }
  
  private static void mungeConfigurationLocation()
  {
    String location = FrameworkProperties.getProperty("osgi.configuration.area");
    if ((location != null) && 
      (location.endsWith(".cfg")))
    {
      int index = location.lastIndexOf('/');
      if (index < 0) {
        index = location.lastIndexOf('\\');
      }
      location = location.substring(0, index + 1);
      FrameworkProperties.setProperty("osgi.configuration.area", location);
    }
  }
  
  public static void initializeLocations()
  {
    String osgiStorage = FrameworkProperties.getProperty("org.osgi.framework.storage");
    if (osgiStorage != null) {
      FrameworkProperties.setProperty("osgi.configuration.area", osgiStorage);
    }
    installLocation = buildLocation("osgi.install.area", null, "", true, false, null);
    
    Location temp = buildLocation("osgi.user.area.default", null, "", false, false, null);
    URL defaultLocation = temp == null ? null : temp.getURL();
    if (defaultLocation == null) {
      defaultLocation = buildURL(new File(FrameworkProperties.getProperty("user.home"), "user").getAbsolutePath(), true);
    }
    userLocation = buildLocation("osgi.user.area", defaultLocation, "", false, false, null);
    
    temp = buildLocation("osgi.instance.area.default", null, "", false, false, ".metadata/.plugins/");
    defaultLocation = temp == null ? null : temp.getURL();
    if (defaultLocation == null) {
      defaultLocation = buildURL(new File(FrameworkProperties.getProperty("user.dir"), "workspace").getAbsolutePath(), true);
    }
    instanceLocation = buildLocation("osgi.instance.area", defaultLocation, "", false, false, ".metadata/.plugins/");
    
    mungeConfigurationLocation();
    
    temp = buildLocation("osgi.configu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd