org.eclipse.update.configurator_3.3.100.v20100512

16:48:42.578 INFO  jd.cli.Main - Decompiling org.eclipse.update.configurator_3.3.100.v20100512.jar
package org.eclipse.update.configurator;

import java.io.IOException;
import java.net.URL;
import org.eclipse.update.internal.configurator.ConfigurationActivator;
import org.eclipse.update.internal.configurator.Utils;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

/**
 * @deprecated
 */
public class ConfiguratorUtils
{
  public static IPlatformConfiguration getCurrentPlatformConfiguration()
  {
    BundleContext context = ConfigurationActivator.getBundleContext();
    ServiceReference configFactorySR = context.getServiceReference(IPlatformConfigurationFactory.class.getName());
    if (configFactorySR == null) {
      throw new IllegalStateException();
    }
    IPlatformConfigurationFactory configFactory = (IPlatformConfigurationFactory)context.getService(configFactorySR);
    if (configFactory == null) {
      throw new IllegalStateException();
    }
    IPlatformConfiguration currentConfig = configFactory.getCurrentPlatformConfiguration();
    context.ungetService(configFactorySR);
    return currentConfig;
  }
  
  public static IPlatformConfiguration getPlatformConfiguration(URL url)
    throws IOException
  {
    BundleContext context = ConfigurationActivator.getBundleContext();
    ServiceReference configFactorySR = context.getServiceReference(IPlatformConfigurationFactory.class.getName());
    if (configFactorySR == null) {
      throw new IllegalStateException();
    }
    IPlatformConfigurationFactory configFactory = (IPlatformConfigurationFactory)context.getService(configFactorySR);
    if (configFactory == null) {
      throw new IllegalStateException();
    }
    IPlatformConfiguration config = configFactory.getPlatformConfiguration(url);
    context.ungetService(configFactorySR);
    return config;
  }
  
  public static IPlatformConfiguration getPlatformConfiguration(URL url, URL loc)
    throws IOException
  {
    BundleContext context = ConfigurationActivator.getBundleContext();
    ServiceReference configFactorySR = context.getServiceReference(IPlatformConfigurationFactory.class.getName());
    if (configFactorySR == null) {
      throw new IllegalStateException();
    }
    IPlatformConfigurationFactory configFactory = (IPlatformConfigurationFactory)context.getService(configFactorySR);
    if (configFactory == null) {
      throw new IllegalStateException();
    }
    IPlatformConfiguration config = configFactory.getPlatformConfiguration(url, loc);
    context.ungetService(configFactorySR);
    return config;
  }
  
  public static URL getInstallURL()
  {
    return Utils.getInstallURL();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.configurator.ConfiguratorUtils
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.configurator;

import java.net.URL;

public abstract interface IPlatformConfiguration$IFeatureEntry
{
  public abstract String getFeatureIdentifier();
  
  public abstract String getFeatureVersion();
  
  public abstract String getFeaturePluginIdentifier();
  
  public abstract String getFeaturePluginVersion();
  
  public abstract String getFeatureApplication();
  
  public abstract URL[] getFeatureRootURLs();
  
  public abstract boolean canBePrimary();
}

/* Location:
 * Qualified Name:     org.eclipse.update.configurator.IPlatformConfiguration.IFeatureEntry
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.configurator;

import java.net.URL;

public abstract interface IPlatformConfiguration$ISiteEntry
{
  public abstract URL getURL();
  
  public abstract IPlatformConfiguration.ISitePolicy getSitePolicy();
  
  public abstract void setSitePolicy(IPlatformConfiguration.ISitePolicy paramISitePolicy);
  
  public abstract String[] getFeatures();
  
  public abstract String[] getPlugins();
  
  public abstract long getChangeStamp();
  
  /**
   * @deprecated
   */
  public abstract long getFeaturesChangeStamp();
  
  /**
   * @deprecated
   */
  public abstract long getPluginsChangeStamp();
  
  public abstract boolean isUpdateable();
  
  public abstract boolean isNativelyLinked();
}

/* Location:
 * Qualified Name:     org.eclipse.update.configurator.IPlatformConfiguration.ISiteEntry
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.configurator;

public abstract interface IPlatformConfiguration$ISitePolicy
{
  public static final int USER_INCLUDE = 0;
  public static final int USER_EXCLUDE = 1;
  public static final int MANAGED_ONLY = 2;
  
  public abstract int getType();
  
  public abstract String[] getList();
  
  public abstract void setList(String[] paramArrayOfString);
}

/* Location:
 * Qualified Name:     org.eclipse.update.configurator.IPlatformConfiguration.ISitePolicy
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.configurator;

import java.io.IOException;
import java.net.URL;

/**
 * @deprecated
 */
public abstract interface IPlatformConfiguration
{
  public abstract ISiteEntry createSiteEntry(URL paramURL, ISitePolicy paramISitePolicy);
  
  public abstract ISitePolicy createSitePolicy(int paramInt, String[] paramArrayOfString);
  
  public abstract IFeatureEntry createFeatureEntry(String paramString1, String paramString2, String paramString3, boolean paramBoolean, String paramString4, URL[] paramArrayOfURL);
  
  public abstract IFeatureEntry createFeatureEntry(String paramString1, String paramString2, String paramString3, String paramString4, boolean paramBoolean, String paramString5, URL[] paramArrayOfURL);
  
  public abstract void configureSite(ISiteEntry paramISiteEntry);
  
  public abstract void configureSite(ISiteEntry paramISiteEntry, boolean paramBoolean);
  
  public abstract void unconfigureSite(ISiteEntry paramISiteEntry);
  
  public abstract ISiteEntry[] getConfiguredSites();
  
  public abstract ISiteEntry findConfiguredSite(URL paramURL);
  
  public abstract void configureFeatureEntry(IFeatureEntry paramIFeatureEntry);
  
  public abstract void unconfigureFeatureEntry(IFeatureEntry paramIFeatureEntry);
  
  public abstract IFeatureEntry[] getConfiguredFeatureEntries();
  
  public abstract IFeatureEntry findConfiguredFeatureEntry(String paramString);
  
  public abstract URL getConfigurationLocation();
  
  public abstract long getChangeStamp();
  
  /**
   * @deprecated
   */
  public abstract long getFeaturesChangeStamp();
  
  /**
   * @deprecated
   */
  public abstract long getPluginsChangeStamp();
  
  public abstract String getPrimaryFeatureIdentifier();
  
  public abstract URL[] getPluginPath();
  
  /**
   * @deprecated
   */
  public abstract String[] getBootstrapPluginIdentifiers();
  
  /**
   * @deprecated
   */
  public abstract void setBootstrapPluginLocation(String paramString, URL paramURL);
  
  public abstract boolean isUpdateable();
  
  public abstract boolean isTransient();
  
  public abstract void isTransient(boolean paramBoolean);
  
  public abstract void refresh();
  
  public abstract void save()
    throws IOException;
  
  public abstract void save(URL paramURL)
    throws IOException;
  
  public static abstract interface IFeatureEntry
  {
    public abstract String getFeatureIdentifier();
    
    public abstract String getFeatureVersion();
    
    public abstract String getFeaturePluginIdentifier();
    
    public abstract String getFeaturePluginVersion();
    
    public abstract String getFeatureApplication();
    
    public abstract URL[] getFeatureRootURLs();
    
    public abstract boolean canBePrimary();
  }
  
  public static abstract interface ISiteEntry
  {
    public abstract URL getURL();
    
    public abstract IPlatformConfiguration.ISitePolicy getSitePolicy();
    
    public abstract void setSitePolicy(IPlatformConfiguration.ISitePolicy paramISitePolicy);
    
    public abstract String[] getFeatures();
    
    public abstract String[] getPlugins();
    
    public abstract long getChangeStamp();
    
    /**
     * @deprecated
     */
    public abstract long getFeaturesChangeStamp();
    
    /**
     * @deprecated
     */
    public abstract long getPluginsChangeStamp();
    
    public abstract boolean isUpdateable();
    
    public abstract boolean isNativelyLinked();
  }
  
  public static abstract interface ISitePolicy
  {
    public static final int USER_INCLUDE = 0;
    public static final int USER_EXCLUDE = 1;
    public static final int MANAGED_ONLY = 2;
    
    public abstract int getType();
    
    public abstract String[] getList();
    
    public abstract void setList(String[] paramArrayOfString);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.configurator.IPlatformConfiguration
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.configurator;

import java.io.IOException;
import java.net.URL;

/**
 * @deprecated
 */
public abstract interface IPlatformConfigurationFactory
{
  public abstract IPlatformConfiguration getCurrentPlatformConfiguration();
  
  public abstract IPlatformConfiguration getPlatformConfiguration(URL paramURL)
    throws IOException;
  
  public abstract IPlatformConfiguration getPlatformConfiguration(URL paramURL1, URL paramURL2)
    throws IOException;
}

/* Location:
 * Qualified Name:     org.eclipse.update.configurator.IPlatformConfigurationFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.configurator;

import org.eclipse.core.runtime.IBundleGroup;
import org.eclipse.core.runtime.IBundleGroupProvider;

public class BundleGroupComponent
  implements IBundleGroupProvider
{
  public IBundleGroup[] getBundleGroups()
  {
    ConfigurationActivator activator = ConfigurationActivator.getConfigurator();
    if (bundleGroupProviderSR != null) {
      return new IBundleGroup[0];
    }
    return activator.getBundleGroups();
  }
  
  public String getName()
  {
    return ConfigurationActivator.getConfigurator().getName();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.configurator.BundleGroupComponent
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.configurator;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleException;

public class BundleManifest
  implements IConfigurationConstants
{
  private File manifestFile;
  private PluginEntry pluginEntry;
  private IOException exception;
  private String bundleURL;
  
  /* Error */
  public BundleManifest(File manifest)
  {
    // Byte code:
    //   0: aload_0
    //   1: invokespecial 158	java/lang/Object:<init>	()V
    //   4: aload_0
    //   5: aload_1
    //   6: putfield 146	org/eclipse/update/internal/configurator/BundleManifest:manifestFile	Ljava/io/File;
    //   9: aload_1
    //   10: invokevirtual 151	java/io/File:exists	()Z
    //   13: ifeq +72 -> 85
    //   16: aload_1
    //   17: invokevirtual 152	java/io/File:isDirectory	()Z
    //   20: ifne +65 -> 85
    //   23: aconst_null
    //   24: astore_2
    //   25: new 75	java/io/FileInputStream
    //   28: dup
    //   29: aload_1
    //   30: invokespecial 156	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   33: astore_2
    //   34: aload_0
    //   35: aload_2
    //   36: invokespecial 170	org/eclipse/update/internal/configurator/BundleManifest:parse	(Ljava/io/InputStream;)V
    //   39: goto +34 -> 73
    //   42: pop
    //   43: aload_2
    //   44: ifnull +41 -> 85
    //   47: aload_2
    //   48: invokevirtual 155	java/io/FileInputStream:close	()V
    //   51: goto +34 -> 85
    //   54: pop
    //   55: goto +30 -> 85
    //   58: astore_3
    //   59: aload_2
    //   60: ifnull +11 -> 71
    //   63: aload_2
    //   64: invokevirtual 155	java/io/FileInputStream:close	()V
    //   67: goto +4 -> 71
    //   70: pop
    //   71: aload_3
    //   72: athrow
    //   73: aload_2
    //   74: ifnull +11 -> 85
    //   77: aload_2
    //   78: invokevirtual 155	java/io/FileInputStream:close	()V
    //   81: goto +4 -> 85
    //   84: pop
    //   85: return
    // Line number table:
    //   Java source line #30	-> byte code offset #0
    //   Java source line #31	-> byte code offset #4
    //   Java source line #32	-> byte code offset #9
    //   Java source line #33	-> byte code offset #23
    //   Java source line #35	-> byte code offset #25
    //   Java source line #36	-> byte code offset #34
    //   Java source line #37	-> byte code offset #42
    //   Java source line #39	-> byte code offset #43
    //   Java source line #41	-> byte code offset #47
    //   Java source line #42	-> byte code offset #54
    //   Java source line #38	-> byte code offset #58
    //   Java source line #39	-> byte code offset #59
    //   Java source line #41	-> byte code offset #63
    //   Java source line #42	-> byte code offset #70
    //   Java source line #45	-> byte code offset #71
    //   Java source line #39	-> byte code offset #73
    //   Java source line #41	-> byte code offset #77
    //   Java source line #42	-> byte code offset #84
    //   Java source line #47	-> byte code offset #85
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	86	0	this	BundleManifest
    //   0	86	1	manifest	File
    //   24	54	2	fos	java.io.FileInputStream
    //   58	14	3	localObject	Object
    //   42	1	4	localIOException1	IOException
    //   54	1	5	localIOException2	IOException
    //   70	1	6	localIOException3	IOException
    //   84	1	7	localIOException4	IOException
    // Exception table:
    //   from	to	target	type
    //   25	39	42	java/io/IOException
    //   47	51	54	java/io/IOException
    //   25	43	58	finally
    //   63	67	70	java/io/IOException
    //   77	81	84	java/io/IOException
  }
  
  public BundleManifest(InputStream input, String bundleUrl)
  {
    bundleURL = bundleUrl;
    if (input != null) {
      parse(input);
    }
  }
  
  private void parse(InputStream in)
  {
    try
    {
      Manifest m = new Manifest(in);
      Attributes a = m.getMainAttributes();
      
      String symbolicName = a.getValue("Bundle-SymbolicName");
      if (symbolicName == null) {
        return;
      }
      try
      {
        ManifestElement[] elements = ManifestElement.parseHeader(
          "Bundle-SymbolicName", symbolicName);
        id = elements[0].getValue();
      }
      catch (BundleException be)
      {
        String id;
        throw new IOException(be.getMessage());
      }
      String id;
      String version = a.getValue("Bundle-Version");
      if (version == null)
      {
        Utils.log(NLS.bind(Messages.BundleManifest_noVersion, new String[] { "Bundle-Version", id }));
        return;
      }
      version = version.trim();
      String hostPlugin = a.getValue("Fragment-Host");
      pluginEntry = new PluginEntry();
      pluginEntry.setVersionedIdentifier(new VersionedIdentifier(id, 
        version));
      pluginEntry.isFragment((hostPlugin != null) && 
        (hostPlugin.length() > 0));
      if (bundleURL != null)
      {
        pluginEntry.setURL(bundleURL);
      }
      else
      {
        File pluginDir = manifestFile.getParentFile();
        if (pluginDir != null) {
          pluginDir = pluginDir.getParentFile();
        }
        if (pluginDir != null) {
          pluginEntry.setURL("plugins/" + pluginDir.getName() + "/");
        }
      }
    }
    catch (IOException ioe)
    {
      exception = ioe;
    }
  }
  
  public boolean exists()
  {
    return (exception != null) || (pluginEntry != null);
  }
  
  public PluginEntry getPluginEntry()
    throws IOException
  {
    if (exception != null) {
      throw exception;
    }
    return pluginEntry;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.configurator.BundleManifest
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.configurator;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.update.configurator.IPlatformConfiguration.IFeatureEntry;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Configuration
  implements IConfigurationConstants
{
  private HashMap sites = new HashMap();
  private HashMap platformURLs = new HashMap();
  private Date date;
  private long lastModified;
  private URL url;
  private boolean transientConfig;
  private boolean isDirty;
  private Configuration linkedConfig;
  private URL associatedInstallURL = Utils.getInstallURL();
  
  public Configuration()
  {
    this(new Date());
    
    isDirty = true;
  }
  
  public Configuration(Date date)
  {
    this.date = date;
  }
  
  public void setURL(URL url)
  {
    this.url = url;
  }
  
  public URL getURL()
  {
    return url;
  }
  
  public void setLinkedConfig(Configuration linkedConfig)
  {
    this.linkedConfig = linkedConfig;
    
    SiteEntry[] linkedSites = linkedConfig.getSites();
    for (int i = 0; i < linkedSites.length; i++) {
      linkedSites[i].setUpdateable(false);
    }
  }
  
  public Configuration getLinkedConfig()
  {
    return linkedConfig;
  }
  
  public boolean isDirty()
  {
    return isDirty;
  }
  
  public void setDirty(boolean dirty)
  {
    isDirty = dirty;
  }
  
  public void addSiteEntry(String url, SiteEntry site)
  {
    url = Utils.canonicalizeURL(url);
    if ((sites.get(url) == null) && ((linkedConfig == null) || (linkedConfig.sites.get(url) == null)))
    {
      site.setConfig(this);
      sites.put(url, site);
      if (url.startsWith("platform:")) {
        try
        {
          URL relSite = null;
          if ((url != null) && (url.startsWith("platform:/config")))
          {
            URL config_loc = getURL();
            relSite = new URL(config_loc, "..");
          }
          else
          {
            relSite = getInstallURL();
          }
          URL pURL = new URL(url);
          URL rURL = PlatformConfiguration.resolvePlatformURL(pURL, relSite);
          String resolvedURL = rURL.toExternalForm();
          platformURLs.put(resolvedURL, pURL);
        }
        catch (IOException localIOException) {}
      }
    }
  }
  
  public void removeSiteEntry(String url)
  {
    url = Utils.canonicalizeURL(url);
    sites.remove(url);
    if (url.startsWith("platform:")) {
      try
      {
        URL relSite = null;
        if ((url != null) && (url.startsWith("platform:/config")))
        {
          URL config_loc = getURL();
          relSite = new URL(config_loc, "..");
        }
        else
        {
          relSite = getInstallURL();
        }
        URL pURL = new URL(url);
        URL rURL = PlatformConfiguration.resolvePlatformURL(pURL, relSite);
        String resolvedURL = rURL.toExternalForm();
        platformURLs.remove(resolvedURL);
      }
      catch (IOException localIOException) {}
    }
  }
  
  public SiteEntry getSiteEntry(String url)
  {
    url = Utils.canonicalizeURL(url);
    SiteEntry site = (SiteEntry)sites.get(url);
    if ((site == null) && (linkedConfig != null)) {
      site = linkedConfig.getSiteEntry(url);
    }
    return site;
  }
  
  public SiteEntry[] getSites()
  {
    if (linkedConfig == null) {
      return (SiteEntry[])sites.values().toArray(new SiteEntry[sites.size()]);
    }
    ArrayList combinedSites = new ArrayList(sites.values());
    combinedSites.addAll(linkedConfig.sites.values());
    return (SiteEntry[])combinedSites.toArray(new SiteEntry[combinedSites.size()]);
  }
  
  public Element toXML(Document doc)
    throws CoreException
  {
    try
    {
      Element configElement = doc.createElement("config");
      
      configElement.setAttribute("version", "3.0");
      configElement.setAttribute("date", String.valueOf(date.getTime()));
      String transitory = isTransient() ? "true" : "false";
      configElement.setAttribute("transient", transitory);
      if (linkedConfig != null) {
        configElement.setAttribute("shared_ur", Utils.makeRelative(getInstallURL(), linkedConfig.getURL()).toExternalForm());
      }
      SiteEntry[] list = (SiteEntry[])sites.values().toArray(new SiteEntry[0]);
      for (int i = 0; i < list.length; i++) {
        if ((linkedConfig == null) || (linkedConfig.getSiteEntry(list[i].getURL().toExternalForm()) == null))
        {
          Element siteElement = list[i].toXML(doc);
          configElement.appendChild(siteElement);
        }
      }
      return configElement;
    }
    catch (Exception e)
    {
      throw Utils.newCoreException("", e);
    }
  }
  
  public boolean isTransient()
  {
    return transientConfig;
  }
  
  public void setTransient(boolean isTransient)
  {
    transientConfig = isTransient;
  }
  
  public Date getDate()
  {
    return date;
  }
  
  public void setDate(Date date)
  {
    this.date = date;
  }
  
  public boolean unconfigureFeatureEntry(IPlatformConfiguration.IFeatureEntry feature)
  {
    SiteEntry[] sites = getSites();
    for (int i = 0; i < sites.length; i++) {
      if (sites[i].unconfigureFeatureEntry(feature)) {
        return true;
      }
    }
    return false;
  }
  
  public void setLastModified(long lastModified)
  {
    this.lastModified = lastModified;
  }
  
  public long lastModified()
  {
    return lastModified != 0L ? lastModified : date.getTime();
  }
  
  public URL asPlatformURL(URL url)
  {
    try
    {
      if (url.getProtocol().equals("file"))
      {
        String rUrl = url.toExternalForm();
        URL pUrl = (URL)platformURLs.get(rUrl);
        if (pUrl == null) {
          return url;
        }
        return pUrl;
      }
      return url;
    }
    catch (Exception localException) {}
    return url;
  }
  
  public URL getInstallURL()
  {
    return associatedInstallURL;
  }
  
  public void setInstallLocation(URL installURL)
  {
    associatedInstallURL = installURL;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.configurator.Configuration
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.configurator;

import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;

class ConfigurationActivator$1
  implements FrameworkListener
{
  final ConfigurationActivator this$0;
  private final boolean[] val$flag;
  
  ConfigurationActivator$1(ConfigurationActivator paramConfigurationActivator, boolean[] paramArrayOfBoolean)
  {
    this$0 = paramConfigurationActivator;val$flag = paramArrayOfBoolean;
  }
  
  public void frameworkEvent(FrameworkEvent event)
  {
    if (event.getType() == 4) {
      synchronized (val$flag)
      {
        val$flag[0] = true;
        val$flag.notifyAll();
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.configurator.ConfigurationActivator.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.configurator;

import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.IBundleGroup;
import org.eclipse.core.runtime.IBundleGroupProvider;
import org.eclipse.osgi.framework.log.FrameworkLog;
import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import org.eclipse.update.configurator.IPlatformConfiguration.IFeatureEntry;
import org.eclipse.update.configurator.IPlatformConfigurationFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.service.startlevel.StartLevel;

public class ConfigurationActivator
  implements BundleActivator, IBundleGroupProvider, IConfigurationConstants
{
  public static String PI_CONFIGURATOR = "org.eclipse.update.configurator";
  public static final String LAST_CONFIG_STAMP = "last.config.stamp";
  public static final String NAME_SPACE = "org.eclipse.update";
  public static final String UPDATE_PREFIX = "update@";
  private static final String INITIAL_PREFIX = "initial@";
  public static String OPTION_DEBUG = PI_CONFIGURATOR + "/debug";
  public static boolean DEBUG = false;
  private static BundleContext context;
  private ServiceRegistration configurationFactorySR;
  ServiceRegistration bundleGroupProviderSR;
  private PlatformConfiguration configuration;
  private Location configLocation;
  private long lastTimeStamp;
  private long lastStateTimeStamp;
  private static ConfigurationActivator configurator;
  static Class class$4;
  
  public ConfigurationActivator()
  {
    configurator = this;
  }
  
  public void start(BundleContext ctx)
    throws Exception
  {
    context = ctx;
    loadOptions();
    acquireFrameworkLogService();
    try
    {
      initialize();
    }
    catch (Exception e)
    {
      Utils.shutdown();
      throw e;
    }
    if (canRunWithCachedData())
    {
      Utils.debug("Running with cached data");
      registerBundleGroupProvider();
      return;
    }
    Utils.debug("Starting update configurator...");
    if (isReconciling()) {
      installBundles();
    }
    registerBundleGroupProvider();
  }
  
  public static boolean isReconciling()
  {
    String reconcile = context.getProperty("org.eclipse.update.reconcile");
    return (reconcile == null) || (reconcile.equalsIgnoreCase("true"));
  }
  
  private void registerBundleGroupProvider()
  {
    String serviceName = IBundleGroupProvider.class.getName();
    try
    {
      ServiceReference[] refs = getBundleContext().getServiceReferences(serviceName, null);
      if (refs != null) {
        for (int i = 0; i < refs.length; i++) {
          if (PI_CONFIGURATOR.equals(refs[i].getBundle().getSymbolicName())) {
            return;
          }
        }
      }
    }
    catch (InvalidSyntaxException localInvalidSyntaxException) {}
    bundleGroupProviderSR = getBundleContext().registerService(serviceName, this, null);
  }
  
  private void initialize()
    throws Exception
  {
    if (!Utils.isRunning()) {
      throw new Exception(Messages.ConfigurationActivator_initialize);
    }
    configLocation = Utils.getConfigurationLocation();
    if (!configLocation.isReadOnly()) {
      try
      {
        URL privateURL = new URL(configLocation.getURL(), "org.eclipse.update");
        f = new File(privateURL.getFile());
        if (!f.exists()) {
          f.mkdirs();
        }
      }
      catch (MalformedURLException localMalformedURLException) {}
    }
    configurationFactorySR = context.registerService(IPlatformConfigurationFactory.class.getName(), new PlatformConfigurationFactory(), null);
    configuration = getPlatformConfiguration(Utils.getInstallURL(), configLocation);
    if (configuration == null) {
      throw Utils.newCoreException(NLS.bind(Messages.ConfigurationActivator_createConfig, new String[] { configLocation.getURL().toExternalForm() }), null);
    }
    DataInputStream stream = null;
    try
    {
      stream = new DataInputStream(new URL(configLocation.getURL(), "org.eclipse.update/last.config.stamp").openStream());
      lastTimeStamp = stream.readLong();
      lastStateTimeStamp = stream.readLong();
    }
    catch (Exception localException)
    {
      lastTimeStamp = (configuration.getChangeStamp() - 1L);
      lastStateTimeStamp = -1L;
      if (stream != null) {
        try
        {
          stream.close();
        }
        catch (IOException e1)
        {
          Utils.log(e1.getLocalizedMessage());
        }
      }
    }
    finally
    {
      if (stream != null) {
        try
        {
          stream.close();
        }
        catch (IOException e1)
        {
          Utils.log(e1.getLocalizedMessage());
        }
      }
    }
  }
  
  public void stop(BundleContext ctx)
    throws Exception
  {
    try
    {
      
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
    configurationFactorySR.unregister();
    if (bundleGroupProviderSR != null) {
      bundleGroupProviderSR.unregister();
    }
    Utils.shutdown();
  }
  
  public boolean installBundles()
  {
    Utils.debug("Installing bundles...");
    ServiceReference reference = context.getServiceReference(StartLevel.class.getName());
    int startLevel = 4;
    String defaultStartLevel = context.getProperty("osgi.bundles.defaultStartLevel");
    if (defaultStartLevel != null) {
      try
      {
        startLevel = Integer.parseInt(defaultStartLevel);
      }
      catch (NumberFormatException localNumberFormatException)
      {
        startLevel = 4;
      }
    }
    if (startLevel < 1) {
      startLevel = 4;
    }
    StartLevel start = null;
    if (reference != null) {
      start = (StartLevel)context.getService(reference);
    }
    try
    {
      Bundle[] cachedBundles = context.getBundles();
      URL[] plugins = configuration.getPluginPath();
      
      List toRefresh = getUnresolvedBundles();
      
      Bundle[] bundlesToUninstall = getBundlesToUninstall(cachedBundles, plugins);
      for (int i = 0; i < bundlesToUninstall.length; i++) {
        try
        {
          if (DEBUG) {
            Utils.debug("Uninstalling " + bundlesToUninstall[i].getLocation());
          }
          toRefresh.add(bundlesToUninstall[i]);
          bundlesToUninstall[i].uninstall();
        }
        catch (Exception localException1)
        {
          Utils.log(NLS.bind(Messages.ConfigurationActivator_uninstallBundle, new String[] { bundlesToUninstall[i].getLocation() }));
        }
      }
      String[] bundlesToInstall = getBundlesToInstall(cachedBundles, plugins);
      ArrayList lazyActivationBundles = new ArrayList(bundlesToInstall.length);
      for (int i = 0; i < bundlesToInstall.length; i++) {
        try
        {
          if (DEBUG) {
            Utils.debug("Installing " + bundlesToInstall[i]);
          }
          URL bundleURL = new URL("reference:file:" + bundlesToInstall[i]);
          
          Bundle target = context.installBundle("update@" + bundlesToInstall[i], bundleURL.openStream());
          
          toRefresh.add(target);
          if (start != null) {
            start.setBundleStartLevel(target, startLevel);
          }
          if (hasLazyActivationPolicy(target)) {
            lazyActivationBundles.add(target);
          }
        }
        catch (Exception e)
        {
          if (!Utils.isAutomaticallyStartedBundle(bundlesToInstall[i])) {
            Utils.log(NLS.bind(Messages.ConfigurationActivator_installBundle, new String[] { bundlesToInstall[i] }) + "   " + e.getMessage());
          }
        }
      }
      context.ungetService(reference);
      removeInitialBundles(toRefresh, cachedBundles);
      refreshPackages((Bundle[])toRefresh.toArray(new Bundle[toRefresh.size()]));
      for (Iterator activateBundles = lazyActivationBundles.iterator(); activateBundles.hasNext();)
      {
        Bundle toActivate = (Bundle)activateBundles.next();
        try
        {
          toActivate.start(2);
        }
        catch (BundleException e)
        {
          if ((toActivate.getState() & 0x4) != 0) {
            Utils.log(NLS.bind(Messages.ConfigurationActivator_installBundle, new String[] { toActivate.getLocation() }) + "   " + e.getMessage());
          }
        }
      }
      writePlatformConfigurationTimeStamp();
      return true;
    }
    catch (Exception localException2) {}
    return false;
  }
  
  private static boolean hasLazyActivationPolicy(Bundle target)
  {
    Dictionary 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 void removeInitialBundles(List bundles, Bundle[] cachedBundles)
  {
    String[] initialSymbolicNames = getInitialSymbolicNames(cachedBundles);
    Iterator iter = bundles.iterator();
    while (iter.hasNext())
    {
      Bundle bundle = (Bundle)iter.next();
      String symbolicName = bundle.getSymbolicName();
      for (int i = 0; i < initialSymbolicNames.length; i++) {
        if (initialSymbolicNames[i].equals(symbolicName))
        {
          iter.remove();
          break;
        }
      }
    }
  }
  
  private String[] getInitialSymbolicNames(Bundle[] cachedBundles)
  {
    ArrayList initial = new ArrayList();
    for (int i = 0; i < cachedBundles.length; i++)
    {
      Bundle bundle = cachedBundles[i];
      if (bundle.getLocation().startsWith("initial@"))
      {
        String symbolicName = bundle.getSymbolicName();
        if (symbolicName != null) {
          initial.add(symbolicName);
        }
      }
    }
    return (String[])initial.toArray(new String[initial.size()]);
  }
  
  private List getUnresolvedBundles()
  {
    Bundle[] allBundles = context.getBundles();
    List unresolved = new ArrayList();
    for (int i = 0; i < allBundles.length; i++) {
      if (allBundles[i].getState() == 2) {
        unresolved.add(allBundles[i]);
      }
    }
    return unresolved;
  }
  
  private String[] getBundlesToInstall(Bundle[] cachedBundles, URL[] newPlugins)
  {
    HashSet cachedBundlesSet = new HashSet(cachedBundles.length);
    int offset = "update@".length();
    for (int i = 0; i < cachedBundles.length; i++) {
      if (cachedBundles[i].getBundleId() != 0L)
      {
        String bundleLocation = cachedBundles[i].getLocation();
        if (bundleLocation.startsWith("update@"))
        {
          bundleLocation = bundleLocation.substring(offset);
          cachedBundlesSet.add(bundleLocation);
          if (Utils.isWindows) {
            cachedBundlesSet.add(bundleLocation.toLowerCase());
          }
        }
      }
    }
    ArrayList bundlesToInstall = new ArrayList(newPlugins.length);
    for (int i = 0; i < newPlugins.length; i++)
    {
      String location = Utils.makeRelative(Utils.getInstallURL(), newPlugins[i]).getFile();
      if (!cachedBundlesSet.contains(location)) {
        if ((!Utils.isWindows) || (!cachedBundlesSet.contains(location.toLowerCase()))) {
          bundlesToInstall.add(location);
        }
      }
    }
    return (String[])bundlesToInstall.toArray(new String[bundlesToInstall.size()]);
  }
  
  private Bundle[] getBundlesToUninstall(Bundle[] cachedBundles, URL[] newPlugins)
  {
    HashSet newPluginsSet = new HashSet(newPlugins.length);
    for (int i = 0; i < newPlugins.length; i++)
    {
      String pluginLocation = Utils.makeRelative(Utils.getInstallURL(), newPlugins[i]).getFile();
      newPluginsSet.add(pluginLocation);
      if (Utils.isWindows) {
        newPluginsSet.add(pluginLocation.toLowerCase());
      }
    }
    ArrayList bundlesToUninstall = new ArrayList();
    int offset = "update@".length();
    for (int i = 0; i < cachedBundles.length; i++) {
      if (cachedBundles[i].getBundleId() != 0L)
      {
        String cachedBundleLocation = cachedBundles[i].getLocation();
        if (cachedBundleLocation.startsWith("update@"))
        {
          cachedBundleLocation = cachedBundleLocation.substring(offset);
          if (!newPluginsSet.contains(cachedBundleLocation)) {
            if ((!Utils.isWindows) || (!newPluginsSet.contains(cachedBundleLocation.toLowerCase()))) {
              bundlesToUninstall.add(cachedBundles[i]);
            }
          }
        }
      }
    }
    return (Bundle[])bundlesToUninstall.toArray(new Bundle[bundlesToUninstall.size()]);
  }
  
  private PlatformConfiguration getPlatformConfiguration(URL installURL, Location configLocation)
  {
    try
    {
      PlatformConfiguration.startup(installURL, configLocation);
    }
    catch (Exception e)
    {
      String message = e.getMessage();
      if (message == null) {
        message = "";
      }
      Utils.log(Utils.newStatus(message, e));
    }
    return PlatformConfiguration.getCurrent();
  }
  
  private void refreshPackages(Bundle[] bundles)
  {
    if (bundles.length == 0) {
      return;
    }
    ServiceReference packageAdminRef = context.getServiceReference(PackageAdmin.class.getName());
    PackageAdmin packageAdmin = null;
    if (packageAdminRef != null)
    {
      packageAdmin = (PackageAdmin)context.getService(packageAdminRef);
      if (packageAdmin == null) {
        return;
      }
    }
    boolean[] flag = new boolean[1];
    FrameworkListener listener = new FrameworkListener()
    {
      private final boolean[] val$flag;
      
      public void frameworkEvent(FrameworkEvent event)
      {
        if (event.getType() == 4) {
          synchronized (val$flag)
          {
            val$flag[0] = true;
            val$flag.notifyAll();
          }
        }
      }
    };
    context.addFrameworkListener(listener);
    packageAdmin.refreshPackages(bundles);
    synchronized (flag)
    {
      while (flag[0] == 0) {
        try
        {
          flag.wait();
        }
        catch (InterruptedException localInterruptedException) {}
      }
    }
    context.removeFrameworkListener(listener);
    context.ungetService(packageAdminRef);
  }
  
  /* Error */
  private void writePlatformConfigurationTimeStamp()
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore_1
    //   2: aload_0
    //   3: getfield 587	org/eclipse/update/internal/configurator/ConfigurationActivator:configLocation	Lorg/eclipse/osgi/service/datalocation/Location;
    //   6: invokeinterface 697 1 0
    //   11: ifeq +25 -> 36
    //   14: aload_1
    //   15: ifnull +20 -> 35
    //   18: aload_1
    //   19: invokevirtual 603	java/io/DataOutputStream:close	()V
    //   22: goto +13 -> 35
    //   25: astore 4
    //   27: aload 4
    //   29: invokevirtual 611	java/io/IOException:getLocalizedMessage	()Ljava/lang/String;
    //   32: invokestatic 681	org/eclipse/update/internal/configurator/Utils:log	(Ljava/lang/String;)V
    //   35: return
    //   36: aload_0
    //   37: getfield 587	org/eclipse/update/internal/configurator/ConfigurationActivator:configLocation	Lorg/eclipse/osgi/service/datalocation/Location;
    //   40: invokeinterface 698 1 0
    //   45: invokevirtu
1 2 3 4 5 6 7

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