コード例 #1
0
  public BundleInfo[] save(Manipulator manipulator, boolean backup) throws IOException {
    List setToInitialConfig = new LinkedList();
    List setToSimpleConfig = new LinkedList();
    ConfigData configData = manipulator.getConfigData();

    if (!divideBundleInfos(
        manipulator,
        setToInitialConfig,
        setToSimpleConfig,
        configData.getInitialBundleStartLevel())) return configData.getBundles();

    File outputFile = getConfigFile(manipulator);
    URI installArea =
        ParserUtils.getOSGiInstallArea(
                Arrays.asList(manipulator.getLauncherData().getProgramArgs()),
                manipulator.getConfigData().getProperties(),
                manipulator.getLauncherData())
            .toURI();
    saveConfiguration(
        (BundleInfo[]) setToSimpleConfig.toArray(new BundleInfo[setToSimpleConfig.size()]),
        outputFile,
        installArea,
        backup);
    configData.setProperty(
        SimpleConfiguratorManipulatorImpl.PROP_KEY_CONFIGURL, outputFile.toURL().toExternalForm());
    return orderingInitialConfig(setToInitialConfig);
  }
コード例 #2
0
  /*
   * InputStream must be closed
   * (non-Javadoc)
   * @see org.eclipse.equinox.simpleconfigurator.manipulator.SimpleConfiguratorManipulator#loadConfiguration(java.io.InputStream, java.net.URI)
   */
  public BundleInfo[] loadConfiguration(InputStream stream, URI installArea) throws IOException {
    if (stream == null) return NULL_BUNDLEINFOS;

    List simpleBundles = SimpleConfiguratorUtils.readConfiguration(stream, installArea);

    // convert to FrameworkAdmin BundleInfo Type
    BundleInfo[] result = new BundleInfo[simpleBundles.size()];
    int i = 0;
    for (Iterator iterator = simpleBundles.iterator(); iterator.hasNext(); ) {
      org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo simpleInfo =
          (org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo) iterator.next();
      URI location = simpleInfo.getLocation();
      if (!location.isAbsolute() && simpleInfo.getBaseLocation() != null)
        location = URIUtil.makeAbsolute(location, simpleInfo.getBaseLocation());

      BundleInfo bundleInfo =
          new BundleInfo(
              simpleInfo.getSymbolicName(),
              simpleInfo.getVersion(),
              location,
              simpleInfo.getStartLevel(),
              simpleInfo.isMarkedAsStarted());
      bundleInfo.setBaseLocation(simpleInfo.getBaseLocation());
      result[i++] = bundleInfo;
    }
    return result;
  }
コード例 #3
0
 private SortedMap getSortedMap(int initialSl, BundleInfo[] bInfos) {
   SortedMap bslToList = new TreeMap();
   for (int i = 0; i < bInfos.length; i++) {
     Integer sL = new Integer(bInfos[i].getStartLevel());
     if (sL.intValue() == BundleInfo.NO_LEVEL) sL = new Integer(initialSl);
     List list = (List) bslToList.get(sL);
     if (list == null) {
       list = new LinkedList();
       bslToList.put(sL, list);
     }
     list.add(bInfos[i]);
   }
   return bslToList;
 }
コード例 #4
0
 private BundleInfo[] orderingInitialConfig(List setToInitialConfig) {
   List notToBeStarted = new LinkedList();
   List toBeStarted = new LinkedList();
   for (Iterator ite2 = setToInitialConfig.iterator(); ite2.hasNext(); ) {
     BundleInfo bInfo = (BundleInfo) ite2.next();
     if (bInfo.isMarkedAsStarted()) toBeStarted.add(bInfo);
     else notToBeStarted.add(bInfo);
   }
   setToInitialConfig.clear();
   setToInitialConfig.addAll(notToBeStarted);
   setToInitialConfig.addAll(toBeStarted);
   return Utils.getBundleInfosFromList(setToInitialConfig);
 }
コード例 #5
0
  public void updateBundles(Manipulator manipulator) throws IOException {
    if (DEBUG)
      System.out.println("SimpleConfiguratorManipulatorImpl#updateBundles()"); // $NON-NLS-1$

    BundlesState bundleState = manipulator.getBundlesState();

    if (bundleState == null) return;
    if (bundleState.isFullySupported()) bundleState.resolve(true);

    BundleInfo[] currentBInfos = bundleState.getExpectedState();
    if (!isTargetConfiguratorBundle(currentBInfos)) return;
    Properties properties = new Properties();
    String[] jvmArgs = manipulator.getLauncherData().getJvmArgs();
    for (int i = 0; i < jvmArgs.length; i++) {
      if (jvmArgs[i].startsWith("-D")) { // $NON-NLS-1$
        int index = jvmArgs[i].indexOf("="); // $NON-NLS-1$
        if (index > 0 && jvmArgs[i].length() > 2) {
          String key = jvmArgs[i].substring(2, index);
          String value = jvmArgs[i].substring(index + 1);
          properties.setProperty(key, value);
        }
      }
    }

    Utils.appendProperties(properties, manipulator.getConfigData().getProperties());
    boolean exclusiveInstallation =
        Boolean.valueOf(
                properties.getProperty(
                    SimpleConfiguratorManipulatorImpl.PROP_KEY_EXCLUSIVE_INSTALLATION))
            .booleanValue();
    File configFile = getConfigFile(manipulator);

    File installArea =
        ParserUtils.getOSGiInstallArea(
            Arrays.asList(manipulator.getLauncherData().getProgramArgs()),
            manipulator.getConfigData().getProperties(),
            manipulator.getLauncherData());
    BundleInfo[] toInstall = new BundleInfo[0];

    boolean isShared = isSharedInstallSetup(installArea, configFile);
    if (!isShared
        || (isShared && !hasBaseChanged(installArea.toURI(), configFile.getParentFile()))) {
      try {
        // input stream will be closed for us
        toInstall = loadConfiguration(new FileInputStream(configFile), installArea.toURI());
      } catch (FileNotFoundException e) {
        // no file, just return an empty list
        toInstall = new BundleInfo[0];
      }
    }

    List toUninstall = new LinkedList();
    if (exclusiveInstallation)
      for (int i = 0; i < currentBInfos.length; i++) {
        boolean install = false;
        for (int j = 0; j < toInstall.length; j++)
          if (currentBInfos[i].getLocation().equals(toInstall[j].getLocation())) {
            install = true;
            break;
          }
        if (!install) toUninstall.add(currentBInfos[i]);
      }

    for (int i = 0; i < toInstall.length; i++) {
      try {
        bundleState.installBundle(toInstall[i]);
      } catch (RuntimeException e) {
        // Ignore
      }
    }
    if (exclusiveInstallation)
      for (Iterator ite = toUninstall.iterator(); ite.hasNext(); ) {
        BundleInfo bInfo = (BundleInfo) ite.next();
        bundleState.uninstallBundle(bInfo);
      }

    bundleState.resolve(true);
    manipulator.getConfigData().setBundles(bundleState.getExpectedState());
  }
コード例 #6
0
  private void algorithm(
      int initialSl,
      SortedMap bslToList,
      BundleInfo configuratorBInfo,
      List setToInitialConfig,
      List setToSimpleConfig,
      LocationInfo info) {
    int configuratorSL = configuratorBInfo.getStartLevel();

    Integer sL0 = (Integer) bslToList.keySet().iterator().next(); // StartLevel == 0;
    List list0 = (List) bslToList.get(sL0);
    if (sL0.intValue() == 0)
      for (Iterator ite2 = list0.iterator(); ite2.hasNext(); ) {
        BundleInfo bInfo = (BundleInfo) ite2.next();
        if (isSystemBundle(bInfo.getLocation(), info)) {
          setToSimpleConfig.add(bInfo);
          break;
        }
      }

    for (Iterator ite = bslToList.keySet().iterator(); ite.hasNext(); ) {
      Integer sL = (Integer) ite.next();
      List list = (List) bslToList.get(sL);

      if (sL.intValue() < configuratorSL) {
        for (Iterator ite2 = list.iterator(); ite2.hasNext(); ) {
          BundleInfo bInfo = (BundleInfo) ite2.next();
          if (!isSystemBundle(bInfo.getLocation(), info)) setToInitialConfig.add(bInfo);
        }
      } else if (sL.intValue() > configuratorSL) {
        for (Iterator ite2 = list.iterator(); ite2.hasNext(); ) {
          BundleInfo bInfo = (BundleInfo) ite2.next();
          if (isPrerequisiteBundles(bInfo.getLocation(), info)
              || isSystemFragmentBundle(bInfo.getLocation(), info))
            if (!isSystemBundle(bInfo.getLocation(), info)) setToInitialConfig.add(bInfo);
          setToSimpleConfig.add(bInfo);
        }
      } else {
        boolean found = false;
        for (Iterator ite2 = list.iterator(); ite2.hasNext(); ) {
          BundleInfo bInfo = (BundleInfo) ite2.next();
          if (found) {
            if (!isSystemBundle(bInfo.getLocation(), info))
              if (isPrerequisiteBundles(bInfo.getLocation(), info)
                  || isSystemFragmentBundle(bInfo.getLocation(), info))
                setToInitialConfig.add(bInfo);
            setToSimpleConfig.add(bInfo);
            continue;
          }
          if (isTargetConfiguratorBundle(bInfo.getLocation())) found = true;
          else if (!isSystemBundle(bInfo.getLocation(), info)) setToInitialConfig.add(bInfo);
          setToSimpleConfig.add(bInfo);
        }
      }
    }

    setToInitialConfig.add(configuratorBInfo);
  }