org.eclipse.equinox.simpleconfigurator.manipulator_2.0.0.v20110808-1657

16:44:48.889 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.simpleconfigurator.manipulator_2.0.0.v20110808-1657.jar
package org.eclipse.equinox.internal.simpleconfigurator.manipulator;

import org.eclipse.equinox.internal.provisional.configuratormanipulator.ConfiguratorManipulator;
import org.eclipse.equinox.internal.provisional.configuratormanipulator.ConfiguratorManipulatorFactory;

public class SimpleConfiguratorManipulatorFactoryImpl
  extends ConfiguratorManipulatorFactory
{
  protected ConfiguratorManipulator createConfiguratorManipulator()
  {
    return new SimpleConfiguratorManipulatorImpl();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.simpleconfigurator.manipulator.SimpleConfiguratorManipulatorFactoryImpl
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.simpleconfigurator.manipulator;

import java.net.URI;

class SimpleConfiguratorManipulatorImpl$LocationInfo
{
  URI[] prerequisiteLocations;
  URI systemBundleLocation;
  URI[] systemFragmentedBundleLocations;
  final SimpleConfiguratorManipulatorImpl this$0;
  
  SimpleConfiguratorManipulatorImpl$LocationInfo(SimpleConfiguratorManipulatorImpl paramSimpleConfiguratorManipulatorImpl)
  {
    this$0 = paramSimpleConfiguratorManipulatorImpl;
    prerequisiteLocations = null;
    systemBundleLocation = null;
    systemFragmentedBundleLocations = null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.simpleconfigurator.manipulator.SimpleConfiguratorManipulatorImpl.LocationInfo
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.simpleconfigurator.manipulator;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URL;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.frameworkadmin.equinox.ParserUtils;
import org.eclipse.equinox.internal.frameworkadmin.utils.Utils;
import org.eclipse.equinox.internal.provisional.configuratormanipulator.ConfiguratorManipulator;
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundlesState;
import org.eclipse.equinox.internal.provisional.frameworkadmin.ConfigData;
import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData;
import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator;
import org.eclipse.equinox.internal.simpleconfigurator.SimpleConfiguratorImpl;
import org.eclipse.equinox.internal.simpleconfigurator.utils.EquinoxUtils;
import org.eclipse.equinox.internal.simpleconfigurator.utils.SimpleConfiguratorUtils;
import org.eclipse.equinox.simpleconfigurator.manipulator.SimpleConfiguratorManipulator;
import org.eclipse.osgi.service.datalocation.Location;
import org.osgi.framework.BundleContext;

public class SimpleConfiguratorManipulatorImpl
  implements SimpleConfiguratorManipulator, ConfiguratorManipulator
{
  private static final boolean DEBUG = false;
  
  class LocationInfo
  {
    URI[] prerequisiteLocations = null;
    URI systemBundleLocation = null;
    URI[] systemFragmentedBundleLocations = null;
    
    LocationInfo() {}
  }
  
  private static final org.eclipse.equinox.frameworkadmin.BundleInfo[] NULL_BUNDLEINFOS = new org.eclipse.equinox.frameworkadmin.BundleInfo[0];
  public static final String PROP_KEY_EXCLUSIVE_INSTALLATION = "org.eclipse.equinox.simpleconfigurator.exclusiveInstallation";
  public static final String CONFIG_LIST = "bundles.info";
  public static final String CONFIGURATOR_FOLDER = "org.eclipse.equinox.simpleconfigurator";
  public static final String PROP_KEY_CONFIGURL = "org.eclipse.equinox.simpleconfigurator.configUrl";
  private Set manipulators = new HashSet();
  
  private static File getConfigFile(Manipulator manipulator)
    throws IllegalStateException
  {
    File fwConfigLoc = manipulator.getLauncherData().getFwConfigLocation();
    File baseDir = null;
    if (fwConfigLoc == null)
    {
      baseDir = manipulator.getLauncherData().getHome();
      if (baseDir == null) {
        if (manipulator.getLauncherData().getLauncher() != null) {
          baseDir = manipulator.getLauncherData().getLauncher().getParentFile();
        } else {
          throw new IllegalStateException("All of fwConfigFile, home, launcher are not set.");
        }
      }
    }
    else if (fwConfigLoc.exists())
    {
      if (fwConfigLoc.isDirectory()) {
        baseDir = fwConfigLoc;
      } else {
        baseDir = fwConfigLoc.getParentFile();
      }
    }
    else if (fwConfigLoc.getName().endsWith(".ini"))
    {
      baseDir = fwConfigLoc.getParentFile();
    }
    else
    {
      baseDir = fwConfigLoc;
    }
    File configuratorFolder = new File(baseDir, "org.eclipse.equinox.simpleconfigurator");
    File targetFile = new File(configuratorFolder, "bundles.info");
    if (!Utils.createParentDir(targetFile)) {
      return null;
    }
    return targetFile;
  }
  
  static boolean isPrerequisiteBundles(URI location, LocationInfo info)
  {
    boolean ret = false;
    if (prerequisiteLocations == null) {
      return false;
    }
    for (int i = 0; i < prerequisiteLocations.length; i++) {
      if (location.equals(prerequisiteLocations[i]))
      {
        ret = true;
        break;
      }
    }
    return ret;
  }
  
  static boolean isSystemBundle(URI location, LocationInfo info)
  {
    if (systemBundleLocation == null) {
      return false;
    }
    if (location.equals(systemBundleLocation)) {
      return true;
    }
    return false;
  }
  
  static boolean isSystemFragmentBundle(URI location, LocationInfo info)
  {
    boolean ret = false;
    if (systemFragmentedBundleLocations == null) {
      return false;
    }
    for (int i = 0; i < systemFragmentedBundleLocations.length; i++) {
      if (location.equals(systemFragmentedBundleLocations[i]))
      {
        ret = true;
        break;
      }
    }
    return ret;
  }
  
  private static boolean isTargetConfiguratorBundle(org.eclipse.equinox.frameworkadmin.BundleInfo[] bInfos)
  {
    for (int i = 0; i < bInfos.length; i++) {
      if (isTargetConfiguratorBundle(bInfos[i].getLocation())) {
        return true;
      }
    }
    return false;
  }
  
  private static boolean isTargetConfiguratorBundle(URI location)
  {
    String symbolic = Utils.getPathFromClause(Utils.getManifestMainAttributes(location, "Bundle-SymbolicName"));
    return "org.eclipse.equinox.simpleconfigurator".equals(symbolic);
  }
  
  private void algorithm(int initialSl, SortedMap bslToList, org.eclipse.equinox.frameworkadmin.BundleInfo configuratorBInfo, List setToInitialConfig, List setToSimpleConfig, LocationInfo info)
  {
    int configuratorSL = configuratorBInfo.getStartLevel();
    
    Integer sL0 = (Integer)bslToList.keySet().iterator().next();
    List list0 = (List)bslToList.get(sL0);
    if (sL0.intValue() == 0) {
      for (Iterator ite2 = list0.iterator(); ite2.hasNext();)
      {
        org.eclipse.equinox.frameworkadmin.BundleInfo bInfo = (org.eclipse.equinox.frameworkadmin.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();)
        {
          org.eclipse.equinox.frameworkadmin.BundleInfo bInfo = (org.eclipse.equinox.frameworkadmin.BundleInfo)ite2.next();
          if (!isSystemBundle(bInfo.getLocation(), info)) {
            setToInitialConfig.add(bInfo);
          }
        }
      }
      else if (sL.intValue() > configuratorSL)
      {
        for (Iterator ite2 = list.iterator(); ite2.hasNext();)
        {
          org.eclipse.equinox.frameworkadmin.BundleInfo bInfo = (org.eclipse.equinox.frameworkadmin.BundleInfo)ite2.next();
          if (((isPrerequisiteBundles(bInfo.getLocation(), info)) || (isSystemFragmentBundle(bInfo.getLocation(), info))) && 
            (!isSystemBundle(bInfo.getLocation(), info))) {
            setToInitialConfig.add(bInfo);
          }
          setToSimpleConfig.add(bInfo);
        }
      }
      else
      {
        boolean found = false;
        for (Iterator ite2 = list.iterator(); ite2.hasNext();)
        {
          org.eclipse.equinox.frameworkadmin.BundleInfo bInfo = (org.eclipse.equinox.frameworkadmin.BundleInfo)ite2.next();
          if (found)
          {
            if ((!isSystemBundle(bInfo.getLocation(), info)) && (
              (isPrerequisiteBundles(bInfo.getLocation(), info)) || (isSystemFragmentBundle(bInfo.getLocation(), info)))) {
              setToInitialConfig.add(bInfo);
            }
            setToSimpleConfig.add(bInfo);
          }
          else
          {
            if (isTargetConfiguratorBundle(bInfo.getLocation())) {
              found = true;
            } else if (!isSystemBundle(bInfo.getLocation(), info)) {
              setToInitialConfig.add(bInfo);
            }
            setToSimpleConfig.add(bInfo);
          }
        }
      }
    }
    setToInitialConfig.add(configuratorBInfo);
  }
  
  private boolean checkResolve(org.eclipse.equinox.frameworkadmin.BundleInfo bInfo, BundlesState state)
  {
    if (bInfo == null) {
      throw new IllegalArgumentException("bInfo is null.");
    }
    if (!state.isResolved()) {
      state.resolve(false);
    }
    if (!state.isResolved(bInfo))
    {
      printoutUnsatisfiedConstraints(bInfo, state);
      return false;
    }
    return true;
  }
  
  private boolean divideBundleInfos(Manipulator manipulator, List setToInitialConfig, List setToSimpleConfig, int initialBSL)
  {
    BundlesState state = manipulator.getBundlesState();
    org.eclipse.equinox.frameworkadmin.BundleInfo[] targetBundleInfos = null;
    if (state.isFullySupported()) {
      targetBundleInfos = state.getExpectedState();
    } else {
      targetBundleInfos = manipulator.getConfigData().getBundles();
    }
    org.eclipse.equinox.frameworkadmin.BundleInfo configuratorBInfo = null;
    for (int i = 0; i < targetBundleInfos.length; i++) {
      if ((isTargetConfiguratorBundle(targetBundleInfos[i].getLocation())) && 
        (targetBundleInfos[i].isMarkedAsStarted()))
      {
        configuratorBInfo = targetBundleInfos[i];
        break;
      }
    }
    if ((configuratorBInfo == null) && (!manipulators.contains(manipulator))) {
      return false;
    }
    if ((manipulators.contains(manipulator)) && (targetBundleInfos.length == 0)) {
      manipulators.remove(manipulator);
    } else if (!manipulators.contains(manipulator)) {
      manipulators.add(manipulator);
    }
    if (state.isFullySupported()) {
      state.resolve(false);
    }
    LocationInfo info = new LocationInfo();
    setSystemBundles(state, info);
    if (configuratorBInfo != null)
    {
      setPrerequisiteBundles(configuratorBInfo, state, info);
      SortedMap bslToList = getSortedMap(initialBSL, targetBundleInfos);
      algorithm(initialBSL, bslToList, configuratorBInfo, setToInitialConfig, setToSimpleConfig, info);
    }
    return true;
  }
  
  private SortedMap getSortedMap(int initialSl, org.eclipse.equinox.frameworkadmin.BundleInfo[] bInfos)
  {
    SortedMap bslToList = new TreeMap();
    for (int i = 0; i < bInfos.length; i++)
    {
      Integer sL = new Integer(bInfos[i].getStartLevel());
      if (sL.intValue() == -1) {
        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;
  }
  
  private org.eclipse.equinox.frameworkadmin.BundleInfo[] orderingInitialConfig(List setToInitialConfig)
  {
    List notToBeStarted = new LinkedList();
    List toBeStarted = new LinkedList();
    for (Iterator ite2 = setToInitialConfig.iterator(); ite2.hasNext();)
    {
      org.eclipse.equinox.frameworkadmin.BundleInfo bInfo = (org.eclipse.equinox.frameworkadmin.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);
  }
  
  private void printoutUnsatisfiedConstraints(org.eclipse.equinox.frameworkadmin.BundleInfo bInfo, BundlesState state) {}
  
  public org.eclipse.equinox.frameworkadmin.BundleInfo[] loadConfiguration(BundleContext context, String infoPath)
    throws IOException
  {
    URI installArea = EquinoxUtils.getInstallLocationURI(context);
    
    URL configURL = null;
    InputStream stream = null;
    if (infoPath == null)
    {
      SimpleConfiguratorImpl simpleImpl = new SimpleConfiguratorImpl(context, null);
      configURL = simpleImpl.getConfigurationURL();
    }
    else
    {
      boolean defaultSource = infoPath == SOURCE_INFO;
      if (defaultSource) {
        infoPath = "org.eclipse.equinox.source/source.info";
      }
      Location configLocation = EquinoxUtils.getConfigLocation(context);
      configURL = configLocation.getDataArea(infoPath);
      try
      {
        stream = configURL.openStream();
      }
      catch (FileNotFoundException localFileNotFoundException1)
      {
        if ((defaultSource) && (configLocation.getParentLocation() != null)) {
          configURL = configLocation.getParentLocation().getDataArea(infoPath);
        } else {
          return new org.eclipse.equinox.frameworkadmin.BundleInfo[0];
        }
      }
    }
    if (configURL == null) {
      return new org.eclipse.equinox.frameworkadmin.BundleInfo[0];
    }
    if (stream == null) {
      try
      {
        stream = configURL.openStream();
      }
      catch (FileNotFoundException localFileNotFoundException2)
      {
        return new org.eclipse.equinox.frameworkadmin.BundleInfo[0];
      }
    }
    return loadConfiguration(stream, installArea);
  }
  
  public org.eclipse.equinox.frameworkadmin.BundleInfo[] loadConfiguration(InputStream stream, URI installArea)
    throws IOException
  {
    if (stream == null) {
      return NULL_BUNDLEINFOS;
    }
    List simpleBundles = SimpleConfiguratorUtils.readConfiguration(stream, installArea);
    
    org.eclipse.equinox.frameworkadmin.BundleInfo[] result = new org.eclipse.equinox.frameworkadmin.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());
      }
      org.eclipse.equinox.frameworkadmin.BundleInfo bundleInfo = new org.eclipse.equinox.frameworkadmin.BundleInfo(simpleInfo.getSymbolicName(), simpleInfo.getVersion(), location, simpleInfo.getStartLevel(), simpleInfo.isMarkedAsStarted());
      bundleInfo.setBaseLocation(simpleInfo.getBaseLocation());
      result[(i++)] = bundleInfo;
    }
    return result;
  }
  
  public void saveConfiguration(org.eclipse.equinox.frameworkadmin.BundleInfo[] configuration, OutputStream stream, URI installArea)
    throws IOException
  {
    org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] simpleInfos = convertBundleInfos(configuration, installArea);
    SimpleConfiguratorManipulatorUtils.writeConfiguration(simpleInfos, stream);
  }
  
  public void saveConfiguration(org.eclipse.equinox.frameworkadmin.BundleInfo[] configuration, File outputFile, URI installArea)
    throws IOException
  {
    saveConfiguration(configuration, outputFile, installArea, false);
  }
  
  private void saveConfiguration(org.eclipse.equinox.frameworkadmin.BundleInfo[] configuration, File outputFile, URI installArea, boolean backup)
    throws IOException
  {
    if ((backup) && (outputFile.exists()))
    {
      File backupFile = Utils.getSimpleDataFormattedFile(outputFile);
      if (!outputFile.renameTo(backupFile)) {
        throw new IOException("Fail to rename from (" + outputFile + ") to (" + backupFile + ")");
      }
    }
    org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] simpleInfos = convertBundleInfos(configuration, installArea);
    if ((simpleInfos == null) || (simpleInfos.length == 0))
    {
      if (outputFile.exists()) {
        outputFile.delete();
      }
      File parentDir = outputFile.getParentFile();
      if (parentDir.exists()) {
        parentDir.delete();
      }
      return;
    }
    SimpleConfiguratorManipulatorUtils.writeConfiguration(simpleInfos, outputFile);
  }
  
  private org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] convertBundleInfos(org.eclipse.equinox.frameworkadmin.BundleInfo[] configuration, URI installArea)
  {
    org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] simpleInfos = new org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[configuration.length];
    for (int i = 0; i < configuration.length; i++)
    {
      org.eclipse.equinox.frameworkadmin.BundleInfo bundleInfo = configuration[i];
      URI location = bundleInfo.getLocation();
      if ((bundleInfo.getSymbolicName() == null) || (bundleInfo.getVersion() == null) || (location == null)) {
        throw new IllegalArgumentException("Cannot persist bundleinfo: " + bundleInfo.toString());
      }
      if (installArea != null) {
        location = URIUtil.makeRelative(location, installArea);
      }
      simpleInfos[i] = new org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo(bundleInfo.getSymbolicName(), bundleInfo.getVersion(), location, bundleInfo.getStartLevel(), bundleInfo.isMarkedAsStarted());
      simpleInfos[i].setBaseLocation(bundleInfo.getBaseLocation());
    }
    return simpleInfos;
  }
  
  public org.eclipse.equinox.frameworkadmin.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((org.eclipse.equinox.frameworkadmin.BundleInfo[])setToSimpleConfig.toArray(new org.eclipse.equinox.frameworkadmin.BundleInfo[setToSimpleConfig.size()]), outputFile, installArea, backup);
    configData.setProperty("org.eclipse.equinox.simpleconfigurator.configUrl", outputFile.toURL().toExternalForm());
    return orderingInitialConfig(setToInitialConfig);
  }
  
  void setPrerequisiteBundles(org.eclipse.equinox.frameworkadmin.BundleInfo configuratorBundleInfo, BundlesState state, LocationInfo info)
  {
    if ((state.isFullySupported()) && 
      (!checkResolve(configuratorBundleInfo, state)))
    {
      printoutUnsatisfiedConstraints(configuratorBundleInfo, state);
      return;
    }
    org.eclipse.equinox.frameworkadmin.BundleInfo[] prerequisites = state.getPrerequisteBundles(configuratorBundleInfo);
    prerequisiteLocations = new URI[prerequisites.length];
    for (int i = 0; i < prerequisites.length; i++) {
      prerequisiteLocations[i] = prerequisites[i].getLocation();
    }
  }
  
  void setSystemBundles(BundlesState state, LocationInfo info)
  {
    org.eclipse.equinox.frameworkadmin.BundleInfo systemBundleInfo = state.getSystemBundle();
    if (systemBundleInfo == null) {
      return;
    }
    if ((state.isFullySupported()) && 
      (!checkResolve(systemBundleInfo, state)))
    {
      printoutUnsatisfiedConstraints(systemBundleInfo, state);
      return;
    }
    systemBundleLocation = systemBundleInfo.getLocation();
    org.eclipse.equinox.frameworkadmin.BundleInfo[] fragments = state.getSystemFragmentedBundles();
    systemFragmentedBundleLocations = new URI[fragments.length];
    for (int i = 0; i < fragments.length; i++) {
      systemFragmentedBundleLocations[i] = fragments[i].getLocation();
    }
  }
  
  public void updateBundles(Manipulator manipulator)
    throws IOException
  {
    BundlesState bundleState = manipulator.getBundlesState();
    if (bundleState == null) {
      return;
    }
    if (bundleState.isFullySupported()) {
      bundleState.resolve(true);
    }
    org.eclipse.equinox.frameworkadmin.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"))
      {
        int index = jvmArgs[i].indexOf("=");
        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("org.eclipse.equinox.simpleconfigurator.exclusiveInstallation")).booleanValue();
    File configFile = getConfigFile(manipulator);
    
    File installArea = ParserUtils.getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), manipulator.getConfigData().getProperties(), manipulator.getLauncherData());
    org.eclipse.equinox.frameworkadmin.BundleInfo[] toInstall = null;
    try
    {
      toInstall = loadConfiguration(new FileInputStream(configFile), installArea.toURI());
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      toInstall = new org.eclipse.equinox.frameworkadmin.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 localRuntimeException) {}
    }
    if (exclusiveInstallation) {
      for (Iterator ite = toUninstall.iterator(); ite.hasNext();)
      {
        org.eclipse.equinox.frameworkadmin.BundleInfo bInfo = (org.eclipse.equinox.frameworkadmin.BundleInfo)ite.next();
        bundleState.uninstallBundle(bInfo);
      }
    }
    bundleState.resolve(true);
    manipulator.getConfigData().setBundles(bundleState.getExpectedState());
  }
  
  public void cleanup(Manipulator manipulator)
  {
    File outputFile = getConfigFile(manipulator);
    outputFile.delete();
    if (outputFile.getParentFile().isDirectory()) {
      outputFile.getParentFile().delete();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.simpleconfigurator.manipulator.SimpleConfiguratorManipulatorImpl
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.simpleconfigurator.manipulator;

import java.util.Comparator;
import org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo;

class SimpleConfiguratorManipulatorUtils$1
  implements Comparator
{
  public int compare(Object o1, Object o2)
  {
    if (((o1 instanceof BundleInfo)) && ((o2 instanceof BundleInfo))) {
      return ((BundleInfo)o1).getSymbolicName().compareTo(((BundleInfo)o2).getSymbolicName());
    }
    return 0;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.simpleconfigurator.manipulator.SimpleConfiguratorManipulatorUtils.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.simpleconfigurator.manipulator;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URI;
import java.util.Arrays;
import java.util.Comparator;
import org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo;
import org.osgi.framework.Version;

public class SimpleConfiguratorManipulatorUtils
{
  private static final String VERSION_PREFIX = "#version=";
  private static final String VERSION_1 = "1";
  private static final Version OLD_STYLE_SIMPLE_CONFIGURATOR_VERSION = new Version("1.0.100.v20081206");
  private static final Version DEFAULT_ENCODING_CONFIGURATOR_VERSION = new Version("2.0.0.v20100329");
  
  /* Error */
  public static void writeConfiguration(BundleInfo[] simpleInfos, java.io.File outputFile)
    throws IOException
  {
    // Byte code:
    //   0: aload_1
    //   1: invokestatic 208	org/eclipse/equinox/internal/frameworkadmin/utils/Utils:createParentDir	(Ljava/io/File;)Z
    //   4: ifne +14 -> 18
    //   7: new 97	java/lang/IllegalStateException
    //   10: dup
    //   11: getstatic 179	org/eclipse/equinox/internal/frameworkadmin/equinox/Messages:exception_failedToCreateDir	Ljava/lang/String;
    //   14: invokespecial 190	java/lang/IllegalStateException:<init>	(Ljava/lang/String;)V
    //   17: athrow
    //   18: aconst_null
    //   19: astore_2
    //   20: aconst_null
    //   21: astore_3
    //   22: new 93	java/io/FileOutputStream
    //   25: dup
    //   26: aload_1
    //   27: invokespecial 186	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   30: astore_3
    //   31: aload_0
    //   32: aload_3
    //   33: invokestatic 210	org/eclipse/equinox/internal/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorUtils:writeConfiguration	([Lorg/eclipse/equinox/internal/simpleconfigurator/utils/BundleInfo;Ljava/io/OutputStream;)V
    //   36: goto +56 -> 92
    //   39: astore 4
    //   41: aload 4
    //   43: astore_2
    //   44: aload_3
    //   45: ifnull +67 -> 112
    //   48: aload_3
    //   49: invokevirtual 187	java/io/OutputStream:close	()V
    //   52: goto +60 -> 112
    //   55: astore 6
    //   57: aload_2
    //   58: ifnull +54 -> 112
    //   61: aload 6
    //   63: astore_2
    //   64: goto +48 -> 112
    //   67: astore 5
    //   69: aload_3
    //   70: ifnull +19 -> 89
    //   73: aload_3
    //   74: invokevirtual 187	java/io/OutputStream:close	()V
    //   77: goto +12 -> 89
    //   80: astore 6
    //   82: aload_2
    //   83: ifnull +6 -> 89
    //   86: aload 6
    //   88: astore_2
    //   89: aload 5
    //   91: athrow
    //   92: aload_3
    //   93: ifnull +19 -> 112
    //   96: aload_3
    //   97: invokevirtual 187	java/io/OutputStream:close	()V
    //   100: goto +12 -> 112
    //   103: astore 6
    //   105: aload_2
    //   106: ifnull +6 -> 112
    //   109: aload 6
    //   111: astore_2
    //   112: aload_2
    //   113: ifnull +5 -> 118
    //   116: aload_2
    //   117: athrow
    //   118: return
    // Line number table:
    //   Java source line #30	-> byte code offset #0
    //   Java source line #31	-> byte code offset #7
    //   Java source line #34	-> byte code offset #18
    //   Java source line #35	-> byte code offset #20
    //   Java source line #37	-> byte code offset #22
    //   Java source line #38	-> byte code offset #31
    //   Java source line #39	-> byte code offset #39
    //   Java source line #40	-> byte code offset #41
    //   Java source line #43	-> byte code offset #44
    //   Java source line #44	-> byte code offset #48
    //   Java source line #45	-> byte code offset #55
    //   Java source line #47	-> byte code offset #57
    //   Java source line #48	-> byte code offset #61
    //   Java source line #41	-> byte code offset #67
    //   Java source line #43	-> byte code offset #69
    //   Java source line #44	-> byte code offset #73
    //   Java source line #45	-> byte code offset #80
    //   Java source line #47	-> byte code offset #82
    //   Java source line #48	-> byte code offset #86
    //   Java source line #50	-> byte code offset #89
    //   Java source line #43	-> byte code offset #92
    //   Java source line #44	-> byte code offset #96
    //   Java source line #45	-> byte code offset #103
    //   Java source line #47	-> byte code offset #105
    //   Java source line #48	-> byte code offset #109
    //   Java source line #51	-> byte code offset #112
    //   Java source line #52	-> byte code offset #116
    //   Java source line #53	-> byte code offset #118
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	119	0	simpleInfos	BundleInfo[]
    //   0	119	1	outputFile	java.io.File
    //   19	98	2	caughtException	IOException
    //   21	76	3	stream	OutputStream
    //   39	3	4	e	IOException
    //   67	23	5	localObject	Object
    //   55	7	6	e	IOException
    //   80	7	6	e	IOException
    //   103	7	6	e	IOException
    // Exception table:
    //   from	to	target	type
    //   22	36	39	java/io/IOException
    //   44	52	55	java/io/IOException
    //   22	44	67	finally
    //   69	77	80	java/io/IOException
    //   92	100	103	java/io/IOException
  }
  
  public static void writeConfiguration(BundleInfo[] simpleInfos, OutputStream stream)
    throws IOException
  {
    Arrays.sort(simpleInfos, new Comparator()
    {
      public int compare(Object o1, Object o2)
      {
        if (((o1 instanceof BundleInfo)) && ((o2 instanceof BundleInfo))) {
          return ((BundleInfo)o1).getSymbolicName().compareTo(((BundleInfo)o2).getSymbolicName());
        }
        return 0;
      }
    });
    BufferedWriter writer = null;
    boolean oldStyle = false;
    boolean utf8 = true;
    for (int i = 0; i < simpleInfos.length; i++) {
      if ("org.eclipse.equinox.simpleconfigurator".equals(simpleInfos[i].getSymbolicName()))
      {
        Version version = new Version(simpleInfos[i].getVersion());
        if (version.compareTo(OLD_STYLE_SIMPLE_CONFIGURATOR_VERSION) < 0) {
          oldStyle = true;
        }
        if (version.compareTo(DEFAULT_ENCODING_CONFIGURATOR_VERSION) > 0) {
          break;
        }
        utf8 = false;
        break;
      }
    }
    if (utf8)
    {
      writer = new BufferedWriter(new OutputStreamWriter(stream, "UTF-8"));
      
      writer.write("#encoding=UTF-8");
      writer.newLine();
    }
    else
    {
      writer = new BufferedWriter(new OutputStreamWriter(stream));
    }
    writer.write(createVersionLine());
    writer.newLine();
    for (int i = 0; i < simpleInfos.length; i++)
    {
      writer.write(createBundleInfoLine(simpleInfos[i], oldStyle));
      writer.newLine();
    }
    writer.flush();
  }
  
  public static String createVersionLine()
  {
    return "#version=1";
  }
  
  public static String createBundleInfoLine(BundleInfo bundleInfo, boolean oldStyle)
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append(bundleInfo.getSymbolicName());
    buffer.append(',');
    buffer.append(bundleInfo.getVersion());
    buffer.append(',');
    buffer.append(createBundleLocation(bundleInfo.getLocation(), oldStyle));
    buffer.append(',');
    buffer.append(bundleInfo.getStartLevel());
    buffer.append(',');
    buffer.append(bundleInfo.isMarkedAsStarted());
    return buffer.toString();
  }
  
  public static String createBundleLocation(URI location, boolean oldStyle)
  {
    if (oldStyle)
    {
      String scheme = location.getScheme();
      if (scheme == null) {
        scheme = "file";
      }
      return scheme + ':' + location.getSchemeSpecificPart();
    }
    String result = location.toString();
    int commaIndex = result.indexOf(',');
    while (commaIndex != -1)
    {
      result = result.substring(0, commaIndex) + "%2C" + result.substring(commaIndex + 1);
      commaIndex = result.indexOf(',');
    }
    return result;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.simpleconfigurator.manipulator.SimpleConfiguratorManipulatorUtils
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.simpleconfigurator.manipulator;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import org.eclipse.equinox.frameworkadmin.BundleInfo;
import org.osgi.framework.BundleContext;

public abstract interface SimpleConfiguratorManipulator
{
  public static final String BUNDLES_INFO_PATH = "org.eclipse.equinox.simpleconfigurator/bundles.info";
  public static final String SOURCE_INFO_PATH = "org.eclipse.equinox.source/source.info";
  public static final String SOURCE_INFO = new String("source.info");
  public static final String SERVICE_PROP_VALUE_CONFIGURATOR_SYMBOLICNAME = "org.eclipse.equinox.simpleconfigurator";
  
  public abstract BundleInfo[] loadConfiguration(BundleContext paramBundleContext, String paramString)
    throws IOException;
  
  public abstract BundleInfo[] loadConfiguration(InputStream paramInputStream, URI paramURI)
    throws IOException;
  
  public abstract void saveConfiguration(BundleInfo[] paramArrayOfBundleInfo, OutputStream paramOutputStream, URI paramURI)
    throws IOException;
  
  public abstract void saveConfiguration(BundleInfo[] paramArrayOfBundleInfo, File paramFile, URI paramURI)
    throws IOException;
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.simpleconfigurator.manipulator.SimpleConfiguratorManipulator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
1

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-2017. Infinite Loop Ltd