/**
  * Reads and returns the VM arguments specified in the running platform's .ini file, or am empty
  * string if none.
  *
  * @return VM arguments specified in the running platform's .ini file
  */
 public static String getIniVMArgs() {
   File installDirectory = new File(Platform.getInstallLocation().getURL().getFile());
   if (Platform.getOS().equals(Platform.OS_MACOSX))
     installDirectory = new File(installDirectory, "Eclipse.app/Contents/MacOS"); // $NON-NLS-1$
   File eclipseIniFile = new File(installDirectory, "eclipse.ini"); // $NON-NLS-1$
   BufferedReader in = null;
   StringBuffer result = new StringBuffer();
   if (eclipseIniFile.exists()) {
     try {
       in = new BufferedReader(new FileReader(eclipseIniFile));
       String str;
       boolean vmargs = false;
       while ((str = in.readLine()) != null) {
         if (vmargs) {
           if (result.length() > 0) result.append(" "); // $NON-NLS-1$
           result.append(str);
         }
         // start concat'ng if we have vmargs
         if (vmargs == false && str.equals("-vmargs")) // $NON-NLS-1$
         vmargs = true;
       }
     } catch (IOException e) {
       MDECore.log(e);
     } finally {
       if (in != null)
         try {
           in.close();
         } catch (IOException e) {
           MDECore.log(e);
         }
     }
   }
   return result.toString();
 }
 /** @return the default list of bundles to use in the osgi.bundles property */
 public static String getDefaultBundleList() {
   StringBuffer buffer = new StringBuffer();
   if (getTargetVersion() > 3.1) {
     buffer.append("org.eclipse.equinox.common@2:start,"); // $NON-NLS-1$
     buffer.append("org.eclipse.update.configurator@3:start,"); // $NON-NLS-1$
     buffer.append("org.eclipse.core.runtime@start"); // $NON-NLS-1$
   } else {
     buffer.append("org.eclipse.core.runtime@2:start,"); // $NON-NLS-1$
     buffer.append("org.eclipse.update.configurator@3:start"); // $NON-NLS-1$
   }
   return buffer.toString();
 }
예제 #3
0
 protected String makeKeys() {
   StringBuffer sb = new StringBuffer();
   for (Iterator it = props.keySet().iterator(); it.hasNext(); ) {
     if (sb.length() > 0) {
       sb.append(',');
     }
     sb.append(it.next().toString());
   }
   for (Iterator it = props_default.keySet().iterator(); it.hasNext(); ) {
     sb.append(',');
     sb.append(it.next().toString());
   }
   return sb.toString();
 }
예제 #4
0
 public String toString() {
   StringBuffer result = new StringBuffer();
   for (int i = 0; i < filters.length; i++) {
     result.append(filters[i]).append('-').append('>').append(outputStrings[i]).append('\n');
   }
   return result.toString();
 }
  /**
   * Removes path information from the given string containing one or more comma separated osgi
   * bundles. Replaces escaped '\:' with ':'. Removes, reference, platform and file prefixes.
   * Removes any other path information converting the location or the last segment to a bundle id.
   *
   * @param osgiBundles list of bundles to strip path information from (commma separated)
   * @return list of bundles with path information stripped
   */
  public static String stripPathInformation(String osgiBundles) {
    StringBuffer result = new StringBuffer();
    StringTokenizer tokenizer = new StringTokenizer(osgiBundles, ","); // $NON-NLS-1$
    while (tokenizer.hasMoreElements()) {
      String token = tokenizer.nextToken();
      token = token.replaceAll("\\\\:|/:", ":"); // $NON-NLS-1$ //$NON-NLS-2$

      // read up until the first @, if there
      int atIndex = token.indexOf('@');
      String bundle = atIndex > 0 ? token.substring(0, atIndex) : token;
      bundle = bundle.trim();

      // strip [reference:][platform:][file:] prefixes if any
      if (bundle.startsWith(REFERENCE_PREFIX) && bundle.length() > REFERENCE_PREFIX.length())
        bundle = bundle.substring(REFERENCE_PREFIX.length());
      if (bundle.startsWith(PLATFORM_PREFIX) && bundle.length() > PLATFORM_PREFIX.length())
        bundle = bundle.substring(PLATFORM_PREFIX.length());
      if (bundle.startsWith(FILE_URL_PREFIX) && bundle.length() > FILE_URL_PREFIX.length())
        bundle = bundle.substring(FILE_URL_PREFIX.length());

      // if the path is relative, the last segment is the bundle symbolic name
      // Otherwise, we need to retrieve the bundle symbolic name ourselves
      IPath path = new Path(bundle);
      String id = null;
      if (path.isAbsolute()) {
        id = getSymbolicName(bundle);
      }
      if (id == null) {
        id = path.lastSegment();
      }
      if (id != null) {
        int underscoreIndex = id.indexOf('_');
        if (underscoreIndex >= 0) {
          id = id.substring(0, underscoreIndex);
        }
        if (id.endsWith(JAR_EXTENSION)) {
          id = id.substring(0, id.length() - 4);
        }
      }
      if (result.length() > 0) result.append(","); // $NON-NLS-1$
      result.append(id != null ? id : bundle);
      if (atIndex > -1) result.append(token.substring(atIndex).trim());
    }
    return result.toString();
  }
  protected BundleContext startFramework(File bundleInfo, File[] additionalBundle) {
    try {
      File simpleConfiguratorBundle = getLocation("org.eclipse.equinox.simpleconfigurator");
      File osgiBundleLoc = getLocation("org.eclipse.osgi");

      // for test purposes create an install.area and configuration.area located in the local bundle
      // data area.
      File installarea = TestActivator.context.getDataFile(getName() + "/eclipse");
      File configarea = new File(installarea, "configuration");
      URL osgiBundle = osgiBundleLoc.toURI().toURL();

      Map frameworkProperties = new HashMap();
      // note that any properties you do not want to be inherited from the hosting Equinox will need
      // to be nulled out.  Otherwise you will pick them up from the hosting env.
      frameworkProperties.put("osgi.framework", null);
      frameworkProperties.put("osgi.install.area", installarea.toURL().toExternalForm());
      frameworkProperties.put("osgi.configuration.area", configarea.toURL().toExternalForm());
      StringBuffer osgiBundles = new StringBuffer();
      for (int i = 0; additionalBundle != null && i < additionalBundle.length; i++) {
        osgiBundles
            .append("reference:")
            .append(additionalBundle[i].toURL().toExternalForm())
            .append(",");
      }
      osgiBundles
          .append("reference:")
          .append(simpleConfiguratorBundle.toURL().toExternalForm())
          .append("@1:start");
      frameworkProperties.put("osgi.bundles", osgiBundles.toString());

      frameworkProperties.put(
          "org.eclipse.equinox.simpleconfigurator.configUrl", bundleInfo.toURL().toExternalForm());
      frameworkProperties.put("osgi.dev", "bin/");

      equinox = new EmbeddedEquinox(frameworkProperties, new String[] {}, new URL[] {osgiBundle});
      return equinox.startFramework();
    } catch (MalformedURLException e) {
      return null;
    }
  }
예제 #7
0
  /** Create the default set of framework (launch) properties. */
  protected void initProperties(FrameworkContext fwCtx) {
    setPropertyIfNotSet(Constants.FRAMEWORK_BOOTDELEGATION, "");
    setPropertyIfNotSet(Constants.FRAMEWORK_BUNDLE_PARENT, Constants.FRAMEWORK_BUNDLE_PARENT_BOOT);
    setPropertyIfNotSet(Constants.FRAMEWORK_EXECPERMISSION, "");

    if (!props.containsKey(Constants.FRAMEWORK_EXECUTIONENVIRONMENT)) {
      StringBuffer ee = new StringBuffer();
      // Always allow ee minimum
      ee.append("OSGi/Minimum-1.0");
      ee.append(",OSGi/Minimum-1.1");
      ee.append(",OSGi/Minimum-1.2");
      // Set up the default ExecutionEnvironment
      if (1 == javaVersionMajor) {
        for (int i = javaVersionMinor; i > 1; i--) {
          ee.append((i > 5) ? ",JavaSE-1." : ",J2SE-1.");
          ee.append(i);
        }
      }
      props.put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, ee.toString());
    }

    setPropertyIfNotSet(Constants.FRAMEWORK_LANGUAGE, Locale.getDefault().getLanguage());
    setPropertyIfNotSet(Constants.FRAMEWORK_LIBRARY_EXTENSIONS, "");

    setPropertyIfNotSet(
        Constants.FRAMEWORK_OS_NAME, Alias.unifyOsName(System.getProperty("os.name")));

    if (!props.containsKey(Constants.FRAMEWORK_OS_VERSION)) {
      String ver = System.getProperty("os.version");
      int maj = 0;
      int min = 0;
      int mic = 0;
      String qual = null;
      if (ver != null) {
        // Convert os.version to a reasonable default
        try {
          StringTokenizer st = new StringTokenizer(ver.trim(), ".");
          maj = Integer.parseInt(st.nextToken());
          if (st.hasMoreTokens()) {
            qual = st.nextToken();
            min = Integer.parseInt(qual);
            qual = null;
            if (st.hasMoreTokens()) {
              qual = st.nextToken();
              mic = Integer.parseInt(qual);
              qual = null;
              if (st.hasMoreTokens()) {
                qual = st.nextToken();
              }
            }
          }
        } catch (Exception ignore) {
        }
      }
      Version osVersion;
      try {
        osVersion = new Version(maj, min, mic, qual);
      } catch (IllegalArgumentException skip) {
        osVersion = new Version(maj, min, mic, null);
      }
      props.put(Constants.FRAMEWORK_OS_VERSION, osVersion.toString());
    }

    setPropertyIfNotSet(
        Constants.FRAMEWORK_PROCESSOR, Alias.unifyProcessor(System.getProperty("os.arch")));

    setPropertyIfNotSet(Constants.FRAMEWORK_SECURITY, "");

    setPropertyIfNotSet(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, "1");

    setPropertyIfNotSet(Constants.FRAMEWORK_STORAGE, "fwdir");

    setPropertyIfNotSet(Constants.FRAMEWORK_STORAGE_CLEAN, "");

    // NYI, fill this with values
    setPropertyIfNotSet(Constants.FRAMEWORK_SYSTEMPACKAGES, "");

    setPropertyIfNotSet(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "");

    setPropertyIfNotSet(Constants.FRAMEWORK_TRUST_REPOSITORIES, "");

    // NYI
    setPropertyIfNotSet(Constants.FRAMEWORK_WINDOWSYSTEM, "");

    // Impl. constants
    props.put(Constants.FRAMEWORK_VERSION, FrameworkContext.SPEC_VERSION);
    props.put(Constants.FRAMEWORK_VENDOR, "Knopflerfish");
    props.put(Constants.SUPPORTS_FRAMEWORK_REQUIREBUNDLE, TRUE);
    props.put(Constants.SUPPORTS_FRAMEWORK_FRAGMENT, TRUE);
    // Only first framework support framework extension
    // NYI! Improve this in the future
    props.put(
        Constants.SUPPORTS_FRAMEWORK_EXTENSION,
        getClass().getClassLoader() instanceof URLClassLoader && fwCtx.id == 0 ? TRUE : FALSE);
    // Only first framework can support bootclasspath extension
    // NYI! Improve this in the future
    setPropertyIfNotSet(Constants.SUPPORTS_BOOTCLASSPATH_EXTENSION, FALSE);
    if (getBooleanProperty(Constants.SUPPORTS_BOOTCLASSPATH_EXTENSION)
        && !(getClass().getClassLoader() instanceof URLClassLoader && fwCtx.id == 1)) {
      props.put(Constants.SUPPORTS_BOOTCLASSPATH_EXTENSION, FALSE);
    }
  }