org.eclipse.equinox.p2.engine_2.1.1.R37x_v20111003

16:44:09.702 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.p2.engine_2.1.1.R37x_v20111003.jar
package org.eclipse.equinox.internal.p2.engine;

import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IRegistryChangeEvent;
import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.InvalidRegistryObjectException;
import org.eclipse.core.runtime.RegistryFactory;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
import org.eclipse.equinox.p2.engine.spi.Touchpoint;
import org.eclipse.equinox.p2.metadata.ITouchpointType;
import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.osgi.util.NLS;

public class ActionManager
  implements IRegistryChangeListener
{
  private static final String PT_ACTIONS = "actions";
  private static final String ELEMENT_ACTION = "action";
  private static final String ATTRIBUTE_CLASS = "class";
  private static final String ATTRIBUTE_NAME = "name";
  private static final String TOUCHPOINT_TYPE = "touchpointType";
  private static final String TOUCHPOINT_VERSION = "touchpointVersion";
  public static final String SERVICE_NAME = ActionManager.class.getName();
  private HashMap<String, IConfigurationElement> actionMap;
  private TouchpointManager touchpointManager;
  
  public ActionManager()
  {
    touchpointManager = new TouchpointManager();
    RegistryFactory.getRegistry().addRegistryChangeListener(this, "org.eclipse.equinox.p2.engine");
  }
  
  public Touchpoint getTouchpointPoint(ITouchpointType type)
  {
    if ((type == null) || (type == ITouchpointType.NONE)) {
      return null;
    }
    return touchpointManager.getTouchpoint(type);
  }
  
  public String getTouchpointQualifiedActionId(String actionId, ITouchpointType type)
  {
    if (actionId.indexOf('.') == -1)
    {
      if ((type == null) || (type == ITouchpointType.NONE)) {
        return actionId;
      }
      Touchpoint touchpoint = touchpointManager.getTouchpoint(type);
      if (touchpoint == null) {
        throw new IllegalArgumentException(NLS.bind(Messages.ActionManager_Required_Touchpoint_Not_Found, type.toString(), actionId));
      }
      actionId = touchpoint.qualifyAction(actionId);
    }
    return actionId;
  }
  
  public ProvisioningAction getAction(String actionId, VersionRange versionRange)
  {
    IConfigurationElement actionElement = (IConfigurationElement)getActionMap().get(actionId);
    if ((actionElement != null) && (actionElement.isValid())) {
      try
      {
        ProvisioningAction action = (ProvisioningAction)actionElement.createExecutableExtension("class");
        
        String touchpointType = actionElement.getAttribute("touchpointType");
        if (touchpointType != null)
        {
          String touchpointVersion = actionElement.getAttribute("touchpointVersion");
          Touchpoint touchpoint = touchpointManager.getTouchpoint(touchpointType, touchpointVersion);
          if (touchpoint == null) {
            throw new IllegalArgumentException(NLS.bind(Messages.ActionManager_Required_Touchpoint_Not_Found, touchpointType, actionId));
          }
          action.setTouchpoint(touchpoint);
        }
        return action;
      }
      catch (InvalidRegistryObjectException localInvalidRegistryObjectException) {}catch (CoreException localCoreException)
      {
        throw new IllegalArgumentException(NLS.bind(Messages.ActionManager_Exception_Creating_Action_Extension, actionId));
      }
    }
    return null;
  }
  
  private synchronized Map<String, IConfigurationElement> getActionMap()
  {
    if (actionMap != null) {
      return actionMap;
    }
    IExtensionPoint point = RegistryFactory.getRegistry().getExtensionPoint("org.eclipse.equinox.p2.engine", "actions");
    IExtension[] extensions = point.getExtensions();
    actionMap = new HashMap(extensions.length);
    for (int i = 0; i < extensions.length; i++) {
      try
      {
        IConfigurationElement[] elements = extensions[i].getConfigurationElements();
        for (int j = 0; j < elements.length; j++)
        {
          IConfigurationElement actionElement = elements[j];
          if (actionElement.getName().equals("action"))
          {
            String actionId = actionElement.getAttribute("name");
            if (actionId != null)
            {
              if (actionId.indexOf('.') == -1) {
                actionId = actionElement.getNamespaceIdentifier() + "." + actionId;
              }
              actionMap.put(actionId, actionElement);
            }
          }
        }
      }
      catch (InvalidRegistryObjectException localInvalidRegistryObjectException) {}
    }
    return actionMap;
  }
  
  public synchronized void registryChanged(IRegistryChangeEvent event)
  {
    actionMap = null;
  }
  
  static void reportError(String errorMsg)
  {
    Status errorStatus = new Status(4, "org.eclipse.equinox.p2.engine", 1, errorMsg, null);
    LogHelper.log(errorStatus);
  }
}

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

import org.eclipse.equinox.p2.engine.IEngine;
import org.eclipse.equinox.p2.engine.IProfile;

public class BeginOperationEvent
  extends TransactionEvent
{
  private static final long serialVersionUID = 6389318375739324865L;
  
  public BeginOperationEvent(IProfile profile, PhaseSet phaseSet, Operand[] operands, IEngine engine)
  {
    super(profile, phaseSet, operands, engine);
  }
}

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

import org.eclipse.equinox.p2.engine.IEngine;
import org.eclipse.equinox.p2.engine.IProfile;

public class CommitOperationEvent
  extends TransactionEvent
{
  private static final long serialVersionUID = -523967775426133720L;
  
  public CommitOperationEvent(IProfile profile, PhaseSet phaseSet, Operand[] operands, IEngine engine)
  {
    super(profile, phaseSet, operands, engine);
  }
}

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

import java.io.File;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.osgi.service.debug.DebugOptions;

public class DebugHelper
{
  public static final String LINE_SEPARATOR = System.getProperty("line.separator");
  public static final boolean DEBUG_PROFILE_REGISTRY;
  public static final boolean DEBUG_ENGINE;
  public static final boolean DEBUG_ENGINE_SESSION;
  
  static
  {
    DebugOptions options = (DebugOptions)ServiceHelper.getService(EngineActivator.getContext(), DebugOptions.class.getName());
    if (options != null)
    {
      DEBUG_PROFILE_REGISTRY = options.getBooleanOption("org.eclipse.equinox.p2.engine/profileregistry/debug", false);
      DEBUG_ENGINE = options.getBooleanOption("org.eclipse.equinox.p2.engine/engine/debug", false);
      DEBUG_ENGINE_SESSION = options.getBooleanOption("org.eclipse.equinox.p2.engine/enginesession/debug", false);
    }
    else
    {
      DEBUG_PROFILE_REGISTRY = false;
      DEBUG_ENGINE = false;
      DEBUG_ENGINE_SESSION = false;
    }
  }
  
  public static void debug(String name, String message)
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append("[");
    buffer.append("org.eclipse.equinox.p2.engine-" + name);
    buffer.append("] ");
    buffer.append(new Date(System.currentTimeMillis()));
    buffer.append(" - [");
    buffer.append(Thread.currentThread().getName());
    buffer.append("] " + LINE_SEPARATOR);
    buffer.append(message);
    System.out.println(buffer.toString());
  }
  
  public static String formatArray(Collection<? extends Object> array, boolean toString, boolean newLines)
  {
    if ((array == null) || (array.size() == 0)) {
      return "[]";
    }
    StringBuffer buffer = new StringBuffer();
    buffer.append('[');
    boolean first = true;
    for (Iterator localIterator = array.iterator(); localIterator.hasNext();)
    {
      Object elem = localIterator.next();
      if (first) {
        first = false;
      } else {
        buffer.append(',');
      }
      if (toString) {
        buffer.append(elem.toString());
      } else {
        buffer.append(elem.getClass().getName());
      }
      if (newLines) {
        buffer.append(LINE_SEPARATOR);
      } else {
        buffer.append(' ');
      }
    }
    buffer.append(']');
    return buffer.toString();
  }
  
  public static String formatOperation(PhaseSet phaseSet, Operand[] operands, ProvisioningContext context)
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append("phaseSet=" + formatPhaseSet(phaseSet));
    buffer.append(",");
    buffer.append(LINE_SEPARATOR);
    buffer.append("operands=" + formatOperands(operands));
    buffer.append(",");
    buffer.append(LINE_SEPARATOR);
    buffer.append("context=" + formatContext(context));
    return buffer.toString();
  }
  
  public static String formatOperands(Operand[] operands)
  {
    String[] operandStrings = new String[operands.length];
    for (int i = 0; i < operands.length; i++) {
      if ((operands[i] instanceof InstallableUnitOperand))
      {
        InstallableUnitOperand iuOperand = (InstallableUnitOperand)operands[i];
        operandStrings[i] = formatInstallableUnitOperand(iuOperand);
      }
      else
      {
        operandStrings[i] = operands[i].toString();
      }
    }
    return formatArray(Arrays.asList(operandStrings), true, true);
  }
  
  public static String formatInstallableUnitOperand(InstallableUnitOperand iuOperand)
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append(iuOperand.first());
    if ((iuOperand.first() != null) && (iuOperand.first().getFragments() != null)) {
      buffer.append(formatArray(iuOperand.first().getFragments(), true, false));
    }
    buffer.append(" --> ");
    buffer.append(iuOperand.second());
    if ((iuOperand.second() != null) && (iuOperand.second().getFragments() != null)) {
      buffer.append(formatArray(iuOperand.second().getFragments(), true, false));
    }
    return buffer.toString();
  }
  
  public static String formatPhaseSet(PhaseSet phaseSet)
  {
    StringBuffer buffer = new StringBuffer(phaseSet.getClass().getName());
    buffer.append(formatArray(Arrays.asList(phaseSet.getPhases()), false, false));
    return buffer.toString();
  }
  
  public static String formatContext(ProvisioningContext context)
  {
    return context.toString();
  }
  
  public static String formatAction(ProvisioningAction action, Map<String, Object> parameters)
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append(action.getClass().getName());
    if ((action instanceof ParameterizedProvisioningAction))
    {
      ParameterizedProvisioningAction parameterizedAction = (ParameterizedProvisioningAction)action;
      buffer.append("{action=" + parameterizedAction.getAction().getClass().getName());
      buffer.append(", actionText=" + parameterizedAction.getActionText() + "}");
    }
    buffer.append(LINE_SEPARATOR);
    buffer.append("parameters=" + formatParameters(parameters));
    return buffer.toString();
  }
  
  public static String formatParameters(Map<String, ? extends Object> parameters)
  {
    Iterator<? extends Map.Entry<String, ? extends Object>> it = parameters.entrySet().iterator();
    if (!it.hasNext()) {
      return "{}";
    }
    StringBuffer buffer = new StringBuffer();
    buffer.append('{');
    for (;;)
    {
      Map.Entry<String, ? extends Object> e = (Map.Entry)it.next();
      String key = (String)e.getKey();
      buffer.append(key);
      buffer.append('=');
      Object value = e.getValue();
      if (((value instanceof String)) || ((value instanceof File)) || ((value instanceof Operand)) || ((value instanceof IArtifactKey)) || ((value instanceof IInstallableUnit))) {
        buffer.append(value);
      } else if ((value instanceof IProfile)) {
        buffer.append(((IProfile)value).getProfileId());
      } else {
        buffer.append(value.getClass().getName());
      }
      if (!it.hasNext())
      {
        buffer.append('}');
        break;
      }
      buffer.append(',');
      buffer.append(LINE_SEPARATOR);
      buffer.append(' ');
    }
    return buffer.toString();
  }
}

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

import java.net.URI;
import java.util.Comparator;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;

class DownloadManager$1
  implements Comparator<IArtifactRepository>
{
  private static final String FILE_PROTOCOL = "file";
  
  public int compare(IArtifactRepository arg0, IArtifactRepository arg1)
  {
    String protocol0 = arg0.getLocation().getScheme();
    String protocol1 = arg1.getLocation().getScheme();
    if (("file".equals(protocol0)) && (!"file".equals(protocol1))) {
      return -1;
    }
    if ((!"file".equals(protocol0)) && ("file".equals(protocol1))) {
      return 1;
    }
    return 0;
  }
}

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

import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
import org.eclipse.equinox.p2.query.ExpressionMatchQuery;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;

public class DownloadManager
{
  private ProvisioningContext provContext = null;
  ArrayList<IArtifactRequest> requestsToProcess = new ArrayList();
  private IProvisioningAgent agent = null;
  private static final Comparator<IArtifactRepository> LOCAL_FIRST_COMPARATOR = new Comparator()
  {
    private static final String FILE_PROTOCOL = "file";
    
    public int compare(IArtifactRepository arg0, IArtifactRepository arg1)
    {
      String protocol0 = arg0.getLocation().getScheme();
      String protocol1 = arg1.getLocation().getScheme();
      if (("file".equals(protocol0)) && (!"file".equals(protocol1))) {
        return -1;
      }
      if ((!"file".equals(protocol0)) && ("file".equals(protocol1))) {
        return 1;
      }
      return 0;
    }
  };
  
  public DownloadManager(ProvisioningContext context, IProvisioningAgent agent)
  {
    provContext = context;
    this.agent = agent;
  }
  
  public void add(IArtifactRequest toAdd)
  {
    Assert.isNotNull(toAdd);
    requestsToProcess.add(toAdd);
  }
  
  public void add(IArtifactRequest[] toAdd)
  {
    Assert.isNotNull(toAdd);
    for (int i = 0; i < toAdd.length; i++) {
      add(toAdd[i]);
    }
  }
  
  private void filterUnfetched()
  {
    for (Iterator<IArtifactRequest> iterator = requestsToProcess.iterator(); iterator.hasNext();)
    {
      IArtifactRequest request = (IArtifactRequest)iterator.next();
      if ((request.getResult() != null) && (request.getResult().isOK())) {
        iterator.remove();
      }
    }
  }
  
  public IStatus start(IProgressMonitor monitor)
  {
    SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.download_artifact, 1000);
    try
    {
      Object localObject2;
      if (requestsToProcess.isEmpty()) {
        return Status.OK_STATUS;
      }
      if (provContext == null) {
        provContext = new ProvisioningContext(agent);
      }
      IQueryable<IArtifactRepository> repoQueryable = provContext.getArtifactRepositories(subMonitor.newChild(250));
      IQuery<IArtifactRepository> all = new ExpressionMatchQuery(IArtifactRepository.class, ExpressionUtil.TRUE_EXPRESSION, new Object[0]);
      IArtifactRepository[] repositories = (IArtifactRepository[])repoQueryable.query(all, subMonitor.newChild(250)).toArray(IArtifactRepository.class);
      if (repositories.length == 0) {
        return new Status(4, "org.eclipse.equinox.p2.engine", Messages.download_no_repository, new Exception("noArtifactRepositoriesAvailable"));
      }
      Arrays.sort(repositories, LOCAL_FIRST_COMPARATOR);
      fetch(repositories, subMonitor.newChild(500));
      return overallStatus(monitor);
    }
    finally
    {
      subMonitor.done();
    }
  }
  
  private void fetch(IArtifactRepository[] repositories, IProgressMonitor mon)
  {
    SubMonitor monitor = SubMonitor.convert(mon, requestsToProcess.size());
    for (int i = 0; (i < repositories.length) && (!requestsToProcess.isEmpty()) && (!monitor.isCanceled()); i++)
    {
      IArtifactRequest[] requests = getRequestsForRepository(repositories[i]);
      IStatus dlStatus = repositories[i].getArtifacts(requests, monitor.newChild(requests.length));
      if (dlStatus.getSeverity() == 8) {
        return;
      }
      filterUnfetched();
      monitor.setWorkRemaining(requestsToProcess.size());
    }
  }
  
  private IArtifactRequest[] getRequestsForRepository(IArtifactRepository repository)
  {
    ArrayList<IArtifactRequest> applicable = new ArrayList();
    for (Iterator localIterator = requestsToProcess.iterator(); localIterator.hasNext();)
    {
      IArtifactRequest request = (IArtifactRequest)localIterator.next();
      if (repository.contains(request.getArtifactKey())) {
        applicable.add(request);
      }
    }
    return (IArtifactRequest[])applicable.toArray(new IArtifactRequest[applicable.size()]);
  }
  
  private IStatus overallStatus(IProgressMonitor monitor)
  {
    if ((monitor != null) && (monitor.isCanceled())) {
      return Status.CANCEL_STATUS;
    }
    if (requestsToProcess.size() == 0) {
      return Status.OK_STATUS;
    }
    MultiStatus result = new MultiStatus("org.eclipse.equinox.p2.engine", 0, null, null);
    for (Iterator localIterator = requestsToProcess.iterator(); localIterator.hasNext();)
    {
      IArtifactRequest request = (IArtifactRequest)localIterator.next();
      IStatus failed = request.getResult();
      if ((failed != null) && (!failed.isOK())) {
        result.add(failed);
      }
    }
    return result;
  }
}

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

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IEngine;
import org.eclipse.equinox.p2.engine.IPhaseSet;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.engine.IProvisioningPlan;
import org.eclipse.equinox.p2.engine.PhaseSetFactory;
import org.eclipse.equinox.p2.engine.ProvisioningContext;

public class Engine
  implements IEngine
{
  private static final String ENGINE = "engine";
  private IProvisioningAgent agent;
  
  public Engine(IProvisioningAgent agent)
  {
    this.agent = agent;
    agent.registerService(ActionManager.SERVICE_NAME, new ActionManager());
  }
  
  private void checkArguments(IProfile iprofile, PhaseSet phaseSet, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor)
  {
    if (iprofile == null) {
      throw new IllegalArgumentException(Messages.null_profile);
    }
    if (phaseSet == null) {
      throw new IllegalArgumentException(Messages.null_phaseset);
    }
    if (operands == null) {
      throw new IllegalArgumentException(Messages.null_operands);
    }
  }
  
  public IStatus perform(IProvisioningPlan plan, IPhaseSet phaseSet, IProgressMonitor monitor)
  {
    return perform(plan.getProfile(), phaseSet, ((ProvisioningPlan)plan).getOperands(), plan.getContext(), monitor);
  }
  
  public IStatus perform(IProvisioningPlan plan, IProgressMonitor monitor)
  {
    return perform(plan, PhaseSetFactory.createDefaultPhaseSet(), monitor);
  }
  
  public IStatus perform(IProfile iprofile, IPhaseSet phases, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor)
  {
    PhaseSet phaseSet = (PhaseSet)phases;
    checkArguments(iprofile, phaseSet, operands, context, monitor);
    if (operands.length == 0) {
      return Status.OK_STATUS;
    }
    SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
    IProvisioningEventBus eventBus = (IProvisioningEventBus)agent.getService(IProvisioningEventBus.SERVICE_NAME);
    if (context == null) {
      context = new ProvisioningContext(agent);
    }
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    Profile profile = profileRegistry.validate(iprofile);
    
    profileRegistry.lockProfile(profile);
    try
    {
      eventBus.publishEvent(new BeginOperationEvent(profile, phaseSet, operands, this));
      if (DebugHelper.DEBUG_ENGINE) {
        DebugHelper.debug("engine", "Beginning engine operation for profile=" + profile.getProfileId() + " [" + profile.getTimestamp() + "]:" + DebugHelper.LINE_SEPARATOR + DebugHelper.formatOperation(phaseSet, operands, context));
      }
      EngineSession session = new EngineSession(agent, profile, context);
      
      MultiStatus result = phaseSet.perform(session, operands, monitor);
      if ((result.isOK()) || (result.matches(3)))
      {
        if (DebugHelper.DEBUG_ENGINE) {
          DebugHelper.debug("engine", "Preparing to commit engine operation for profile=" + profile.getProfileId());
        }
        result.merge(session.prepare(monitor));
      }
      if (result.matches(12))
      {
        if (DebugHelper.DEBUG_ENGINE) {
          DebugHelper.debug("engine", "Rolling back engine operation for profile=" + profile.getProfileId() + ". Reason was: " + result.toString());
        }
        IStatus status = session.rollback(monitor, result.getSeverity());
        if (status.matches(4)) {
          LogHelper.log(status);
        }
        eventBus.publishEvent(new RollbackOperationEvent(profile, phaseSet, operands, this, result));
      }
      else
      {
        if (DebugHelper.DEBUG_ENGINE) {
          DebugHelper.debug("engine", "Committing engine operation for profile=" + profile.getProfileId());
        }
        if (profile.isChanged()) {
          profileRegistry.updateProfile(profile);
        }
        IStatus status = session.commit(monitor);
        if (status.matches(4)) {
          LogHelper.log(status);
        }
        eventBus.publishEvent(new CommitOperationEvent(profile, phaseSet, operands, this));
      }
      IStatus[] children = result.getChildren();
      return children.length == 1 ? children[0] : result;
    }
    finally
    {
      profileRegistry.unlockProfile(profile);
      profile.setChanged(false);
    }
  }
  
  protected IStatus validate(IProfile iprofile, PhaseSet phaseSet, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor)
  {
    checkArguments(iprofile, phaseSet, operands, context, monitor);
    if (context == null) {
      context = new ProvisioningContext(agent);
    }
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    ActionManager actionManager = (ActionManager)agent.getService(ActionManager.SERVICE_NAME);
    return phaseSet.validate(actionManager, iprofile, operands, context, monitor);
  }
  
  public IProvisioningPlan createPlan(IProfile profile, ProvisioningContext context)
  {
    return new ProvisioningPlan(profile, null, context);
  }
}

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

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class EngineActivator
  implements BundleActivator
{
  private static BundleContext context;
  public static final String ID = "org.eclipse.equinox.p2.engine";
  public static final String PROP_PROFILE_FORMAT = "eclipse.p2.profileFormat";
  public static final String PROFILE_FORMAT_UNCOMPRESSED = "uncompressed";
  public static final String PROP_UNSIGNED_POLICY = "eclipse.p2.unsignedPolicy";
  public static final String UNSIGNED_PROMPT = "prompt";
  public static final String UNSIGNED_FAIL = "fail";
  public static final String UNSIGNED_ALLOW = "allow";
  
  public static BundleContext getContext()
  {
    return context;
  }
  
  public void start(BundleContext aContext)
    throws Exception
  {
    context = aContext;
  }
  
  public void stop(BundleContext aContext)
    throws Exception
  {
    context = null;
  }
}

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

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

public class EngineComponent
  implements IAgentServiceFactory
{
  public Object createService(IProvisioningAgent agent)
  {
    agent.getService("org.eclipse.equinox.internal.p2.garbagecollector.GarbageCollector");
    
    return new Engine(agent);
  }
}

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

import java.util.ArrayList;
import java.util.List;
import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;

class EngineSession$ActionsRecord
{
  Operand operand;
  List<ProvisioningAction> actions = new ArrayList();
  
  EngineSession$ActionsRecord(Operand operand)
  {
    this.operand = operand;
  }
}

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

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
import org.eclipse.equinox.p2.engine.spi.Touchpoint;
import org.eclipse.osgi.util.NLS;

public class EngineSession
{
  private static final String ENGINE_SESSION = "enginesession";
  private static final String EMPTY_STRING = "";
  
  private static class ActionsRecord
  {
    Operand operand;
    List<ProvisioningAction> actions = new ArrayList();
    
    ActionsRecord(Operand operand)
    {
      this.operand = operand;
    }
  }
  
  private List<Object[]> phaseActionRecordsPairs = new ArrayList();
  private Phase currentPhase;
  boolean currentPhaseActive;
  private List<ActionsRecord> currentActionRecords;
  private ActionsRecord currentRecord;
  private IProfile profile;
  private ProvisioningContext context;
  private final HashMap<String, Object> sessionServices = new HashMap();
  private Set<Touchpoint> touchpoints = new HashSet();
  private final IProvisioningAgent agent;
  
  public EngineSession(IProvisioningAgent agent, IProfile profile, ProvisioningContext context)
  {
    this.agent = agent;
    this.profile = profile;
    this.context = context;
  }
  
  public IProfile getProfile()
  {
    return profile;
  }
  
  public IProvisioningAgent getAgent()
  {
    return agent;
  }
  
  public ProvisioningContext getProvisioningContext()
  {
    return context;
  }
  
  public File getProfileDataDirectory()
  {
    SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
    return profileRegistry.getProfileDataDirectory(profile.getProfileId());
  }
  
  public Object getxService(String serviceName)
  {
    Object result = sessionServices.get(serviceName);
    if (result != null) {
      return result;
    }
    return agent.getService(serviceName);
  }
  
  IStatus prepare(IProgressMonitor monitor)
  {
    monitor.subTask(Messages.preparing);
    MultiStatus status = new MultiStatus("org.eclipse.equinox.p2.engine", 0, null, null);
    for (Iterator localIterator = touchpoints.iterator(); localIterator.hasNext();)
    {
      Touchpoint touchpoint = (Touchpoint)localIterator.next();
      try
      {
        status.add(touchpoint.prepare(profile));
      }
      catch (RuntimeException e)
      {
        status.add(new Status(4, "org.eclipse.equinox.p2.engine", NLS.bind(Messages.touchpoint_prepare_error, touchpoint.getClass().getName()), e));
      }
      catch (LinkageError e)
      {
        status.add(new Status(4, "org.eclipse.equinox.p2.engine", NLS.bind(Messages.touchpoint_prepare_error, touchpoint.getClass().getName()), e));
      }
    }
    if (status.matches(4))
    {
      MultiStatus result = new MultiStatus("org.eclipse.equinox.p2.engine", 4, NLS.bind(Messages.session_prepare_error, profile.getProfileId()), null);
      result.merge(status);
      return result;
    }
    return status;
  }
  
  IStatus commit(IProgressMonitor monitor)
  {
    monitor.subTask(Messages.committing);
    MultiStatus status = new MultiStatus("org.eclipse.equinox.p2.engine", 0, null, null);
    phaseActionRecordsPairs.clear();
    for (Iterator localIterator = touchpoints.iterator(); localIterator.hasNext();)
    {
      Touchpoint touchpoint = (Touchpoint)localIterator.next();
      try
      {
        IStatus result = touchpoint.commit(profile);
        if (!result.isOK()) {
          status.add(result);
        }
      }
      catch (RuntimeException e)
      {
        status.add(new Status(4, "org.eclipse.equinox.p2.engine", NLS.bind(Messages.touchpoint_commit_error, touchpoint.getClass().getName()), e));
      }
      catch (LinkageError e)
      {
        status.add(new Status(4, "org.eclipse.equinox.p2.engine", NLS.bind(Messages.touchpoint_commit_error, touchpoint.getClass().getName()), e));
      }
    }
    if (status.matches(4))
    {
      MultiStatus result = new MultiStatus("org.eclipse.equinox.p2.engine", 4, NLS.bind(Messages.session_commit_error, profile.getProfileId()), null);
      result.merge(status);
      return result;
    }
    return status;
  }
  
  IStatus rollback(IProgressMonitor monitor, int severity)
  {
    if (severity == 8) {
      monitor.subTask(Messages.rollingback_cancel);
    }
    if (severity == 4) {
      monitor.subTask(Messages.rollingback_error);
    }
    MultiStatus status = new MultiStatus("org.eclipse.equinox.p2.engine", 0, null, null);
    if (currentPhaseActive)
    {
      try
      {
        IStatus result = rollBackPhase(currentPhase, currentActionRecords);
        if (!result.isOK()) {
          status.add(result);
        }
      }
      catch (RuntimeException e)
      {
        status.add(new Status(4, "org.eclipse.equinox.p2.engine", NLS.bind(Messages.phase_undo_error, currentPhase.getClass().getName()), e));
      }
      catch (LinkageError e)
      {
        status.add(new Status(4, "org.eclipse.equinox.p2.engine", NLS.bind(Messages.phase_undo_error, currentPhase.getClass().getName()), e));
      }
      currentPhaseActive = false;
      currentActionRecords = null;
      currentRecord = null;
    }
    currentPhase = null;
    for (ListIterator<Object[]> it = phaseActionRecordsPairs.listIterator(phaseActionRecordsPairs.size()); it.hasPrevious();)
    {
      pair = (Object[])it.previous();
      Phase phase = (Phase)pair[0];
      
      List<ActionsRecord> actionRecords = (List)pair[1];
      try
      {
        IStatus result = rollBackPhase(phase, actionRecords);
        if (!result.isOK()) {
          status.add(result);
        }
      }
      catch (RuntimeException e)
      {
        status.add(new Status(4, "org.eclipse.equinox.p2.engine", NLS.bind(Messages.phase_undo_error, phase.getClass().getName()), e));
      }
      catch (LinkageError e)
      {
        status.add(new Status(4, "org.eclipse.equinox.p2.engine", NLS.bind(Messages.phase_undo_error, phase.getClass().getName()), e));
      }
    }
    phaseActionRecordsPairs.clear();
    for (Object[] pair = touchpoints.iterator(); pair.hasNext();)
    {
      Touchpoint touchpoint = (Touchpoint)pair.next();
      try
      {
        IStatus result = touchpoint.rollback(profile);
        if (!result.isOK()) {
          status.add(result);
        }
      }
      catch (RuntimeException e)
      {
        status.add(new Status(4, "org.eclipse.equinox.p2.engine", NLS.bind(Messages.touchpoint_rollback_error, touchpoint.getClass().getName()), e));
      }
      catch (LinkageError e)
      {
        status.add(new Status(4, "org.eclipse.equinox.p2.engine", NLS.bind(Messages.touchpoint_rollback_error, touchpoint.getClass().getName()), e));
      }
    }
    if (status.matches(4))
    {
      MultiStatus result = new MultiStatus("org.eclipse.equinox.p2.engine", 4, NLS.bind(Messages.session_commit_error, profile.getProfileId()), null);
      result.merge(status);
      return result;
    }
    return status;
  }
  
  /* Error */
  private IStatus rollBackPhase(Phase phase, List<ActionsRecord> actionRecords)
  {
    // Byte code:
    //   0: new 197	org/eclipse/core/runtime/MultiStatus
    //   3: dup
    //   4: ldc 3
    //   6: iconst_0
    //   7: aconst_null
    //   8: aconst_null
    //   9: invokespecial 434	org/eclipse/core/runtime/MultiStatus:<init>	(Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
    //   12: astore_3
    //   13: aload_1
    //   14: aload_0
    //   15: getfield 388	org/eclipse/equinox/internal/p2/engine/EngineSession:agent	Lorg/eclipse/equinox/p2/core/IProvisioningAgent;
    //   18: getstatic 379	org/eclipse/equinox/internal/p2/engine/ActionManager:SERVICE_NAME	Ljava/lang/String;
    //   21: invokeinterface 477 2 0
    //   26: checkcast 200	org/eclipse/equinox/internal/p2/engine/ActionManager
    //   29: putfield 414	org/eclipse/equinox/internal/p2/engine/Phase:actionManager	Lorg/eclipse/equinox/internal/p2/engine/ActionManager;
    //   32: aload_0
    //   33: getfield 381	org/eclipse/equinox/internal/p2/engine/EngineSession:currentPhaseActive	Z
    //   36: ifne +16 -> 52
    //   39: aload_1
    //   40: aload_3
    //   41: aload_0
    //   42: new 198	org/eclipse/core/runtime/NullProgressMonitor
    //   45: dup
    //   46: invokespecial 435	org/eclipse/core/runtime/NullProgressMonitor:<init>	()V
    //   49: invokevirtual 452	org/eclipse/equinox/internal/p2/engine/Phase:prePerform	(Lorg/eclipse/core/runtime/MultiStatus;Lorg/eclipse/equinox/internal/p2/engine/EngineSession;Lorg/eclipse/core/runtime/IProgressMonitor;)V
    //   52: aload_2
    //   53: aload_2
    //   54: invokeinterface 464 1 0
    //   59: invokeinterface 469 2 0
    //   64: astore 4
    //   66: goto +158 -> 224
    //   69: aload 4
    //   71: invokeinterface 472 1 0
    //   76: checkcast 203	org/eclipse/equinox/internal/p2/engine/EngineSession$ActionsRecord
    //   79: astore 5
    //   81: new 187	java/util/ArrayList
    //   84: dup
    //   85: aload 5
    //   87: getfield 391	org/eclipse/equinox/internal/p2/engine/EngineSession$ActionsRecord:actions	Ljava/util/List;
    //   90: invokespecial 426	java/util/ArrayList:<init>	(Ljava/util/Collection;)V
    //   93: astore 6
    //   95: aload 6
    //   97: invokestatic 427	java/util/Collections:reverse	(Ljava/util/List;)V
    //   100: aload 6
    //   102: aload 5
    //   104: getfield 391	org/eclipse/equinox/internal/p2/engine/EngineSession$ActionsRecord:actions	Ljava/util/List;
    //   107: invokeinterface 464 1 0
    //   112: anewarray 211	org/eclipse/equinox/p2/engine/spi/ProvisioningAction
    //   115: invokeinterface 470 2 0
    //   120: checkcast 179	[Lorg/eclipse/equinox/p2/engine/spi/ProvisioningAction;
    //   123: astore 7
    //   125: aload_1
    //   126: aload_3
    //   127: aload_0
    //   128: aload_0
    //   129: getfield 389	org/eclipse/equinox/internal/p2/engine/EngineSession:profile	Lorg/eclipse/equinox/p2/engine/IProfile;
    //   132: aload 5
    //   134: getfield 392	org/eclipse/equinox/internal/p2/engine/EngineSession$ActionsRecord:operand	Lorg/eclipse/equinox/internal/p2/engine/Operand;
    //   137: aload 7
    //   139: aload_0
    //   140: getfield 390	org/eclipse/equinox/internal/p2/engine/EngineSession:context	Lorg/eclipse/equinox/p2/engine/ProvisioningContext;
    //   143: invokevirtual 453	org/eclipse/equinox/internal/p2/engine/Phase:undo	(Lorg/eclipse/core/runtime/MultiStatus;Lorg/eclipse/equinox/internal/p2/engine/EngineSession;Lorg/eclipse/equinox/p2/engine/IProfile;Lorg/eclipse/equinox/internal/p2/engine/Operand;[Lorg/eclipse/equinox/p2/engine/spi/ProvisioningAction;Lorg/eclipse/equinox/p2/engine/ProvisioningContext;)V
    //   146: goto +78 -> 224
    //   149: astore 8
    //   151: aload_3
    //   152: new 199	org/eclipse/core/runtime/Status
    //   155: dup
    //   156: iconst_4
    //   157: ldc 3
    //   159: getstatic 404	org/eclipse/equinox/internal/p2/engine/Messages:phase_undo_operand_error	Ljava/lang/String;
    //   162: aload_1
    //   163: invokevirtual 420	java/lang/Object:getClass	()Ljava/lang/Class;
    //   166: invokevirtual 416	java/lang/Class:getName	()Ljava/lang/String;
    //   169: aload 5
    //   171: getfield 392	org/eclipse/equinox/internal/p2/engine/EngineSession$ActionsRecord:operand	Lorg/eclipse/equinox/internal/p2/engine/Operand;
    //   174: invokestatic 461	org/eclipse/osgi/util/NLS:bind	(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/String;
    //   177: aload 8
    //   179: invokespecial 436	org/
1 2 3 4 5 6 7 8 9 10 11

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