org.eclipse.equinox.p2.reconciler.dropins_1.1.200.v20120301-2145

x.p2.cache.extensions", updatedCacheExtensions, context, null);
      if ((engineResult.getSeverity() != 4) && (engineResult.getSeverity() != 8)) {
        writeTimestamps();
      }
      return engineResult;
    }
    if (updatedCacheExtensions != null) {
      request.setProfileProperty("org.eclipse.equinox.p2.cache.extensions", updatedCacheExtensions);
    }
    IStatus moveResult = performRemoveForMovedIUs(request, context, monitor);
    if ((moveResult.getSeverity() == 4) || (moveResult.getSeverity() == 8)) {
      return moveResult;
    }
    IStatus addRemoveResult = performAddRemove(request, context, monitor);
    if ((addRemoveResult.getSeverity() == 4) || (addRemoveResult.getSeverity() == 8)) {
      return addRemoveResult;
    }
    writeTimestamps();
    IStatus applyResult = applyConfiguration(false);
    
    IProfileRegistry profileRegistry = (IProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
    if (profileRegistry != null)
    {
      IStatus result = profileRegistry.setProfileStateProperty(profile.getProfileId(), profile.getTimestamp(), "org.eclipse.equinox.p2.state.hidden", Boolean.TRUE.toString());
      if (!result.isOK()) {
        LogHelper.log(result);
      }
    }
    return applyResult;
  }
  
  private IQueryResult<IInstallableUnit> getStrictRoots()
  {
    return profile.query(new IUProfilePropertyQuery("org.eclipse.equinox.p2.internal.inclusion.rules", "STRICT"), null);
  }
  
  private IStatus performAddRemove(ReconcilerProfileChangeRequest request, ProvisioningContext context, IProgressMonitor monitor)
  {
    for (Iterator localIterator = request.getMoves().iterator(); localIterator.hasNext();)
    {
      IInstallableUnit iu = (IInstallableUnit)localIterator.next();
      request.add(iu);
      request.setInstallableUnitProfileProperty(iu, "org.eclipse.equinox.p2.reconciler.dropins", Boolean.TRUE.toString());
      request.setInstallableUnitInclusionRules(iu, ProfileInclusionRules.createOptionalInclusionRule(iu));
      request.setInstallableUnitProfileProperty(iu, "org.eclipse.equinox.p2.type.lock", Integer.toString(1));
    }
    Collection<IInstallableUnit> additions = request.getAdditions();
    Object removals = request.getRemovals();
    if ((additions.isEmpty()) && (((Collection)removals).isEmpty())) {
      return Status.OK_STATUS;
    }
    boolean removeStrictRoots = false;
    if (removeStrictRoots) {
      return performStrictRootRemoval(request, context, monitor);
    }
    IProvisioningPlan plan = createProvisioningPlan(request, context, monitor);
    debug(request, plan);
    return executePlan(plan, context, monitor);
  }
  
  private IStatus performStrictRootRemoval(ReconcilerProfileChangeRequest request, ProvisioningContext context, IProgressMonitor monitor)
  {
    Collection<IInstallableUnit> removals = request.getRemovals();
    if (removals.isEmpty())
    {
      IProvisioningPlan plan = createProvisioningPlan(request, context, monitor);
      debug(request, plan);
      return executePlan(plan, context, monitor);
    }
    ProfileChangeRequest finalRequest = (ProfileChangeRequest)request.clone();
    
    Set<IInstallableUnit> strictRoots = getStrictRoots().toUnmodifiableSet();
    Collection<IRequirement> forceNegation = new ArrayList(removals.size());
    for (Iterator localIterator1 = removals.iterator(); localIterator1.hasNext();)
    {
      IInstallableUnit iu = (IInstallableUnit)localIterator1.next();
      forceNegation.add(createNegation(iu));
    }
    request.addExtraRequirements(forceNegation);
    for (localIterator1 = strictRoots.iterator(); localIterator1.hasNext();)
    {
      IInstallableUnit iu = (IInstallableUnit)localIterator1.next();
      request.setInstallableUnitProfileProperty(iu, "org.eclipse.equinox.p2.internal.inclusion.rules", "OPTIONAL");
    }
    IProvisioningPlan plan = createProvisioningPlan(request, context, monitor);
    debug(request, plan);
    if (!plan.getStatus().isOK()) {
      return plan.getStatus();
    }
    int removedRoots = 0;
    for (Iterator localIterator2 = strictRoots.iterator(); localIterator2.hasNext();)
    {
      IInstallableUnit initialRoot = (IInstallableUnit)localIterator2.next();
      if (!plan.getRemovals().query(QueryUtil.createIUQuery(initialRoot), null).isEmpty())
      {
        finalRequest.remove(initialRoot);
        finalRequest.setInstallableUnitProfileProperty(initialRoot, "org.eclipse.equinox.p2.internal.inclusion.rules", "OPTIONAL");
        IRequirement negation = createNegation(initialRoot);
        Collection<IRequirement> extra = new ArrayList();
        extra.add(negation);
        request.addExtraRequirements(extra);
        LogHelper.log(new Status(1, "org.eclipse.equinox.p2.reconciler.dropins", NLS.bind(Messages.remove_root, initialRoot.getId(), initialRoot.getVersion())));
        removedRoots++;
      }
    }
    if (removedRoots == strictRoots.size()) {
      return new Status(4, "org.eclipse.equinox.p2.reconciler.dropins", Messages.remove_all_roots);
    }
    plan = createProvisioningPlan(finalRequest, context, monitor);
    if (!plan.getStatus().isOK())
    {
      System.out.println("original request");
      System.out.println(request);
      System.out.println("final request");
      System.out.println(finalRequest);
      throw new IllegalStateException("The second plan is not resolvable.");
    }
    return executePlan(plan, context, monitor);
  }
  
  private IStatus performRemoveForMovedIUs(ReconcilerProfileChangeRequest request, ProvisioningContext context, IProgressMonitor monitor)
  {
    Collection<IInstallableUnit> moves = request.getMoves();
    if (moves.isEmpty()) {
      return Status.OK_STATUS;
    }
    IEngine engine = (IEngine)agent.getService(IEngine.SERVICE_NAME);
    IProvisioningPlan plan = engine.createPlan(profile, context);
    for (Iterator localIterator = moves.iterator(); localIterator.hasNext();)
    {
      IInstallableUnit unit = (IInstallableUnit)localIterator.next();
      plan.removeInstallableUnit(unit);
    }
    return executePlan(plan, context, monitor);
  }
  
  /* Error */
  private void writeTimestamps()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 850	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:timestamps	Ljava/util/Map;
    //   4: invokeinterface 995 1 0
    //   9: aload_0
    //   10: getfield 850	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:timestamps	Ljava/util/Map;
    //   13: ldc 3
    //   15: aload_0
    //   16: getfield 852	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:profile	Lorg/eclipse/equinox/p2/engine/IProfile;
    //   19: invokeinterface 1014 1 0
    //   24: invokestatic 877	java/lang/Long:toString	(J)Ljava/lang/String;
    //   27: invokeinterface 1002 3 0
    //   32: pop
    //   33: aload_0
    //   34: getfield 849	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:repositoryMap	Ljava/util/Map;
    //   37: invokeinterface 998 1 0
    //   42: invokeinterface 1007 1 0
    //   47: astore_2
    //   48: goto +84 -> 132
    //   51: aload_2
    //   52: invokeinterface 986 1 0
    //   57: checkcast 477	java/util/Map$Entry
    //   60: astore_1
    //   61: aload_1
    //   62: invokeinterface 1004 1 0
    //   67: checkcast 514	org/eclipse/equinox/p2/repository/metadata/IMetadataRepository
    //   70: astore_3
    //   71: aload_3
    //   72: invokeinterface 1036 1 0
    //   77: astore 4
    //   79: aconst_null
    //   80: astore 5
    //   82: aload 4
    //   84: ifnull +18 -> 102
    //   87: aload 4
    //   89: ldc_w 443
    //   92: invokeinterface 1000 2 0
    //   97: checkcast 464	java/lang/String
    //   100: astore 5
    //   102: aload 5
    //   104: ifnonnull +7 -> 111
    //   107: ldc 1
    //   109: astore 5
    //   111: aload_0
    //   112: getfield 850	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:timestamps	Ljava/util/Map;
    //   115: aload_1
    //   116: invokeinterface 1003 1 0
    //   121: checkcast 464	java/lang/String
    //   124: aload 5
    //   126: invokeinterface 1002 3 0
    //   131: pop
    //   132: aload_2
    //   133: invokeinterface 985 1 0
    //   138: ifne -87 -> 51
    //   141: invokestatic 922	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:getContext	()Lorg/osgi/framework/BundleContext;
    //   144: new 465	java/lang/StringBuffer
    //   147: dup
    //   148: ldc 11
    //   150: invokespecial 890	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   153: aload_0
    //   154: getfield 852	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:profile	Lorg/eclipse/equinox/p2/engine/IProfile;
    //   157: invokeinterface 1015 1 0
    //   162: invokevirtual 880	java/lang/String:hashCode	()I
    //   165: invokevirtual 892	java/lang/StringBuffer:append	(I)Ljava/lang/StringBuffer;
    //   168: invokevirtual 889	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   171: invokeinterface 1040 2 0
    //   176: astore_1
    //   177: new 465	java/lang/StringBuffer
    //   180: dup
    //   181: ldc_w 415
    //   184: invokespecial 890	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   187: aload_1
    //   188: invokevirtual 861	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   191: invokevirtual 894	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   194: invokevirtual 889	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   197: invokestatic 920	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:trace	(Ljava/lang/Object;)V
    //   200: new 447	java/io/BufferedOutputStream
    //   203: dup
    //   204: new 451	java/io/FileOutputStream
    //   207: dup
    //   208: aload_1
    //   209: invokespecial 863	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   212: invokespecial 860	java/io/BufferedOutputStream:<init>	(Ljava/io/OutputStream;)V
    //   215: astore_2
    //   216: aload_0
    //   217: getfield 850	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:timestamps	Ljava/util/Map;
    //   220: aload_2
    //   221: new 465	java/lang/StringBuffer
    //   224: dup
    //   225: ldc_w 409
    //   228: invokespecial 890	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   231: aload_0
    //   232: getfield 852	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:profile	Lorg/eclipse/equinox/p2/engine/IProfile;
    //   235: invokeinterface 1015 1 0
    //   240: invokevirtual 894	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   243: invokevirtual 889	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   246: invokestatic 914	org/eclipse/equinox/internal/p2/core/helpers/CollectionUtils:storeProperties	(Ljava/util/Map;Ljava/io/OutputStream;Ljava/lang/String;)V
    //   249: getstatic 844	org/eclipse/equinox/internal/p2/core/helpers/Tracing:DEBUG_RECONCILER	Z
    //   252: ifeq +98 -> 350
    //   255: aload_0
    //   256: getfield 850	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:timestamps	Ljava/util/Map;
    //   259: invokeinterface 999 1 0
    //   264: invokeinterface 1007 1 0
    //   269: astore_3
    //   270: goto +55 -> 325
    //   273: aload_3
    //   274: invokeinterface 986 1 0
    //   279: checkcast 464	java/lang/String
    //   282: astore 4
    //   284: aload_0
    //   285: getfield 850	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:timestamps	Ljava/util/Map;
    //   288: aload 4
    //   290: invokeinterface 1000 2 0
    //   295: astore 5
    //   297: new 465	java/lang/StringBuffer
    //   300: dup
    //   301: aload 4
    //   303: invokestatic 886	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   306: invokespecial 890	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   309: bipush 61
    //   311: invokevirtual 891	java/lang/StringBuffer:append	(C)Ljava/lang/StringBuffer;
    //   314: aload 5
    //   316: invokevirtual 893	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   319: invokevirtual 889	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   322: invokestatic 920	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:trace	(Ljava/lang/Object;)V
    //   325: aload_3
    //   326: invokeinterface 985 1 0
    //   331: ifne -58 -> 273
    //   334: goto +16 -> 350
    //   337: astore 6
    //   339: aload_2
    //   340: ifnull +7 -> 347
    //   343: aload_2
    //   344: invokevirtual 866	java/io/OutputStream:close	()V
    //   347: aload 6
    //   349: athrow
    //   350: aload_2
    //   351: ifnull +15 -> 366
    //   354: aload_2
    //   355: invokevirtual 866	java/io/OutputStream:close	()V
    //   358: goto +8 -> 366
    //   361: pop
    //   362: goto +4 -> 366
    //   365: pop
    //   366: return
    // Line number table:
    //   Java source line #278	-> byte code offset #0
    //   Java source line #279	-> byte code offset #9
    //   Java source line #280	-> byte code offset #33
    //   Java source line #281	-> byte code offset #61
    //   Java source line #282	-> byte code offset #71
    //   Java source line #283	-> byte code offset #79
    //   Java source line #284	-> byte code offset #82
    //   Java source line #285	-> byte code offset #87
    //   Java source line #286	-> byte code offset #102
    //   Java source line #287	-> byte code offset #107
    //   Java source line #289	-> byte code offset #111
    //   Java source line #280	-> byte code offset #132
    //   Java source line #293	-> byte code offset #141
    //   Java source line #294	-> byte code offset #177
    //   Java source line #295	-> byte code offset #200
    //   Java source line #297	-> byte code offset #216
    //   Java source line #298	-> byte code offset #249
    //   Java source line #299	-> byte code offset #255
    //   Java source line #300	-> byte code offset #273
    //   Java source line #301	-> byte code offset #284
    //   Java source line #302	-> byte code offset #297
    //   Java source line #299	-> byte code offset #325
    //   Java source line #305	-> byte code offset #337
    //   Java source line #306	-> byte code offset #339
    //   Java source line #307	-> byte code offset #343
    //   Java source line #308	-> byte code offset #347
    //   Java source line #306	-> byte code offset #350
    //   Java source line #307	-> byte code offset #354
    //   Java source line #309	-> byte code offset #361
    //   Java source line #311	-> byte code offset #365
    //   Java source line #314	-> byte code offset #366
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	367	0	this	ProfileSynchronizer
    //   60	56	1	entry	Map.Entry<String, IMetadataRepository>
    //   176	33	1	file	java.io.File
    //   47	86	2	localIterator	Iterator
    //   215	140	2	os	Object
    //   70	2	3	repository	IMetadataRepository
    //   269	57	3	iter	Iterator<String>
    //   77	11	4	props	Map<String, String>
    //   282	20	4	key	String
    //   80	45	5	timestamp	String
    //   295	20	5	value	Object
    //   337	11	6	localObject1	Object
    //   361	1	12	localFileNotFoundException	java.io.FileNotFoundException
    //   365	1	13	localIOException	java.io.IOException
    // Exception table:
    //   from	to	target	type
    //   216	337	337	finally
    //   141	358	361	java/io/FileNotFoundException
    //   141	358	365	java/io/IOException
  }
  
  private boolean isUpToDate()
  {
    if ("true".equals(Activator.getContext().getProperty("osgi.checkConfiguration")))
    {
      Activator.trace("User requested forced reconciliation via \"osgi.checkConfiguration=true\" System property.");
      Activator.trace("Performing reconciliation.");
      return false;
    }
    String lastKnownProfileTimeStamp = (String)timestamps.remove("PROFILE");
    if (lastKnownProfileTimeStamp == null)
    {
      Activator.trace("Profile timestamp not found in cache.");
      Activator.trace("Performing reconciliation.");
      return false;
    }
    String currentProfileTimestamp = Long.toString(profile.getTimestamp());
    if (!lastKnownProfileTimeStamp.equals(currentProfileTimestamp))
    {
      Activator.trace("Profile timestamps not equal, expected: " + lastKnownProfileTimeStamp + ", actual=" + currentProfileTimestamp);
      Activator.trace("Performing reconciliation.");
      return false;
    }
    for (Iterator localIterator = repositoryMap.entrySet().iterator(); localIterator.hasNext();)
    {
      Map.Entry<String, IMetadataRepository> entry = (Map.Entry)localIterator.next();
      IMetadataRepository repository = (IMetadataRepository)entry.getValue();
      
      Map<String, String> props = repository.getProperties();
      String currentTimestamp = null;
      if (props != null) {
        currentTimestamp = (String)props.get("p2.timestamp");
      }
      if (currentTimestamp == null) {
        currentTimestamp = "-1";
      }
      String key = (String)entry.getKey();
      String lastKnownTimestamp = (String)timestamps.remove(key);
      if (lastKnownTimestamp == null)
      {
        Activator.trace("No cached timestamp found for: " + key);
        Activator.trace("Performing reconciliation.");
        return false;
      }
      if (!lastKnownTimestamp.equals(currentTimestamp))
      {
        Activator.trace("Timestamps not equal for file: " + key + ", expected: " + lastKnownTimestamp + ", actual: " + currentTimestamp);
        Activator.trace("Performing reconciliation.");
        return false;
      }
    }
    if (timestamps.size() == 0)
    {
      Activator.trace("Timestamps valid.");
      Activator.trace("Skipping reconciliation.");
      return true;
    }
    if (Tracing.DEBUG_RECONCILER)
    {
      Activator.trace("Extra values in timestamp file:");
      for (Iterator<String> iter = timestamps.keySet().iterator(); iter.hasNext();) {
        Activator.trace(iter.next());
      }
      Activator.trace("Performing reconciliation.");
    }
    return false;
  }
  
  /* Error */
  private void readTimestamps()
  {
    // Byte code:
    //   0: invokestatic 922	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:getContext	()Lorg/osgi/framework/BundleContext;
    //   3: new 465	java/lang/StringBuffer
    //   6: dup
    //   7: ldc 11
    //   9: invokespecial 890	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   12: aload_0
    //   13: getfield 852	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:profile	Lorg/eclipse/equinox/p2/engine/IProfile;
    //   16: invokeinterface 1015 1 0
    //   21: invokevirtual 880	java/lang/String:hashCode	()I
    //   24: invokevirtual 892	java/lang/StringBuffer:append	(I)Ljava/lang/StringBuffer;
    //   27: invokevirtual 889	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   30: invokeinterface 1040 2 0
    //   35: astore_1
    //   36: new 446	java/io/BufferedInputStream
    //   39: dup
    //   40: new 449	java/io/FileInputStream
    //   43: dup
    //   44: aload_1
    //   45: invokespecial 862	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   48: invokespecial 859	java/io/BufferedInputStream:<init>	(Ljava/io/InputStream;)V
    //   51: astore_2
    //   52: aload_0
    //   53: aload_2
    //   54: invokestatic 913	org/eclipse/equinox/internal/p2/core/helpers/CollectionUtils:loadProperties	(Ljava/io/InputStream;)Ljava/util/Map;
    //   57: putfield 850	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:timestamps	Ljava/util/Map;
    //   60: goto +14 -> 74
    //   63: astore_3
    //   64: aload_2
    //   65: ifnull +7 -> 72
    //   68: aload_2
    //   69: invokevirtual 865	java/io/InputStream:close	()V
    //   72: aload_3
    //   73: athrow
    //   74: aload_2
    //   75: ifnull +78 -> 153
    //   78: aload_2
    //   79: invokevirtual 865	java/io/InputStream:close	()V
    //   82: goto +71 -> 153
    //   85: pop
    //   86: aload_0
    //   87: new 473	java/util/HashMap
    //   90: dup
    //   91: invokespecial 906	java/util/HashMap:<init>	()V
    //   94: putfield 850	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:timestamps	Ljava/util/Map;
    //   97: ldc_w 408
    //   100: invokestatic 920	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:trace	(Ljava/lang/Object;)V
    //   103: ldc_w 403
    //   106: invokestatic 920	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:trace	(Ljava/lang/Object;)V
    //   109: goto +44 -> 153
    //   112: astore_2
    //   113: aload_0
    //   114: new 473	java/util/HashMap
    //   117: dup
    //   118: invokespecial 906	java/util/HashMap:<init>	()V
    //   121: putfield 850	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:timestamps	Ljava/util/Map;
    //   124: new 465	java/lang/StringBuffer
    //   127: dup
    //   128: ldc_w 400
    //   131: invokespecial 890	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   134: aload_2
    //   135: invokevirtual 864	java/io/IOException:getMessage	()Ljava/lang/String;
    //   138: invokevirtual 894	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   141: invokevirtual 889	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   144: invokestatic 920	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:trace	(Ljava/lang/Object;)V
    //   147: ldc_w 403
    //   150: invokestatic 920	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:trace	(Ljava/lang/Object;)V
    //   153: return
    // Line number table:
    //   Java source line #387	-> byte code offset #0
    //   Java source line #389	-> byte code offset #36
    //   Java source line #391	-> byte code offset #52
    //   Java source line #392	-> byte code offset #63
    //   Java source line #393	-> byte code offset #64
    //   Java source line #394	-> byte code offset #68
    //   Java source line #395	-> byte code offset #72
    //   Java source line #393	-> byte code offset #74
    //   Java source line #394	-> byte code offset #78
    //   Java source line #396	-> byte code offset #85
    //   Java source line #398	-> byte code offset #86
    //   Java source line #399	-> byte code offset #97
    //   Java source line #400	-> byte code offset #103
    //   Java source line #401	-> byte code offset #112
    //   Java source line #403	-> byte code offset #113
    //   Java source line #404	-> byte code offset #124
    //   Java source line #405	-> byte code offset #147
    //   Java source line #407	-> byte code offset #153
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	154	0	this	ProfileSynchronizer
    //   35	10	1	file	java.io.File
    //   51	28	2	is	java.io.InputStream
    //   112	23	2	e	java.io.IOException
    //   63	10	3	localObject	Object
    //   85	1	5	localFileNotFoundException	java.io.FileNotFoundException
    // Exception table:
    //   from	to	target	type
    //   52	63	63	finally
    //   36	82	85	java/io/FileNotFoundException
    //   36	82	112	java/io/IOException
  }
  
  private ProvisioningContext getContext()
  {
    ArrayList<URI> repoURLs = new ArrayList();
    for (Iterator<String> iterator = repositoryMap.keySet().iterator(); iterator.hasNext();) {
      try
      {
        repoURLs.add(new URI((String)iterator.next()));
      }
      catch (URISyntaxException localURISyntaxException) {}
    }
    ProvisioningContext result = new ProvisioningContext(agent);
    result.setMetadataRepositories((URI[])repoURLs.toArray(new URI[repoURLs.size()]));
    result.setArtifactRepositories(new URI[0]);
    return result;
  }
  
  private String synchronizeCacheExtensions()
  {
    List<String> currentExtensions = new ArrayList();
    StringBuffer buffer = new StringBuffer();
    
    List<String> repositories = new ArrayList(repositoryMap.keySet());
    URL installArea = Activator.getOSGiInstallArea();
    try
    {
      final String OSGiInstallArea = URIUtil.toURI(installArea).toString() + ".eclipseextension";
      
      Collections.sort(repositories, new Comparator()
      {
        public int compare(String left, String right)
        {
          if (OSGiInstallArea.equals(left)) {
            return -1;
          }
          if (OSGiInstallArea.equals(right)) {
            return 1;
          }
          return left.compareTo(right);
        }
      });
    }
    catch (URISyntaxException e)
    {
      LogHelper.log(new Status(4, "org.eclipse.equinox.p2.reconciler.dropins", "Unable to convert OSGi install area: " + installArea + " into URI.", e));
    }
    for (Iterator<String> it = repositories.iterator(); it.hasNext();)
    {
      String repositoryId = (String)it.next();
      try
      {
        IArtifactRepository repository = Activator.loadArtifactRepository(new URI(repositoryId), null);
        if ((repository instanceof IFileArtifactRepository))
        {
          currentExtensions.add(escapePipe(repositoryId));
          buffer.append(repositoryId);
          if (it.hasNext()) {
            buffer.append("|");
          }
        }
      }
      catch (ProvisionException localProvisionException) {}catch (URISyntaxException e)
      {
        e.printStackTrace();
      }
    }
    String currentExtensionsProperty = buffer.length() == 0 ? null : buffer.toString();
    
    List<String> previousExtensions = new ArrayList();
    String previousExtensionsProperty = profile.getProperty("org.eclipse.equinox.p2.cache.extensions");
    if (previousExtensionsProperty != null)
    {
      StringTokenizer tokenizer = new StringTokenizer(previousExtensionsProperty, "|");
      while (tokenizer.hasMoreTokens()) {
        previousExtensions.add(tokenizer.nextToken());
      }
    }
    if ((previousExtensions.size() == currentExtensions.size()) && (previousExtensions.containsAll(currentExtensions))) {
      return null;
    }
    return currentExtensionsProperty;
  }
  
  private String escapePipe(String location)
  {
    String result = location;
    int pipeIndex;
    while ((pipeIndex = result.indexOf(',')) != -1)
    {
      int pipeIndex;
      result = result.substring(0, pipeIndex) + "%7C" + result.substring(pipeIndex + 1);
    }
    return result;
  }
  
  private Map<IInstallableUnit, IInstallableUnit> getProfileIUs()
  {
    IQueryResult<IInstallableUnit> profileQueryResult = profile.query(QueryUtil.createIUAnyQuery(), null);
    Map<IInstallableUnit, IInstallableUnit> result = new HashMap();
    for (Iterator<IInstallableUnit> it = profileQueryResult.iterator(); it.hasNext();)
    {
      IInstallableUnit iu = (IInstallableUnit)it.next();
      result.put(iu, iu);
    }
    return result;
  }
  
  private Map<IInstallableUnit, IInstallableUnit> getAvailableProfileIUs()
  {
    IQueryResult<IInstallableUnit> profileQueryResult = profile.available(QueryUtil.createIUAnyQuery(), null);
    Map<IInstallableUnit, IInstallableUnit> result = new HashMap();
    for (Iterator<IInstallableUnit> it = profileQueryResult.iterator(); it.hasNext();)
    {
      IInstallableUnit iu = (IInstallableUnit)it.next();
      result.put(iu, iu);
    }
    return result;
  }
  
  public ReconcilerProfileChangeRequest createProfileChangeRequest(ProvisioningContext context)
  {
    ReconcilerProfileChangeRequest request = new ReconcilerProfileChangeRequest(profile);
    
    boolean resolve = Boolean.valueOf(profile.getProperty("org.eclipse.equinox.p2.resolve")).booleanValue();
    if (resolve) {
      request.removeProfileProperty("org.eclipse.equinox.p2.resolve");
    }
    List<IInstallableUnit> toRemove = new ArrayList();
    List<IInstallableUnit> toMove = new ArrayList();
    
    boolean foundIUsToAdd = false;
    Map<IInstallableUnit, IInstallableUnit> profileIUs = getProfileIUs();
    
    Map<IInstallableUnit, IInstallableUnit> availableProfileIUs = getAvailableProfileIUs();
    
    IQueryResult<IInstallableUnit> allIUs = getAllIUsFromRepos();
    for (Iterator<IInstallableUnit> iter = allIUs.iterator(); iter.hasNext();)
    {
      IInstallableUnit iu = (IInstallableUnit)iter.next();
      IInstallableUnit existing = (IInstallableUnit)profileIUs.get(iu);
      if (existing != null)
      {
        String one = iu.getProperty("file.name");
        String two = existing.getProperty("file.name");
        if ((one != null) && (two != null) && (!one.equals(two)))
        {
          toMove.add(iu);
          continue;
        }
      }
      if (QueryUtil.isGroup(iu)) {
        request.setInstallableUnitProfileProperty(iu, "org.eclipse.equinox.p2.type.root", Boolean.TRUE.toString());
      }
      request.setInstallableUnitProfileProperty(iu, "org.eclipse.equinox.p2.reconciler.dropins", Boolean.TRUE.toString());
      request.setInstallableUnitInclusionRules(iu, ProfileInclusionRules.createOptionalInclusionRule(iu));
      request.setInstallableUnitProfileProperty(iu, "org.eclipse.equinox.p2.type.lock", Integer.toString(1));
      if ((!foundIUsToAdd) && (availableProfileIUs.get(iu) == null)) {
        foundIUsToAdd = true;
      }
    }
    IQueryResult<IInstallableUnit> dropinIUs = profile.query(new IUProfilePropertyQuery("org.eclipse.equinox.p2.reconciler.dropins", Boolean.TRUE.toString()), null);
    Set<IInstallableUnit> all = allIUs.toUnmodifiableSet();
    for (Iterator<IInstallableUnit> iter = dropinIUs.iterator(); iter.hasNext();)
    {
      IInstallableUnit iu = (IInstallableUnit)iter.next();
      if ("STRICT".equals(profile.getInstallableUnitProperty(iu, "org.eclipse.equinox.p2.internal.inclusion.rules")))
      {
        request.removeInstallableUnitProfileProperty(iu, "org.eclipse.equinox.p2.reconciler.dropins");
        request.removeInstallableUnitProfileProperty(iu, "org.eclipse.equinox.p2.type.lock");
      }
      else if (!all.contains(iu))
      {
        toRemove.add(iu);
      }
    }
    if ((!foundIUsToAdd) && (toRemove.isEmpty()) && (!resolve) && (toMove.isEmpty()))
    {
      if (Tracing.DEBUG_RECONCILER) {
        Tracing.debug("[reconciler] Nothing to do.");
      }
      return null;
    }
    request.addAll(all);
    request.removeAll(toRemove);
    request.moveAll(toMove);
    
    debug(request);
    return request;
  }
  
  private IRequirement createNegation(IInstallableUnit unit)
  {
    return MetadataFactory.createRequirement("org.eclipse.equinox.p2.iu", unit.getId(), 
      new VersionRange(unit.getVersion(), true, unit.getVersion(), true), null, 0, 0, false);
  }
  
  private void debug(ReconcilerProfileChangeRequest request, IProvisioningPlan plan)
  {
    if (!Tracing.DEBUG_RECONCILER) {
      return;
    }
    List<IInstallableUnit> toAdd = new ArrayList(request.getAdditions());
    List<IInstallableUnit> toRemove = new ArrayList(request.getRemovals());
    List<IInstallableUnit> toMove = new ArrayList(request.getMoves());
    for (Iterator<IInstallableUnit> iterator = plan.getRemovals().query(QueryUtil.createIUAnyQuery(), null).iterator(); iterator.hasNext();)
    {
      IInstallableUnit iu = (IInstallableUnit)iterator.next();
      if (!toRemove.remove(iu)) {
        Tracing.debug("[reconciler] [plan] " + iu + " will be removed");
      }
    }
    IInstallableUnit iu;
    for (Iterator<IInstallableUnit> iterator = plan.getAdditions().query(QueryUtil.createIUAnyQuery(), null).iterator(); iterator.hasNext();)
    {
      iu = (IInstallableUnit)iterator.next();
      if (!toAdd.remove(iu)) {
        Tracing.debug("[reconciler] [plan] " + iu + " will be added");
      }
    }
    toAdd.removeAll(toMove);
    if ((toAdd.size() == 0) && (toRemove.size() == 0)) {
      Tracing.debug("[reconciler] [plan] Plan matches the request.");
    }
    if (toAdd.size() != 0)
    {
      Tracing.debug("[reconciler] [plan] Some units will not be installed, because they are already installed or there are dependency issues:");
      for (iu = toAdd.iterator(); iu.hasNext();)
      {
        IInstallableUnit unit = (IInstallableUnit)iu.next();
        Tracing.debug("[reconciler] [plan] " + unit);
      }
    }
    if (toRemove.size() != 0)
    {
      Tracing.debug("[reconciler] [plan] Some units will not be uninstalled:");
      for (iu = toRemove.iterator(); iu.hasNext();)
      {
        IInstallableUnit unit = (IInstallableUnit)iu.next();
        Tracing.debug("[reconciler] [plan] " + unit);
      }
    }
  }
  
  private void debug(ReconcilerProfileChangeRequest request)
  {
    if (!Tracing.DEBUG_RECONCILER) {
      return;
    }
    Collection<IInstallableUnit> toAdd = request.getAdditions();
    if ((toAdd == null) || (toAdd.size() == 0)) {
      Tracing.debug("[reconciler] No installable units to add.");
    } else {
      for (Iterator localIterator1 = toAdd.iterator(); localIterator1.hasNext();)
      {
        IInstallableUnit add = (IInstallableUnit)localIterator1.next();
        Tracing.debug("[reconciler] Adding IU: " + add.getId() + ' ' + add.getVersion());
      }
    }
    Map<IInstallableUnit, Map<String, String>> propsToAdd = request.getInstallableUnitProfilePropertiesToAdd();
    if ((propsToAdd == null) || (propsToAdd.isEmpty())) {
      Tracing.debug("[reconciler] No IU properties to add.");
    } else {
      for (Iterator localIterator2 = propsToAdd.entrySet().iterator(); localIterator2.hasNext();)
      {
        Object entry = (Map.Entry)localIterator2.next();
        Tracing.debug("[reconciler] Adding IU property: " + ((Map.Entry)entry).getKey() + "->" + ((Map.Entry)entry).getValue());
      }
    }
    Object toRemove = request.getRemovals();
    if ((toRemove == null) || (((Collection)toRemove).size() == 0)) {
      Tracing.debug("[reconciler] No installable units to remove.");
    } else {
      for (Iterator localIterator3 = ((Collection)toRemove).iterator(); localIterator3.hasNext();)
      {
        IInstallableUnit remove = (IInstallableUnit)localIterator3.next();
        Tracing.debug("[reconciler] Removing IU: " + remove.getId() + ' ' + remove.getVersion());
      }
    }
    Object propsToRemove = request.getInstallableUnitProfilePropertiesToRemove();
    if ((propsToRemove == null) || (((Map)propsToRemove).isEmpty())) {
      Tracing.debug("[reconciler] No IU properties to remove.");
    } else {
      for (Iterator localIterator4 = ((Map)propsToRemove).entrySet().iterator(); localIterator4.hasNext();)
      {
        Object entry = (Map.Entry)localIterator4.next();
        Tracing.debug("[reconciler] Removing IU property: " + ((Map.Entry)entry).getKey() + "->" + ((Map.Entry)entry).getValue());
      }
    }
    Object toMove = request.getMoves();
    if ((toMove == null) || (((Collection)toMove).isEmpty())) {
      Tracing.debug("[reconciler] No installable units to move.");
    } else {
      for (Iterator localIterator5 = ((Collection)toMove).iterator(); localIterator5.hasNext();)
      {
        IInstallableUnit move = (IInstallableUnit)localIterator5.next();
        Tracing.debug("[reconciler] Moving IU: " + move.getId() + ' ' + move.getVersion());
      }
    }
    Object extra = request.getExtraRequirements();
    if ((extra == null) || (((Collection)extra).isEmpty())) {
      Tracing.debug("[reconciler] No extra requirements.");
    } else {
      for (Iterator localIterator6 = ((Collection)extra).iterator(); localIterator6.hasNext();)
      {
        IRequirement requirement = (IRequirement)localIterator6.next();
        Tracing.debug("[reconciler] Extra requirement: " + requirement);
      }
    }
  }
  
  private IQueryResult<IInstallableUnit> getAllIUsFromRepos()
  {
    Collector<IInstallableUnit> allRepos = new Collector();
    for (Iterator localIterator = repositoryMap.values().iterator(); localIterator.hasNext();)
    {
      IMetadataRepository repository = (IMetadataRepository)localIterator.next();
      allRepos.addAll(repository.query(QueryUtil.createIUAnyQuery(), null));
    }
    return allRepos;
  }
  
  private IProvisioningPlan createProvisioningPlan(ProfileChangeRequest request, ProvisioningContext provisioningContext, IProgressMonitor monitor)
  {
    IPlanner planner = (IPlanner)agent.getService(IPlanner.SERVICE_NAME);
    return planner.getProvisioningPlan(request, provisioningContext, monitor);
  }
  
  private IStatus setProperty(String key, String value, ProvisioningContext provisioningContext, IProgressMonitor monitor)
  {
    IEngine engine = (IEngine)agent.getService(IEngine.SERVICE_NAME);
    IProvisioningPlan plan = engine.createPlan(profile, provisioningContext);
    plan.setProfileProperty(key, value);
    IPhaseSet phaseSet = PhaseSetFactory.createPhaseSetIncluding(new String[] { PhaseSetFactory.PHASE_PROPERTY });
    return engine.perform(plan, phaseSet, monitor);
  }
  
  private IStatus executePlan(IProvisioningPlan plan, ProvisioningContext provisioningContext, IProgressMonitor monitor)
  {
    IEngine engine = (IEngine)agent.getService(IEngine.SERVICE_NAME);
    IPhaseSet phaseSet = PhaseSetFactory.createDefaultPhaseSetExcluding(new String[] { PhaseSetFactory.PHASE_COLLECT, PhaseSetFactory.PHASE_CHECK_TRUST });
    if (plan.getInstallerPlan() != null)
    {
      IStatus installerPlanStatus = engine.perform(plan.getInstallerPlan(), phaseSet, monitor);
      if (!installerPlanStatus.isOK()) {
        return installerPlanStatus;
      }
      applyConfiguration(true);
    }
    return engine.perform(plan, phaseSet, monitor);
  }
  
  /* Error */
  private IStatus applyConfiguration(boolean isInstaller)
  {
    // Byte code:
    //   0: iload_1
    //   1: ifne +13 -> 14
    //   4: invokestatic 926	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:isReconciliationApplicationRunning	()Z
    //   7: ifeq +7 -> 14
    //   10: getstatic 843	org/eclipse/core/runtime/Status:OK_STATUS	Lorg/eclipse/core/runtime/IStatus;
    //   13: areturn
    //   14: invokestatic 922	org/eclipse/equinox/internal/p2/reconciler/dropins/Activator:getContext	()Lorg/osgi/framework/BundleContext;
    //   17: astore_2
    //   18: aload_2
    //   19: getstatic 847	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:class$0	Ljava/lang/Class;
    //   22: dup
    //   23: ifnonnull +29 -> 52
    //   26: pop
    //   27: ldc_w 435
    //   30: invokestatic 874	java/lang/Class:forName	(Ljava/lang/String;)Ljava/lang/Class;
    //   33: dup
    //   34: putstatic 847	org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer:class$0	Ljava/lang/Class;
    //   37: goto +15 -> 52
    //   40: new 462	java/lang/NoClassDefFoundError
    //   43: dup_x1
    //   44: swap
    //   45: invokevirtual 895	java/lang/Throwable:getMessage	()Ljava/lang/String;
    //   48: invokespecial 878	java/lang/NoClassDefFoundError:<init>	(Ljava/lang/String;)V
    //   51: athrow
    //   52: invokeinterface 1043 2 0
    //   57: astore_3
    //   58: aload_2
    //   59: aload_3
    //   60: invokeinterface 1041 2 0
    //   65: checkcast 493	org/eclipse/equinox/internal/provisional/configurator/Configurator
    //   68: astore 4
    //   70: aload 4
    //   72: invokeinterface 1010 1 0
    //   77: goto +46 -> 123
    //   80: astore 5
    //   82: new 481	org/eclipse/core/runtime/Status
    //   85: dup
    //   86: iconst_4
    //   87: ldc 9
    //   89: ldc_w 413
    //   92: aload 5
    //   94: invokespecial 911	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
    //   97: astore 7
    //   99: aload_2
    //   100: aload_3
    //   101: invokeinterface 1039 2 0
    //   106: pop
    //   107: aload 7
    //   109: areturn
    //   110: astore 6
    //   112: aload_2
    //   113: aload_3
    //   114: invokeinterface 1039 2 0
    //   119: pop
    //   120: aload 6
    //   122: athrow
    //   123: aload_2
    //   124: aload_3
    //   125: invokeinterface 1039 2 0
    //   130: pop
    //   131: getstatic 843	org/eclipse/core/runtime/Status:OK_STATUS	Lorg/eclipse/c
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-2019. Infinite Loop Ltd