org.eclipse.equinox.p2.garbagecollector_1.0.200.v20110815-1419

16:44:13.034 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.p2.garbagecollector_1.0.200.v20110815-1419.jar
package org.eclipse.equinox.internal.p2.garbagecollector;

import java.util.Map;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.IProvisioningAgentProvider;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;

public class Application
  implements IApplication
{
  private static final String DEFAULT_PROFILE_ID = "SDKProfile";
  private String profileId;
  private IProvisioningAgent agent;
  
  private IProfile getProfile(String id)
  {
    IProfileRegistry profileRegistry = (IProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
    return profileRegistry == null ? null : profileRegistry.getProfile(id);
  }
  
  public Object start(IApplicationContext context)
    throws Exception
  {
    Map<?, ?> allArgs = context.getArguments();
    String[] args = (String[])allArgs.get("application.args");
    processArguments(args);
    if (profileId == null) {
      profileId = "SDKProfile";
    }
    initializeServices();
    IProfile profile = getProfile(profileId);
    if (profile == null) {
      throw new IllegalArgumentException("\"" + profileId + "\" is not a valid profile identifier.");
    }
    GarbageCollector gc = (GarbageCollector)agent.getService(GarbageCollector.SERVICE_NAME);
    gc.runGC(profile);
    agent.stop();
    return null;
  }
  
  private void initializeServices()
    throws ProvisionException
  {
    IProvisioningAgentProvider provider = (IProvisioningAgentProvider)GCActivator.getService(IProvisioningAgentProvider.class);
    agent = provider.createAgent(null);
  }
  
  public void stop() {}
  
  public void processArguments(String[] args)
    throws Exception
  {
    if (args == null) {
      return;
    }
    for (int i = 0; i < args.length; i++)
    {
      String opt = args[i];
      if ((i != args.length - 1) && (!args[(i + 1)].startsWith("-")))
      {
        String arg = args[(++i)];
        if (opt.equalsIgnoreCase("-profile")) {
          profileId = arg;
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.garbagecollector.Application
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.garbagecollector;

import java.util.Iterator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.repository.IRunnableWithProgress;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;

class CoreGarbageCollector$1
  implements IRunnableWithProgress
{
  final CoreGarbageCollector this$0;
  
  CoreGarbageCollector$1(CoreGarbageCollector paramCoreGarbageCollector, IQueryResult paramIQueryResult, IArtifactRepository paramIArtifactRepository) {}
  
  public void run(IProgressMonitor monitor)
  {
    for (Iterator<IArtifactKey> iterator = val$inactive.iterator(); iterator.hasNext();)
    {
      IArtifactKey key = (IArtifactKey)iterator.next();
      val$aRepository.removeDescriptor(key);
      if (CoreGarbageCollector.debugMode) {
        Tracing.debug("Key removed:" + key);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.garbagecollector.CoreGarbageCollector.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.garbagecollector;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.IRunnableWithProgress;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;

public class CoreGarbageCollector
{
  static boolean debugMode = false;
  
  public synchronized void clean(IArtifactKey[] markSet, final IArtifactRepository aRepository)
  {
    Set<IArtifactKey> set = new HashSet(Arrays.asList(markSet));
    
    IQuery<IArtifactKey> query = QueryUtil.createQuery(tmp15_12, "unique($0)", new Object[] { set });
    final IQueryResult<IArtifactKey> inactive = aRepository.query(query, null);
    aRepository.executeBatch(new IRunnableWithProgress()
    
      new NullProgressMonitor
      {
        public void run(IProgressMonitor monitor)
        {
          for (Iterator<IArtifactKey> iterator = inactive.iterator(); iterator.hasNext();)
          {
            IArtifactKey key = (IArtifactKey)iterator.next();
            aRepository.removeDescriptor(key);
            if (CoreGarbageCollector.debugMode) {
              Tracing.debug("Key removed:" + key);
            }
          }
        }
      }, new NullProgressMonitor());
  }
  
  public static void setDebugMode(boolean inDebugMode)
  {
    debugMode = inDebugMode;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.garbagecollector.CoreGarbageCollector
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.garbagecollector;

import org.eclipse.osgi.service.debug.DebugOptions;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

public class GCActivator
  implements BundleActivator
{
  public static final String ID = "org.eclipse.equinox.p2.garbagecollector";
  public static final String GC_ENABLED = "gc_enabled";
  private static final String DEBUG_STRING = "org.eclipse.equinox.p2.garbagecollector/debug";
  private static final boolean DEFAULT_DEBUG = false;
  static BundleContext context;
  
  static <T> T getService(Class<T> clazz)
  {
    ServiceReference<T> reference = context.getServiceReference(clazz);
    if (reference == null) {
      return null;
    }
    T result = context.getService(reference);
    context.ungetService(reference);
    return result;
  }
  
  public void start(BundleContext inContext)
    throws Exception
  {
    context = inContext;
    DebugOptions debug = (DebugOptions)getService(DebugOptions.class);
    if (debug != null) {
      CoreGarbageCollector.setDebugMode(debug.getBooleanOption("org.eclipse.equinox.p2.garbagecollector/debug", false));
    }
  }
  
  public void stop(BundleContext inContext)
    throws Exception
  {
    context = null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.garbagecollector.GCActivator
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.garbagecollector;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.p2.engine.IProfile;

class GarbageCollector$ParameterizedSafeRunnable
  implements ISafeRunnable
{
  IProfile aProfile;
  MarkSet[] aProfileMarkSets;
  IConfigurationElement cfg;
  final GarbageCollector this$0;
  
  public GarbageCollector$ParameterizedSafeRunnable(GarbageCollector paramGarbageCollector, IConfigurationElement runtAttribute, IProfile profile)
  {
    cfg = runtAttribute;
    aProfile = profile;
  }
  
  public MarkSet[] getResult()
  {
    return aProfileMarkSets;
  }
  
  public void handleException(Throwable exception)
  {
    LogHelper.log(new Status(4, "org.eclipse.equinox.p2.garbagecollector", Messages.Error_in_extension, exception));
  }
  
  public void run()
    throws Exception
  {
    MarkSetProvider aMarkSetProvider = (MarkSetProvider)cfg.createExecutableExtension("class");
    if (aMarkSetProvider == null)
    {
      aProfileMarkSets = null;
      return;
    }
    aProfileMarkSets = aMarkSetProvider.getMarkSets(this$0.agent, aProfile);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.garbagecollector.GarbageCollector.ParameterizedSafeRunnable
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.garbagecollector;

import java.util.ArrayList;
import java.util.Collection;
import java.util.EventObject;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.RegistryFactory;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.engine.CommitOperationEvent;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitEvent;
import org.eclipse.equinox.internal.p2.engine.RollbackOperationEvent;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.SynchronousProvisioningListener;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.spi.IAgentService;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.osgi.service.prefs.Preferences;

public class GarbageCollector
  implements SynchronousProvisioningListener, IAgentService
{
  public static final String SERVICE_NAME = GarbageCollector.class.getName();
  private static final String ATTRIBUTE_CLASS = "class";
  private static final String PT_MARKSET = "org.eclipse.equinox.p2.garbagecollector.marksetproviders";
  final IProvisioningAgent agent;
  
  private class ParameterizedSafeRunnable
    implements ISafeRunnable
  {
    IProfile aProfile;
    MarkSet[] aProfileMarkSets;
    IConfigurationElement cfg;
    
    public ParameterizedSafeRunnable(IConfigurationElement runtAttribute, IProfile profile)
    {
      cfg = runtAttribute;
      aProfile = profile;
    }
    
    public MarkSet[] getResult()
    {
      return aProfileMarkSets;
    }
    
    public void handleException(Throwable exception)
    {
      LogHelper.log(new Status(4, "org.eclipse.equinox.p2.garbagecollector", Messages.Error_in_extension, exception));
    }
    
    public void run()
      throws Exception
    {
      MarkSetProvider aMarkSetProvider = (MarkSetProvider)cfg.createExecutableExtension("class");
      if (aMarkSetProvider == null)
      {
        aProfileMarkSets = null;
        return;
      }
      aProfileMarkSets = aMarkSetProvider.getMarkSets(agent, aProfile);
    }
  }
  
  String uninstallEventProfileId = null;
  private Map<IArtifactRepository, Collection<IArtifactKey>> markSet;
  
  public GarbageCollector(IProvisioningAgent agent)
  {
    this.agent = agent;
  }
  
  private void addKeys(Collection<IArtifactKey> keyList, IArtifactKey[] keyArray)
  {
    for (int i = 0; i < keyArray.length; i++) {
      keyList.add(keyArray[i]);
    }
  }
  
  private void contributeMarkSets(IConfigurationElement runAttribute, IProfile profile, boolean addRepositories)
  {
    ParameterizedSafeRunnable providerExecutor = new ParameterizedSafeRunnable(runAttribute, profile);
    SafeRunner.run(providerExecutor);
    MarkSet[] aProfileMarkSets = providerExecutor.getResult();
    if ((aProfileMarkSets == null) || (aProfileMarkSets.length == 0) || (aProfileMarkSets[0] == null)) {
      return;
    }
    for (int i = 0; i < aProfileMarkSets.length; i++) {
      if (aProfileMarkSets[i] != null)
      {
        Collection<IArtifactKey> keys = (Collection)markSet.get(aProfileMarkSets[i].getRepo());
        if (keys == null)
        {
          if (addRepositories)
          {
            keys = new HashSet();
            markSet.put(aProfileMarkSets[i].getRepo(), keys);
            addKeys(keys, aProfileMarkSets[i].getKeys());
          }
        }
        else {
          addKeys(keys, aProfileMarkSets[i].getKeys());
        }
      }
    }
  }
  
  protected boolean getBooleanPreference(String key, boolean defaultValue)
  {
    IPreferencesService prefService = (IPreferencesService)GCActivator.getService(IPreferencesService.class);
    if (prefService == null) {
      return defaultValue;
    }
    List<IEclipsePreferences> nodes = new ArrayList();
    
    nodes.add(new ConfigurationScope().getNode("org.eclipse.equinox.p2.garbagecollector"));
    nodes.add(new DefaultScope().getNode("org.eclipse.equinox.p2.garbagecollector"));
    return Boolean.valueOf(prefService.get(key, Boolean.toString(defaultValue), (Preferences[])nodes.toArray(new Preferences[nodes.size()]))).booleanValue();
  }
  
  private void invokeCoreGC()
  {
    for (Iterator localIterator = markSet.keySet().iterator(); localIterator.hasNext();)
    {
      IArtifactRepository nextRepo = (IArtifactRepository)localIterator.next();
      IArtifactKey[] keys = (IArtifactKey[])((Collection)markSet.get(nextRepo)).toArray(new IArtifactKey[0]);
      MarkSet aMarkSet = new MarkSet(keys, nextRepo);
      new CoreGarbageCollector().clean(aMarkSet.getKeys(), aMarkSet.getRepo());
    }
  }
  
  public void notify(EventObject o)
  {
    if ((o instanceof InstallableUnitEvent))
    {
      InstallableUnitEvent event = (InstallableUnitEvent)o;
      if ((event.isUninstall()) && (event.isPost())) {
        uninstallEventProfileId = event.getProfile().getProfileId();
      }
    }
    else if ((o instanceof CommitOperationEvent))
    {
      if (uninstallEventProfileId != null)
      {
        CommitOperationEvent event = (CommitOperationEvent)o;
        if ((uninstallEventProfileId.equals(event.getProfile().getProfileId())) && (getBooleanPreference("gc_enabled", true))) {
          runGC(event.getProfile());
        }
        uninstallEventProfileId = null;
      }
    }
    else if (((o instanceof RollbackOperationEvent)) && 
      (uninstallEventProfileId != null) && (uninstallEventProfileId.equals(((RollbackOperationEvent)o).getProfile().getProfileId())))
    {
      uninstallEventProfileId = null;
    }
  }
  
  public void runGC(IProfile profile)
  {
    markSet = new HashMap();
    if (!traverseMainProfile(profile)) {
      return;
    }
    traverseRegisteredProfiles();
    
    invokeCoreGC();
  }
  
  public void start()
  {
    IProvisioningEventBus eventBus = (IProvisioningEventBus)agent.getService(IProvisioningEventBus.SERVICE_NAME);
    if (eventBus == null) {
      return;
    }
    eventBus.addListener(this);
  }
  
  public void stop()
  {
    IProvisioningEventBus eventBus = (IProvisioningEventBus)agent.getService(IProvisioningEventBus.SERVICE_NAME);
    if (eventBus != null) {
      eventBus.removeListener(this);
    }
  }
  
  private boolean traverseMainProfile(IProfile profile)
  {
    IExtensionRegistry registry = RegistryFactory.getRegistry();
    IConfigurationElement[] configElts = registry.getConfigurationElementsFor("org.eclipse.equinox.p2.garbagecollector.marksetproviders");
    for (int i = 0; i < configElts.length; i++) {
      if (configElts[i].getName().equals("run"))
      {
        IConfigurationElement runAttribute = configElts[i];
        if (runAttribute != null) {
          contributeMarkSets(runAttribute, profile, true);
        }
      }
    }
    return true;
  }
  
  private void traverseRegisteredProfiles()
  {
    IExtensionRegistry registry = RegistryFactory.getRegistry();
    IConfigurationElement[] configElts = registry.getConfigurationElementsFor("org.eclipse.equinox.p2.garbagecollector.marksetproviders");
    for (int i = 0; i < configElts.length; i++) {
      if (configElts[i].getName().equals("run"))
      {
        IConfigurationElement runAttribute = configElts[i];
        if (runAttribute != null)
        {
          IProfileRegistry profileRegistry = (IProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
          if (profileRegistry == null) {
            return;
          }
          IProfile[] registeredProfiles = profileRegistry.getProfiles();
          for (int j = 0; j < registeredProfiles.length; j++) {
            contributeMarkSets(runAttribute, registeredProfiles[j], false);
          }
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.garbagecollector.GarbageCollector
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.garbagecollector;

import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;

public class GarbageCollectorComponent
  implements IAgentServiceFactory
{
  public Object createService(IProvisioningAgent agent)
  {
    return new GarbageCollector(agent);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.garbagecollector.GarbageCollectorComponent
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.garbagecollector;

import org.eclipse.core.runtime.Assert;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;

public class MarkSet
{
  private IArtifactKey[] keys;
  private IArtifactRepository repo;
  
  public MarkSet(IArtifactKey[] inKeys, IArtifactRepository inRepo)
  {
    Assert.isNotNull(inKeys);
    Assert.isNotNull(inRepo);
    keys = inKeys;
    repo = inRepo;
  }
  
  public IArtifactKey[] getKeys()
  {
    return keys;
  }
  
  public IArtifactRepository getRepo()
  {
    return repo;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.garbagecollector.MarkSet
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.garbagecollector;

import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;

public abstract class MarkSetProvider
{
  public abstract MarkSet[] getMarkSets(IProvisioningAgent paramIProvisioningAgent, IProfile paramIProfile);
  
  public abstract IArtifactRepository getRepository(IProvisioningAgent paramIProvisioningAgent, IProfile paramIProfile);
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.garbagecollector.MarkSetProvider
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.garbagecollector;

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.p2.garbagecollector.messages";
  public static String Error_in_extension;
  
  static
  {
    NLS.initializeMessages("org.eclipse.equinox.internal.p2.garbagecollector.messages", Messages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.garbagecollector.Messages
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd