org.eclipse.equinox.p2.reconciler.dropins_1.1.100.v20110815-1419

16:44:23.319 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.p2.reconciler.dropins_1.1.100.v20110815-1419.jar
package org.eclipse.equinox.internal.p2.reconciler.dropins;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.artifact.repository.ArtifactRepositoryManager;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
import org.eclipse.equinox.internal.p2.core.helpers.URLUtil;
import org.eclipse.equinox.internal.p2.extensionlocation.ExtensionLocationArtifactRepositoryFactory;
import org.eclipse.equinox.internal.p2.extensionlocation.ExtensionLocationMetadataRepositoryFactory;
import org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager;
import org.eclipse.equinox.internal.p2.update.Configuration;
import org.eclipse.equinox.internal.p2.update.PathUtil;
import org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryWatcher;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.osgi.service.datalocation.Location;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator
  implements BundleActivator
{
  static final String PROP_APPLICATION_STATUS = "org.eclipse.equinox.p2.reconciler.application.status";
  public static final String ID = "org.eclipse.equinox.p2.reconciler.dropins";
  private static final String DROPINS_DIRECTORY = "org.eclipse.equinox.p2.reconciler.dropins.directory";
  private static final String DROPINS = "dropins";
  private static final String LINKS = "links";
  private static final String CONFIG_INI = "config.ini";
  private static final String PLATFORM_CFG = "org.eclipse.update/platform.xml";
  private static final String CACHE_FILENAME = "cache.timestamps";
  private static final String DIR_ECLIPSE = "eclipse";
  private static final String DIR_PLUGINS = "plugins";
  private static final String DIR_FEATURES = "features";
  private static final String EXT_LINK = ".link";
  public static final String TRACING_PREFIX = "[reconciler] ";
  private static BundleContext bundleContext;
  private static final Set<IMetadataRepository> repositories = new HashSet();
  private Collection<File> filesToCheck = null;
  
  public static IMetadataRepository createExtensionLocationMetadataRepository(URI location, String name, Map<String, String> properties)
    throws ProvisionException
  {
    IProvisioningAgent agent = getAgent();
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager)agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
    if (manager == null) {
      throw new IllegalStateException("MetadataRepositoryManager not registered.");
    }
    ExtensionLocationMetadataRepositoryFactory factory = new ExtensionLocationMetadataRepositoryFactory();
    factory.setAgent(agent);
    
    Map<String, String> repositoryProperties = new HashMap();
    repositoryProperties.put("p2.compressed", Boolean.TRUE.toString());
    if (properties != null) {
      repositoryProperties.putAll(properties);
    }
    IMetadataRepository repository = factory.create(location, name, "org.eclipse.equinox.p2.extensionlocation.metadataRepository", repositoryProperties);
    
    ((MetadataRepositoryManager)manager).addRepository(repository);
    manager.setRepositoryProperty(location, "p2.system", String.valueOf(true));
    return repository;
  }
  
  private static IProvisioningAgent getAgent()
  {
    return (IProvisioningAgent)ServiceHelper.getService(getContext(), IProvisioningAgent.SERVICE_NAME);
  }
  
  public static IMetadataRepository loadMetadataRepository(URI location, IProgressMonitor monitor)
    throws ProvisionException
  {
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager)getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
    if (manager == null) {
      throw new IllegalStateException("MetadataRepositoryManager not registered.");
    }
    IMetadataRepository repository = manager.loadRepository(location, monitor);
    manager.setRepositoryProperty(location, "p2.system", String.valueOf(true));
    return repository;
  }
  
  public static IArtifactRepository createExtensionLocationArtifactRepository(URI location, String name, Map<String, String> properties)
    throws ProvisionException
  {
    IProvisioningAgent agent = getAgent();
    IArtifactRepositoryManager manager = (IArtifactRepositoryManager)agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
    if (manager == null) {
      throw new IllegalStateException("ArtifactRepositoryManager not registered.");
    }
    ExtensionLocationArtifactRepositoryFactory factory = new ExtensionLocationArtifactRepositoryFactory();
    factory.setAgent(agent);
    
    Map<String, String> repositoryProperties = new HashMap();
    repositoryProperties.put("p2.compressed", Boolean.TRUE.toString());
    if (properties != null) {
      repositoryProperties.putAll(properties);
    }
    IArtifactRepository repository = factory.create(location, name, "org.eclipse.equinox.p2.extensionlocation.artifactRepository", repositoryProperties);
    
    ((ArtifactRepositoryManager)manager).addRepository(repository);
    manager.setRepositoryProperty(location, "p2.system", String.valueOf(true));
    return repository;
  }
  
  public static IArtifactRepository loadArtifactRepository(URI location, IProgressMonitor monitor)
    throws ProvisionException
  {
    IArtifactRepositoryManager manager = (IArtifactRepositoryManager)getAgent().getService(IArtifactRepositoryManager.SERVICE_NAME);
    if (manager == null) {
      throw new IllegalStateException("ArtifactRepositoryManager not registered.");
    }
    IArtifactRepository repository = manager.loadRepository(location, monitor);
    manager.setRepositoryProperty(location, "p2.system", String.valueOf(true));
    return repository;
  }
  
  public static Set<IMetadataRepository> getRepositories()
  {
    return repositories;
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    bundleContext = context;
    if (isUpToDate())
    {
      filesToCheck = null;
      return;
    }
    checkConfigIni();
    
    watchDropins();
    
    watchConfiguration();
    
    synchronize(null);
    writeTimestamps();
    
    repositories.clear();
    filesToCheck = null;
  }
  
  /* Error */
  private void checkConfigIni()
  {
    // Byte code:
    //   0: invokestatic 746	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:getConfigurationLocation	()Ljava/io/File;
    //   3: astore_1
    //   4: aload_1
    //   5: ifnonnull +20 -> 25
    //   8: new 377	org/eclipse/core/runtime/Status
    //   11: dup
    //   12: iconst_4
    //   13: ldc 14
    //   15: ldc_w 335
    //   18: invokespecial 726	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;Ljava/lang/String;)V
    //   21: invokestatic 729	org/eclipse/equinox/internal/p2/core/helpers/LogHelper:log	(Lorg/eclipse/core/runtime/IStatus;)V
    //   24: return
    //   25: new 346	java/io/File
    //   28: dup
    //   29: aload_1
    //   30: ldc 6
    //   32: invokespecial 677	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   35: astore_2
    //   36: aload_2
    //   37: invokevirtual 667	java/io/File:exists	()Z
    //   40: ifne +135 -> 175
    //   43: invokestatic 748	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:getParentConfigurationLocation	()Ljava/io/File;
    //   46: astore_3
    //   47: aload_3
    //   48: ifnonnull +4 -> 52
    //   51: return
    //   52: new 374	java/util/Properties
    //   55: dup
    //   56: invokespecial 717	java/util/Properties:<init>	()V
    //   59: astore 4
    //   61: aconst_null
    //   62: astore 5
    //   64: new 345	java/io/BufferedOutputStream
    //   67: dup
    //   68: new 348	java/io/FileOutputStream
    //   71: dup
    //   72: aload_2
    //   73: invokespecial 679	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   76: invokespecial 664	java/io/BufferedOutputStream:<init>	(Ljava/io/OutputStream;)V
    //   79: astore 5
    //   81: aload_3
    //   82: invokevirtual 676	java/io/File:toURL	()Ljava/net/URL;
    //   85: invokevirtual 710	java/net/URL:toExternalForm	()Ljava/lang/String;
    //   88: invokestatic 752	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:getOSGiInstallArea	()Ljava/net/URL;
    //   91: invokestatic 776	org/eclipse/equinox/internal/p2/update/PathUtil:makeRelative	(Ljava/lang/String;Ljava/net/URL;)Ljava/lang/String;
    //   94: bipush 92
    //   96: bipush 47
    //   98: invokevirtual 695	java/lang/String:replace	(CC)Ljava/lang/String;
    //   101: astore 6
    //   103: aload 4
    //   105: ldc_w 341
    //   108: aload 6
    //   110: invokevirtual 725	java/util/Properties:put	(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    //   113: pop
    //   114: aload 4
    //   116: aload 5
    //   118: ldc_w 326
    //   121: invokevirtual 723	java/util/Properties:store	(Ljava/io/OutputStream;Ljava/lang/String;)V
    //   124: goto +18 -> 142
    //   127: astore 7
    //   129: aload 5
    //   131: ifnull +8 -> 139
    //   134: aload 5
    //   136: invokevirtual 681	java/io/OutputStream:close	()V
    //   139: aload 7
    //   141: athrow
    //   142: aload 5
    //   144: ifnull +31 -> 175
    //   147: aload 5
    //   149: invokevirtual 681	java/io/OutputStream:close	()V
    //   152: goto +23 -> 175
    //   155: astore 5
    //   157: new 377	org/eclipse/core/runtime/Status
    //   160: dup
    //   161: iconst_4
    //   162: ldc 14
    //   164: ldc_w 333
    //   167: aload 5
    //   169: invokespecial 727	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
    //   172: invokestatic 729	org/eclipse/equinox/internal/p2/core/helpers/LogHelper:log	(Lorg/eclipse/core/runtime/IStatus;)V
    //   175: return
    // Line number table:
    //   Java source line #187	-> byte code offset #0
    //   Java source line #188	-> byte code offset #4
    //   Java source line #189	-> byte code offset #8
    //   Java source line #190	-> byte code offset #24
    //   Java source line #193	-> byte code offset #25
    //   Java source line #194	-> byte code offset #36
    //   Java source line #196	-> byte code offset #43
    //   Java source line #197	-> byte code offset #47
    //   Java source line #198	-> byte code offset #51
    //   Java source line #201	-> byte code offset #52
    //   Java source line #203	-> byte code offset #61
    //   Java source line #205	-> byte code offset #64
    //   Java source line #206	-> byte code offset #81
    //   Java source line #207	-> byte code offset #103
    //   Java source line #208	-> byte code offset #114
    //   Java source line #209	-> byte code offset #127
    //   Java source line #210	-> byte code offset #129
    //   Java source line #211	-> byte code offset #134
    //   Java source line #212	-> byte code offset #139
    //   Java source line #210	-> byte code offset #142
    //   Java source line #211	-> byte code offset #147
    //   Java source line #213	-> byte code offset #155
    //   Java source line #214	-> byte code offset #157
    //   Java source line #217	-> byte code offset #175
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	176	0	this	Activator
    //   3	27	1	configuration	File
    //   35	38	2	configIni	File
    //   46	36	3	parentConfiguration	File
    //   59	56	4	props	Properties
    //   62	86	5	os	java.io.OutputStream
    //   155	13	5	e	IOException
    //   101	8	6	externalForm	String
    //   127	13	7	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   64	127	127	finally
    //   61	152	155	java/io/IOException
  }
  
  private boolean isUpToDate()
  {
    if ("true".equals(getContext().getProperty("osgi.checkConfiguration")))
    {
      trace("User requested forced reconciliation via \"osgi.checkConfiguration=true\" System property.");
      trace("Performing reconciliation.");
      return false;
    }
    Properties timestamps = readTimestamps();
    if (timestamps.isEmpty())
    {
      trace("Cached timestamp file empty.");
      trace("Performing reconciliation.");
      return false;
    }
    Collection<File> files = getFilesToCheck();
    for (Iterator<File> iter = files.iterator(); iter.hasNext();)
    {
      File file = (File)iter.next();
      String key = file.getAbsolutePath();
      String timestamp = timestamps.getProperty(key);
      if (timestamp == null)
      {
        trace("Missing timestamp for file: " + key);
        trace("Performing reconciliation.");
        return false;
      }
      long lastModified = file.lastModified();
      if (!Long.toString(lastModified).equals(timestamp))
      {
        trace("Timestamp has been updated for file: " + key + ", expected: " + timestamp + ", actual: " + lastModified);
        trace("Performing reconciliation.");
        return false;
      }
      timestamps.remove(key);
    }
    boolean result = timestamps.isEmpty();
    if (result)
    {
      trace("Cached timestamp values up to date.");
      trace("Reconciliation skipped.");
    }
    else if (Tracing.DEBUG_RECONCILER)
    {
      trace("Found extra values in cached timestamp file: ");
      for (Iterator<Object> iter = timestamps.keySet().iterator(); iter.hasNext();) {
        trace(iter.next());
      }
      trace("Performing reconciliation. ");
    }
    return result;
  }
  
  /* Error */
  private Properties readTimestamps()
  {
    // Byte code:
    //   0: new 374	java/util/Properties
    //   3: dup
    //   4: invokespecial 717	java/util/Properties:<init>	()V
    //   7: astore_1
    //   8: invokestatic 757	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:getContext	()Lorg/osgi/framework/BundleContext;
    //   11: ldc 5
    //   13: invokeinterface 807 2 0
    //   18: astore_2
    //   19: aload_2
    //   20: invokevirtual 667	java/io/File:exists	()Z
    //   23: ifne +5 -> 28
    //   26: aload_1
    //   27: areturn
    //   28: new 361	java/lang/StringBuffer
    //   31: dup
    //   32: ldc_w 330
    //   35: invokespecial 703	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   38: aload_2
    //   39: invokevirtual 673	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   42: invokevirtual 707	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   45: invokevirtual 702	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   48: invokestatic 751	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:trace	(Ljava/lang/Object;)V
    //   51: aconst_null
    //   52: astore_3
    //   53: new 344	java/io/BufferedInputStream
    //   56: dup
    //   57: new 347	java/io/FileInputStream
    //   60: dup
    //   61: aload_2
    //   62: invokespecial 678	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   65: invokespecial 663	java/io/BufferedInputStream:<init>	(Ljava/io/InputStream;)V
    //   68: astore_3
    //   69: aload_1
    //   70: aload_3
    //   71: invokevirtual 719	java/util/Properties:load	(Ljava/io/InputStream;)V
    //   74: goto +55 -> 129
    //   77: astore 4
    //   79: new 377	org/eclipse/core/runtime/Status
    //   82: dup
    //   83: iconst_4
    //   84: ldc 14
    //   86: ldc_w 323
    //   89: aload 4
    //   91: invokespecial 727	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
    //   94: invokestatic 729	org/eclipse/equinox/internal/p2/core/helpers/LogHelper:log	(Lorg/eclipse/core/runtime/IStatus;)V
    //   97: aload_3
    //   98: ifnull +43 -> 141
    //   101: aload_3
    //   102: invokevirtual 680	java/io/InputStream:close	()V
    //   105: goto +36 -> 141
    //   108: pop
    //   109: goto +32 -> 141
    //   112: astore 5
    //   114: aload_3
    //   115: ifnull +11 -> 126
    //   118: aload_3
    //   119: invokevirtual 680	java/io/InputStream:close	()V
    //   122: goto +4 -> 126
    //   125: pop
    //   126: aload 5
    //   128: athrow
    //   129: aload_3
    //   130: ifnull +11 -> 141
    //   133: aload_3
    //   134: invokevirtual 680	java/io/InputStream:close	()V
    //   137: goto +4 -> 141
    //   140: pop
    //   141: getstatic 651	org/eclipse/equinox/internal/p2/core/helpers/Tracing:DEBUG_RECONCILER	Z
    //   144: ifeq +75 -> 219
    //   147: aload_1
    //   148: invokevirtual 720	java/util/Properties:keySet	()Ljava/util/Set;
    //   151: invokeinterface 795 1 0
    //   156: astore 4
    //   158: goto +51 -> 209
    //   161: aload 4
    //   163: invokeinterface 784 1 0
    //   168: astore 5
    //   170: aload_1
    //   171: aload 5
    //   173: invokevirtual 721	java/util/Properties:get	(Ljava/lang/Object;)Ljava/lang/Object;
    //   176: astore 6
    //   178: new 361	java/lang/StringBuffer
    //   181: dup
    //   182: aload 5
    //   184: invokevirtual 689	java/lang/Object:toString	()Ljava/lang/String;
    //   187: invokestatic 701	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   190: invokespecial 703	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   193: bipush 61
    //   195: invokevirtual 704	java/lang/StringBuffer:append	(C)Ljava/lang/StringBuffer;
    //   198: aload 6
    //   200: invokevirtual 706	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   203: invokevirtual 702	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   206: invokestatic 751	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:trace	(Ljava/lang/Object;)V
    //   209: aload 4
    //   211: invokeinterface 783 1 0
    //   216: ifne -55 -> 161
    //   219: aload_1
    //   220: areturn
    // Line number table:
    //   Java source line #279	-> byte code offset #0
    //   Java source line #280	-> byte code offset #8
    //   Java source line #281	-> byte code offset #19
    //   Java source line #282	-> byte code offset #26
    //   Java source line #283	-> byte code offset #28
    //   Java source line #284	-> byte code offset #51
    //   Java source line #286	-> byte code offset #53
    //   Java source line #287	-> byte code offset #69
    //   Java source line #288	-> byte code offset #77
    //   Java source line #289	-> byte code offset #79
    //   Java source line #292	-> byte code offset #97
    //   Java source line #293	-> byte code offset #101
    //   Java source line #294	-> byte code offset #108
    //   Java source line #290	-> byte code offset #112
    //   Java source line #292	-> byte code offset #114
    //   Java source line #293	-> byte code offset #118
    //   Java source line #294	-> byte code offset #125
    //   Java source line #297	-> byte code offset #126
    //   Java source line #292	-> byte code offset #129
    //   Java source line #293	-> byte code offset #133
    //   Java source line #294	-> byte code offset #140
    //   Java source line #298	-> byte code offset #141
    //   Java source line #299	-> byte code offset #147
    //   Java source line #300	-> byte code offset #161
    //   Java source line #301	-> byte code offset #170
    //   Java source line #302	-> byte code offset #178
    //   Java source line #299	-> byte code offset #209
    //   Java source line #305	-> byte code offset #219
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	221	0	this	Activator
    //   7	213	1	result	Properties
    //   18	44	2	file	File
    //   52	82	3	input	java.io.InputStream
    //   77	13	4	e	IOException
    //   156	54	4	iter	Iterator<Object>
    //   112	15	5	localObject1	Object
    //   168	15	5	key	Object
    //   176	23	6	value	Object
    //   108	1	9	localIOException1	IOException
    //   125	1	10	localIOException2	IOException
    //   140	1	11	localIOException3	IOException
    // Exception table:
    //   from	to	target	type
    //   53	74	77	java/io/IOException
    //   97	105	108	java/io/IOException
    //   53	97	112	finally
    //   114	122	125	java/io/IOException
    //   129	137	140	java/io/IOException
  }
  
  private Collection<File> getFilesToCheck()
  {
    if (filesToCheck != null) {
      return filesToCheck;
    }
    Set<File> result = new HashSet();
    
    File configuration = getConfigurationLocation();
    if (configuration != null)
    {
      result.add(new File(configuration, "org.eclipse.update/platform.xml"));
      File parent = configuration.getParentFile();
      if (parent != null)
      {
        File plugins = new File(parent, "plugins");
        result.add(plugins);
        File features = new File(parent, "features");
        result.add(features);
      }
    }
    File parentConfiguration = getParentConfigurationLocation();
    if (parentConfiguration != null)
    {
      result.add(new File(parentConfiguration, "org.eclipse.update/platform.xml"));
      File parent = parentConfiguration.getParentFile();
      if (parent != null)
      {
        File plugins = new File(parent, "plugins");
        result.add(plugins);
        File features = new File(parent, "features");
        result.add(features);
      }
    }
    File[] dropins = getDropinsDirectories();
    result.addAll(getDropinsToCheck(dropins));
    
    File[] links = getLinksDirectories();
    result.addAll(getDropinsToCheck(links));
    
    filesToCheck = result;
    return filesToCheck;
  }
  
  private Collection<File> getDropinsToCheck(File[] files)
  {
    Collection<File> result = new HashSet();
    for (int outer = 0; outer < files.length; outer++)
    {
      result.add(files[outer]);
      
      File[] children = files[outer].listFiles();
      for (int inner = 0; (children != null) && (inner < children.length); inner++)
      {
        File child = children[inner];
        if ((child.isFile()) && (child.getName().toLowerCase().endsWith(".link")))
        {
          DropinsRepositoryListener.LinkedRepository repo = DropinsRepositoryListener.getLinkedRepository(child);
          if ((repo != null) && (repo.exists()))
          {
            File target = repo.getLocation();
            result.add(child);
            result.add(target);
            File eclipse = new File(target, "eclipse");
            result.add(eclipse);
            result.add(new File(eclipse, "plugins"));
            result.add(new File(eclipse, "features"));
          }
        }
        else if (child.getName().equalsIgnoreCase("eclipse"))
        {
          result.add(child);
          result.add(new File(child, "plugins"));
          result.add(new File(child, "features"));
        }
        else if (child.isDirectory())
        {
          result.add(child);
          
          File eclipse = new File(child, "eclipse");
          File parent;
          File parent;
          if (eclipse.exists())
          {
            result.add(eclipse);
            parent = eclipse;
          }
          else
          {
            parent = child;
          }
          File plugins = new File(parent, "plugins");
          if (plugins.exists()) {
            result.add(plugins);
          }
          File features = new File(parent, "features");
          if (features.exists()) {
            result.add(features);
          }
        }
      }
    }
    return result;
  }
  
  /* Error */
  private void writeTimestamps()
  {
    // Byte code:
    //   0: new 374	java/util/Properties
    //   3: dup
    //   4: invokespecial 717	java/util/Properties:<init>	()V
    //   7: astore_1
    //   8: aload_0
    //   9: invokespecial 753	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:getFilesToCheck	()Ljava/util/Collection;
    //   12: astore_2
    //   13: aload_2
    //   14: invokeinterface 782 1 0
    //   19: astore_3
    //   20: goto +32 -> 52
    //   23: aload_3
    //   24: invokeinterface 784 1 0
    //   29: checkcast 346	java/io/File
    //   32: astore 4
    //   34: aload_1
    //   35: aload 4
    //   37: invokevirtual 673	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   40: aload 4
    //   42: invokevirtual 665	java/io/File:lastModified	()J
    //   45: invokestatic 686	java/lang/Long:toString	(J)Ljava/lang/String;
    //   48: invokevirtual 725	java/util/Properties:put	(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    //   51: pop
    //   52: aload_3
    //   53: invokeinterface 783 1 0
    //   58: ifne -35 -> 23
    //   61: invokestatic 757	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:getContext	()Lorg/osgi/framework/BundleContext;
    //   64: ldc 5
    //   66: invokeinterface 807 2 0
    //   71: astore_3
    //   72: new 361	java/lang/StringBuffer
    //   75: dup
    //   76: ldc_w 337
    //   79: invokespecial 703	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   82: aload_3
    //   83: invokevirtual 673	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   86: invokevirtual 707	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   89: invokevirtual 702	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   92: invokestatic 751	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:trace	(Ljava/lang/Object;)V
    //   95: aconst_null
    //   96: astore 4
    //   98: aload_3
    //   99: invokevirtual 666	java/io/File:delete	()Z
    //   102: pop
    //   103: new 345	java/io/BufferedOutputStream
    //   106: dup
    //   107: new 348	java/io/FileOutputStream
    //   110: dup
    //   111: aload_3
    //   112: invokespecial 679	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   115: invokespecial 664	java/io/BufferedOutputStream:<init>	(Ljava/io/OutputStream;)V
    //   118: astore 4
    //   120: aload_1
    //   121: aload 4
    //   123: aconst_null
    //   124: invokevirtual 723	java/util/Properties:store	(Ljava/io/OutputStream;Ljava/lang/String;)V
    //   127: getstatic 651	org/eclipse/equinox/internal/p2/core/helpers/Tracing:DEBUG_RECONCILER	Z
    //   130: ifeq +134 -> 264
    //   133: aload_1
    //   134: invokevirtual 720	java/util/Properties:keySet	()Ljava/util/Set;
    //   137: invokeinterface 795 1 0
    //   142: astore 5
    //   144: goto +51 -> 195
    //   147: aload 5
    //   149: invokeinterface 784 1 0
    //   154: astore 6
    //   156: aload_1
    //   157: aload 6
    //   159: invokevirtual 721	java/util/Properties:get	(Ljava/lang/Object;)Ljava/lang/Object;
    //   162: astore 7
    //   164: new 361	java/lang/StringBuffer
    //   167: dup
    //   168: aload 6
    //   170: invokevirtual 689	java/lang/Object:toString	()Ljava/lang/String;
    //   173: invokestatic 701	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   176: invokespecial 703	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   179: bipush 61
    //   181: invokevirtual 704	java/lang/StringBuffer:append	(C)Ljava/lang/StringBuffer;
    //   184: aload 7
    //   186: invokevirtual 706	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   189: invokevirtual 702	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   192: invokestatic 751	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:trace	(Ljava/lang/Object;)V
    //   195: aload 5
    //   197: invokeinterface 783 1 0
    //   202: ifne -55 -> 147
    //   205: goto +59 -> 264
    //   208: astore 5
    //   210: new 377	org/eclipse/core/runtime/Status
    //   213: dup
    //   214: iconst_4
    //   215: ldc 14
    //   217: ldc_w 324
    //   220: aload 5
    //   222: invokespecial 727	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
    //   225: invokestatic 729	org/eclipse/equinox/internal/p2/core/helpers/LogHelper:log	(Lorg/eclipse/core/runtime/IStatus;)V
    //   228: aload 4
    //   230: ifnull +48 -> 278
    //   233: aload 4
    //   235: invokevirtual 681	java/io/OutputStream:close	()V
    //   238: goto +40 -> 278
    //   241: pop
    //   242: goto +36 -> 278
    //   245: astore 8
    //   247: aload 4
    //   249: ifnull +12 -> 261
    //   252: aload 4
    //   254: invokevirtual 681	java/io/OutputStream:close	()V
    //   257: goto +4 -> 261
    //   260: pop
    //   261: aload 8
    //   263: athrow
    //   264: aload 4
    //   266: ifnull +12 -> 278
    //   269: aload 4
    //   271: invokevirtual 681	java/io/OutputStream:close	()V
    //   274: goto +4 -> 278
    //   277: pop
    //   278: return
    // Line number table:
    //   Java source line #418	-> byte code offset #0
    //   Java source line #419	-> byte code offset #8
    //   Java source line #420	-> byte code offset #13
    //   Java source line #421	-> byte code offset #23
    //   Java source line #422	-> byte code offset #34
    //   Java source line #420	-> byte code offset #52
    //   Java source line #426	-> byte code offset #61
    //   Java source line #427	-> byte code offset #72
    //   Java source line #428	-> byte code offset #95
    //   Java source line #430	-> byte code offset #98
    //   Java source line #431	-> byte code offset #103
    //   Java source line #432	-> byte code offset #120
    //   Java source line #433	-> byte code offset #127
    //   Java source line #434	-> byte code offset #133
    //   Java source line #435	-> byte code offset #147
    //   Java source line #436	-> byte code offset #156
    //   Java source line #437	-> byte code offset #164
    //   Java source line #434	-> byte code offset #195
    //   Java source line #440	-> byte code offset #208
    //   Java source line #441	-> byte code offset #210
    //   Java source line #443	-> byte code offset #228
    //   Java source line #445	-> byte code offset #233
    //   Java source line #446	-> byte code offset #241
    //   Java source line #442	-> byte code offset #245
    //   Java source line #443	-> byte code offset #247
    //   Java source line #445	-> byte code offset #252
    //   Java source line #446	-> byte code offset #260
    //   Java source line #449	-> byte code offset #261
    //   Java source line #443	-> byte code offset #264
    //   Java source line #445	-> byte code offset #269
    //   Java source line #446	-> byte code offset #277
    //   Java source line #450	-> byte code offset #278
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	279	0	this	Activator
    //   7	150	1	timestamps	Properties
    //   12	2	2	files	Collection<File>
    //   19	34	3	iter	Iterator<File>
    //   71	41	3	file	File
    //   32	9	4	file	File
    //   96	174	4	output	java.io.OutputStream
    //   142	54	5	iter	Iterator<Object>
    //   208	13	5	e	IOException
    //   154	15	6	key	Object
    //   162	23	7	value	Object
    //   245	17	8	localObject1	Object
    //   241	1	12	localIOException1	IOException
    //   260	1	13	localIOException2	IOException
    //   277	1	14	localIOException3	IOException
    // Exception table:
    //   from	to	target	type
    //   98	205	208	java/io/IOException
    //   233	238	241	java/io/IOException
    //   98	228	245	finally
    //   252	257	260	java/io/IOException
    //   269	274	277	java/io/IOException
  }
  
  public static synchronized void synchronize(IProgressMonitor monitor)
  {
    IProfile profile = getCurrentProfile(bundleContext);
    if (profile == null) {
      return;
    }
    ProfileSynchronizer synchronizer = new ProfileSynchronizer(getAgent(), profile, repositories);
    IStatus result = synchronizer.synchronize(monitor);
    if (ProfileSynchronizer.isReconciliationApplicationRunning()) {
      System.getProperties().put("org.eclipse.equinox.p2.reconciler.application.status", result);
    }
    if ((!result.isOK()) && (result.getSeverity() != 8)) {
      LogHelper.log(result);
    }
  }
  
  private void watchConfiguration()
  {
    File configFile = getConfigurationLocation();
    if (configFile == null)
    {
      LogHelper.log(new Status(4, "org.eclipse.equinox.p2.reconciler.dropins", "Unable to determine configuration location."));
      return;
    }
    configFile = new File(configFile, "org.eclipse.update/platform.xml");
    if (!configFile.exists())
    {
      File parentConfiguration = getParentConfigurationLocation();
      if (parentConfiguration == null) {
        return;
      }
      File shareConfigFile = new File(parentConfiguration, "org.eclipse.update/platform.xml");
      if (!shareConfigFile.exists()) {
        return;
      }
      Configuration config = new Configuration();
      config.setDate(Long.toString(new Date().getTime()));
      config.setVersion("3.0");
      try
      {
        String sharedUR = PathUtil.makeRelative(shareConfigFile.toURL().toExternalForm(), getOSGiInstallArea()).replace('\\', '/');
        config.setSharedUR(sharedUR);
        
        configFile.getParentFile().mkdirs();
        config.save(configFile, getOSGiInstallArea());
      }
      catch (IOException e)
      {
        LogHelper.log(new Status(4, "org.eclipse.equinox.p2.reconciler.dropins", "Unable to create linked platform.xml.", e));
        return;
      }
      catch (ProvisionException e)
      {
        LogHelper.log(new Status(4, "org.eclipse.equinox.p2.reconciler.dropins", "Unable to create linked platform.xml.", e));
        return;
      }
    }
    DirectoryWatcher watcher = new DirectoryWatcher(configFile.getParentFile());
    PlatformXmlListener listener = new PlatformXmlListener(configFile);
    watcher.addListener(listener);
    watcher.poll();
    repositories.addAll(listener.getMetadataRepositories());
  }
  
  private void watchDropins()
  {
    List<File> directories = new ArrayList();
    File[] dropinsDirectories = getDropinsDirectories();
    directories.addAll(Arrays.asList(dropinsDirectories));
    File[] linksDirectories = getLinksDirectories();
    directories.addAll(Arrays.asList(linksDirectories));
    if (directories.isEmpty()) {
      return;
    }
    Map<String, String> properties = new HashMap();
    properties.put("p2.compressed", Boolean.TRUE.toString());
    properties.put("p2.system", Boolean.TRUE.toString());
    
    DropinsRepositoryListener listener = new DropinsRepositoryListener(getAgent(), "dropins", properties);
    DirectoryWatcher watcher = new DirectoryWatcher((File[])directories.toArray(new File[directories.size()]));
    watcher.addListener(listener);
    watcher.poll();
    repositories.addAll(listener.getMetadataRepositories());
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    bundleContext = null;
  }
  
  public static BundleContext getContext()
  {
    return bundleContext;
  }
  
  public static File getConfigurationLocation()
  {
    Location configurationLocation = (Location)ServiceHelper.getService(getContext(), Location.class.getName(), Location.CONFIGURATION_FILTER);
    if ((configurationLocation == null) || (!configurationLocation.isSet())) {
      return null;
    }
    URL url = configurationLocation.getURL();
    if (url == null) {
      return null;
    }
    return URLUtil.toFile(url);
  }
  
  public static File getParentConfigurationLocation()
  {
    Location configurationLocation = (Location)ServiceHelper.getService(getContext(), Location.class.getName(), Location.CONFIGURATION_FILTER);
    if ((configurationLocation == null) || (!configurationLocation.isSet())) {
      return null;
    }
    Location sharedConfigurationLocation = configurationLocation.getParentLocation();
    if (sharedConfigurationLocation == null) {
      return null;
    }
    URL url = sharedConfigurationLocation.getURL();
    if (url == null) {
      return null;
    }
    return URLUtil.toFile(url);
  }
  
  public static URL getOSGiInstallArea()
  {
    Location location = (Location)ServiceHelper.getService(getContext(), Location.class.getName(), Location.INSTALL_FILTER);
    if (location == null) {
      return null;
    }
    if (!location.isSet()) {
      return null;
    }
    return location.getURL();
  }
  
  public static String substituteVariables(String path)
  {
    if (path == null) {
      return path;
    }
    int beginIndex = path.indexOf('%');
    if (beginIndex == -1) {
      return path;
    }
    beginIndex++;
    int endIndex = path.indexOf('%', beginIndex);
    if (endIndex == -1) {
      return path;
    }
    String var = path.substring(beginIndex, endIndex);
    if ((var.length() == 0) || (var.indexOf(File.pathSeparatorChar) != -1)) {
      return path;
    }
    var = getContext().getProperty(var);
    if (var == null) {
      return path;
    }
    return path.substring(0, beginIndex - 1) + var + path.substring(endIndex + 1);
  }
  
  public static File getEclipseHome()
  {
    Location eclipseHome = (Location)ServiceHelper.getService(getContext(), Location.class.getName(), Location.ECLIPSE_HOME_FILTER);
    if ((eclipseHome == null) || (!eclipseHome.isSet())) {
      return null;
    }
    URL url = eclipseHome.getURL();
    if (url == null) {
      return null;
    }
    return URLUtil.toFile(url);
  }
  
  private static File[] getLinksDirectories()
  {
    List<File> linksDirectories = new ArrayList();
    File root = getEclipseHome();
    if (root != null) {
      linksDirectories.add(new File(root, "links"));
    }
    if (getParentConfigurationLocation() != null)
    {
      File configuration = getConfigurationLocation();
      if ((configuration != null) && (configuration.getParentFile() != null)) {
        linksDirectories.add(new File(configuration.getParentFile(), "links"));
      }
    }
    return (File[])linksDirectories.toArray(new File[linksDirectories.size()]);
  }
  
  private static File[] getDropinsDirectories()
  {
    List<File> dropinsDirectories = new ArrayList();
    
    String watchedDirectoryProperty = bundleContext.getProperty("org.eclipse.equinox.p2.reconciler.dropins.directory");
    if (watchedDirectoryProperty != null)
    {
      watchedDirectoryProperty = substituteVariables(watchedDirectoryProperty);
      dropinsDirectories.add(new File(watchedDirectoryProperty));
    }
    File root = getEclipseHome();
    if (root != null) {
      dropinsDirectories.add(new File(root, "dropins"));
    }
    if (getParentConfigurationLocation() != null)
    {
      File configuration = getConfigurationLocation();
      if ((configuration != null) && (configuration.getParentFile() != null)) {
        dropinsDirectories.add(new File(configuration.getParentFile(), "dropins"));
      }
    }
    return (File[])dropinsDirectories.toArray(new File[dropinsDirectories.size()]);
  }
  
  public static IProfile getCurrentProfile(BundleContext context)
  {
    IProvisioningAgent agent = getAgent();
    IProfileRegistry profileRegistry = (IProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
    if (profileRegistry == null) {
      return null;
    }
    return profileRegistry.getProfile("_SELF_");
  }
  
  public static void trace(Object message)
  {
    if (Tracing.DEBUG_RECONCILER) {
      Tracing.debug("[reconciler] " + message);
    }
1 2 3 4

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