diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.engine/src')
67 files changed, 1741 insertions, 1086 deletions
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ActionManager.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ActionManager.java index fb11e168f..acbca8436 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ActionManager.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ActionManager.java @@ -10,15 +10,14 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.engine; -import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange; - import java.util.HashMap; import java.util.Map; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction; -import org.eclipse.equinox.internal.provisional.p2.engine.Touchpoint; -import org.eclipse.equinox.internal.provisional.p2.metadata.ITouchpointType; +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 { @@ -29,8 +28,13 @@ public class ActionManager implements IRegistryChangeListener { private static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$ private static final String TOUCHPOINT_TYPE = "touchpointType"; //$NON-NLS-1$ private static final String TOUCHPOINT_VERSION = "touchpointVersion"; //$NON-NLS-1$ + /** + * Service name constant for the action manager service. This service is used internally + * by the engine implementation and should not be referenced directly by clients. + */ + public static final String SERVICE_NAME = ActionManager.class.getName(); - private HashMap actionMap; + private HashMap<String, IConfigurationElement> actionMap; private TouchpointManager touchpointManager; public ActionManager() { @@ -58,7 +62,7 @@ public class ActionManager implements IRegistryChangeListener { } public ProvisioningAction getAction(String actionId, VersionRange versionRange) { - IConfigurationElement actionElement = (IConfigurationElement) getActionMap().get(actionId); + IConfigurationElement actionElement = getActionMap().get(actionId); if (actionElement != null && actionElement.isValid()) { try { ProvisioningAction action = (ProvisioningAction) actionElement.createExecutableExtension(ATTRIBUTE_CLASS); @@ -81,12 +85,12 @@ public class ActionManager implements IRegistryChangeListener { return null; } - private synchronized Map getActionMap() { + private synchronized Map<String, IConfigurationElement> getActionMap() { if (actionMap != null) return actionMap; IExtensionPoint point = RegistryFactory.getRegistry().getExtensionPoint(EngineActivator.ID, PT_ACTIONS); IExtension[] extensions = point.getExtensions(); - actionMap = new HashMap(extensions.length); + actionMap = new HashMap<String, IConfigurationElement>(extensions.length); for (int i = 0; i < extensions.length; i++) { try { IConfigurationElement[] elements = extensions[i].getConfigurationElements(); diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DebugHelper.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DebugHelper.java index 04df2dfdb..ec9ebd502 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DebugHelper.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DebugHelper.java @@ -14,9 +14,10 @@ import java.io.File; import java.util.*; import java.util.Map.Entry; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; -import org.eclipse.equinox.internal.provisional.p2.engine.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.engine.*; +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 { @@ -52,8 +53,8 @@ public class DebugHelper { System.out.println(buffer.toString()); } - public static String formatArray(Object[] array, boolean toString, boolean newLines) { - if (array == null || array.length == 0) + public static String formatArray(List<? extends Object> array, boolean toString, boolean newLines) { + if (array == null || array.size() == 0) return "[]"; //$NON-NLS-1$ StringBuffer buffer = new StringBuffer(); @@ -61,11 +62,11 @@ public class DebugHelper { int i = 0; for (;;) { if (toString) - buffer.append(array[i].toString()); + buffer.append(array.get(i).toString()); else - buffer.append(array[i].getClass().getName()); + buffer.append(array.get(i).getClass().getName()); i++; - if (i == array.length) + if (i == array.size()) break; buffer.append(','); if (newLines) @@ -99,7 +100,7 @@ public class DebugHelper { operandStrings[i] = operands[i].toString(); } } - return DebugHelper.formatArray(operandStrings, true, true); + return DebugHelper.formatArray(Arrays.asList(operandStrings), true, true); } public static String formatInstallableUnitOperand(InstallableUnitOperand iuOperand) { @@ -116,19 +117,19 @@ public class DebugHelper { public static String formatPhaseSet(PhaseSet phaseSet) { StringBuffer buffer = new StringBuffer(phaseSet.getClass().getName()); - buffer.append(DebugHelper.formatArray(phaseSet.getPhases(), false, false)); + buffer.append(DebugHelper.formatArray(Arrays.asList(phaseSet.getPhases()), false, false)); return buffer.toString(); } public static String formatContext(ProvisioningContext context) { StringBuffer buffer = new StringBuffer(); - buffer.append("{artifactRepos=" + DebugHelper.formatArray(context.getArtifactRepositories(), true, false)); //$NON-NLS-1$ - buffer.append(", metadataRepos=" + DebugHelper.formatArray(context.getMetadataRepositories(), true, false)); //$NON-NLS-1$ + buffer.append("{artifactRepos=" + DebugHelper.formatArray(Arrays.asList(context.getArtifactRepositories()), true, false)); //$NON-NLS-1$ + buffer.append(", metadataRepos=" + DebugHelper.formatArray(Arrays.asList(context.getMetadataRepositories()), true, false)); //$NON-NLS-1$ buffer.append(", properties=" + context.getProperties() + "}"); //$NON-NLS-1$ //$NON-NLS-2$ return buffer.toString(); } - public static String formatAction(ProvisioningAction action, Map parameters) { + public static String formatAction(ProvisioningAction action, Map<String, Object> parameters) { StringBuffer buffer = new StringBuffer(); buffer.append(action.getClass().getName()); if (action instanceof ParameterizedProvisioningAction) { @@ -141,16 +142,16 @@ public class DebugHelper { return buffer.toString(); } - public static String formatParameters(Map parameters) { - Iterator it = parameters.entrySet().iterator(); + public static String formatParameters(Map<String, ? extends Object> parameters) { + Iterator<? extends Entry<String, ? extends Object>> it = parameters.entrySet().iterator(); if (!it.hasNext()) return "{}"; //$NON-NLS-1$ StringBuffer buffer = new StringBuffer(); buffer.append('{'); for (;;) { - Entry e = (Entry) it.next(); - String key = (String) e.getKey(); + Entry<String, ? extends Object> e = it.next(); + String key = e.getKey(); buffer.append(key); buffer.append('='); Object value = e.getValue(); diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DownloadManager.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DownloadManager.java index 9f1486c71..0db1b83d0 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DownloadManager.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DownloadManager.java @@ -14,29 +14,25 @@ package org.eclipse.equinox.internal.p2.engine; import java.net.URI; import java.util.*; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningContext; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.engine.ProvisioningContext; +import org.eclipse.equinox.p2.repository.IRepositoryManager; +import org.eclipse.equinox.p2.repository.artifact.*; public class DownloadManager { private ProvisioningContext provContext = null; - ArrayList requestsToProcess = new ArrayList(); + ArrayList<IArtifactRequest> requestsToProcess = new ArrayList<IArtifactRequest>(); private static final String FILE_PROTOCOL = "file"; //$NON-NLS-1$ /** - * This Comparator sorts the repositories such that ´local´ repositories are first + * This Comparator sorts the repositories such that �local� repositories are first */ - private static final Comparator LOCAL_FIRST_COMPARATOR = new Comparator() { + private static final Comparator<URI> LOCAL_FIRST_COMPARATOR = new Comparator<URI>() { - public int compare(Object arg0, Object arg1) { - Assert.isTrue(arg0 instanceof URI); - Assert.isTrue(arg1 instanceof URI); - - String protocol0 = ((URI) arg0).getScheme(); - String protocol1 = ((URI) arg1).getScheme(); + public int compare(URI arg0, URI arg1) { + String protocol0 = arg0.getScheme(); + String protocol1 = arg1.getScheme(); if (FILE_PROTOCOL.equals(protocol0) && !FILE_PROTOCOL.equals(protocol1)) return -1; @@ -45,9 +41,11 @@ public class DownloadManager { return 0; } }; + private final IArtifactRepositoryManager repositoryManager; - public DownloadManager(ProvisioningContext context) { + public DownloadManager(ProvisioningContext context, IArtifactRepositoryManager repositoryManager) { provContext = context; + this.repositoryManager = repositoryManager; } /* @@ -67,8 +65,8 @@ public class DownloadManager { } private void filterUnfetched() { - for (Iterator iterator = requestsToProcess.iterator(); iterator.hasNext();) { - IArtifactRequest request = (IArtifactRequest) iterator.next(); + for (Iterator<IArtifactRequest> iterator = requestsToProcess.iterator(); iterator.hasNext();) { + IArtifactRequest request = iterator.next(); if (request.getResult() != null && request.getResult().isOK()) { iterator.remove(); } @@ -84,26 +82,25 @@ public class DownloadManager { if (requestsToProcess.isEmpty()) return Status.OK_STATUS; - IArtifactRepositoryManager repoMgr = (IArtifactRepositoryManager) ServiceHelper.getService(EngineActivator.getContext(), IArtifactRepositoryManager.class.getName()); URI[] repositories = null; if (provContext == null || provContext.getArtifactRepositories() == null) - repositories = repoMgr.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL); + repositories = repositoryManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL); else repositories = provContext.getArtifactRepositories(); if (repositories.length == 0) return new Status(IStatus.ERROR, EngineActivator.ID, Messages.download_no_repository, new Exception()); Arrays.sort(repositories, LOCAL_FIRST_COMPARATOR); - fetch(repoMgr, repositories, subMonitor); + fetch(repositories, subMonitor); return overallStatus(monitor); } finally { subMonitor.done(); } } - private void fetch(IArtifactRepositoryManager repoMgr, URI[] repositories, SubMonitor monitor) { + private void fetch(URI[] repositories, SubMonitor monitor) { for (int i = 0; i < repositories.length && !requestsToProcess.isEmpty() && !monitor.isCanceled(); i++) { try { - IArtifactRepository current = repoMgr.loadRepository(repositories[i], monitor.newChild(0)); + IArtifactRepository current = repositoryManager.loadRepository(repositories[i], monitor.newChild(0)); IArtifactRequest[] requests = getRequestsForRepository(current); IStatus dlStatus = current.getArtifacts(requests, monitor.newChild(requests.length)); if (dlStatus.getSeverity() == IStatus.CANCEL) @@ -117,13 +114,12 @@ public class DownloadManager { } private IArtifactRequest[] getRequestsForRepository(IArtifactRepository repository) { - ArrayList applicable = new ArrayList(); - for (Iterator it = requestsToProcess.iterator(); it.hasNext();) { - IArtifactRequest request = (IArtifactRequest) it.next(); + ArrayList<IArtifactRequest> applicable = new ArrayList<IArtifactRequest>(); + for (IArtifactRequest request : requestsToProcess) { if (repository.contains(request.getArtifactKey())) applicable.add(request); } - return (IArtifactRequest[]) applicable.toArray(new IArtifactRequest[applicable.size()]); + return applicable.toArray(new IArtifactRequest[applicable.size()]); } // private void notifyFetched() { @@ -139,8 +135,8 @@ public class DownloadManager { return Status.OK_STATUS; MultiStatus result = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); - for (Iterator iterator = requestsToProcess.iterator(); iterator.hasNext();) { - IStatus failed = ((IArtifactRequest) iterator.next()).getResult(); + for (IArtifactRequest request : requestsToProcess) { + IStatus failed = request.getResult(); if (failed != null && !failed.isOK()) result.add(failed); } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/Engine.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Engine.java index 0ff2d0f12..c9c10ad3b 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/Engine.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Engine.java @@ -8,28 +8,25 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.internal.p2.engine; -import java.io.File; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.p2.engine.*; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.engine.*; /** * TODO Move concrete class to non-API package */ public class Engine implements IEngine { - private static final String ENGINE = "engine"; //$NON-NLS-1$ - - private ActionManager actionManager; - private final IProvisioningEventBus eventBus; - private SimpleProfileRegistry profileRegistry; + private static final String ENGINE = "engine"; //$NON-NLS-1$ + private IProvisioningAgent agent; - public Engine(IProvisioningEventBus eventBus) { - this.eventBus = eventBus; - this.actionManager = new ActionManager(); + 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) { @@ -43,8 +40,19 @@ public class Engine implements IEngine { throw new IllegalArgumentException(Messages.null_operands); } - public IStatus perform(IProfile iprofile, PhaseSet phaseSet, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor) { + public IStatus perform(IProvisioningPlan plan, IPhaseSet phaseSet, IProgressMonitor monitor) { + return perform(plan.getProfile(), phaseSet, plan.getOperands(), plan.getContext(), monitor); + } + + public IStatus perform(IProvisioningPlan plan, IProgressMonitor monitor) { + return perform(plan.getProfile(), new DefaultPhaseSet(), plan.getOperands(), plan.getContext(), monitor); + } + + public IStatus perform(IProfile iprofile, IPhaseSet phases, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor) { + PhaseSet phaseSet = (PhaseSet) phases; checkArguments(iprofile, phaseSet, operands, context, monitor); + SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME); + IProvisioningEventBus eventBus = (IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME); if (context == null) context = new ProvisioningContext(); @@ -60,11 +68,9 @@ public class Engine implements IEngine { if (DebugHelper.DEBUG_ENGINE) DebugHelper.debug(ENGINE, "Beginning engine operation for profile=" + profile.getProfileId() + " [" + profile.getTimestamp() + "]:" + DebugHelper.LINE_SEPARATOR + DebugHelper.formatOperation(phaseSet, operands, context)); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ - File profileDataDirectory = profileRegistry.getProfileDataDirectory(profile.getProfileId()); + EngineSession session = new EngineSession(agent, profile, context); - EngineSession session = new EngineSession(profile, profileDataDirectory, context); - - MultiStatus result = phaseSet.perform(actionManager, session, profile, operands, context, monitor); + MultiStatus result = phaseSet.perform(session, operands, monitor); if (result.isOK() || result.matches(IStatus.INFO | IStatus.WARNING)) { if (DebugHelper.DEBUG_ENGINE) DebugHelper.debug(ENGINE, "Preparing to commit engine operation for profile=" + profile.getProfileId()); //$NON-NLS-1$ @@ -73,7 +79,7 @@ public class Engine implements IEngine { if (result.matches(IStatus.ERROR | IStatus.CANCEL)) { if (DebugHelper.DEBUG_ENGINE) DebugHelper.debug(ENGINE, "Rolling back engine operation for profile=" + profile.getProfileId() + ". Reason was: " + result.toString()); //$NON-NLS-1$ //$NON-NLS-2$ - IStatus status = session.rollback(actionManager, monitor, result.getSeverity()); + IStatus status = session.rollback(monitor, result.getSeverity()); if (status.matches(IStatus.ERROR)) LogHelper.log(status); eventBus.publishEvent(new RollbackOperationEvent(profile, phaseSet, operands, this, result)); @@ -96,17 +102,6 @@ public class Engine implements IEngine { } } - public void setProfileRegistry(IProfileRegistry registry) { - //we can only work with our own registry implementation - if (registry instanceof SimpleProfileRegistry) - this.profileRegistry = (SimpleProfileRegistry) registry; - } - - public void unsetProfileRegistry(IProfileRegistry registry) { - if (this.profileRegistry == registry) - this.profileRegistry = null; - } - public IStatus validate(IProfile iprofile, PhaseSet phaseSet, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor) { checkArguments(iprofile, phaseSet, operands, context, monitor); @@ -116,6 +111,19 @@ public class Engine implements IEngine { if (monitor == null) monitor = new NullProgressMonitor(); + ActionManager actionManager = (ActionManager) agent.getService(ActionManager.SERVICE_NAME); return phaseSet.validate(actionManager, iprofile, operands, context, monitor); } + + public IPhaseSet createPhaseSetExcluding(String[] excludes) { + return PhaseSet.createPhaseSetExcluding(excludes); + } + + public IPhaseSet createPhaseSetIncluding(String[] includes) { + return PhaseSet.createPhaseSetIncluding(includes); + } + + public IProvisioningPlan createCustomPlan(IProfile profile, Operand[] operands, ProvisioningContext context) { + return new ProvisioningPlan(profile, operands, context); + } } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineActivator.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineActivator.java index ead37e3b0..114b2caea 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineActivator.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineActivator.java @@ -11,9 +11,8 @@ package org.eclipse.equinox.internal.p2.engine; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; -import org.eclipse.equinox.internal.provisional.p2.engine.Engine; -import org.eclipse.equinox.internal.provisional.p2.engine.IEngine; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.engine.IEngine; import org.osgi.framework.*; import org.osgi.util.tracker.ServiceTracker; import org.osgi.util.tracker.ServiceTrackerCustomizer; @@ -67,9 +66,11 @@ public class EngineActivator implements BundleActivator, ServiceTrackerCustomize public Object addingService(ServiceReference reference) { if (registration == null) { - IProvisioningEventBus eventBus = (IProvisioningEventBus) context.getService(reference); - registration = context.registerService(IEngine.SERVICE_NAME, new Engine(eventBus), null); - return eventBus; + //TODO: eventually we shouldn't register a singleton engine automatically + IProvisioningAgent agent = (IProvisioningAgent) context.getService(reference); + IEngine engine = (IEngine) agent.getService(IEngine.SERVICE_NAME); + registration = context.registerService(IEngine.SERVICE_NAME, engine, null); + return agent; } return null; } @@ -87,7 +88,9 @@ public class EngineActivator implements BundleActivator, ServiceTrackerCustomize public void start(BundleContext aContext) throws Exception { EngineActivator.context = aContext; - tracker = new ServiceTracker(aContext, IProvisioningEventBus.SERVICE_NAME, this); + //only want to register a service for the agent of the currently running system + String filter = "(&(objectClass=" + IProvisioningAgent.SERVICE_NAME + ")(agent.current=true))"; //$NON-NLS-1$ //$NON-NLS-2$ + tracker = new ServiceTracker(context, aContext.createFilter(filter), this); tracker.open(); } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineComponent.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineComponent.java index 6a8de3a60..7a20606d7 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineComponent.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineComponent.java @@ -10,10 +10,9 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.engine; -import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; -import org.eclipse.equinox.internal.provisional.p2.engine.*; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory; +import org.eclipse.equinox.p2.engine.IEngine; /** * Component that provides a factory that can create and initialize @@ -25,9 +24,7 @@ public class EngineComponent implements IAgentServiceFactory { * @see org.eclipse.equinox.p2.core.spi.IAgentServiceFactory#createService(org.eclipse.equinox.p2.core.IProvisioningAgent) */ public Object createService(IProvisioningAgent agent) { - IProvisioningEventBus bus = (IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME); - Engine result = new Engine(bus); - result.setProfileRegistry((IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME)); - return result; + //various parts of the engine may need an open-ended set of services, so we pass the agent to the engine directly + return new Engine(agent); } } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/EngineSession.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineSession.java index cfc97cb88..e9f6b1919 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/EngineSession.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineSession.java @@ -8,14 +8,20 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.internal.p2.engine; import java.io.File; import java.util.*; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.p2.engine.*; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.engine.spi.Touchpoint; import org.eclipse.osgi.util.NLS; +/** + * TODO: not API + */ public class EngineSession { private static final String ENGINE_SESSION = "enginesession"; //$NON-NLS-1$ @@ -23,44 +29,71 @@ public class EngineSession { private static class ActionsRecord { Operand operand; - List actions = new ArrayList(); + List<ProvisioningAction> actions = new ArrayList<ProvisioningAction>(); ActionsRecord(Operand operand) { this.operand = operand; } } - private List phaseActionRecordsPairs = new ArrayList(); + private List<Object[]> phaseActionRecordsPairs = new ArrayList<Object[]>(); private Phase currentPhase; boolean currentPhaseActive; - private List currentActionRecords; + private List<ActionsRecord> currentActionRecords; private ActionsRecord currentRecord; private IProfile profile; - private File profileDataDirectory; - private ProvisioningContext context; - private Set touchpoints = new HashSet(); + private final HashMap<String, Object> sessionServices = new HashMap<String, Object>(); + + private Set<Touchpoint> touchpoints = new HashSet<Touchpoint>(); + + private final IProvisioningAgent agent; - public EngineSession(IProfile profile, File profileDataDirectory, ProvisioningContext context) { + public EngineSession(IProvisioningAgent agent, IProfile profile, ProvisioningContext context) { + super(); + this.agent = agent; this.profile = profile; - this.profileDataDirectory = profileDataDirectory; this.context = context; } + public IProfile getProfile() { + return profile; + } + + public IProvisioningAgent getAgent() { + return agent; + } + + public ProvisioningContext getProvisioningContext() { + return context; + } + public File getProfileDataDirectory() { - return profileDataDirectory; + SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME); + return profileRegistry.getProfileDataDirectory(profile.getProfileId()); + } + + /** + * This is the interface through which parts of the engine obtain the services they need + * @param serviceName The name of the service to obtain + * @return The service instance, or <code>null</code> if no such service is available + */ + 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(EngineActivator.ID, IStatus.OK, null, null); - for (Iterator iterator = touchpoints.iterator(); iterator.hasNext();) { - Touchpoint touchpoint = (Touchpoint) iterator.next(); + for (Touchpoint touchpoint : touchpoints) { try { status.add(touchpoint.prepare(profile)); } catch (RuntimeException e) { @@ -85,8 +118,7 @@ public class EngineSession { monitor.subTask(Messages.committing); MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); phaseActionRecordsPairs.clear(); - for (Iterator iterator = touchpoints.iterator(); iterator.hasNext();) { - Touchpoint touchpoint = (Touchpoint) iterator.next(); + for (Touchpoint touchpoint : touchpoints) { try { IStatus result = touchpoint.commit(profile); if (!result.isOK()) @@ -109,7 +141,7 @@ public class EngineSession { return status; } - IStatus rollback(ActionManager actionManager, IProgressMonitor monitor, int severity) { + IStatus rollback(IProgressMonitor monitor, int severity) { if (severity == IStatus.CANCEL) monitor.subTask(Messages.rollingback_cancel); @@ -120,7 +152,7 @@ public class EngineSession { if (currentPhaseActive) { try { - IStatus result = rollBackPhase(currentPhase, currentActionRecords, actionManager); + IStatus result = rollBackPhase(currentPhase, currentActionRecords); if (!result.isOK()) status.add(result); } catch (RuntimeException e) { @@ -137,12 +169,13 @@ public class EngineSession { } currentPhase = null; - for (ListIterator it = phaseActionRecordsPairs.listIterator(phaseActionRecordsPairs.size()); it.hasPrevious();) { - Object[] pair = (Object[]) it.previous(); + for (ListIterator<Object[]> it = phaseActionRecordsPairs.listIterator(phaseActionRecordsPairs.size()); it.hasPrevious();) { + Object[] pair = it.previous(); Phase phase = (Phase) pair[0]; - List actionRecords = (List) pair[1]; + @SuppressWarnings("unchecked") + List<ActionsRecord> actionRecords = (List<ActionsRecord>) pair[1]; try { - final IStatus result = rollBackPhase(phase, actionRecords, actionManager); + final IStatus result = rollBackPhase(phase, actionRecords); if (!result.isOK()) status.add(result); } catch (RuntimeException e) { @@ -156,8 +189,7 @@ public class EngineSession { } phaseActionRecordsPairs.clear(); - for (Iterator iterator = touchpoints.iterator(); iterator.hasNext();) { - Touchpoint touchpoint = (Touchpoint) iterator.next(); + for (Touchpoint touchpoint : touchpoints) { try { IStatus result = touchpoint.rollback(profile); if (!result.isOK()) @@ -180,17 +212,17 @@ public class EngineSession { return status; } - private IStatus rollBackPhase(Phase phase, List actionRecords, ActionManager actionManager) { + private IStatus rollBackPhase(Phase phase, List<ActionsRecord> actionRecords) { MultiStatus result = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); try { - phase.actionManager = actionManager; + phase.actionManager = (ActionManager) agent.getService(ActionManager.SERVICE_NAME); if (!currentPhaseActive) - phase.prePerform(result, this, profile, context, new NullProgressMonitor()); + phase.prePerform(result, this, new NullProgressMonitor()); - for (ListIterator it = actionRecords.listIterator(actionRecords.size()); it.hasPrevious();) { - ActionsRecord record = (ActionsRecord) it.previous(); - ProvisioningAction[] actions = (ProvisioningAction[]) record.actions.toArray(new ProvisioningAction[record.actions.size()]); + for (ListIterator<ActionsRecord> it = actionRecords.listIterator(actionRecords.size()); it.hasPrevious();) { + ActionsRecord record = it.previous(); + ProvisioningAction[] actions = record.actions.toArray(new ProvisioningAction[record.actions.size()]); try { phase.undo(result, this, profile, record.operand, actions, context); } catch (RuntimeException e) { @@ -202,7 +234,7 @@ public class EngineSession { result.add(new Status(IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.phase_undo_operand_error, phase.getClass().getName(), record.operand), e)); } } - phase.postPerform(result, profile, context, new NullProgressMonitor()); + phase.postPerform(result, this, new NullProgressMonitor()); } finally { phase.actionManager = null; } @@ -230,7 +262,7 @@ public class EngineSession { throw new IllegalArgumentException(Messages.not_current_phase); currentPhaseActive = true; - currentActionRecords = new ArrayList(); + currentActionRecords = new ArrayList<ActionsRecord>(); } void recordPhaseEnd(Phase phase) { @@ -284,7 +316,7 @@ public class EngineSession { debugOperandEnd(operand); } - void recordActionExecute(ProvisioningAction action, Map parameters) { + void recordActionExecute(ProvisioningAction action, Map<String, Object> parameters) { if (action == null) throw new IllegalArgumentException(Messages.null_action); @@ -298,7 +330,7 @@ public class EngineSession { debugActionExecute(action, parameters); } - public void recordActionUndo(ProvisioningAction action, Map parameters) { + public void recordActionUndo(ProvisioningAction action, Map<String, Object> parameters) { if (DebugHelper.DEBUG_ENGINE_SESSION) debugActionUndo(action, parameters); } @@ -357,11 +389,11 @@ public class EngineSession { DebugHelper.debug(ENGINE_SESSION, "Ending processing of operand: " + operand.toString()); //$NON-NLS-1$ } - private static void debugActionExecute(ProvisioningAction action, Map parameters) { + private static void debugActionExecute(ProvisioningAction action, Map<String, Object> parameters) { DebugHelper.debug(ENGINE_SESSION, "Executing action: " + DebugHelper.formatAction(action, parameters)); //$NON-NLS-1$ } - private static void debugActionUndo(ProvisioningAction action, Map parameters) { + private static void debugActionUndo(ProvisioningAction action, Map<String, Object> parameters) { DebugHelper.debug(ENGINE_SESSION, "Undoing action: " + DebugHelper.formatAction(action, parameters)); //$NON-NLS-1$ } } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/InstallableUnitPhase.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/InstallableUnitPhase.java index 8766ffdc0..8bf334353 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/InstallableUnitPhase.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/InstallableUnitPhase.java @@ -9,13 +9,15 @@ * IBM Corporation - initial API and implementation * WindRiver - https://bugs.eclipse.org/bugs/show_bug.cgi?id=227372 *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.internal.p2.engine; import java.util.*; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.p2.engine.EngineActivator; -import org.eclipse.equinox.internal.p2.engine.InstructionParser; -import org.eclipse.equinox.internal.provisional.p2.metadata.*; +import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.engine.spi.Touchpoint; +import org.eclipse.equinox.p2.metadata.*; public abstract class InstallableUnitPhase extends Phase { public static final String PARM_ARTIFACT = "artifact"; //$NON-NLS-1$ @@ -30,12 +32,12 @@ public abstract class InstallableUnitPhase extends Phase { this(phaseId, weight, false); } - protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { + protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) { parameters.put(PARM_INSTALL_FOLDER, profile.getProperty(IProfile.PROP_INSTALL_FOLDER)); return super.initializePhase(monitor, profile, parameters); } - protected IStatus initializeOperand(IProfile profile, Operand operand, Map parameters, IProgressMonitor monitor) { + protected IStatus initializeOperand(IProfile profile, Operand operand, Map<String, Object> parameters, IProgressMonitor monitor) { InstallableUnitOperand iuOperand = (InstallableUnitOperand) operand; MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); mergeStatus(status, initializeOperand(profile, iuOperand, parameters, monitor)); @@ -50,11 +52,11 @@ public abstract class InstallableUnitPhase extends Phase { return status; } - protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) { + protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map<String, Object> parameters, IProgressMonitor monitor) { return Status.OK_STATUS; } - protected IStatus completeOperand(IProfile profile, Operand operand, Map parameters, IProgressMonitor monitor) { + protected IStatus completeOperand(IProfile profile, Operand operand, Map<String, Object> parameters, IProgressMonitor monitor) { InstallableUnitOperand iuOperand = (InstallableUnitOperand) operand; MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); @@ -63,11 +65,11 @@ public abstract class InstallableUnitPhase extends Phase { return status; } - protected IStatus completeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) { + protected IStatus completeOperand(IProfile profile, InstallableUnitOperand operand, Map<String, Object> parameters, IProgressMonitor monitor) { return Status.OK_STATUS; } - final protected ProvisioningAction[] getActions(Operand operand) { + final protected List<ProvisioningAction> getActions(Operand operand) { if (!(operand instanceof InstallableUnitOperand)) return null; @@ -75,7 +77,7 @@ public abstract class InstallableUnitPhase extends Phase { return getActions(iuOperand); } - protected abstract ProvisioningAction[] getActions(InstallableUnitOperand operand); + protected abstract List<ProvisioningAction> getActions(InstallableUnitOperand operand); final public boolean isApplicable(Operand operand) { if (!(operand instanceof InstallableUnitOperand)) @@ -89,32 +91,32 @@ public abstract class InstallableUnitPhase extends Phase { return true; } - protected final ProvisioningAction[] getActions(IInstallableUnit unit, String key) { - ITouchpointInstruction[] instructions = getInstructions(unit, key); - if (instructions == null || instructions.length == 0) + protected final List<ProvisioningAction> getActions(IInstallableUnit unit, String key) { + List<ITouchpointInstruction> instructions = getInstructions(unit, key); + int instrSize = instructions.size(); + if (instrSize == 0) return null; - List actions = new ArrayList(); + List<ProvisioningAction> actions = new ArrayList<ProvisioningAction>(); InstructionParser instructionParser = new InstructionParser(getActionManager()); - for (int i = 0; i < instructions.length; i++) { - actions.addAll(Arrays.asList(instructionParser.parseActions(instructions[i], unit.getTouchpointType()))); + for (int i = 0; i < instrSize; i++) { + actions.addAll(instructionParser.parseActions(instructions.get(i), unit.getTouchpointType())); } - return (ProvisioningAction[]) actions.toArray(new ProvisioningAction[actions.size()]); + return actions; } - private final static ITouchpointInstruction[] getInstructions(IInstallableUnit unit, String key) { - ITouchpointData[] data = unit.getTouchpointData(); - if (data == null) - return null; + private final static List<ITouchpointInstruction> getInstructions(IInstallableUnit unit, String key) { + List<ITouchpointData> data = unit.getTouchpointData(); + int dataSize = data.size(); + if (dataSize == 0) + return CollectionUtils.emptyList(); - ArrayList matches = new ArrayList(data.length); - for (int i = 0; i < data.length; i++) { - ITouchpointInstruction instructions = data[i].getInstruction(key); + ArrayList<ITouchpointInstruction> matches = new ArrayList<ITouchpointInstruction>(dataSize); + for (int i = 0; i < dataSize; i++) { + ITouchpointInstruction instructions = data.get(i).getInstruction(key); if (instructions != null) matches.add(instructions); } - - ITouchpointInstruction[] result = (ITouchpointInstruction[]) matches.toArray(new ITouchpointInstruction[matches.size()]); - return result; + return matches; } } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/InstructionParser.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/InstructionParser.java index 19560ef9c..c84dd4719 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/InstructionParser.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/InstructionParser.java @@ -10,14 +10,12 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.engine; -import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange; - import java.util.*; import org.eclipse.core.runtime.Assert; -import org.eclipse.equinox.internal.provisional.p2.engine.MissingAction; -import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction; -import org.eclipse.equinox.internal.provisional.p2.metadata.ITouchpointInstruction; -import org.eclipse.equinox.internal.provisional.p2.metadata.ITouchpointType; +import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils; +import org.eclipse.equinox.p2.engine.MissingAction; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.metadata.*; import org.eclipse.osgi.util.NLS; public class InstructionParser { @@ -41,22 +39,21 @@ public class InstructionParser { this.actionManager = actionManager; } - public ProvisioningAction[] parseActions(ITouchpointInstruction instruction, ITouchpointType touchpointType) { - List actions = new ArrayList(); - Map importMap = parseImportAttribute(instruction.getImportAttribute()); + public List<ProvisioningAction> parseActions(ITouchpointInstruction instruction, ITouchpointType touchpointType) { + List<ProvisioningAction> actions = new ArrayList<ProvisioningAction>(); + Map<String, ActionEntry> importMap = parseImportAttribute(instruction.getImportAttribute()); StringTokenizer tokenizer = new StringTokenizer(instruction.getBody(), ";"); //$NON-NLS-1$ while (tokenizer.hasMoreTokens()) { actions.add(parseAction(tokenizer.nextToken(), importMap, touchpointType)); } - - return (ProvisioningAction[]) actions.toArray(new ProvisioningAction[actions.size()]); + return actions; } - private Map parseImportAttribute(String importAttribute) { + private Map<String, ActionEntry> parseImportAttribute(String importAttribute) { if (importAttribute == null) - return Collections.EMPTY_MAP; + return CollectionUtils.emptyMap(); - Map result = new HashMap(); + Map<String, ActionEntry> result = new HashMap<String, ActionEntry>(); StringTokenizer tokenizer = new StringTokenizer(importAttribute, ","); //$NON-NLS-1$ while (tokenizer.hasMoreTokens()) { StringTokenizer actionTokenizer = new StringTokenizer(tokenizer.nextToken(), ";"); //$NON-NLS-1$ @@ -75,7 +72,7 @@ public class InstructionParser { return result; } - private ProvisioningAction parseAction(String statement, Map qualifier, ITouchpointType touchpointType) { + private ProvisioningAction parseAction(String statement, Map<String, ActionEntry> qualifier, ITouchpointType touchpointType) { int openBracket = statement.indexOf('('); int closeBracket = statement.lastIndexOf(')'); if (openBracket == -1 || closeBracket == -1 || openBracket > closeBracket) @@ -87,10 +84,10 @@ public class InstructionParser { String nameValuePairs = statement.substring(openBracket + 1, closeBracket); if (nameValuePairs.length() == 0) - return new ParameterizedProvisioningAction(action, Collections.EMPTY_MAP, statement); + return new ParameterizedProvisioningAction(action, CollectionUtils.<String, String> emptyMap(), statement); StringTokenizer tokenizer = new StringTokenizer(nameValuePairs, ","); //$NON-NLS-1$ - Map parameters = new HashMap(); + Map<String, String> parameters = new HashMap<String, String>(); while (tokenizer.hasMoreTokens()) { String nameValuePair = tokenizer.nextToken(); int colonIndex = nameValuePair.indexOf(":"); //$NON-NLS-1$ @@ -103,9 +100,9 @@ public class InstructionParser { return new ParameterizedProvisioningAction(action, parameters, statement); } - private ProvisioningAction lookupAction(String actionId, Map importMap, ITouchpointType touchpointType) { + private ProvisioningAction lookupAction(String actionId, Map<String, ActionEntry> importMap, ITouchpointType touchpointType) { VersionRange versionRange = null; - ActionEntry actionEntry = (ActionEntry) importMap.get(actionId); + ActionEntry actionEntry = importMap.get(actionId); if (actionEntry != null) { actionId = actionEntry.actionId; versionRange = actionEntry.versionRange; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Messages.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Messages.java index 77be0e226..fbdf962fe 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Messages.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Messages.java @@ -12,46 +12,98 @@ package org.eclipse.equinox.internal.p2.engine; import org.eclipse.osgi.util.NLS; -class Messages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.p2.engine.messages"; //$NON-NLS-1$ +public class Messages extends NLS { + public static String action_not_found; + + public static String action_syntax_error; + public static String action_undo_error; public static String ActionManager_Exception_Creating_Action_Extension; public static String ActionManager_Required_Touchpoint_Not_Found; + + public static String actions_not_found; + private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.p2.engine.messages"; //$NON-NLS-1$ + + public static String CertificateChecker_CertificateError; + public static String CertificateChecker_CertificateRejected; + public static String CertificateChecker_KeystoreConnectionError; + + public static String CertificateChecker_SignedContentError; + public static String CertificateChecker_SignedContentIOError; + public static String CertificateChecker_UnsignedNotAllowed; + + public static String committing; public static String download_artifact; public static String download_no_repository; - + public static String Engine_Operation_Canceled_By_User; public static String error_parsing_profile; - public static String error_persisting_profile; + public static String forced_action_execute_error; + public static String InstallableUnitEvent_type_not_install_or_uninstall; + public static String io_FailedRead; + public static String io_NotFound; + public static String not_current_operand; + public static String not_current_phase; + public static String null_action; - public static String ParameterizedProvisioningAction_action_or_parameters_null; + public static String null_operand; + public static String null_operands; + public static String null_phase; + public static String null_phases; + public static String null_phaseset; + public static String null_profile; + public static String operand_not_started; - public static String profile_does_not_exist; + public static String operand_started; + public static String ParameterizedProvisioningAction_action_or_parameters_null; + public static String phase_error; + public static String phase_not_started; + public static String phase_started; + public static String phase_undo_error; + public static String phase_undo_operand_error; + + public static String Phase_Collect_Error; + public static String Phase_Install_Error; + public static String Phase_Configure_Error; + public static String Phase_Configure_Task; + public static String Phase_Install_Task; + public static String Phase_Sizing_Error; + public static String Phase_Sizing_Warning; + public static String Phase_Unconfigure_Error; + public static String Phase_Uninstall_Error; + + public static String phaseid_not_positive; + public static String phaseid_not_set; + public static String preparing; + public static String profile_does_not_exist; + public static String Profile_Duplicate_Root_Profile_Id; + public static String profile_lock_not_reentrant; public static String profile_not_current; - public static String profile_not_registered; - - public static String Profile_Duplicate_Root_Profile_Id; public static String Profile_Null_Profile_Id; public static String Profile_Parent_Not_Found; - public static String ProfilePreferences_saving; - public static String reg_dir_not_available; + public static String rollingback_cancel; + public static String rollingback_error; + public static String session_commit_error; + public static String session_context; + public static String session_prepare_error; + public static String shared_profile_not_found; + public static String SimpleProfileRegistry_Bad_profile_location; + public static String SimpleProfileRegistry_CannotRemoveCurrentSnapshot; public static String SimpleProfileRegistry_Parser_Error_Parsing_Registry; public static String SimpleProfileRegistry_Parser_Has_Incompatible_Version; - public static String SimpleProfileRegistry_Profile_in_use; public static String SimpleProfileRegistry_Profile_not_locked; public static String SimpleProfileRegistry_Profile_not_locked_due_to_exception; - public static String SimpleProfileRegistry_Bad_profile_location; - - public static String SimpleProfileRegistry_CannotRemoveCurrentSnapshot; public static String thread_not_owner; - public static String profile_lock_not_reentrant; + public static String touchpoint_commit_error; + public static String touchpoint_prepare_error; + public static String touchpoint_rollback_error; public static String TouchpointManager_Attribute_Not_Specified; public static String TouchpointManager_Conflicting_Touchpoint_Types; @@ -59,12 +111,6 @@ class Messages extends NLS { public static String TouchpointManager_Incorrectly_Named_Extension; public static String TouchpointManager_Null_Creating_Touchpoint_Extension; public static String TouchpointManager_Null_Touchpoint_Type_Argument; - public static String shared_profile_not_found; - public static String action_syntax_error; - - public static String io_FailedRead; - - public static String io_NotFound; static { // initialize resource bundles diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ParameterizedProvisioningAction.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ParameterizedProvisioningAction.java index 3005e2290..0b73128fa 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ParameterizedProvisioningAction.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ParameterizedProvisioningAction.java @@ -13,16 +13,16 @@ package org.eclipse.equinox.internal.p2.engine; import java.util.*; import java.util.Map.Entry; import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction; -import org.eclipse.equinox.internal.provisional.p2.engine.Touchpoint; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.engine.spi.Touchpoint; public class ParameterizedProvisioningAction extends ProvisioningAction { private ProvisioningAction action; - private Map actionParameters; + private Map<String, String> actionParameters; private String actionText; - public ParameterizedProvisioningAction(ProvisioningAction action, Map actionParameters, String actionText) { + public ParameterizedProvisioningAction(ProvisioningAction action, Map<String, String> actionParameters, String actionText) { if (action == null || actionParameters == null) throw new IllegalArgumentException(Messages.ParameterizedProvisioningAction_action_or_parameters_null); this.action = action; @@ -30,28 +30,27 @@ public class ParameterizedProvisioningAction extends ProvisioningAction { this.actionText = actionText; } - public IStatus execute(Map parameters) { + public IStatus execute(Map<String, Object> parameters) { parameters = processActionParameters(parameters); return action.execute(parameters); } - public IStatus undo(Map parameters) { + public IStatus undo(Map<String, Object> parameters) { parameters = processActionParameters(parameters); return action.undo(parameters); } - private Map processActionParameters(Map parameters) { - Map result = new HashMap(parameters); - for (Iterator it = actionParameters.entrySet().iterator(); it.hasNext();) { - Entry entry = (Entry) it.next(); - String name = (String) entry.getKey(); - String value = processVariables((String) entry.getValue(), parameters); + private Map<String, Object> processActionParameters(Map<String, Object> parameters) { + Map<String, Object> result = new HashMap<String, Object>(parameters); + for (Entry<String, String> entry : actionParameters.entrySet()) { + String name = entry.getKey(); + String value = processVariables(entry.getValue(), parameters); result.put(name, value); } return Collections.unmodifiableMap(result); } - private String processVariables(String parameterValue, Map parameters) { + private String processVariables(String parameterValue, Map<String, Object> parameters) { int variableBeginIndex = parameterValue.indexOf("${"); //$NON-NLS-1$ if (variableBeginIndex == -1) @@ -85,7 +84,7 @@ public class ParameterizedProvisioningAction extends ProvisioningAction { return action; } - public Map getParameters() { + public Map<String, String> getParameters() { return actionParameters; } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/Phase.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Phase.java index 1262df290..88b3cb0d5 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/Phase.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Phase.java @@ -8,14 +8,15 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.internal.p2.engine; import java.util.*; import java.util.Map.Entry; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.p2.engine.ActionManager; -import org.eclipse.equinox.internal.p2.engine.EngineActivator; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.engine.spi.Touchpoint; import org.eclipse.osgi.util.NLS; public abstract class Phase { @@ -24,6 +25,10 @@ public abstract class Phase { protected static final String PARM_PROFILE = "profile"; //$NON-NLS-1$ protected static final String PARM_PROFILE_DATA_DIRECTORY = "profileDataDirectory"; //$NON-NLS-1$ protected static final String PARM_CONTEXT = "context"; //$NON-NLS-1$ + /** + * Internal property. + */ + protected static final String PARM_AGENT = "agent"; //$NON-NLS-1$ protected static final String PARM_FORCED = "forced"; //$NON-NLS-1$ protected static final String PARM_TOUCHPOINT = "touchpoint"; //$NON-NLS-1$ @@ -33,10 +38,10 @@ public abstract class Phase { protected int prePerformWork = 1000; protected int mainPerformWork = 10000; protected int postPerformWork = 1000; - private Map operandParameters = null; - private Map phaseParameters = new HashMap(); - private Map touchpointToTouchpointPhaseParameters = new HashMap(); - private Map touchpointToTouchpointOperandParameters = new HashMap(); + private Map<String, Object> operandParameters = null; + private Map<String, Object> phaseParameters = new HashMap<String, Object>(); + private Map<Touchpoint, Map<String, Object>> touchpointToTouchpointPhaseParameters = new HashMap<Touchpoint, Map<String, Object>>(); + private Map<Touchpoint, Map<String, Object>> touchpointToTouchpointOperandParameters = new HashMap<Touchpoint, Map<String, Object>>(); ActionManager actionManager; // injected from phaseset protected Phase(String phaseId, int weight, boolean forced) { @@ -61,22 +66,22 @@ public abstract class Phase { return getClass().getName() + " - " + this.weight; //$NON-NLS-1$ } - public final void perform(MultiStatus status, EngineSession session, IProfile profile, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor) { + void perform(MultiStatus status, EngineSession session, Operand[] operands, IProgressMonitor monitor) { SubMonitor subMonitor = SubMonitor.convert(monitor, prePerformWork + mainPerformWork + postPerformWork); session.recordPhaseEnter(this); - prePerform(status, session, profile, context, subMonitor.newChild(prePerformWork)); + prePerform(status, session, subMonitor.newChild(prePerformWork)); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; session.recordPhaseStart(this); subMonitor.setWorkRemaining(mainPerformWork + postPerformWork); - mainPerform(status, session, profile, operands, context, subMonitor.newChild(mainPerformWork)); + mainPerform(status, session, operands, subMonitor.newChild(mainPerformWork)); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; session.recordPhaseEnd(this); subMonitor.setWorkRemaining(postPerformWork); - postPerform(status, profile, context, subMonitor.newChild(postPerformWork)); + postPerform(status, session, subMonitor.newChild(postPerformWork)); phaseParameters.clear(); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; @@ -84,16 +89,19 @@ public abstract class Phase { subMonitor.done(); } - void prePerform(MultiStatus status, EngineSession session, IProfile profile, ProvisioningContext context, IProgressMonitor monitor) { + void prePerform(MultiStatus status, EngineSession session, IProgressMonitor monitor) { + IProfile profile = session.getProfile(); phaseParameters.put(PARM_PROFILE, profile); phaseParameters.put(PARM_PROFILE_DATA_DIRECTORY, session.getProfileDataDirectory()); - phaseParameters.put(PARM_CONTEXT, context); + phaseParameters.put(PARM_CONTEXT, session.getProvisioningContext()); phaseParameters.put(PARM_PHASE_ID, phaseId); phaseParameters.put(PARM_FORCED, Boolean.toString(forced)); + phaseParameters.put(PARM_AGENT, session.getAgent()); mergeStatus(status, initializePhase(monitor, profile, phaseParameters)); } - private void mainPerform(MultiStatus status, EngineSession session, IProfile profile, Operand[] operands, ProvisioningContext context, SubMonitor subMonitor) { + private void mainPerform(MultiStatus status, EngineSession session, Operand[] operands, SubMonitor subMonitor) { + IProfile profile = session.getProfile(); subMonitor.beginTask("", operands.length); //$NON-NLS-1$ for (int i = 0; i < operands.length; i++) { subMonitor.setWorkRemaining(operands.length - i); @@ -104,8 +112,8 @@ public abstract class Phase { continue; session.recordOperandStart(operand); - ProvisioningAction[] actions = getActions(operand); - operandParameters = new HashMap(phaseParameters); + List<ProvisioningAction> actions = getActions(operand); + operandParameters = new HashMap<String, Object>(phaseParameters); operandParameters.put(PARM_OPERAND, operand); mergeStatus(status, initializeOperand(profile, operand, operandParameters, subMonitor)); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) { @@ -119,21 +127,21 @@ public abstract class Phase { if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; - operandParameters = (Map) touchpointToTouchpointOperandParameters.get(operandTouchpoint); + operandParameters = touchpointToTouchpointOperandParameters.get(operandTouchpoint); } operandParameters = Collections.unmodifiableMap(operandParameters); if (actions != null) { - for (int j = 0; j < actions.length; j++) { - ProvisioningAction action = actions[j]; - Map parameters = operandParameters; + for (int j = 0; j < actions.size(); j++) { + ProvisioningAction action = actions.get(j); + Map<String, Object> parameters = operandParameters; Touchpoint touchpoint = action.getTouchpoint(); if (touchpoint != null) { mergeStatus(status, initializeTouchpointParameters(profile, operand, touchpoint, subMonitor)); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; - parameters = (Map) touchpointToTouchpointOperandParameters.get(touchpoint); + parameters = touchpointToTouchpointOperandParameters.get(touchpoint); } IStatus actionStatus = null; try { @@ -176,16 +184,16 @@ public abstract class Phase { if (touchpointToTouchpointOperandParameters.containsKey(touchpoint)) return Status.OK_STATUS; - Map touchpointPhaseParameters = (Map) touchpointToTouchpointPhaseParameters.get(touchpoint); + Map<String, Object> touchpointPhaseParameters = touchpointToTouchpointPhaseParameters.get(touchpoint); if (touchpointPhaseParameters == null) { - touchpointPhaseParameters = new HashMap(phaseParameters); + touchpointPhaseParameters = new HashMap<String, Object>(phaseParameters); IStatus status = touchpoint.initializePhase(monitor, profile, phaseId, touchpointPhaseParameters); if (status != null && status.matches(IStatus.ERROR | IStatus.CANCEL)) return status; touchpointToTouchpointPhaseParameters.put(touchpoint, touchpointPhaseParameters); } - Map touchpointOperandParameters = new HashMap(touchpointPhaseParameters); + Map<String, Object> touchpointOperandParameters = new HashMap<String, Object>(touchpointPhaseParameters); touchpointOperandParameters.putAll(operandParameters); IStatus status = touchpoint.initializeOperand(profile, operand, touchpointOperandParameters); if (status != null && status.matches(IStatus.ERROR | IStatus.CANCEL)) @@ -202,14 +210,15 @@ public abstract class Phase { multi.merge(status); } - void postPerform(MultiStatus status, IProfile profile, ProvisioningContext context, IProgressMonitor monitor) { + void postPerform(MultiStatus status, EngineSession session, IProgressMonitor monitor) { + IProfile profile = session.getProfile(); mergeStatus(status, touchpointCompletePhase(monitor, profile, phaseParameters)); mergeStatus(status, completePhase(monitor, profile, phaseParameters)); } void undo(MultiStatus status, EngineSession session, IProfile profile, Operand operand, ProvisioningAction[] actions, ProvisioningContext context) { if (operandParameters == null) { - operandParameters = new HashMap(phaseParameters); + operandParameters = new HashMap<String, Object>(phaseParameters); operandParameters.put(PARM_OPERAND, operand); mergeStatus(status, initializeOperand(profile, operand, operandParameters, new NullProgressMonitor())); Touchpoint operandTouchpoint = (Touchpoint) operandParameters.get(PARM_TOUCHPOINT); @@ -218,20 +227,20 @@ public abstract class Phase { if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; - operandParameters = (Map) touchpointToTouchpointOperandParameters.get(operandTouchpoint); + operandParameters = touchpointToTouchpointOperandParameters.get(operandTouchpoint); } operandParameters = Collections.unmodifiableMap(operandParameters); } for (int j = 0; j < actions.length; j++) { ProvisioningAction action = actions[j]; - Map parameters = operandParameters; + Map<String, Object> parameters = operandParameters; Touchpoint touchpoint = action.getTouchpoint(); if (touchpoint != null) { mergeStatus(status, initializeTouchpointParameters(profile, operand, touchpoint, new NullProgressMonitor())); if (status.matches(IStatus.ERROR)) return; - parameters = (Map) touchpointToTouchpointOperandParameters.get(touchpoint); + parameters = touchpointToTouchpointOperandParameters.get(touchpoint); } IStatus actionStatus = null; try { @@ -260,53 +269,51 @@ public abstract class Phase { return true; } - protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { + protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) { return Status.OK_STATUS; } - protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { + protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) { return Status.OK_STATUS; } - IStatus touchpointCompletePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { + IStatus touchpointCompletePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) { if (touchpointToTouchpointPhaseParameters.isEmpty()) return Status.OK_STATUS; MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); - for (Iterator it = touchpointToTouchpointPhaseParameters.entrySet().iterator(); it.hasNext();) { - Entry entry = (Entry) it.next(); - Touchpoint touchpoint = (Touchpoint) entry.getKey(); - Map touchpointParameters = (Map) entry.getValue(); + for (Entry<Touchpoint, Map<String, Object>> entry : touchpointToTouchpointPhaseParameters.entrySet()) { + Touchpoint touchpoint = entry.getKey(); + Map<String, Object> touchpointParameters = entry.getValue(); mergeStatus(status, touchpoint.completePhase(monitor, profile, phaseId, touchpointParameters)); } touchpointToTouchpointPhaseParameters.clear(); return status; } - protected IStatus completeOperand(IProfile profile, Operand operand, Map parameters, IProgressMonitor monitor) { + protected IStatus completeOperand(IProfile profile, Operand operand, Map<String, Object> parameters, IProgressMonitor monitor) { return Status.OK_STATUS; } - IStatus touchpointCompleteOperand(IProfile profile, Operand operand, Map parameters, IProgressMonitor monitor) { + IStatus touchpointCompleteOperand(IProfile profile, Operand operand, Map<String, Object> parameters, IProgressMonitor monitor) { if (touchpointToTouchpointOperandParameters.isEmpty()) return Status.OK_STATUS; MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); - for (Iterator it = touchpointToTouchpointOperandParameters.entrySet().iterator(); it.hasNext();) { - Entry entry = (Entry) it.next(); - Touchpoint touchpoint = (Touchpoint) entry.getKey(); - Map touchpointParameters = (Map) entry.getValue(); + for (Entry<Touchpoint, Map<String, Object>> entry : touchpointToTouchpointOperandParameters.entrySet()) { + Touchpoint touchpoint = entry.getKey(); + Map<String, Object> touchpointParameters = entry.getValue(); mergeStatus(status, touchpoint.completeOperand(profile, operand, touchpointParameters)); } touchpointToTouchpointOperandParameters.clear(); return status; } - protected IStatus initializeOperand(IProfile profile, Operand operand, Map parameters, IProgressMonitor monitor) { + protected IStatus initializeOperand(IProfile profile, Operand operand, Map<String, Object> parameters, IProgressMonitor monitor) { return Status.OK_STATUS; } - protected abstract ProvisioningAction[] getActions(Operand operand); + protected abstract List<ProvisioningAction> getActions(Operand operand); /** * Returns a human-readable message to be displayed in case of an error performing diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/PhaseSet.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/PhaseSet.java index 2c24a2fb0..e215cc820 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/PhaseSet.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/PhaseSet.java @@ -8,18 +8,55 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.internal.p2.engine; -import java.util.HashSet; -import java.util.Set; +import java.util.*; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.p2.engine.ActionManager; -import org.eclipse.equinox.internal.p2.engine.EngineActivator; +import org.eclipse.equinox.internal.p2.engine.phases.*; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; import org.eclipse.osgi.util.NLS; -public abstract class PhaseSet { +public class PhaseSet implements IPhaseSet { + + public static final List<String> DEFAULT_PHASES = Arrays.asList(new String[] {IPhaseSet.PHASE_COLLECT, IPhaseSet.PHASE_UNCONFIGURE, IPhaseSet.PHASE_UNINSTALL, IPhaseSet.PHASE_PROPERTY, IPhaseSet.PHASE_CHECK_TRUST, IPhaseSet.PHASE_INSTALL, IPhaseSet.PHASE_CONFIGURE}); + + public static final boolean forcedUninstall = Boolean.valueOf(EngineActivator.getContext().getProperty("org.eclipse.equinox.p2.engine.forcedUninstall")).booleanValue(); //$NON-NLS-1$ + private final Phase[] phases; + public static IPhaseSet createPhaseSetExcluding(String[] excludes) { + ArrayList<String> phases = new ArrayList<String>(DEFAULT_PHASES); + if (excludes != null) { + for (int i = 0; i < excludes.length; i++) { + phases.remove(excludes[i]); + } + } + return createPhaseSetIncluding(phases.toArray(new String[phases.size()])); + } + + public static IPhaseSet createPhaseSetIncluding(String[] includes) { + ArrayList<Phase> phases = new ArrayList<Phase>(); + for (int i = 0; i < includes.length; i++) { + String current = includes[i]; + if (current.equals(IPhaseSet.PHASE_CONFIGURE)) + phases.add(new Configure(10)); + else if (current.equals(IPhaseSet.PHASE_CHECK_TRUST)) + phases.add(new CheckTrust(10)); + else if (current.equals(IPhaseSet.PHASE_COLLECT)) + phases.add(new Collect(100)); + else if (current.equals(IPhaseSet.PHASE_INSTALL)) + phases.add(new Install(50)); + else if (current.equals(IPhaseSet.PHASE_PROPERTY)) + phases.add(new Property(1)); + else if (current.equals(IPhaseSet.PHASE_UNCONFIGURE)) + phases.add(new Unconfigure(10, forcedUninstall)); + else if (current.equals(IPhaseSet.PHASE_UNINSTALL)) + phases.add(new Uninstall(50, forcedUninstall)); + } + return new PhaseSet(phases.toArray(new Phase[phases.size()])); + } + public PhaseSet(Phase[] phases) { if (phases == null) throw new IllegalArgumentException(Messages.null_phases); @@ -27,7 +64,7 @@ public abstract class PhaseSet { this.phases = phases; } - public final MultiStatus perform(ActionManager actionManager, EngineSession session, IProfile profile, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor) { + public final MultiStatus perform(EngineSession session, Operand[] operands, IProgressMonitor monitor) { MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); int[] weights = getProgressWeights(operands); int totalWork = getTotalWork(weights); @@ -39,9 +76,9 @@ public abstract class PhaseSet { return status; } Phase phase = phases[i]; - phase.actionManager = actionManager; + phase.actionManager = (ActionManager) session.getAgent().getService(ActionManager.SERVICE_NAME); try { - phase.perform(status, session, profile, operands, context, pm.newChild(weights[i])); + phase.perform(status, session, operands, pm.newChild(weights[i])); } catch (OperationCanceledException e) { // propagate operation cancellation status.add(new Status(IStatus.CANCEL, EngineActivator.ID, e.getMessage(), e)); @@ -73,7 +110,7 @@ public abstract class PhaseSet { } public final IStatus validate(ActionManager actionManager, IProfile profile, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor) { - Set missingActions = new HashSet(); + Set<MissingAction> missingActions = new HashSet<MissingAction>(); for (int i = 0; i < phases.length; i++) { Phase phase = phases[i]; phase.actionManager = actionManager; @@ -84,13 +121,13 @@ public abstract class PhaseSet { if (!phase.isApplicable(operand)) continue; - ProvisioningAction[] actions = phase.getActions(operand); + List<ProvisioningAction> actions = phase.getActions(operand); if (actions == null) continue; - for (int k = 0; k < actions.length; k++) { - ProvisioningAction action = actions[k]; + for (int k = 0; k < actions.size(); k++) { + ProvisioningAction action = actions.get(k); if (action instanceof MissingAction) - missingActions.add(action); + missingActions.add((MissingAction) action); } } catch (RuntimeException e) { // "perform" calls user code and might throw an unchecked exception @@ -106,7 +143,7 @@ public abstract class PhaseSet { } } if (!missingActions.isEmpty()) { - MissingAction[] missingActionsArray = (MissingAction[]) missingActions.toArray(new MissingAction[missingActions.size()]); + MissingAction[] missingActionsArray = missingActions.toArray(new MissingAction[missingActions.size()]); MissingActionsException exception = new MissingActionsException(missingActionsArray); return (new Status(IStatus.ERROR, EngineActivator.ID, exception.getMessage(), exception)); } @@ -145,6 +182,14 @@ public abstract class PhaseSet { return count; } + public String[] getPhaseIds() { + String[] ids = new String[phases.length]; + for (int i = 0; i < ids.length; i++) { + ids[i] = phases[i].phaseId; + } + return ids; + } + public Phase[] getPhases() { return phases; } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Profile.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Profile.java index 46261ff7a..6e08b69c0 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Profile.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Profile.java @@ -11,13 +11,17 @@ package org.eclipse.equinox.internal.p2.engine; import java.util.*; import java.util.Map.Entry; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils; import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; -import org.eclipse.equinox.internal.provisional.p2.engine.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.*; +import org.eclipse.equinox.p2.engine.IProfile; +import org.eclipse.equinox.p2.engine.ISurrogateProfileHandler; +import org.eclipse.equinox.p2.engine.query.IUProfilePropertyQuery; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.query.*; import org.eclipse.osgi.util.NLS; -public class Profile implements IQueryable, IProfile { +public class Profile implements IProfile { //Internal id of the profile private final String profileId; @@ -27,22 +31,21 @@ public class Profile implements IQueryable, IProfile { /** * A collection of child profiles. */ - private List subProfileIds; // child profile ids + private List<String> subProfileIds; // child profile ids - private static final String[] noSubProfiles = new String[0]; /** * This storage is to be used by the touchpoints to store data. */ private OrderedProperties storage = new OrderedProperties(); - private Set ius = new HashSet(); - private Map iuProperties = new HashMap(); + private Set<IInstallableUnit> ius = new HashSet<IInstallableUnit>(); + private Map<IInstallableUnit, OrderedProperties> iuProperties = new HashMap<IInstallableUnit, OrderedProperties>(); private boolean changed = false; private long timestamp; private ISurrogateProfileHandler surrogateProfileHandler; - public Profile(String profileId, Profile parent, Map properties) { + public Profile(String profileId, Profile parent, Map<String, String> properties) { if (profileId == null || profileId.length() == 0) { throw new IllegalArgumentException(NLS.bind(Messages.Profile_Null_Profile_Id, null)); } @@ -91,7 +94,7 @@ public class Profile implements IQueryable, IProfile { public void addSubProfile(String subProfileId) throws IllegalArgumentException { if (subProfileIds == null) - subProfileIds = new ArrayList(); + subProfileIds = new ArrayList<String>(); if (!subProfileIds.contains(subProfileId)) subProfileIds.add(subProfileId); @@ -115,11 +118,10 @@ public class Profile implements IQueryable, IProfile { /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.engine.IProfile#getSubProfileIds() */ - public String[] getSubProfileIds() { + public List<String> getSubProfileIds() { if (subProfileIds == null) - return noSubProfiles; - - return (String[]) subProfileIds.toArray(new String[subProfileIds.size()]); + return CollectionUtils.emptyList(); + return Collections.unmodifiableList(subProfileIds); } /* (non-Javadoc) @@ -157,25 +159,39 @@ public class Profile implements IQueryable, IProfile { /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.engine.IProfile#query(org.eclipse.equinox.internal.provisional.p2.query.Query, org.eclipse.equinox.internal.provisional.p2.query.Collector, org.eclipse.core.runtime.IProgressMonitor) */ - public Collector query(Query query, Collector collector, IProgressMonitor monitor) { + public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor) { + propagateProfileContext(query); + if (query instanceof IUProfilePropertyQuery) { + return query.perform(iuProperties.keySet().iterator()); + } + return query.perform(ius.iterator()); + } + + private <T> void propagateProfileContext(IQuery<T> query) { + // FIXME if (query instanceof IUProfilePropertyQuery) { ((IUProfilePropertyQuery) query).setProfile(this); - return query.perform(iuProperties.keySet().iterator(), collector); + return; + } + if (query instanceof ICompositeQuery<?>) { + List<IQuery<T>> queries = ((ICompositeQuery<T>) query).getQueries(); + for (int i = 0; i < queries.size(); i++) { + propagateProfileContext(queries.get(i)); + } } - return query.perform(ius.iterator(), collector); } - public Collector available(Query query, Collector collector, IProgressMonitor monitor) { + public IQueryResult<IInstallableUnit> available(IQuery<IInstallableUnit> query, IProgressMonitor monitor) { if (surrogateProfileHandler != null) - return surrogateProfileHandler.queryProfile(this, query, collector, monitor); - return query(query, collector, monitor); + return surrogateProfileHandler.queryProfile(this, query, monitor); + return query(query, new NullProgressMonitor()); } /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.engine.IProfile#getInstallableUnitProperty(org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit, java.lang.String) */ public String getInstallableUnitProperty(IInstallableUnit iu, String key) { - OrderedProperties properties = (OrderedProperties) iuProperties.get(iu); + OrderedProperties properties = iuProperties.get(iu); if (properties == null) return null; @@ -184,7 +200,7 @@ public class Profile implements IQueryable, IProfile { public String setInstallableUnitProperty(IInstallableUnit iu, String key, String value) { // String iuKey = createIUKey(iu); - OrderedProperties properties = (OrderedProperties) iuProperties.get(iu); + OrderedProperties properties = iuProperties.get(iu); if (properties == null) { properties = new OrderedProperties(); iuProperties.put(iu, properties); @@ -196,11 +212,11 @@ public class Profile implements IQueryable, IProfile { public String removeInstallableUnitProperty(IInstallableUnit iu, String key) { // String iuKey = createIUKey(iu); - OrderedProperties properties = (OrderedProperties) iuProperties.get(iu); + OrderedProperties properties = iuProperties.get(iu); if (properties == null) return null; - String oldValue = (String) properties.remove(key); + String oldValue = properties.remove(key); if (properties.isEmpty()) iuProperties.remove(iu); @@ -215,18 +231,18 @@ public class Profile implements IQueryable, IProfile { /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.engine.IProfile#getLocalProperties() */ - public Map getLocalProperties() { + public Map<String, String> getLocalProperties() { return OrderedProperties.unmodifiableProperties(storage); } /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.engine.IProfile#getProperties() */ - public Map getProperties() { + public Map<String, String> getProperties() { if (parentProfile == null) return getLocalProperties(); - Map properties = new HashMap(parentProfile.getProperties()); + Map<String, String> properties = new HashMap<String, String>(parentProfile.getProperties()); properties.putAll(storage); return OrderedProperties.unmodifiableProperties(properties); } @@ -235,7 +251,7 @@ public class Profile implements IQueryable, IProfile { * Add all the properties in the map to the local properties * of the profile. */ - public void addProperties(Map properties) { + public void addProperties(Map<String, String> properties) { storage.putAll(properties); changed = true; } @@ -258,8 +274,8 @@ public class Profile implements IQueryable, IProfile { /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.engine.IProfile#getInstallableUnitProperties(org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit) */ - public Map getInstallableUnitProperties(IInstallableUnit iu) { - OrderedProperties properties = (OrderedProperties) iuProperties.get(iu); + public Map<String, String> getInstallableUnitProperties(IInstallableUnit iu) { + OrderedProperties properties = iuProperties.get(iu); if (properties == null) properties = new OrderedProperties(); @@ -296,16 +312,14 @@ public class Profile implements IQueryable, IProfile { snapshot.setTimestamp(timestamp); if (subProfileIds != null) { - for (Iterator it = subProfileIds.iterator(); it.hasNext();) { - String subProfileId = (String) it.next(); + for (String subProfileId : subProfileIds) { snapshot.addSubProfile(subProfileId); } } - for (Iterator it = ius.iterator(); it.hasNext();) { - IInstallableUnit iu = (IInstallableUnit) it.next(); + for (IInstallableUnit iu : ius) { snapshot.addInstallableUnit(iu); - Map properties = getInstallableUnitProperties(iu); + Map<String, String> properties = getInstallableUnitProperties(iu); if (properties != null) snapshot.addInstallableUnitProperties(iu, properties); } @@ -313,12 +327,9 @@ public class Profile implements IQueryable, IProfile { return snapshot; } - public void addInstallableUnitProperties(IInstallableUnit iu, Map properties) { - for (Iterator it = properties.entrySet().iterator(); it.hasNext();) { - Entry entry = (Entry) it.next(); - String key = (String) entry.getKey(); - String value = (String) entry.getValue(); - setInstallableUnitProperty(iu, key, value); + public void addInstallableUnitProperties(IInstallableUnit iu, Map<String, String> properties) { + for (Entry<String, String> entry : properties.entrySet()) { + setInstallableUnitProperty(iu, entry.getKey(), entry.getValue()); } } @@ -328,17 +339,16 @@ public class Profile implements IQueryable, IProfile { } public void clearOrphanedInstallableUnitProperties() { - Set keys = iuProperties.keySet(); + Set<IInstallableUnit> keys = iuProperties.keySet(); // Set orphans = new HashSet(); - Collection toRemove = new ArrayList(); - for (Iterator iterator = keys.iterator(); iterator.hasNext();) { - Object iu = iterator.next(); + Collection<IInstallableUnit> toRemove = new ArrayList<IInstallableUnit>(); + for (IInstallableUnit iu : keys) { if (!ius.contains(iu)) toRemove.add(iu); } - for (Iterator iterator = toRemove.iterator(); iterator.hasNext();) { - iuProperties.remove(iterator.next()); + for (IInstallableUnit iu : toRemove) { + iuProperties.remove(iu); } // List iuKeys = new ArrayList(); // for (Iterator it = ius.iterator(); it.hasNext();) @@ -358,4 +368,11 @@ public class Profile implements IQueryable, IProfile { public void setSurrogateProfileHandler(ISurrogateProfileHandler surrogateProfileHandler) { this.surrogateProfileHandler = surrogateProfileHandler; } + + /** + * Prints a string representation for debugging purposes only. + */ + public String toString() { + return "Profile(" + getProfileId() + ')'; //$NON-NLS-1$ + } } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileMetadataRepository.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileMetadataRepository.java index 20224db15..02e396f0b 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileMetadataRepository.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileMetadataRepository.java @@ -18,14 +18,15 @@ import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.metadata.repository.Activator; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; -import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.Query; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; import org.eclipse.equinox.internal.provisional.p2.repository.RepositoryEvent; -import org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.AbstractMetadataRepository; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.engine.IProfile; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.query.IQuery; +import org.eclipse.equinox.p2.query.IQueryResult; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.metadata.spi.AbstractMetadataRepository; import org.eclipse.osgi.util.NLS; public class ProfileMetadataRepository extends AbstractMetadataRepository { @@ -50,19 +51,18 @@ public class ProfileMetadataRepository extends AbstractMetadataRepository { } private void publishArtifactRepos() { - List artifactRepos = findArtifactRepos(); + List<URI> artifactRepos = findArtifactRepos(); IProvisioningEventBus bus = (IProvisioningEventBus) ServiceHelper.getService(EngineActivator.getContext(), IProvisioningEventBus.SERVICE_NAME); if (bus == null) return; - for (Iterator it = artifactRepos.iterator(); it.hasNext();) { - URI repo = (URI) it.next(); + for (URI repo : artifactRepos) { bus.publishEvent(new RepositoryEvent(repo, IRepository.TYPE_ARTIFACT, RepositoryEvent.DISCOVERED, true)); } } - private List findArtifactRepos() { - List artifactRepos = new ArrayList(); + private List<URI> findArtifactRepos() { + List<URI> artifactRepos = new ArrayList<URI>(); File p2Directory = findP2Directory(); // Add the profile registry's default agent artifact repository. @@ -155,8 +155,8 @@ public class ProfileMetadataRepository extends AbstractMetadataRepository { // nothing to do } - public Collector query(Query query, Collector collector, IProgressMonitor monitor) { - return profile.query(query, collector, monitor); + public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor) { + return profile.query(query, monitor); } public static void validate(URI location, IProgressMonitor monitor) throws ProvisionException { diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileMetadataRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileMetadataRepositoryFactory.java index 0b92907f3..1eba1a3d6 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileMetadataRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileMetadataRepositoryFactory.java @@ -13,10 +13,10 @@ package org.eclipse.equinox.internal.p2.engine; import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; -import org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.MetadataRepositoryFactory; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.repository.IRepositoryManager; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.metadata.spi.MetadataRepositoryFactory; public class ProfileMetadataRepositoryFactory extends MetadataRepositoryFactory { @@ -24,7 +24,7 @@ public class ProfileMetadataRepositoryFactory extends MetadataRepositoryFactory * @throws ProvisionException * documenting to avoid warning */ - public IMetadataRepository create(URI location, String name, String type, Map properties) throws ProvisionException { + public IMetadataRepository create(URI location, String name, String type, Map<String, String> properties) throws ProvisionException { return null; } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileParser.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileParser.java index d62dae1c2..0a6becaf6 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileParser.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileParser.java @@ -10,12 +10,11 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.engine; -import org.eclipse.equinox.internal.provisional.p2.metadata.Version; - import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.equinox.internal.p2.metadata.repository.io.MetadataParser; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.Version; import org.osgi.framework.BundleContext; import org.xml.sax.Attributes; @@ -97,7 +96,7 @@ public abstract class ProfileParser extends MetadataParser implements ProfileXML return 0; } - public Map getProperties() { + public Map<String, String> getProperties() { if (propertiesHandler == null) return null; return propertiesHandler.getProperties(); @@ -109,16 +108,16 @@ public abstract class ProfileParser extends MetadataParser implements ProfileXML return unitsHandler.getUnits(); } - public Map getIUProperties(IInstallableUnit iu) { + public Map<String, String> getIUProperties(IInstallableUnit iu) { if (iusPropertiesHandler == null) return null; - Map iusPropertiesMap = iusPropertiesHandler.getIUsPropertiesMap(); + Map<String, Map<String, String>> iusPropertiesMap = iusPropertiesHandler.getIUsPropertiesMap(); if (iusPropertiesMap == null) return null; String iuIdentity = iu.getId() + "_" + iu.getVersion().toString(); //$NON-NLS-1$ - return (Map) iusPropertiesMap.get(iuIdentity); + return iusPropertiesMap.get(iuIdentity); } } @@ -127,10 +126,10 @@ public abstract class ProfileParser extends MetadataParser implements ProfileXML private final String[] required = new String[] {ID_ATTRIBUTE, VERSION_ATTRIBUTE}; private String iuIdentity; - private Map iusPropertiesMap; + private Map<String, Map<String, String>> iusPropertiesMap; private PropertiesHandler propertiesHandler; - public IUPropertiesHandler(AbstractHandler parentHandler, Attributes attributes, Map iusPropertiesMap) { + public IUPropertiesHandler(AbstractHandler parentHandler, Attributes attributes, Map<String, Map<String, String>> iusPropertiesMap) { super(parentHandler, IU_PROPERTIES_ELEMENT); this.iusPropertiesMap = iusPropertiesMap; @@ -157,15 +156,16 @@ public abstract class ProfileParser extends MetadataParser implements ProfileXML protected class IUsPropertiesHandler extends AbstractHandler { - private Map iusPropertiesMap; + private Map<String, Map<String, String>> iusPropertiesMap; public IUsPropertiesHandler(AbstractHandler parentHandler, Attributes attributes) { super(parentHandler, IUS_PROPERTIES_ELEMENT); - String size = parseOptionalAttribute(attributes, COLLECTION_SIZE_ATTRIBUTE); - iusPropertiesMap = (size != null ? new LinkedHashMap(new Integer(size).intValue()) : new LinkedHashMap(4)); + String sizeStr = parseOptionalAttribute(attributes, COLLECTION_SIZE_ATTRIBUTE); + int size = (sizeStr != null ? new Integer(sizeStr).intValue() : 4); + iusPropertiesMap = new LinkedHashMap<String, Map<String, String>>(size); } - public Map getIUsPropertiesMap() { + public Map<String, Map<String, String>> getIUsPropertiesMap() { return iusPropertiesMap; } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java index 8c84e4031..362f9f289 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java @@ -17,10 +17,11 @@ import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.equinox.internal.p2.core.helpers.*; -import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; -import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; +import org.eclipse.equinox.p2.core.IAgentLocation; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.engine.IProfileRegistry; +import org.eclipse.equinox.security.storage.EncodingUtils; +import org.osgi.framework.*; import org.osgi.service.prefs.BackingStoreException; /** @@ -50,7 +51,7 @@ public class ProfilePreferences extends EclipsePreferences { } // cache which nodes have been loaded from disk - private static Set loadedNodes = Collections.synchronizedSet(new HashSet()); + private static Set<String> loadedNodes = Collections.synchronizedSet(new HashSet<String>()); public static final Object PROFILE_SAVE_JOB_FAMILY = new Object(); @@ -69,25 +70,26 @@ public class ProfilePreferences extends EclipsePreferences { public ProfilePreferences(EclipsePreferences nodeParent, String nodeName) { super(nodeParent, nodeName); + //path is /profile/{agent location}/{profile id}/qualifier // cache the segment count String path = absolutePath(); segmentCount = getSegmentCount(path); - if (segmentCount <= 1) + if (segmentCount <= 2) return; - if (segmentCount == 2) + if (segmentCount == 3) profileLock = new Object(); - if (segmentCount < 3) + if (segmentCount < 4) return; // cache the qualifier - qualifier = getSegment(path, 2); + qualifier = getSegment(path, 3); } - private boolean containsProfile(String profileId) { - IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(EngineActivator.getContext(), IProfileRegistry.class.getName()); + private boolean containsProfile(IProvisioningAgent agent, String profileId) { + IProfileRegistry profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME); if (profileId == null || profileRegistry == null) return false; return profileRegistry.containsProfile(profileId); @@ -99,22 +101,68 @@ public class ProfilePreferences extends EclipsePreferences { */ protected void doSave() throws BackingStoreException { synchronized (((ProfilePreferences) parent).profileLock) { - String profileId = getSegment(absolutePath(), 1); - if (!containsProfile(profileId)) { - //use the default location for the self profile, otherwise just do nothing and return - if (IProfileRegistry.SELF.equals(profileId)) { - IPath location = getDefaultLocation(); - if (location != null) { - super.save(location); - return; + ServiceReference agentRef = getAgent(getSegment(absolutePath(), 1)); + IProvisioningAgent agent = (IProvisioningAgent) EngineActivator.getContext().getService(agentRef); + try { + String profileId = getSegment(absolutePath(), 2); + if (!containsProfile(agent, profileId)) { + //use the default location for the self profile, otherwise just do nothing and return + if (IProfileRegistry.SELF.equals(profileId)) { + IPath location = getDefaultLocation(); + if (location != null) { + super.save(location); + return; + } } + if (Tracing.DEBUG_PROFILE_PREFERENCES) + Tracing.debug("Not saving preferences since there is no file for node: " + absolutePath()); //$NON-NLS-1$ + return; } - if (Tracing.DEBUG_PROFILE_PREFERENCES) - Tracing.debug("Not saving preferences since there is no file for node: " + absolutePath()); //$NON-NLS-1$ - return; + super.save(getProfileLocation(agent, profileId)); + } finally { + EngineActivator.getContext().ungetService(agentRef); + } + } + } + + /** + * Returns a reference to the agent service corresponding to the given encoded + * agent location. Never returns null; throws an exception if the agent could not be found. + */ + private ServiceReference getAgent(String segment) throws BackingStoreException { + String locationString = EncodingUtils.decodeSlashes(segment); + Exception failure = null; + try { + String filter = "(locationURI=" + encodeForFilter(locationString) + ')'; //$NON-NLS-1$ + ServiceReference[] refs = EngineActivator.getContext().getServiceReferences(IProvisioningAgent.SERVICE_NAME, filter); + if (refs != null && refs.length > 0) + return refs[0]; + } catch (InvalidSyntaxException e) { + failure = e; + } + throw new BackingStoreException("Unable to determine provisioning agent from location: " + segment, failure); //$NON-NLS-1$ + } + + /** + * Encodes a string so that it is suitable for use as a value for a filter property. + * Any reserved filter characters are escaped. + */ + private String encodeForFilter(String string) { + StringBuffer result = new StringBuffer(string.length()); + char[] input = string.toCharArray(); + for (int i = 0; i < input.length; i++) { + switch (input[i]) { + case '(' : + case ')' : + case '*' : + case '\\' : + result.append('\\'); + //fall through + default : + result.append(input[i]); } - super.save(getProfileLocation(profileId)); } + return result.toString(); } /** @@ -122,12 +170,12 @@ public class ProfilePreferences extends EclipsePreferences { */ private IPath getDefaultLocation() { //use engine agent location for preferences if there is no self profile - AgentLocation location = (AgentLocation) ServiceHelper.getService(EngineActivator.getContext(), AgentLocation.SERVICE_NAME); + IAgentLocation location = (IAgentLocation) ServiceHelper.getService(EngineActivator.getContext(), IAgentLocation.SERVICE_NAME); if (location == null) { LogHelper.log(new Status(IStatus.WARNING, EngineActivator.ID, "Agent location service not available", new RuntimeException())); //$NON-NLS-1$ return null; } - IPath dataArea = new Path(URLUtil.toFile(location.getDataArea(EngineActivator.ID)).getAbsolutePath()); + IPath dataArea = new Path(URIUtil.toFile(location.getDataArea(EngineActivator.ID)).getAbsolutePath()); return computeLocation(dataArea, qualifier); } @@ -139,7 +187,7 @@ public class ProfilePreferences extends EclipsePreferences { // Walk backwards up the tree starting at this node. // This is important to avoid a chicken/egg thing on startup. IEclipsePreferences node = this; - for (int i = 3; i < segmentCount; i++) + for (int i = 4; i < segmentCount; i++) node = (EclipsePreferences) node.parent(); loadLevel = node; } @@ -149,8 +197,8 @@ public class ProfilePreferences extends EclipsePreferences { /** * Returns the location of the preference file for the given profile. */ - private IPath getProfileLocation(String profileId) { - SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry) ServiceHelper.getService(EngineActivator.getContext(), IProfileRegistry.class.getName()); + private IPath getProfileLocation(IProvisioningAgent agent, String profileId) { + SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME); File profileDataDirectory = profileRegistry.getProfileDataDirectory(profileId); return computeLocation(new Path(profileDataDirectory.getAbsolutePath()), qualifier); } @@ -173,21 +221,27 @@ public class ProfilePreferences extends EclipsePreferences { */ protected void load() throws BackingStoreException { synchronized (((ProfilePreferences) parent).profileLock) { - String profileId = getSegment(absolutePath(), 1); - if (!containsProfile(profileId)) { - //use the default location for the self profile, otherwise just do nothing and return - if (IProfileRegistry.SELF.equals(profileId)) { - IPath location = getDefaultLocation(); - if (location != null) { - load(location); - return; + ServiceReference agentRef = getAgent(getSegment(absolutePath(), 1)); + IProvisioningAgent agent = (IProvisioningAgent) EngineActivator.getContext().getService(agentRef); + try { + String profileId = getSegment(absolutePath(), 2); + if (!containsProfile(agent, profileId)) { + //use the default location for the self profile, otherwise just do nothing and return + if (IProfileRegistry.SELF.equals(profileId)) { + IPath location = getDefaultLocation(); + if (location != null) { + load(location); + return; + } } + if (Tracing.DEBUG_PROFILE_PREFERENCES) + Tracing.debug("Not loading preferences since there is no file for node: " + absolutePath()); //$NON-NLS-1$ + return; } - if (Tracing.DEBUG_PROFILE_PREFERENCES) - Tracing.debug("Not loading preferences since there is no file for node: " + absolutePath()); //$NON-NLS-1$ - return; + load(getProfileLocation(agent, profileId)); + } finally { + EngineActivator.getContext().ungetService(agentRef); } - load(getProfileLocation(profileId)); } } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileRegistryComponent.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileRegistryComponent.java index 1e05b8a91..1870b5989 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileRegistryComponent.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileRegistryComponent.java @@ -11,10 +11,10 @@ package org.eclipse.equinox.internal.p2.engine; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; -import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; -import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry; +import org.eclipse.equinox.p2.core.IAgentLocation; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory; +import org.eclipse.equinox.p2.engine.IProfileRegistry; /** * Instantiates default instances of {@link IProfileRegistry}. @@ -22,7 +22,7 @@ import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory; public class ProfileRegistryComponent implements IAgentServiceFactory { public Object createService(IProvisioningAgent agent) { - AgentLocation location = (AgentLocation) agent.getService(AgentLocation.SERVICE_NAME); + IAgentLocation location = (IAgentLocation) agent.getService(IAgentLocation.SERVICE_NAME); SimpleProfileRegistry registry = new SimpleProfileRegistry(SimpleProfileRegistry.getDefaultRegistryDirectory(location)); registry.setEventBus((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)); return registry; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileWriter.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileWriter.java index 01d1d1e47..1af6717c4 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileWriter.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileWriter.java @@ -14,10 +14,9 @@ import java.io.IOException; import java.io.OutputStream; import java.util.*; import org.eclipse.equinox.internal.p2.metadata.repository.io.MetadataWriter; -import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.p2.engine.IProfile; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery; public class ProfileWriter extends MetadataWriter implements ProfileXMLConstants { @@ -29,16 +28,10 @@ public class ProfileWriter extends MetadataWriter implements ProfileXMLConstants start(PROFILE_ELEMENT); attribute(ID_ATTRIBUTE, profile.getProfileId()); attribute(TIMESTAMP_ATTRIBUTE, Long.toString(profile.getTimestamp())); - IProfile parentProfile = profile.getParentProfile(); - if (parentProfile != null) - attribute(PARENT_ID_ATTRIBUTE, parentProfile.getProfileId()); - writeProperties(profile.getLocalProperties()); - Collector collector = profile.query(InstallableUnitQuery.ANY, new Collector(), null); - ArrayList ius = new ArrayList(collector.toCollection()); - Collections.sort(ius, new Comparator() { - public int compare(Object o1, Object o2) { - IInstallableUnit iu1 = (IInstallableUnit) o1; - IInstallableUnit iu2 = (IInstallableUnit) o2; + writeProperties(profile.getProperties()); + ArrayList<IInstallableUnit> ius = new ArrayList<IInstallableUnit>(profile.query(InstallableUnitQuery.ANY, null).unmodifiableSet()); + Collections.sort(ius, new Comparator<IInstallableUnit>() { + public int compare(IInstallableUnit iu1, IInstallableUnit iu2) { int IdCompare = iu1.getId().compareTo(iu2.getId()); if (IdCompare != 0) return IdCompare; @@ -52,14 +45,14 @@ public class ProfileWriter extends MetadataWriter implements ProfileXMLConstants flush(); } - private void writeInstallableUnitsProperties(Iterator it, int size, IProfile profile) { + private void writeInstallableUnitsProperties(Iterator<IInstallableUnit> it, int size, IProfile profile) { if (size == 0) return; start(IUS_PROPERTIES_ELEMENT); attribute(COLLECTION_SIZE_ATTRIBUTE, size); while (it.hasNext()) { - IInstallableUnit iu = (IInstallableUnit) it.next(); - Map properties = profile.getInstallableUnitProperties(iu); + IInstallableUnit iu = it.next(); + Map<String, String> properties = profile.getInstallableUnitProperties(iu); if (properties.isEmpty()) continue; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileXMLConstants.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileXMLConstants.java index 20b15ee9e..f28e9e0b0 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileXMLConstants.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileXMLConstants.java @@ -10,10 +10,9 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.engine; -import org.eclipse.equinox.internal.provisional.p2.metadata.Version; -import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange; - import org.eclipse.equinox.internal.p2.persistence.XMLConstants; +import org.eclipse.equinox.p2.metadata.Version; +import org.eclipse.equinox.p2.metadata.VersionRange; /** * Constants defining the structure of the XML for a Profile @@ -21,9 +20,9 @@ import org.eclipse.equinox.internal.p2.persistence.XMLConstants; public interface ProfileXMLConstants extends XMLConstants { // A format version number for profile XML. - public static final Version CURRENT_VERSION = new Version(1, 0, 0); - public static final Version COMPATIBLE_VERSION = new Version(0, 0, 1); - public static final VersionRange XML_TOLERANCE = new VersionRange(COMPATIBLE_VERSION, true, new Version(2, 0, 0), false); + public static final Version CURRENT_VERSION = Version.createOSGi(1, 0, 0); + public static final Version COMPATIBLE_VERSION = Version.createOSGi(0, 0, 1); + public static final VersionRange XML_TOLERANCE = new VersionRange(COMPATIBLE_VERSION, true, Version.createOSGi(2, 0, 0), false); // Constants for profile elements diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java index 6febf6915..2b18f2f39 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java @@ -8,13 +8,9 @@ ******************************************************************************/ package org.eclipse.equinox.internal.p2.engine; -import org.eclipse.equinox.internal.provisional.p2.metadata.Version; -import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange; - import java.io.*; import java.lang.ref.SoftReference; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.util.*; import java.util.Map.Entry; import java.util.zip.GZIPInputStream; @@ -22,16 +18,18 @@ import java.util.zip.GZIPOutputStream; import javax.xml.parsers.ParserConfigurationException; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.*; -import org.eclipse.equinox.internal.provisional.p2.core.*; +import org.eclipse.equinox.internal.p2.metadata.TranslationSupport; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; -import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; -import org.eclipse.equinox.internal.provisional.p2.engine.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.p2.core.IAgentLocation; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.metadata.*; +import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.p2.query.IQueryResult; import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.util.NLS; import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -47,8 +45,8 @@ public class SimpleProfileRegistry implements IProfileRegistry { /** * Reference to Map of String(Profile id)->Profile. */ - private SoftReference profiles; - private Map profileLocks = new HashMap(); + private SoftReference<Map<String, Profile>> profiles; + private Map<String, ProfileLock> profileLocks = new HashMap<String, ProfileLock>(); private String self; @@ -68,24 +66,38 @@ public class SimpleProfileRegistry implements IProfileRegistry { public SimpleProfileRegistry(File registryDirectory, ISurrogateProfileHandler handler, boolean updateSelfProfile) { store = registryDirectory; surrogateProfileHandler = handler; - self = EngineActivator.getContext().getProperty("eclipse.p2.profile"); //$NON-NLS-1$ Assert.isNotNull(store, "Profile registry requires a directory"); //$NON-NLS-1$ + findSelf(); this.updateSelfProfile = updateSelfProfile; } - public static File getDefaultRegistryDirectory(AgentLocation agent) { + /** + * Determine the id of the "self" profile. This is only applicable for the registry + * of the currently running system. + */ + private void findSelf() { + //the location for the currently running system is registered as a service + ServiceReference ref = EngineActivator.getContext().getServiceReference(IAgentLocation.SERVICE_NAME); + if (ref == null) + return; + IAgentLocation location = (IAgentLocation) EngineActivator.getContext().getService(ref); + if (location == null) + return; + if (store.equals(getDefaultRegistryDirectory(location))) { + //we are the registry for the currently running system + self = EngineActivator.getContext().getProperty("eclipse.p2.profile"); //$NON-NLS-1$ + } + EngineActivator.getContext().ungetService(ref); + } + + public static File getDefaultRegistryDirectory(IAgentLocation agent) { File registryDirectory = null; if (agent == null) throw new IllegalStateException("Profile Registry inialization failed: Agent Location is not available"); //$NON-NLS-1$ - final URL engineDataArea = agent.getDataArea(EngineActivator.ID); - try { - URL registryURL = new URL(engineDataArea, DEFAULT_STORAGE_DIR); - registryDirectory = new File(registryURL.getPath()); - registryDirectory.mkdirs(); - } catch (MalformedURLException e) { - //this is not possible because we know the above URL is valid - throw new IllegalStateException("Profile Registry inialization failed. Agent Location is invalid:" + engineDataArea); //$NON-NLS-1$ - } + final URI engineDataArea = agent.getDataArea(EngineActivator.ID); + URI registryURL = URIUtil.append(engineDataArea, DEFAULT_STORAGE_DIR); + registryDirectory = new File(registryURL); + registryDirectory.mkdirs(); return registryDirectory; } @@ -93,13 +105,17 @@ public class SimpleProfileRegistry implements IProfileRegistry { * If the current profile for self is marked as a roaming profile, we need * to update its install and bundle pool locations. */ - private void updateSelfProfile(Map profileMap) { + private void updateSelfProfile(Map<String, Profile> profileMap) { if (profileMap == null) return; - Profile selfProfile = (Profile) profileMap.get(self); + Profile selfProfile = profileMap.get(self); if (selfProfile == null) return; + //register default locale provider where metadata translations are found + //TODO ideally this should not be hard-coded to the current profile + TranslationSupport.getInstance().setTranslationSource(selfProfile); + if (DebugHelper.DEBUG_PROFILE_REGISTRY) DebugHelper.debug(PROFILE_REGISTRY, "SimpleProfileRegistry.updateSelfProfile"); //$NON-NLS-1$ boolean changed = false; @@ -172,7 +188,7 @@ public class SimpleProfileRegistry implements IProfileRegistry { } catch (IOException e) { LogHelper.log(new Status(IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.error_parsing_profile, profileFile), e)); } - return (IProfile) parser.getProfileMap().get(id); + return parser.getProfileMap().get(id); } public synchronized long[] listProfileTimestamps(String id) { @@ -209,7 +225,7 @@ public class SimpleProfileRegistry implements IProfileRegistry { private Profile internalGetProfile(String id) { if (SELF.equals(id)) id = self; - Profile profile = (Profile) getProfileMap().get(id); + Profile profile = getProfileMap().get(id); if (profile == null && self != null && self.equals(id)) profile = createSurrogateProfile(id); @@ -226,16 +242,15 @@ public class SimpleProfileRegistry implements IProfileRegistry { saveProfile(profile); resetProfiles(); - return (Profile) getProfileMap().get(id); + return getProfileMap().get(id); } public synchronized IProfile[] getProfiles() { - Map profileMap = getProfileMap(); + Map<String, Profile> profileMap = getProfileMap(); Profile[] result = new Profile[profileMap.size()]; int i = 0; - for (Iterator it = profileMap.values().iterator(); it.hasNext(); i++) { - Profile profile = (Profile) it.next(); - result[i] = profile.snapshot(); + for (Profile profile : profileMap.values()) { + result[i++] = profile.snapshot(); } return result; } @@ -243,16 +258,16 @@ public class SimpleProfileRegistry implements IProfileRegistry { /** * Returns an initialized map of String(Profile id)->Profile. */ - protected Map getProfileMap() { + protected Map<String, Profile> getProfileMap() { if (profiles != null) { - Map result = (Map) profiles.get(); + Map<String, Profile> result = profiles.get(); if (result != null) return result; } - Map result = restore(); + Map<String, Profile> result = restore(); if (result == null) - result = new LinkedHashMap(8); - profiles = new SoftReference(result); + result = new LinkedHashMap<String, Profile>(8); + profiles = new SoftReference<Map<String, Profile>>(result); if (updateSelfProfile) { //update self profile on first load updateSelfProfile(result); @@ -266,18 +281,18 @@ public class SimpleProfileRegistry implements IProfileRegistry { if (current == null) throw new IllegalArgumentException(NLS.bind(Messages.profile_does_not_exist, id)); - ProfileLock lock = (ProfileLock) profileLocks.get(id); + ProfileLock lock = profileLocks.get(id); lock.checkLocked(); current.clearLocalProperties(); current.clearInstallableUnits(); current.addProperties(profile.getLocalProperties()); - Collector collector = profile.query(InstallableUnitQuery.ANY, new Collector(), null); - for (Iterator collectorIt = collector.iterator(); collectorIt.hasNext();) { - IInstallableUnit iu = (IInstallableUnit) collectorIt.next(); + IQueryResult<IInstallableUnit> queryResult = profile.query(InstallableUnitQuery.ANY, null); + for (Iterator<IInstallableUnit> queryResultIt = queryResult.iterator(); queryResultIt.hasNext();) { + IInstallableUnit iu = queryResultIt.next(); current.addInstallableUnit(iu); - Map iuProperties = profile.getInstallableUnitProperties(iu); + Map<String, String> iuProperties = profile.getInstallableUnitProperties(iu); if (iuProperties != null) current.addInstallableUnitProperties(iu, iuProperties); } @@ -291,14 +306,14 @@ public class SimpleProfileRegistry implements IProfileRegistry { return addProfile(id, null, null); } - public IProfile addProfile(String id, Map profileProperties) throws ProvisionException { + public IProfile addProfile(String id, Map<String, String> profileProperties) throws ProvisionException { return addProfile(id, profileProperties, null); } - public synchronized IProfile addProfile(String id, Map profileProperties, String parentId) throws ProvisionException { + public synchronized IProfile addProfile(String id, Map<String, String> profileProperties, String parentId) throws ProvisionException { if (SELF.equals(id)) id = self; - Map profileMap = getProfileMap(); + Map<String, Profile> profileMap = getProfileMap(); if (profileMap.get(id) != null) throw new ProvisionException(NLS.bind(Messages.Profile_Duplicate_Root_Profile_Id, id)); @@ -306,7 +321,7 @@ public class SimpleProfileRegistry implements IProfileRegistry { if (parentId != null) { if (SELF.equals(parentId)) parentId = self; - parent = (Profile) profileMap.get(parentId); + parent = profileMap.get(parentId); if (parent == null) throw new ProvisionException(NLS.bind(Messages.Profile_Parent_Not_Found, parentId)); } @@ -324,14 +339,14 @@ public class SimpleProfileRegistry implements IProfileRegistry { if (SELF.equals(profileId)) profileId = self; //note we need to maintain a reference to the profile map until it is persisted to prevent gc - Map profileMap = getProfileMap(); - Profile profile = (Profile) profileMap.get(profileId); + Map<String, Profile> profileMap = getProfileMap(); + Profile profile = profileMap.get(profileId); if (profile == null) return; - String[] subProfileIds = profile.getSubProfileIds(); - for (int i = 0; i < subProfileIds.length; i++) { - removeProfile(subProfileIds[i]); + List<String> subProfileIds = profile.getSubProfileIds(); + for (int i = 0; i < subProfileIds.size(); i++) { + removeProfile(subProfileIds.get(i)); } internalLockProfile(profile); // The above call recursively locked the parent(s). So save it away to rewind the locking process. @@ -383,9 +398,9 @@ public class SimpleProfileRegistry implements IProfileRegistry { * Restores the profile registry from disk, and returns the loaded profile map. * Returns <code>null</code> if unable to read the registry. */ - private Map restore() { + private Map<String, Profile> restore() { if (store == null || !store.isDirectory()) - throw new IllegalStateException(Messages.reg_dir_not_available); + throw new IllegalStateException(NLS.bind(Messages.reg_dir_not_available, store)); Parser parser = new Parser(EngineActivator.getContext(), EngineActivator.ID); File[] profileDirectories = store.listFiles(new FileFilter() { @@ -396,7 +411,7 @@ public class SimpleProfileRegistry implements IProfileRegistry { for (int i = 0; i < profileDirectories.length; i++) { String directoryName = profileDirectories[i].getName(); String profileId = unescape(directoryName.substring(0, directoryName.lastIndexOf(PROFILE_EXT))); - ProfileLock lock = (ProfileLock) profileLocks.get(profileId); + ProfileLock lock = profileLocks.get(profileId); if (lock == null) { lock = new ProfileLock(this, profileDirectories[i]); profileLocks.put(profileId, lock); @@ -502,7 +517,7 @@ public class SimpleProfileRegistry implements IProfileRegistry { return false; //check whether the profile contains the p2 engine from 3.5.0 or earlier - return profile.available(new InstallableUnitQuery("org.eclipse.equinox.p2.engine", new VersionRange("[0.0.0, 1.0.101)")), new Collector(), null).isEmpty(); //$NON-NLS-1$//$NON-NLS-2$ + return profile.available(new InstallableUnitQuery("org.eclipse.equinox.p2.engine", new VersionRange("[0.0.0, 1.0.101)")), null).isEmpty(); //$NON-NLS-1$//$NON-NLS-2$ } private void deleteProfile(String profileId) { @@ -570,7 +585,7 @@ public class SimpleProfileRegistry implements IProfileRegistry { * as written by the Writer class. */ class Parser extends ProfileParser { - private final Map profileHandlers = new HashMap(); + private final Map<String, ProfileHandler> profileHandlers = new HashMap<String, ProfileHandler>(); public Parser(BundleContext context, String bundleId) { super(context, bundleId); @@ -613,26 +628,25 @@ public class SimpleProfileRegistry implements IProfileRegistry { return this; } - public Map getProfileMap() { - Map profileMap = new HashMap(); - for (Iterator it = profileHandlers.keySet().iterator(); it.hasNext();) { - String profileId = (String) it.next(); + public Map<String, Profile> getProfileMap() { + Map<String, Profile> profileMap = new HashMap<String, Profile>(); + for (String profileId : profileHandlers.keySet()) { addProfile(profileId, profileMap); } return profileMap; } - private void addProfile(String profileId, Map profileMap) { + private void addProfile(String profileId, Map<String, Profile> profileMap) { if (profileMap.containsKey(profileId)) return; - ProfileHandler profileHandler = (ProfileHandler) profileHandlers.get(profileId); + ProfileHandler profileHandler = profileHandlers.get(profileId); Profile parentProfile = null; String parentId = profileHandler.getParentId(); if (parentId != null) { addProfile(parentId, profileMap); - parentProfile = (Profile) profileMap.get(parentId); + parentProfile = profileMap.get(parentId); } Profile profile = new Profile(profileId, parentProfile, profileHandler.getProperties()); @@ -646,13 +660,10 @@ public class SimpleProfileRegistry implements IProfileRegistry { for (int i = 0; i < ius.length; i++) { IInstallableUnit iu = ius[i]; profile.addInstallableUnit(iu); - Map iuProperties = profileHandler.getIUProperties(iu); + Map<String, String> iuProperties = profileHandler.getIUProperties(iu); if (iuProperties != null) { - for (Iterator it = iuProperties.entrySet().iterator(); it.hasNext();) { - Entry entry = (Entry) it.next(); - String key = (String) entry.getKey(); - String value = (String) entry.getValue(); - profile.setInstallableUnitProperty(iu, key, value); + for (Entry<String, String> entry : iuProperties.entrySet()) { + profile.setInstallableUnitProperty(iu, entry.getKey(), entry.getValue()); } } } @@ -732,26 +743,12 @@ public class SimpleProfileRegistry implements IProfileRegistry { } private boolean internalLockProfile(IProfile profile) { - ProfileLock lock = (ProfileLock) profileLocks.get(profile.getProfileId()); + ProfileLock lock = profileLocks.get(profile.getProfileId()); if (lock == null) { lock = new ProfileLock(this, new File(store, escape(profile.getProfileId()) + PROFILE_EXT)); profileLocks.put(profile.getProfileId(), lock); } - if (!lock.lock()) - return false; - - if (profile.getParentProfile() == null) - return true; - - boolean locked = false; - try { - locked = internalLockProfile(profile.getParentProfile()); - } finally { - // this check is done here to ensure we unlock even if a runtime exception is thrown - if (!locked) - lock.unlock(); - } - return locked; + return lock.lock(); } private boolean checkTimestamps(IProfile profile, IProfile internalProfile) { @@ -772,9 +769,6 @@ public class SimpleProfileRegistry implements IProfileRegistry { return false; } - if (profile.getParentProfile() != null) - return checkTimestamps(profile.getParentProfile(), internalProfile.getParentProfile()); - return true; } @@ -816,10 +810,7 @@ public class SimpleProfileRegistry implements IProfileRegistry { } private void internalUnlockProfile(IProfile profile) { - if (profile.getParentProfile() != null) - internalUnlockProfile(profile.getParentProfile()); - - ProfileLock lock = (ProfileLock) profileLocks.get(profile.getProfileId()); + ProfileLock lock = profileLocks.get(profile.getProfileId()); lock.unlock(); } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java index ec59aedc0..5e3448745 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java @@ -17,21 +17,23 @@ import java.net.URL; import java.util.Iterator; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; -import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; -import org.eclipse.equinox.internal.provisional.p2.engine.ISurrogateProfileHandler; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.*; +import org.eclipse.equinox.p2.engine.IProfile; +import org.eclipse.equinox.p2.engine.ISurrogateProfileHandler; +import org.eclipse.equinox.p2.engine.query.IUProfilePropertyQuery; +import org.eclipse.equinox.p2.engine.query.UserVisibleRootQuery; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.p2.query.*; import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.util.NLS; public class SurrogateProfileHandler implements ISurrogateProfileHandler { private static final String NATIVE_TOUCHPOINT_TYPE = "org.eclipse.equinox.p2.native"; //$NON-NLS-1$ - private static final String PROP_TYPE_ROOT = "org.eclipse.equinox.p2.type.root"; //$NON-NLS-1$ private static final String P2_ENGINE_DIR = "p2/" + EngineActivator.ID + "/"; //$NON-NLS-1$//$NON-NLS-2$ private static final String OSGI_INSTALL_AREA = "osgi.install.area"; //$NON-NLS-1$ private static final String ECLIPSE_INI_IGNORED = "eclipse.ini.ignored"; //$NON-NLS-1$ - private static final String IU_LOCKED = Integer.toString(IInstallableUnit.LOCK_UNINSTALL | IInstallableUnit.LOCK_UPDATE); + private static final String IU_LOCKED = Integer.toString(IProfile.LOCK_UNINSTALL | IProfile.LOCK_UPDATE); private static final String PROP_SURROGATE = "org.eclipse.equinox.p2.surrogate"; //$NON-NLS-1$ private static final String PROP_SHARED_TIMESTAMP = "org.eclipse.equinox.p2.shared.timestamp"; //$NON-NLS-1$ private static final String PROP_BASE = "org.eclipse.equinox.p2.base"; //$NON-NLS-1$ @@ -41,63 +43,37 @@ public class SurrogateProfileHandler implements ISurrogateProfileHandler { private SimpleProfileRegistry profileRegistry; - private SoftReference cachedProfile; + private SoftReference<IProfile> cachedProfile; private static void addSharedProfileBaseIUs(final IProfile sharedProfile, final Profile userProfile) { - Query rootIUQuery = new MatchQuery() { - public boolean isMatch(Object candidate) { - if (candidate instanceof IInstallableUnit) { - IInstallableUnit iu = (IInstallableUnit) candidate; - if (Boolean.valueOf(sharedProfile.getInstallableUnitProperty(iu, PROP_TYPE_ROOT)).booleanValue()) - return true; - if (iu.getTouchpointType().getId().equals(NATIVE_TOUCHPOINT_TYPE)) - return true; - } - return false; + IQuery<IInstallableUnit> rootIUQuery = CompoundQuery.createCompoundQuery(new UserVisibleRootQuery(), new MatchQuery<IInstallableUnit>() { + public boolean isMatch(IInstallableUnit iu) { + return iu.getTouchpointType().getId().equals(NATIVE_TOUCHPOINT_TYPE); } - }; - Collector rootIUs = sharedProfile.query(rootIUQuery, new Collector(), null); - for (Iterator iterator = rootIUs.iterator(); iterator.hasNext();) { - IInstallableUnit iu = (IInstallableUnit) iterator.next(); + }, false); + IQueryResult<IInstallableUnit> rootIUs = sharedProfile.query(rootIUQuery, null); + for (Iterator<IInstallableUnit> iterator = rootIUs.iterator(); iterator.hasNext();) { + IInstallableUnit iu = iterator.next(); userProfile.addInstallableUnit(iu); userProfile.addInstallableUnitProperties(iu, sharedProfile.getInstallableUnitProperties(iu)); - userProfile.setInstallableUnitProperty(iu, IInstallableUnit.PROP_PROFILE_LOCKED_IU, IU_LOCKED); + userProfile.setInstallableUnitProperty(iu, IProfile.PROP_PROFILE_LOCKED_IU, IU_LOCKED); userProfile.setInstallableUnitProperty(iu, PROP_BASE, Boolean.TRUE.toString()); } } private static void removeUserProfileBaseIUs(final Profile userProfile) { - Query rootIUQuery = new MatchQuery() { - public boolean isMatch(Object candidate) { - if (candidate instanceof IInstallableUnit) { - IInstallableUnit iu = (IInstallableUnit) candidate; - if (Boolean.valueOf(userProfile.getInstallableUnitProperty(iu, PROP_BASE)).booleanValue()) - return true; - } - return false; - } - }; - Collector rootIUs = userProfile.query(rootIUQuery, new Collector(), null); - for (Iterator iterator = rootIUs.iterator(); iterator.hasNext();) { - IInstallableUnit iu = (IInstallableUnit) iterator.next(); + IQuery<IInstallableUnit> rootIUQuery = new IUProfilePropertyQuery(PROP_BASE, Boolean.TRUE.toString()); + IQueryResult<IInstallableUnit> rootIUs = userProfile.query(rootIUQuery, null); + for (Iterator<IInstallableUnit> iterator = rootIUs.iterator(); iterator.hasNext();) { + IInstallableUnit iu = iterator.next(); userProfile.removeInstallableUnit(iu); } } private static void markRootsOptional(final Profile userProfile) { - Query rootIUQuery = new MatchQuery() { - public boolean isMatch(Object candidate) { - if (candidate instanceof IInstallableUnit) { - IInstallableUnit iu = (IInstallableUnit) candidate; - if (Boolean.valueOf(userProfile.getInstallableUnitProperty(iu, PROP_TYPE_ROOT)).booleanValue()) - return true; - } - return false; - } - }; - Collector rootIUs = userProfile.query(rootIUQuery, new Collector(), null); - for (Iterator iterator = rootIUs.iterator(); iterator.hasNext();) { - IInstallableUnit iu = (IInstallableUnit) iterator.next(); + IQueryResult<IInstallableUnit> rootIUs = userProfile.query(new UserVisibleRootQuery(), null); + for (Iterator<IInstallableUnit> iterator = rootIUs.iterator(); iterator.hasNext();) { + IInstallableUnit iu = iterator.next(); userProfile.setInstallableUnitProperty(iu, PROP_INCLUSION_RULES, OPTIONAL); } } @@ -158,14 +134,14 @@ public class SurrogateProfileHandler implements ISurrogateProfileHandler { //see if we have a cached profile if (cachedProfile != null) { - IProfile profile = (IProfile) cachedProfile.get(); + IProfile profile = cachedProfile.get(); if (profile != null && profile.getProfileId().equals(id) && profile.getTimestamp() == currentTimestamp) return profile; } final IProfile profile = registry.getProfile(id, currentTimestamp); if (profile != null) - cachedProfile = new SoftReference(profile); + cachedProfile = new SoftReference<IProfile>(profile); return profile; } @@ -195,12 +171,16 @@ public class SurrogateProfileHandler implements ISurrogateProfileHandler { /* (non-Javadoc) * @see org.eclipse.equinox.internal.p2.engine.ISurrogateProfileHandler#queryProfile(org.eclipse.equinox.internal.provisional.p2.engine.IProfile, org.eclipse.equinox.internal.provisional.p2.query.Query, org.eclipse.equinox.internal.provisional.p2.query.Collector, org.eclipse.core.runtime.IProgressMonitor) */ - public Collector queryProfile(IProfile profile, Query query, Collector collector, IProgressMonitor monitor) { + public IQueryResult<IInstallableUnit> queryProfile(IProfile profile, IQuery<IInstallableUnit> query, IProgressMonitor monitor) { IProfile sharedProfile = getSharedProfile(profile.getProfileId()); - if (sharedProfile != null) - sharedProfile.query(query, collector, monitor); + if (sharedProfile == null) + return profile.query(query, monitor); - return profile.query(query, collector, monitor); + // TODO: Should consider using a sequenced iterator here instead of collecting + Collector<IInstallableUnit> result = new Collector<IInstallableUnit>(); + result.addAll(sharedProfile.query(query, monitor)); + result.addAll(profile.query(query, monitor)); + return result; } public boolean updateProfile(IProfile userProfile) { @@ -217,7 +197,7 @@ public class SurrogateProfileHandler implements ISurrogateProfileHandler { Profile writableUserProfile = (Profile) userProfile; updateProperties(sharedProfile, writableUserProfile); removeUserProfileBaseIUs(writableUserProfile); - if (!userProfile.query(InstallableUnitQuery.ANY, new Collector(), null).isEmpty()) { + if (!userProfile.query(InstallableUnitQuery.ANY, null).isEmpty()) { writableUserProfile.setProperty(PROP_RESOLVE, Boolean.TRUE.toString()); markRootsOptional(writableUserProfile); } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/TouchpointManager.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/TouchpointManager.java index 8da1e0b66..fb5e4dfff 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/TouchpointManager.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/TouchpointManager.java @@ -10,15 +10,12 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.engine; -import org.eclipse.equinox.internal.provisional.p2.metadata.Version; -import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange; - import java.util.HashMap; import java.util.Map; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.provisional.p2.engine.Touchpoint; -import org.eclipse.equinox.internal.provisional.p2.metadata.ITouchpointType; +import org.eclipse.equinox.p2.engine.spi.Touchpoint; +import org.eclipse.equinox.p2.metadata.*; import org.eclipse.osgi.util.NLS; //TODO This needs to support multiple version of each touchpoint and have a lookup that supports version semantics @@ -65,7 +62,7 @@ public class TouchpointManager implements IRegistryChangeListener { public Version getVersion() { try { - return new Version(element.getAttribute(ATTRIBUTE_VERSION)); + return Version.create(element.getAttribute(ATTRIBUTE_VERSION)); } catch (InvalidRegistryObjectException e) { return null; } @@ -92,7 +89,7 @@ public class TouchpointManager implements IRegistryChangeListener { // TODO: Do we really want to store the touchpoints? The danger is // that if two installations are performed simultaneously, then... // TODO: Figure out locking, concurrency requirements for touchpoints. - private Map touchpointEntries; + private Map<String, TouchpointEntry> touchpointEntries; public TouchpointManager() { RegistryFactory.getRegistry().addRegistryChangeListener(this, EngineActivator.ID); @@ -116,7 +113,7 @@ public class TouchpointManager implements IRegistryChangeListener { if (typeId == null || typeId.length() == 0) throw new IllegalArgumentException(Messages.TouchpointManager_Null_Touchpoint_Type_Argument); - TouchpointEntry entry = (TouchpointEntry) getTouchpointEntries().get(typeId); + TouchpointEntry entry = getTouchpointEntries().get(typeId); if (entry == null) return null; if (versionRange != null) { @@ -131,13 +128,13 @@ public class TouchpointManager implements IRegistryChangeListener { /* * Construct a map of the extensions that implement the touchpoints extension point. */ - private synchronized Map getTouchpointEntries() { + private synchronized Map<String, TouchpointEntry> getTouchpointEntries() { if (touchpointEntries != null) return touchpointEntries; IExtensionPoint point = RegistryFactory.getRegistry().getExtensionPoint(EngineActivator.ID, PT_TOUCHPOINTS); IExtension[] extensions = point.getExtensions(); - touchpointEntries = new HashMap(extensions.length); + touchpointEntries = new HashMap<String, TouchpointEntry>(extensions.length); for (int i = 0; i < extensions.length; i++) { try { IConfigurationElement[] elements = extensions[i].getConfigurationElements(); @@ -155,7 +152,7 @@ public class TouchpointManager implements IRegistryChangeListener { if (touchpointEntries.get(id) == null) { touchpointEntries.put(id, new TouchpointEntry(elements[j])); } else { - reportError(NLS.bind(Messages.TouchpointManager_Conflicting_Touchpoint_Types, ATTRIBUTE_TYPE, id)); + reportError(NLS.bind(Messages.TouchpointManager_Conflicting_Touchpoint_Types, id)); } } } catch (InvalidRegistryObjectException e) { diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/messages.properties b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/messages.properties index a491c286a..f9bc0c30c 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/messages.properties +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/messages.properties @@ -44,9 +44,61 @@ SimpleProfileRegistry_CannotRemoveCurrentSnapshot=Cannot remove the current prof profile_does_not_exist=Profile to be updated does not exist: {0}. profile_not_current=Profile {0} is not current. profile_not_registered=Profile {0} not registered. -reg_dir_not_available=Registry Directory not available. +reg_dir_not_available=Registry Directory not available: {0}. thread_not_owner=Thread not lock owner. profile_lock_not_reentrant=Lock failed. Profile does not permit reentrant locking. shared_profile_not_found=Shared profile {0} not found. ProfilePreferences_saving=Saving profile preferences +phase_error=An error occurred during the {0} phase. +action_undo_error=An error occurred while rolling back the engine operation while undoing the {0} action. +forced_action_execute_error=An error occurred while performing the engine operation while executing the {0} action in forced mode. The operation will continue. +phaseid_not_positive=Phase weight must be positive. +phaseid_not_set=Phase id must be set. +action_not_found=No action found for: {0}. +actions_not_found=No actions found for: {0}. +not_current_phase=Current phase does not match argument. +null_operands=Operands must not be null. +null_phase=Phase must not be null. +null_phases=Phases must not be null +null_phaseset=PhaseSet must not be null. +null_profile=Profile must not be null. +touchpoint_prepare_error=An error occurred while preparing the engine operation for the {0} touchpoint. +touchpoint_commit_error=An error occurred while committing the engine operation for the {0} touchpoint. +touchpoint_rollback_error=An error occurred while rolling back the engine operation for the {0} touchpoint. +phase_undo_error=An error occurred while undoing the {0} phase. +phase_undo_operand_error=An error occurred while undoing the {0} phase for operand {1}. +phase_not_started=There is no phase to end. +phase_started=A phase is already started. + +session_prepare_error=An error occurred while preparing the engine session for profile: {0}. +session_commit_error=An error occurred while committing the engine session for profile: {0}. +null_operand=Operand must not be null. +operand_started=An operand is already started. +operand_not_started=There is no operand to end. +not_current_operand=Current operand does not match argument. +null_action=Action must not be null +session_context=session context was:(profile={0}, phase={1}, operand={2}, action={3}). +preparing=Preparing to commit the provisioning operation. +committing=Committing the provisioning operation. +rollingback_error=An error was detected while performing the engine operation and the changes are being rolled back. See the log for details. +rollingback_cancel=The engine operation was cancelled and the changes are being rolled back. + +Engine_Operation_Canceled_By_User=Operation canceled by the user. +InstallableUnitEvent_type_not_install_or_uninstall=type must be either UNINSTALL(0) or INSTALL(1) +CertificateChecker_CertificateError=An invalid certificate was found. +CertificateChecker_CertificateRejected=One or more certificates rejected. Cannot proceed with installation. +CertificateChecker_KeystoreConnectionError=Cannot connect to keystore. +CertificateChecker_SignedContentError=Error with signed content. +CertificateChecker_SignedContentIOError=Error reading signed content. +CertificateChecker_UnsignedNotAllowed=Installing unsigned artifacts is not permitted: {0} + +Phase_Collect_Error=An error occurred while collecting items to be installed +Phase_Configure_Error=An error occurred while configuring the installed items +Phase_Configure_Task=Configuring {0} +Phase_Install_Error=An error occurred while installing the items +Phase_Install_Task=Installing {0} +Phase_Sizing_Error=Error computing the size. Some of the items to be installed could not be found. +Phase_Sizing_Warning=The size may not be accurate. Some of the items did not report a size. +Phase_Unconfigure_Error=An error occurred while unconfiguring the items to uninstall +Phase_Uninstall_Error=An error occurred while uninstalling diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/CertificateChecker.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/CertificateChecker.java index 8d049b9f9..42f04bcbf 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/CertificateChecker.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/CertificateChecker.java @@ -8,53 +8,64 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.internal.p2.engine.phases; import java.io.File; import java.io.IOException; import java.security.GeneralSecurityException; import java.security.cert.Certificate; import java.util.ArrayList; -import java.util.Iterator; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.engine.EngineActivator; +import org.eclipse.equinox.internal.p2.engine.Messages; import org.eclipse.equinox.internal.provisional.p2.core.IServiceUI; import org.eclipse.equinox.internal.provisional.p2.core.IServiceUI.TrustInfo; +import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.osgi.service.security.TrustEngine; import org.eclipse.osgi.signedcontent.*; import org.eclipse.osgi.util.NLS; -import org.osgi.util.tracker.ServiceTracker; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; public class CertificateChecker { - private ArrayList artifacts; - private ServiceTracker trustEngineTracker; + private ArrayList<File> artifacts; + private final IProvisioningAgent agent; public CertificateChecker() { - artifacts = new ArrayList(); - trustEngineTracker = new ServiceTracker(EngineActivator.getContext(), TrustEngine.class.getName(), null); - trustEngineTracker.open(); + this(null); + } + + public CertificateChecker(IProvisioningAgent agent) { + this.agent = agent; + artifacts = new ArrayList<File>(); } public IStatus start() { - return checkCertificates(); + final BundleContext context = EngineActivator.getContext(); + ServiceReference contentFactoryRef = context.getServiceReference(SignedContentFactory.class.getName()); + SignedContentFactory verifierFactory = (SignedContentFactory) context.getService(contentFactoryRef); + ServiceReference trustEngineRef = context.getServiceReference(TrustEngine.class.getName()); + TrustEngine trustEngine = (TrustEngine) context.getService(trustEngineRef); + try { + return checkCertificates(trustEngine, verifierFactory); + } finally { + context.ungetService(contentFactoryRef); + context.ungetService(trustEngineRef); + } } - private IStatus checkCertificates() { - SignedContentFactory verifierFactory = (SignedContentFactory) ServiceHelper.getService(EngineActivator.getContext(), SignedContentFactory.class.getName()); - IServiceUI serviceUI = (IServiceUI) ServiceHelper.getService(EngineActivator.getContext(), IServiceUI.class.getName()); + private IStatus checkCertificates(TrustEngine trustEngine, SignedContentFactory verifierFactory) { + IServiceUI serviceUI = (IServiceUI) agent.getService(IServiceUI.SERVICE_NAME); SignedContent content = null; SignerInfo[] signerInfo = null; - ArrayList untrusted = new ArrayList(); - ArrayList unsigned = new ArrayList(); - ArrayList untrustedChain = new ArrayList(); + ArrayList<Certificate> untrusted = new ArrayList<Certificate>(); + ArrayList<File> unsigned = new ArrayList<File>(); + ArrayList<Certificate[]> untrustedChain = new ArrayList<Certificate[]>(); IStatus status = Status.OK_STATUS; if (artifacts.size() == 0 || serviceUI == null) return status; - TrustEngine trustEngine = (TrustEngine) trustEngineTracker.getService(); - for (Iterator it = artifacts.iterator(); it.hasNext();) { - File artifact = (File) it.next(); + for (File artifact : artifacts) { try { content = verifierFactory.getSignedContent(artifact); if (!content.isSigned()) { @@ -103,7 +114,7 @@ public class CertificateChecker { } else { unTrustedCertificateChains = new Certificate[untrustedChain.size()][]; for (int i = 0; i < untrustedChain.size(); i++) { - unTrustedCertificateChains[i] = (Certificate[]) untrustedChain.get(i); + unTrustedCertificateChains[i] = untrustedChain.get(i); } } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/CheckTrust.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/CheckTrust.java index 28445c322..090aba5c7 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/CheckTrust.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/CheckTrust.java @@ -8,14 +8,18 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine.phases; +package org.eclipse.equinox.internal.p2.engine.phases; +import java.io.File; import java.util.*; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.provisional.p2.engine.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.metadata.ITouchpointType; +import org.eclipse.equinox.internal.p2.engine.InstallableUnitPhase; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.ITouchpointType; /** * An install phase that checks if the certificates used to sign the artifacts @@ -23,7 +27,7 @@ import org.eclipse.equinox.internal.provisional.p2.metadata.ITouchpointType; */ public class CheckTrust extends InstallableUnitPhase { - private static final String PHASE_ID = "checkTrust"; //$NON-NLS-1$ + private static final String PHASE_ID = IPhaseSet.PHASE_CHECK_TRUST; public static final String PARM_ARTIFACT_FILES = "artifactFiles"; //$NON-NLS-1$ public CheckTrust(int weight) { @@ -34,20 +38,22 @@ public class CheckTrust extends InstallableUnitPhase { return (op.second() != null); } - protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { - Collection artifactRequests = (Collection) parameters.get(PARM_ARTIFACT_FILES); + protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) { + @SuppressWarnings("unchecked") + Collection<File> artifactRequests = (Collection<File>) parameters.get(PARM_ARTIFACT_FILES); + IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT); // Instantiate a check trust manager - CertificateChecker certificateChecker = new CertificateChecker(); + CertificateChecker certificateChecker = new CertificateChecker(agent); certificateChecker.add(artifactRequests.toArray()); IStatus status = certificateChecker.start(); return status; } - protected ProvisioningAction[] getActions(InstallableUnitOperand operand) { + protected List<ProvisioningAction> getActions(InstallableUnitOperand operand) { IInstallableUnit unit = operand.second(); - ProvisioningAction[] parsedActions = getActions(unit, phaseId); + List<ProvisioningAction> parsedActions = getActions(unit, phaseId); if (parsedActions != null) return parsedActions; @@ -60,18 +66,18 @@ public class CheckTrust extends InstallableUnitPhase { if (action == null) { return null; } - return new ProvisioningAction[] {action}; + return Collections.singletonList(action); } - protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) { + protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map<String, Object> parameters, IProgressMonitor monitor) { IInstallableUnit iu = operand.second(); parameters.put(PARM_IU, iu); return super.initializeOperand(profile, operand, parameters, monitor); } - protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { - parameters.put(PARM_ARTIFACT_FILES, new ArrayList()); + protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) { + parameters.put(PARM_ARTIFACT_FILES, new ArrayList<File>()); return super.initializePhase(monitor, profile, parameters); } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Collect.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Collect.java index c0fc59c5e..1993d49ab 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Collect.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Collect.java @@ -9,22 +9,25 @@ * IBM Corporation - initial API and implementation * WindRiver - https://bugs.eclipse.org/bugs/show_bug.cgi?id=227372 *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine.phases; +package org.eclipse.equinox.internal.p2.engine.phases; import java.util.*; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.p2.engine.DownloadManager; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRequest; -import org.eclipse.equinox.internal.provisional.p2.engine.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.metadata.ITouchpointType; +import org.eclipse.equinox.internal.p2.engine.*; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.ITouchpointType; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest; /** * The goal of the collect phase is to ask the touchpoints if the artifacts associated with an IU need to be downloaded. */ public class Collect extends InstallableUnitPhase { - private static final String PHASE_ID = "collect"; //$NON-NLS-1$ + private static final String PHASE_ID = IPhaseSet.PHASE_COLLECT; public static final String PARM_ARTIFACT_REQUESTS = "artifactRequests"; //$NON-NLS-1$ public Collect(int weight) { @@ -39,9 +42,9 @@ public class Collect extends InstallableUnitPhase { return (op.second() != null && !op.second().equals(op.first())); } - protected ProvisioningAction[] getActions(InstallableUnitOperand operand) { + protected List<ProvisioningAction> getActions(InstallableUnitOperand operand) { IInstallableUnit unit = operand.second(); - ProvisioningAction[] parsedActions = getActions(unit, phaseId); + List<ProvisioningAction> parsedActions = getActions(unit, phaseId); if (parsedActions != null) return parsedActions; @@ -54,27 +57,29 @@ public class Collect extends InstallableUnitPhase { if (action == null) { return null; } - return new ProvisioningAction[] {action}; + return Collections.singletonList(action); } protected String getProblemMessage() { return Messages.Phase_Collect_Error; } - protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { - List artifactRequests = (List) parameters.get(PARM_ARTIFACT_REQUESTS); + protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) { + @SuppressWarnings("unchecked") + List<IArtifactRequest[]> artifactRequests = (List<IArtifactRequest[]>) parameters.get(PARM_ARTIFACT_REQUESTS); ProvisioningContext context = (ProvisioningContext) parameters.get(PARM_CONTEXT); + IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT); + IArtifactRepositoryManager repositoryManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); - DownloadManager dm = new DownloadManager(context); - for (Iterator it = artifactRequests.iterator(); it.hasNext();) { - IArtifactRequest[] requests = (IArtifactRequest[]) it.next(); + DownloadManager dm = new DownloadManager(context, repositoryManager); + for (IArtifactRequest[] requests : artifactRequests) { dm.add(requests); } return dm.start(monitor); } - protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { - parameters.put(PARM_ARTIFACT_REQUESTS, new ArrayList()); + protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) { + parameters.put(PARM_ARTIFACT_REQUESTS, new ArrayList<IArtifactRequest[]>()); return null; } } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Configure.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Configure.java index 78e7f2529..01dd52695 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Configure.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Configure.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,28 +8,32 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine.phases; +package org.eclipse.equinox.internal.p2.engine.phases; -import java.util.Map; +import java.util.*; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.provisional.p2.engine.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.internal.p2.engine.InstallableUnitPhase; +import org.eclipse.equinox.internal.p2.engine.Messages; +import org.eclipse.equinox.p2.engine.*; +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.equinox.p2.metadata.query.FragmentQuery; import org.eclipse.osgi.util.NLS; public class Configure extends InstallableUnitPhase { public Configure(int weight) { - super("configure", weight); //$NON-NLS-1$ + super(IPhaseSet.PHASE_CONFIGURE, weight); } protected boolean isApplicable(InstallableUnitOperand op) { return (op.second() != null); } - protected ProvisioningAction[] getActions(InstallableUnitOperand currentOperand) { + protected List<ProvisioningAction> getActions(InstallableUnitOperand currentOperand) { IInstallableUnit unit = currentOperand.second(); - if (unit.isFragment()) + if (FragmentQuery.isFragment(unit)) return null; return getActions(unit, phaseId); } @@ -38,14 +42,14 @@ public class Configure extends InstallableUnitPhase { return Messages.Phase_Configure_Error; } - protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) { + protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map<String, Object> parameters, IProgressMonitor monitor) { IInstallableUnit iu = operand.second(); monitor.subTask(NLS.bind(Messages.Phase_Configure_Task, iu.getId())); parameters.put(PARM_IU, iu); - IArtifactKey[] artifacts = iu.getArtifacts(); - if (artifacts != null && artifacts.length > 0) - parameters.put(PARM_ARTIFACT, artifacts[0]); + Collection<IArtifactKey> artifacts = iu.getArtifacts(); + if (artifacts != null && artifacts.size() > 0) + parameters.put(PARM_ARTIFACT, artifacts.iterator().next()); return Status.OK_STATUS; } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Install.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Install.java index e0e9c0f3a..3fa36fb1e 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Install.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Install.java @@ -8,64 +8,70 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine.phases; +package org.eclipse.equinox.internal.p2.engine.phases; -import java.util.Map; +import java.util.*; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; -import org.eclipse.equinox.internal.p2.engine.EngineActivator; -import org.eclipse.equinox.internal.p2.engine.Profile; +import org.eclipse.equinox.internal.p2.engine.*; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; -import org.eclipse.equinox.internal.provisional.p2.engine.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.engine.spi.Touchpoint; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.query.FragmentQuery; import org.eclipse.osgi.util.NLS; public class Install extends InstallableUnitPhase { final static class BeforeInstallEventAction extends ProvisioningAction { - public IStatus execute(Map parameters) { + public IStatus execute(Map<String, Object> parameters) { IProfile profile = (IProfile) parameters.get(PARM_PROFILE); String phaseId = (String) parameters.get(PARM_PHASE_ID); InstallableUnitOperand operand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); - ((IProvisioningEventBus) ServiceHelper.getService(EngineActivator.getContext(), IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, operand, InstallableUnitEvent.INSTALL, getTouchpoint())); + IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT); + ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, operand, InstallableUnitEvent.INSTALL, getTouchpoint())); return null; } - public IStatus undo(Map parameters) { + public IStatus undo(Map<String, Object> parameters) { Profile profile = (Profile) parameters.get(PARM_PROFILE); String phaseId = (String) parameters.get(PARM_PHASE_ID); InstallableUnitOperand operand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU); profile.removeInstallableUnit(iu); - ((IProvisioningEventBus) ServiceHelper.getService(EngineActivator.getContext(), IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, operand, InstallableUnitEvent.UNINSTALL, getTouchpoint())); + IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT); + ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, operand, InstallableUnitEvent.UNINSTALL, getTouchpoint())); return null; } } final static class AfterInstallEventAction extends ProvisioningAction { - public IStatus execute(Map parameters) { + public IStatus execute(Map<String, Object> parameters) { Profile profile = (Profile) parameters.get(PARM_PROFILE); String phaseId = (String) parameters.get(PARM_PHASE_ID); InstallableUnitOperand operand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU); profile.addInstallableUnit(iu); - ((IProvisioningEventBus) ServiceHelper.getService(EngineActivator.getContext(), IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, operand, InstallableUnitEvent.INSTALL, getTouchpoint())); + IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT); + ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, operand, InstallableUnitEvent.INSTALL, getTouchpoint())); return null; } - public IStatus undo(Map parameters) { + public IStatus undo(Map<String, Object> parameters) { IProfile profile = (IProfile) parameters.get(PARM_PROFILE); String phaseId = (String) parameters.get(PARM_PHASE_ID); InstallableUnitOperand operand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); - ((IProvisioningEventBus) ServiceHelper.getService(EngineActivator.getContext(), IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, operand, InstallableUnitEvent.UNINSTALL, getTouchpoint())); + IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT); + ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, operand, InstallableUnitEvent.UNINSTALL, getTouchpoint())); return null; } } - private static final String PHASE_ID = "install"; //$NON-NLS-1$ + private static final String PHASE_ID = IPhaseSet.PHASE_INSTALL; public Install(int weight) { super(PHASE_ID, weight); @@ -75,7 +81,7 @@ public class Install extends InstallableUnitPhase { return (op.second() != null && !op.second().equals(op.first())); } - protected ProvisioningAction[] getActions(InstallableUnitOperand currentOperand) { + protected List<ProvisioningAction> getActions(InstallableUnitOperand currentOperand) { //TODO: monitor.subTask(NLS.bind(Messages.Engine_Installing_IU, unit.getId())); ProvisioningAction beforeAction = new BeforeInstallEventAction(); @@ -88,17 +94,18 @@ public class Install extends InstallableUnitPhase { afterAction.setTouchpoint(touchpoint); } - if (unit.isFragment()) - return new ProvisioningAction[] {beforeAction, afterAction}; + ArrayList<ProvisioningAction> actions = new ArrayList<ProvisioningAction>(); + actions.add(beforeAction); - ProvisioningAction[] parsedActions = getActions(unit, phaseId); - if (parsedActions == null) - return new ProvisioningAction[] {beforeAction, afterAction}; + if (FragmentQuery.isFragment(unit)) { + actions.add(afterAction); + return actions; + } - ProvisioningAction[] actions = new ProvisioningAction[parsedActions.length + 2]; - actions[0] = beforeAction; - System.arraycopy(parsedActions, 0, actions, 1, parsedActions.length); - actions[actions.length - 1] = afterAction; + List<ProvisioningAction> parsedActions = getActions(unit, phaseId); + if (parsedActions != null) + actions.addAll(parsedActions); + actions.add(afterAction); return actions; } @@ -106,14 +113,14 @@ public class Install extends InstallableUnitPhase { return Messages.Phase_Install_Error; } - protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) { + protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map<String, Object> parameters, IProgressMonitor monitor) { IInstallableUnit iu = operand.second(); monitor.subTask(NLS.bind(Messages.Phase_Install_Task, iu.getId())); parameters.put(PARM_IU, iu); - IArtifactKey[] artifacts = iu.getArtifacts(); - if (artifacts != null && artifacts.length > 0) - parameters.put(PARM_ARTIFACT, artifacts[0]); + Collection<IArtifactKey> artifacts = iu.getArtifacts(); + if (artifacts != null && artifacts.size() > 0) + parameters.put(PARM_ARTIFACT, artifacts.iterator().next()); return Status.OK_STATUS; } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Property.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Property.java index 7a2387170..95d0a828f 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Property.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Property.java @@ -8,19 +8,21 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine.phases; +package org.eclipse.equinox.internal.p2.engine.phases; -import java.util.Map; +import java.util.*; import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.p2.engine.Phase; import org.eclipse.equinox.internal.p2.engine.Profile; -import org.eclipse.equinox.internal.provisional.p2.engine.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; public class Property extends Phase { public class ProfilePropertyAction extends ProvisioningAction { - public IStatus execute(Map parameters) { + public IStatus execute(Map<String, Object> parameters) { Profile profile = (Profile) parameters.get(PARM_PROFILE); PropertyOperand propertyOperand = (PropertyOperand) parameters.get(PARM_OPERAND); @@ -32,7 +34,7 @@ public class Property extends Phase { return null; } - public IStatus undo(Map parameters) { + public IStatus undo(Map<String, Object> parameters) { Profile profile = (Profile) parameters.get(PARM_PROFILE); PropertyOperand propertyOperand = (PropertyOperand) parameters.get(PARM_OPERAND); @@ -69,10 +71,10 @@ public class Property extends Phase { public class UpdateInstallableUnitProfilePropertiesAction extends ProvisioningAction { // we do not need to use a memento here since the profile is not persisted unless the operation is successful - Map originalSourceProperties; - Map originalTargetProperties; + Map<String, String> originalSourceProperties; + Map<String, String> originalTargetProperties; - public IStatus execute(Map parameters) { + public IStatus execute(Map<String, Object> parameters) { Profile profile = (Profile) parameters.get(PARM_PROFILE); InstallableUnitOperand iuOperand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); @@ -88,7 +90,7 @@ public class Property extends Phase { return null; } - public IStatus undo(Map parameters) { + public IStatus undo(Map<String, Object> parameters) { Profile profile = (Profile) parameters.get(PARM_PROFILE); InstallableUnitOperand iuOperand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); @@ -107,10 +109,10 @@ public class Property extends Phase { public class RemoveInstallableUnitProfilePropertiesAction extends ProvisioningAction { // we do not need to use a memento here since the profile is not persisted unless the operation is successful - Map originalSourceProperties; - Map originalTargetProperties; + Map<String, String> originalSourceProperties; + Map<String, String> originalTargetProperties; - public IStatus execute(Map parameters) { + public IStatus execute(Map<String, Object> parameters) { Profile profile = (Profile) parameters.get(PARM_PROFILE); InstallableUnitOperand iuOperand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); @@ -121,7 +123,7 @@ public class Property extends Phase { return null; } - public IStatus undo(Map parameters) { + public IStatus undo(Map<String, Object> parameters) { Profile profile = (Profile) parameters.get(PARM_PROFILE); InstallableUnitOperand iuOperand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); @@ -133,23 +135,23 @@ public class Property extends Phase { } } - private static final String PHASE_ID = "property"; //$NON-NLS-1$ + private static final String PHASE_ID = IPhaseSet.PHASE_PROPERTY; public Property(int weight) { super(PHASE_ID, weight); } - protected ProvisioningAction[] getActions(Operand operand) { + protected List<ProvisioningAction> getActions(Operand operand) { if (operand instanceof PropertyOperand) - return new ProvisioningAction[] {new ProfilePropertyAction()}; + return Collections.<ProvisioningAction> singletonList(new ProfilePropertyAction()); if (operand instanceof InstallableUnitOperand) { InstallableUnitOperand iuOperand = (InstallableUnitOperand) operand; if (iuOperand.first() != null) { if (iuOperand.second() != null) { - return new ProvisioningAction[] {new UpdateInstallableUnitProfilePropertiesAction()}; + return Collections.<ProvisioningAction> singletonList(new UpdateInstallableUnitProfilePropertiesAction()); } - return new ProvisioningAction[] {new RemoveInstallableUnitProfilePropertiesAction()}; + return Collections.<ProvisioningAction> singletonList(new RemoveInstallableUnitProfilePropertiesAction()); } } return null; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Sizing.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Sizing.java index 1145fb79a..7fba95408 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Sizing.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Sizing.java @@ -8,19 +8,20 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine.phases; +package org.eclipse.equinox.internal.p2.engine.phases; import java.net.URI; import java.util.*; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; -import org.eclipse.equinox.internal.p2.engine.EngineActivator; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.engine.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.metadata.ITouchpointType; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; +import org.eclipse.equinox.internal.p2.engine.*; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.ITouchpointType; +import org.eclipse.equinox.p2.repository.IRepositoryManager; +import org.eclipse.equinox.p2.repository.artifact.*; public class Sizing extends InstallableUnitPhase { private static final String PHASE_ID = "sizing"; //$NON-NLS-1$ @@ -45,9 +46,9 @@ public class Sizing extends InstallableUnitPhase { return dlSize; } - protected ProvisioningAction[] getActions(InstallableUnitOperand operand) { + protected List<ProvisioningAction> getActions(InstallableUnitOperand operand) { IInstallableUnit unit = operand.second(); - ProvisioningAction[] parsedActions = getActions(unit, COLLECT_PHASE_ID); + List<ProvisioningAction> parsedActions = getActions(unit, COLLECT_PHASE_ID); if (parsedActions != null) return parsedActions; @@ -60,22 +61,23 @@ public class Sizing extends InstallableUnitPhase { if (action == null) { return null; } - return new ProvisioningAction[] {action}; + return Collections.singletonList(action); } protected String getProblemMessage() { return Messages.Phase_Sizing_Error; } - protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { - List artifactRequests = (List) parameters.get(Collect.PARM_ARTIFACT_REQUESTS); + protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) { + @SuppressWarnings("unchecked") + List<IArtifactRequest[]> artifactRequests = (List<IArtifactRequest[]>) parameters.get(Collect.PARM_ARTIFACT_REQUESTS); ProvisioningContext context = (ProvisioningContext) parameters.get(PARM_CONTEXT); + IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT); int statusCode = 0; - Set artifactsToObtain = new HashSet(artifactRequests.size()); + Set<IArtifactRequest> artifactsToObtain = new HashSet<IArtifactRequest>(artifactRequests.size()); - for (Iterator it = artifactRequests.iterator(); it.hasNext();) { - IArtifactRequest[] requests = (IArtifactRequest[]) it.next(); + for (IArtifactRequest[] requests : artifactRequests) { if (requests == null) continue; for (int i = 0; i < requests.length; i++) { @@ -86,15 +88,16 @@ public class Sizing extends InstallableUnitPhase { if (monitor.isCanceled()) return Status.CANCEL_STATUS; - IArtifactRepositoryManager repoMgr = (IArtifactRepositoryManager) ServiceHelper.getService(EngineActivator.getContext(), IArtifactRepositoryManager.class.getName()); + IArtifactRepositoryManager repoMgr = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); URI[] repositories = null; if (context == null || context.getArtifactRepositories() == null) repositories = repoMgr.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL); else repositories = context.getArtifactRepositories(); - for (Iterator iterator = artifactsToObtain.iterator(); iterator.hasNext() && !monitor.isCanceled();) { - IArtifactRequest artifactRequest = (IArtifactRequest) iterator.next(); + for (IArtifactRequest artifactRequest : artifactsToObtain) { + if (monitor.isCanceled()) + break; boolean found = false; for (int i = 0; i < repositories.length; i++) { IArtifactRepository repo; @@ -128,8 +131,8 @@ public class Sizing extends InstallableUnitPhase { return null; } - protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { - parameters.put(Collect.PARM_ARTIFACT_REQUESTS, new ArrayList()); + protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) { + parameters.put(Collect.PARM_ARTIFACT_REQUESTS, new ArrayList<IArtifactRequest[]>()); return null; } } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Unconfigure.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Unconfigure.java index 2eb8eb458..9142e300e 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Unconfigure.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Unconfigure.java @@ -8,18 +8,22 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine.phases; +package org.eclipse.equinox.internal.p2.engine.phases; -import java.util.Map; +import java.util.*; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.provisional.p2.engine.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.internal.p2.engine.InstallableUnitPhase; +import org.eclipse.equinox.internal.p2.engine.Messages; +import org.eclipse.equinox.p2.engine.*; +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.equinox.p2.metadata.query.FragmentQuery; public class Unconfigure extends InstallableUnitPhase { public Unconfigure(int weight, boolean forced) { - super("unconfigure", weight, forced); //$NON-NLS-1$ + super(IPhaseSet.PHASE_UNCONFIGURE, weight, forced); } public Unconfigure(int weight) { @@ -30,11 +34,11 @@ public class Unconfigure extends InstallableUnitPhase { return (op.first() != null); } - protected ProvisioningAction[] getActions(InstallableUnitOperand currentOperand) { + protected List<ProvisioningAction> getActions(InstallableUnitOperand currentOperand) { //TODO: monitor.subTask(NLS.bind(Messages.Engine_Unconfiguring_IU, unit.getId())); IInstallableUnit unit = currentOperand.first(); - if (unit.isFragment()) + if (FragmentQuery.isFragment(unit)) return null; return getActions(unit, phaseId); @@ -44,13 +48,13 @@ public class Unconfigure extends InstallableUnitPhase { return Messages.Phase_Unconfigure_Error; } - protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) { + protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map<String, Object> parameters, IProgressMonitor monitor) { IInstallableUnit iu = operand.first(); parameters.put(PARM_IU, iu); - IArtifactKey[] artifacts = iu.getArtifacts(); - if (artifacts != null && artifacts.length > 0) - parameters.put(PARM_ARTIFACT, artifacts[0]); + Collection<IArtifactKey> artifacts = iu.getArtifacts(); + if (artifacts != null && artifacts.size() > 0) + parameters.put(PARM_ARTIFACT, artifacts.iterator().next()); return Status.OK_STATUS; } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Uninstall.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Uninstall.java index 5b66522de..a58d9bbe6 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Uninstall.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/Uninstall.java @@ -8,64 +8,68 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine.phases; +package org.eclipse.equinox.internal.p2.engine.phases; -import java.util.Map; +import java.util.*; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; -import org.eclipse.equinox.internal.p2.engine.EngineActivator; -import org.eclipse.equinox.internal.p2.engine.Profile; +import org.eclipse.equinox.internal.p2.engine.*; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; -import org.eclipse.equinox.internal.provisional.p2.engine.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.engine.spi.Touchpoint; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.query.FragmentQuery; public class Uninstall extends InstallableUnitPhase { final static class BeforeUninstallEventAction extends ProvisioningAction { - public IStatus execute(Map parameters) { + public IStatus execute(Map<String, Object> parameters) { IProfile profile = (IProfile) parameters.get(PARM_PROFILE); String phaseId = (String) parameters.get(PARM_PHASE_ID); InstallableUnitOperand operand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); - ((IProvisioningEventBus) ServiceHelper.getService(EngineActivator.getContext(), IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, operand, InstallableUnitEvent.UNINSTALL, getTouchpoint())); + IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT); + ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, operand, InstallableUnitEvent.UNINSTALL, getTouchpoint())); return null; } - public IStatus undo(Map parameters) { + public IStatus undo(Map<String, Object> parameters) { Profile profile = (Profile) parameters.get(PARM_PROFILE); String phaseId = (String) parameters.get(PARM_PHASE_ID); InstallableUnitOperand operand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU); profile.addInstallableUnit(iu); - ((IProvisioningEventBus) ServiceHelper.getService(EngineActivator.getContext(), IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, operand, InstallableUnitEvent.INSTALL, getTouchpoint())); + IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT); + ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, operand, InstallableUnitEvent.INSTALL, getTouchpoint())); return null; } } final static class AfterUninstallEventAction extends ProvisioningAction { - public IStatus execute(Map parameters) { + public IStatus execute(Map<String, Object> parameters) { Profile profile = (Profile) parameters.get(PARM_PROFILE); String phaseId = (String) parameters.get(PARM_PHASE_ID); InstallableUnitOperand operand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU); profile.removeInstallableUnit(iu); - ((IProvisioningEventBus) ServiceHelper.getService(EngineActivator.getContext(), IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, operand, InstallableUnitEvent.UNINSTALL, getTouchpoint())); + IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT); + ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, operand, InstallableUnitEvent.UNINSTALL, getTouchpoint())); return null; } - public IStatus undo(Map parameters) { + public IStatus undo(Map<String, Object> parameters) { IProfile profile = (IProfile) parameters.get(PARM_PROFILE); String phaseId = (String) parameters.get(PARM_PHASE_ID); InstallableUnitOperand operand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); - ((IProvisioningEventBus) ServiceHelper.getService(EngineActivator.getContext(), IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, operand, InstallableUnitEvent.INSTALL, getTouchpoint())); + IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT); + ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, operand, InstallableUnitEvent.INSTALL, getTouchpoint())); return null; } } - private static final String PHASE_ID = "uninstall"; //$NON-NLS-1$ - public Uninstall(int weight, boolean forced) { - super(PHASE_ID, weight, forced); + super(IPhaseSet.PHASE_UNINSTALL, weight, forced); } public Uninstall(int weight) { @@ -76,7 +80,7 @@ public class Uninstall extends InstallableUnitPhase { return (op.first() != null && !op.first().equals(op.second())); } - protected ProvisioningAction[] getActions(InstallableUnitOperand currentOperand) { + protected List<ProvisioningAction> getActions(InstallableUnitOperand currentOperand) { //TODO: monitor.subTask(NLS.bind(Messages.Engine_Uninstalling_IU, unit.getId())); ProvisioningAction beforeAction = new BeforeUninstallEventAction(); @@ -89,16 +93,18 @@ public class Uninstall extends InstallableUnitPhase { afterAction.setTouchpoint(touchpoint); } - if (unit.isFragment()) - return new ProvisioningAction[] {beforeAction, afterAction}; - ProvisioningAction[] parsedActions = getActions(unit, phaseId); - if (parsedActions == null) - return new ProvisioningAction[] {beforeAction, afterAction}; + ArrayList<ProvisioningAction> actions = new ArrayList<ProvisioningAction>(); + actions.add(beforeAction); + + if (FragmentQuery.isFragment(unit)) { + actions.add(afterAction); + return actions; + } - ProvisioningAction[] actions = new ProvisioningAction[parsedActions.length + 2]; - actions[0] = beforeAction; - System.arraycopy(parsedActions, 0, actions, 1, parsedActions.length); - actions[actions.length - 1] = afterAction; + List<ProvisioningAction> parsedActions = getActions(unit, phaseId); + if (parsedActions != null) + actions.addAll(parsedActions); + actions.add(afterAction); return actions; } @@ -106,13 +112,13 @@ public class Uninstall extends InstallableUnitPhase { return Messages.Phase_Uninstall_Error; } - protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) { + protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map<String, Object> parameters, IProgressMonitor monitor) { IInstallableUnit iu = operand.first(); parameters.put(PARM_IU, iu); - IArtifactKey[] artifacts = iu.getArtifacts(); - if (artifacts != null && artifacts.length > 0) - parameters.put(PARM_ARTIFACT, artifacts[0]); + Collection<IArtifactKey> artifacts = iu.getArtifacts(); + if (artifacts != null && artifacts.size() > 0) + parameters.put(PARM_ARTIFACT, artifacts.iterator().next()); return Status.OK_STATUS; } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/IEngine.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/IEngine.java deleted file mode 100644 index 16db9b281..000000000 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/IEngine.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Band XI International, LLC and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Band XI - initial API and implementation - * IBM - ongoing development - *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; - -public interface IEngine { - /** - * Service name constant for the engine service. - */ - public static final String SERVICE_NAME = IEngine.class.getName(); - - public IStatus perform(IProfile profile, PhaseSet phaseSet, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor); - - public IStatus validate(IProfile iprofile, PhaseSet phaseSet, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor); -} diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/Messages.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/Messages.java deleted file mode 100644 index b4aef5af8..000000000 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/Messages.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; - -import org.eclipse.osgi.util.NLS; - -//TODO Shouldn't have messages class in API package -public class Messages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.provisional.p2.engine.messages"; //$NON-NLS-1$ - public static String CertificateChecker_CertificateError; - public static String CertificateChecker_CertificateRejected; - public static String CertificateChecker_KeystoreConnectionError; - public static String CertificateChecker_SignedContentIOError; - public static String CertificateChecker_SignedContentError; - public static String CertificateChecker_UnsignedNotAllowed; - public static String not_current_phase; - public static String null_operands; - public static String null_phase; - public static String null_phases; - public static String null_phaseset; - public static String null_profile; - public static String phase_error; - public static String phase_not_started; - public static String phase_started; - public static String phaseid_not_positive; - public static String phaseid_not_set; - public static String Engine_Operation_Canceled_By_User; - public static String InstallableUnitEvent_type_not_install_or_uninstall; - public static String touchpoint_prepare_error; - public static String touchpoint_commit_error; - public static String touchpoint_rollback_error; - public static String phase_undo_error; - public static String phase_undo_operand_error; - public static String session_prepare_error; - public static String session_commit_error; - public static String null_operand; - public static String operand_started; - public static String operand_not_started; - public static String not_current_operand; - public static String null_action; - public static String session_context; - public static String action_not_found; - public static String actions_not_found; - public static String preparing; - public static String committing; - public static String rollingback_cancel; - public static String rollingback_error; - public static String action_undo_error; - public static String forced_action_execute_error; - - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - // - } -} diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/messages.properties b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/messages.properties deleted file mode 100644 index 364307adc..000000000 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/messages.properties +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################### -# Copyright (c) 2007, 2009 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -action_not_found=No action found for: {0}. -action_undo_error=An error occurred while rolling back the engine operation while undoing the {0} action. -forced_action_execute_error=An error occurred while performing the engine operation while executing the {0} action in forced mode. The operation will continue. -actions_not_found=No actions found for: {0}. -not_current_phase=Current phase does not match argument. -null_operands=Operands must not be null. -null_phase=Phase must not be null. -null_phases=Phases must not be null -null_phaseset=PhaseSet must not be null. -null_profile=Profile must not be null. -touchpoint_prepare_error=An error occurred while preparing the engine operation for the {0} touchpoint. -touchpoint_commit_error=An error occurred while committing the engine operation for the {0} touchpoint. -touchpoint_rollback_error=An error occurred while rolling back the engine operation for the {0} touchpoint. -phase_error=An error occurred during the {0} phase. -phase_undo_error=An error occurred while undoing the {0} phase. -phase_undo_operand_error=An error occurred while undoing the {0} phase for operand {1}. -phase_not_started=There is no phase to end. -phase_started=A phase is already started. -phaseid_not_positive=Phase weight must be positive. -phaseid_not_set=Phase id must be set. -session_prepare_error=An error occurred while preparing the engine session for profile: {0}. -session_commit_error=An error occurred while committing the engine session for profile: {0}. -null_operand=Operand must not be null. -operand_started=An operand is already started. -operand_not_started=There is no operand to end. -not_current_operand=Current operand does not match argument. -null_action=Action must not be null -session_context=session context was:(profile={0}, phase={1}, operand={2}, action={3}). -preparing=Preparing to commit the provisioning operation. -committing=Committing the provisioning operation. -rollingback_error=An error was detected while performing the engine operation and the changes are being rolled back. See the log for details. -rollingback_cancel=The engine operation was cancelled and the changes are being rolled back. - -Engine_Operation_Canceled_By_User=Operation canceled by the user. -InstallableUnitEvent_type_not_install_or_uninstall=type must be either UNINSTALL(0) or INSTALL(1) -CertificateChecker_CertificateError=An invalid certificate was found. -CertificateChecker_CertificateRejected=One or more certificates rejected. Cannot proceed with installation. -CertificateChecker_KeystoreConnectionError=Cannot connect to keystore. -CertificateChecker_SignedContentError=Error with signed content. -CertificateChecker_SignedContentIOError=Error reading signed content. -CertificateChecker_UnsignedNotAllowed=Installing unsigned artifacts is not permitted: {0} diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Messages.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Messages.java deleted file mode 100644 index 081b6f233..000000000 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Messages.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine.phases; - -import org.eclipse.osgi.util.NLS; - -//TODO Shouldn't have messages class in API package -class Messages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.provisional.p2.engine.phases.messages"; //$NON-NLS-1$ - public static String Phase_Collect_Error; - public static String Phase_Install_Error; - public static String Phase_Configure_Error; - public static String Phase_Configure_Task; - public static String Phase_Install_Task; - public static String Phase_Sizing_Error; - public static String Phase_Sizing_Warning; - public static String Phase_Unconfigure_Error; - public static String Phase_Uninstall_Error; - - static { - // initialize resource bundles - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - // Do not instantiate - } - -} diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/messages.properties b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/messages.properties deleted file mode 100644 index 58a0dd1e5..000000000 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/messages.properties +++ /dev/null @@ -1,20 +0,0 @@ -############################################################################### -# Copyright (c) 2007, 2009 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### - -Phase_Collect_Error=An error occurred while collecting items to be installed -Phase_Configure_Error=An error occurred while configuring the installed items -Phase_Configure_Task=Configuring {0} -Phase_Install_Error=An error occurred while installing the items -Phase_Install_Task=Installing {0} -Phase_Sizing_Error=Error computing the size. Some of the items to be installed could not be found. -Phase_Sizing_Warning=The size may not be accurate. Some of the items did not report a size. -Phase_Unconfigure_Error=An error occurred while unconfiguring the items to uninstall -Phase_Uninstall_Error=An error occurred while uninstalling diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/BeginOperationEvent.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/BeginOperationEvent.java index d9de82c07..98576a326 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/BeginOperationEvent.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/BeginOperationEvent.java @@ -8,8 +8,13 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; +import org.eclipse.equinox.internal.p2.engine.PhaseSet; + +/** + * @since 2.0 + */ public class BeginOperationEvent extends TransactionEvent { private static final long serialVersionUID = 6389318375739324865L; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/CommitOperationEvent.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/CommitOperationEvent.java index 00f89a13d..5b993dc39 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/CommitOperationEvent.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/CommitOperationEvent.java @@ -8,8 +8,13 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; +import org.eclipse.equinox.internal.p2.engine.PhaseSet; + +/** + * @since 2.0 + */ public class CommitOperationEvent extends TransactionEvent { private static final long serialVersionUID = -523967775426133720L; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/DefaultPhaseSet.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/DefaultPhaseSet.java index 4842ad1f1..c6fe87bdf 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/DefaultPhaseSet.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/DefaultPhaseSet.java @@ -8,23 +8,26 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; import java.util.ArrayList; -import org.eclipse.equinox.internal.p2.engine.EngineActivator; -import org.eclipse.equinox.internal.provisional.p2.engine.phases.*; +import org.eclipse.equinox.internal.p2.engine.*; +import org.eclipse.equinox.internal.p2.engine.phases.*; +/** + * @since 2.0 + */ public class DefaultPhaseSet extends PhaseSet { private static final boolean forcedUninstall = Boolean.valueOf(EngineActivator.getContext().getProperty("org.eclipse.equinox.p2.engine.forcedUninstall")).booleanValue(); //$NON-NLS-1$ - public static int PHASE_CHECK_TRUST = 0x01; public static int PHASE_COLLECT = 0x02; - public static int PHASE_CONFIGURE = 0x04; - public static int PHASE_INSTALL = 0x08; - public static int PHASE_PROPERTY = 0x10; public static int PHASE_UNCONFIGURE = 0x20; public static int PHASE_UNINSTALL = 0x40; + public static int PHASE_PROPERTY = 0x10; + public static int PHASE_CHECK_TRUST = 0x01; + public static int PHASE_INSTALL = 0x08; + public static int PHASE_CONFIGURE = 0x04; public DefaultPhaseSet() { this(new Phase[] {new Collect(100), new Unconfigure(10, forcedUninstall), new Uninstall(50, forcedUninstall), new Property(1), new CheckTrust(10), new Install(50), new Configure(10)}); @@ -43,7 +46,7 @@ public class DefaultPhaseSet extends PhaseSet { * @return the {@link PhaseSet} */ public static final PhaseSet createDefaultPhaseSet(int exclude) { - ArrayList phases = new ArrayList(); + ArrayList<Phase> phases = new ArrayList<Phase>(); if ((PHASE_COLLECT & exclude) != PHASE_COLLECT) phases.add(new Collect(100)); if ((PHASE_UNCONFIGURE & exclude) != PHASE_UNCONFIGURE) @@ -58,6 +61,6 @@ public class DefaultPhaseSet extends PhaseSet { phases.add(new Install(50)); if ((PHASE_CONFIGURE & exclude) != PHASE_CONFIGURE) phases.add(new Configure(10)); - return new DefaultPhaseSet((Phase[]) phases.toArray(new Phase[phases.size()])); + return new DefaultPhaseSet(phases.toArray(new Phase[phases.size()])); } } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IEngine.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IEngine.java new file mode 100644 index 000000000..67d0f8d28 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IEngine.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2008, 2009 Band XI International, LLC and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Band XI - initial API and implementation + * IBM - ongoing development + *******************************************************************************/ +package org.eclipse.equinox.p2.engine; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; + +/** + * The engine is a service that naively performs a set of requested changes to a provisioned + * system. No attempt is made to determine whether the requested changes or the + * resulting system are valid or consistent. It is assumed that the engine client has + * crafted a valid provisioning plan for the engine to perform, typically by using a planner + * service. + * <p> + * The engine operates by executing a series of installation phases. The client can + * customize the set of phases that are executed, or else the engine will execute + * a default set of phases. During each phase the changes described by the provisioning + * plan are performed against the profile being provisioned. + * + * @since 2.0 + */ +public interface IEngine { + /** + * Service name constant for the engine service. + */ + public static final String SERVICE_NAME = IEngine.class.getName(); + + /** + * Creates a customized provisioning plan describing a set of changes that have already been validated. + * This is an advanced method for clients that know they are creating changes that do + * not require validation by a planner. Most clients should instead obtain a validated plan + * from a planner. + * + * @param profile The profile to operate against + * @param operands The operands to perform + * @param context The provisioning context for the plan + * @return A provisioning plan + */ + public IProvisioningPlan createCustomPlan(IProfile profile, Operand[] operands, ProvisioningContext context); + + /** + * Creates a phase set with a default set of phases, excluding the specified phases. + * @param excludes The phases to exclude, or <code>null</code> to include + * all default phases. + * + * @return A new phase set + */ + public IPhaseSet createPhaseSetExcluding(String[] excludes); + + /** + * Creates and returns a phase set including only the specified phases. + * @param includes The phases to include + * @return A new phase set + */ + public IPhaseSet createPhaseSetIncluding(String[] includes); + + /** + * Executes a provisioning plan. + * + * @param plan The plan describing the changes to be made + * @param phaseSet The phases to run, or <code>null</code> to run default phases + * @param monitor A progress monitor, or <code>null</code> if progress reporting is not required + * @return The result of executing the plan + */ + public IStatus perform(IProvisioningPlan plan, IPhaseSet phaseSet, IProgressMonitor monitor); + + /** + * Executes a provisioning plan with a default phase set and context. + * + * @param plan The plan describing the changes to be made + * @param monitor A progress monitor, or <code>null</code> if progress reporting is not required + * @return The result of executing the plan + */ + public IStatus perform(IProvisioningPlan plan, IProgressMonitor monitor); +} diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IPhaseSet.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IPhaseSet.java new file mode 100644 index 000000000..4344c61d8 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IPhaseSet.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.engine; + + +/** + * Describes a set of provisioning phases to be performed by an {@link IEngine}. + * + * @noimplement This interface is not intended to be implemented by clients. + * @noextend This interface is not intended to be extended by clients. + * @since 2.0 + */ +public interface IPhaseSet { + + /** + * A phase id (value "checkTrust") describing the certificate trust check phase. + * This phase examines the code signing certificates of the artifacts being installed + * to ensure they are signed and trusted by the running system. + */ + public static String PHASE_CHECK_TRUST = "checkTrust"; //$NON-NLS-1$ + /** + * A phase id (value "collect") describing the collect phase. + * This phase gathers all the artifacts to be installed, typically by copying them + * from some repository into a suitable local location for the application being installed. + */ + public static String PHASE_COLLECT = "collect"; //$NON-NLS-1$ + /** + * A phase id (value "configure") describing the configuration phase. + * This phase writes configuration data related to the software being provisioned. + * Until configuration occurs the end user of the software will be have access to + * the installed functionality. + */ + public static String PHASE_CONFIGURE = "configure"; //$NON-NLS-1$ + /** + * A phase id (value "install") describing the install phase. + * This phase performs any necessary transformations on the downloaded + * artifacts to put them in the correct shape for the running application, such + * as decompressing or moving content, setting file permissions, etc). + */ + public static String PHASE_INSTALL = "install"; //$NON-NLS-1$ + /** + * A phase id (value "property") describing the property modification phase. + * This phase performs changes to profile properties. + */ + public static String PHASE_PROPERTY = "property"; //$NON-NLS-1$ + /** + * A phase id (value "unconfigure") describing the unconfigure phase. + * This phase removes configuration data related to the software being removed. + * This phase is the inverse of the changes performed in the configure phase. + */ + public static String PHASE_UNCONFIGURE = "unconfigure"; //$NON-NLS-1$ + /** + * A phase id (value "uninstall") describing the uninstall phase. + * This phase removes artifacts from the system being provisioned that are + * no longer required in the new profile. + */ + public static String PHASE_UNINSTALL = "uninstall"; //$NON-NLS-1$ + + /** + * Returns the ids of the phases to be performed by this phase set. The order + * of the returned ids indicates the order in which the phases will be run. + * @return The phase ids. + */ + public String[] getPhaseIds(); +} diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/IProfile.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfile.java index 686f36ac5..3019f6917 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/IProfile.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfile.java @@ -8,19 +8,52 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.*; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.query.*; -public interface IProfile extends IQueryable { +/** + * @since 2.0 + */ +public interface IProfile extends IQueryable<IInstallableUnit> { /** - * Profile property constant indicating the flavor for the profile. + * Constant used to indicate that an installable unit is not locked in anyway. + * @see #PROP_PROFILE_LOCKED_IU */ - public static final String PROP_FLAVOR = "org.eclipse.equinox.p2.flavor"; //$NON-NLS-1$ + public static int LOCK_NONE = 0; + /** + * Constant used to indicate that an installable unit is locked so that it may + * not be uninstalled. + * @see #PROP_PROFILE_LOCKED_IU + */ + public static int LOCK_UNINSTALL = 1 << 0; + /** + * Constant used to indicate that an installable unit is locked so that it may + * not be updated. updates. + * @see #PROP_PROFILE_LOCKED_IU + */ + public static int LOCK_UPDATE = 1 << 1; + + /** + * A property key (value <code>"org.eclipse.equinox.p2.type.lock"</code>) for an + * integer property indicating how an installable unit is locked in its profile. + * The integer is a bit-mask indicating the different locks defined on the installable + * unit. The property should be obtained from a profile using + * IProfile#getInstallableUnitProperty(IInstallableUnit, String). + * + * @see #LOCK_UNINSTALL + * @see #LOCK_UPDATE + * @see #LOCK_NONE + */ + public static final String PROP_PROFILE_LOCKED_IU = "org.eclipse.equinox.p2.type.lock"; //$NON-NLS-1$ + + //TODO Move to UI + public static final String PROP_PROFILE_ROOT_IU = "org.eclipse.equinox.p2.type.root"; //$NON-NLS-1$ + /** * Profile property constant indicating the install folder for the profile. */ @@ -80,52 +113,21 @@ public interface IProfile extends IQueryable { public String getProfileId(); - public IProfile getParentProfile(); - - /* - * A profile is a root profile if it is not a sub-profile - * of another profile. - */ - public boolean isRootProfile(); - - public boolean hasSubProfiles(); - - public String[] getSubProfileIds(); - /** * Get the stored value associated with the given key. - * If the profile is a sub-profile and there is no value - * locally associated with the key, then the chain - * of parent profiles will be traversed to get an associated - * value from the nearest ancestor. * - * <code>null</code> is return if none of this profile - * or its ancestors associates a value with the key. + * <code>null</code> is returned if this property is not present */ public String getProperty(String key); - /** - * Get the stored value associated with the given key in this profile. - * No traversal of the ancestor hierarchy is done for sub-profiles. - */ - public String getLocalProperty(String key); - public String getInstallableUnitProperty(IInstallableUnit iu, String key); - /** - * Get an <i>unmodifiable copy</i> of the local properties - * associated with the profile. - * - * @return an <i>unmodifiable copy</i> of the Profile properties. - */ - public Map getLocalProperties(); - - public Map getProperties(); + public Map<String, String> getProperties(); - public Map getInstallableUnitProperties(IInstallableUnit iu); + public Map<String, String> getInstallableUnitProperties(IInstallableUnit iu); public long getTimestamp(); - public Collector available(Query query, Collector collector, IProgressMonitor monitor); + public IQueryResult<IInstallableUnit> available(IQuery<IInstallableUnit> query, IProgressMonitor monitor); }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/IProfileRegistry.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfileRegistry.java index 2b7cace00..adbd48360 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/IProfileRegistry.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfileRegistry.java @@ -8,14 +8,15 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; import java.util.Map; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; +import org.eclipse.equinox.p2.core.ProvisionException; /** * This encapsulates the access to the profile registry. * It deals with persistence in a transparent way. + * @since 2.0 */ public interface IProfileRegistry { public static final String SELF = "_SELF_"; //$NON-NLS-1$ @@ -79,19 +80,7 @@ public interface IProfileRegistry { * @throws ProvisionException if a profile * with the same id is already present in the registry. */ - IProfile addProfile(String id, Map properties) throws ProvisionException; - - /** - * Add the given profile to this profile registry. - * - * @param id the profile id - * @param properties the profile properties - * @param parentId the id of a parent profile - * - * @throws ProvisionException if a profile - * with the same id is already present in the registry or the parentId is not a registered Profile. - */ - IProfile addProfile(String id, Map properties, String parentId) throws ProvisionException; + IProfile addProfile(String id, Map<String, String> properties) throws ProvisionException; /** * Returns whether this profile registry contains a profile with the given id. diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProvisioningPlan.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProvisioningPlan.java new file mode 100644 index 000000000..0f24afff7 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProvisioningPlan.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.engine; + +import java.util.Map; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.query.IQueryable; + +/** + * A provisioning plan describes a proposed set of changes to a profile. The + * proposed changes may represent a valid and consistent set of changes, or it + * may represent a set of changes that would cause errors if executed. In this + * case the plan contains information about the severity and explanation for the + * problems. + * + * @since 2.0 + */ +public interface IProvisioningPlan { + + /** + * Returns the proposed set of installable units to be added to the profile. + * + * @return The proposed profile additions + */ + public abstract IQueryable<IInstallableUnit> getAdditions(); + + /** + * Returns the provisioning context in which this plan was created. + * + * @return The plan's provisioning context + */ + public ProvisioningContext getContext(); + + /** + * Returns a plan describing the proposed set of changes to the provisioning infrastructure + * required by this plan. The installer changes must be performed before this plan + * can be successfully executed. + * + * @return The installer plan. + */ + public abstract IProvisioningPlan getInstallerPlan(); + + /** + * The operands to pass to the engine. + * @return the operands to be executed. This may be an empty array if the + * plan has errors or if there is nothing to do. + */ + public abstract Operand[] getOperands(); + + /** + * Returns the profile that this plan will operate on. + * + * @return The target profile for this plan + */ + public abstract IProfile getProfile(); + + /** + * Returns the proposed set of installable units to be removed from this profile. + * + * @return The proposed profile removals. + */ + public abstract IQueryable<IInstallableUnit> getRemovals(); + + /** + * Returns the problems associated with changes to the given installable unit + * in this plan. A status with severity {@link IStatus#OK} is returned if the unit + * can be provisioned successfully, or if this plan does not include changes to the + * given unit. + * + * @param iu The installable unit to return status for + * @return The status for the given unit in this plan + */ + public abstract IStatus getRequestStatus(IInstallableUnit iu); + + /** + * Returns a map of side-effects that will occur as a result of the plan being executed. + * Side-effects of an install may include: + * <ul> + * <li>Optional software being installed that will become satisfied once the plan + * is executed.</li> + * <li>Optional software currently in the profile that will be uninstalled as a result + * of the plan being executed. This occurs when the optional software has dependencies + * that are incompatible with the software being installed. + * This includes additional software that will be installed as a result of the change, + * or optional + * @return A map of {@link IInstallableUnit} to {@link IStatus} of the additional + * changes and their corresponding explanation. + */ + public abstract Map<IInstallableUnit, IStatus> getSideEffectChanges(); + + /** + * Returns the overall plan status. The severity of this status indicates + * whether the plan can be successfully executed or not: + * <ul> + * <li>A status of {@link IStatus#OK} indicates that the plan can be executed successfully.</li> + * <li>A status of {@link IStatus#INFO} or {@link IStatus#WARNING} indicates + * that the plan can be executed but may cause problems.</li> + * <li>A status of {@link IStatus#ERROR} indicates that the plan cannot be executed + * successfully.</li> + * <li>A status of {@link IStatus#CANCEL} indicates that the plan computation was + * canceled and is incomplete. A canceled plan cannot be executed.</li> + * </ul> + * + * @return The overall plan status. + */ + public abstract IStatus getStatus(); + +}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ISurrogateProfileHandler.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ISurrogateProfileHandler.java index 55f79aa71..00faa2baf 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ISurrogateProfileHandler.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ISurrogateProfileHandler.java @@ -8,19 +8,23 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.Query; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.query.IQuery; +import org.eclipse.equinox.p2.query.IQueryResult; +/** + * @since 2.0 + */ public interface ISurrogateProfileHandler { public abstract IProfile createProfile(String id); public abstract boolean isSurrogate(IProfile profile); - public abstract Collector queryProfile(IProfile profile, Query query, Collector collector, IProgressMonitor monitor); + public abstract IQueryResult<IInstallableUnit> queryProfile(IProfile profile, IQuery<IInstallableUnit> query, IProgressMonitor monitor); public abstract boolean updateProfile(IProfile selfProfile); diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/InstallableUnitEvent.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/InstallableUnitEvent.java index 13f988922..80ca32abe 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/InstallableUnitEvent.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/InstallableUnitEvent.java @@ -8,12 +8,17 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; import java.util.EventObject; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.equinox.internal.p2.engine.Messages; +import org.eclipse.equinox.p2.engine.spi.Touchpoint; +/** + * @since 2.0 + */ public class InstallableUnitEvent extends EventObject { public static final int UNINSTALL = 0; public static final int INSTALL = 1; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/InstallableUnitOperand.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/InstallableUnitOperand.java index f469d4810..edab40f53 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/InstallableUnitOperand.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/InstallableUnitOperand.java @@ -8,11 +8,14 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; import org.eclipse.core.runtime.Assert; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +/** + * @since 2.0 + */ public class InstallableUnitOperand extends Operand { private final IInstallableUnit first; private final IInstallableUnit second; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/InstallableUnitPropertyOperand.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/InstallableUnitPropertyOperand.java index 0e299f187..265da8d80 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/InstallableUnitPropertyOperand.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/InstallableUnitPropertyOperand.java @@ -8,11 +8,14 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; import org.eclipse.core.runtime.Assert; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +/** + * @since 2.0 + */ public class InstallableUnitPropertyOperand extends PropertyOperand { private final IInstallableUnit iu; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/MissingAction.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/MissingAction.java index b8bfe06b9..40115b1a7 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/MissingAction.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/MissingAction.java @@ -8,15 +8,19 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; - -import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange; +package org.eclipse.equinox.p2.engine; import java.util.Map; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.equinox.internal.p2.engine.Messages; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.metadata.VersionRange; import org.eclipse.osgi.util.NLS; +/** + * @since 2.0 + */ public class MissingAction extends ProvisioningAction { private String actionId; @@ -35,7 +39,7 @@ public class MissingAction extends ProvisioningAction { return versionRange; } - public IStatus execute(Map parameters) { + public IStatus execute(Map<String, Object> parameters) { throw new IllegalArgumentException(NLS.bind(Messages.action_not_found, actionId + (versionRange == null ? "" : "/" + versionRange.toString()))); //$NON-NLS-1$ //$NON-NLS-2$ } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/MissingActionsException.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/MissingActionsException.java index 0c68603df..2385e4609 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/MissingActionsException.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/MissingActionsException.java @@ -8,11 +8,15 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; +import org.eclipse.equinox.internal.p2.engine.Messages; +import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.osgi.util.NLS; +/** + * @since 2.0 + */ public class MissingActionsException extends ProvisionException { private static final long serialVersionUID = 8617693596359747490L; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/Operand.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/Operand.java index fa7b27807..7efeb9e88 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/Operand.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/Operand.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 IBM Corporation and others. + * Copyright (c) 2008, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,12 +8,13 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; /** * The common base class for engine operands. * - * @see IEngine#perform(IProfile, PhaseSet, Operand[], ProvisioningContext, org.eclipse.core.runtime.IProgressMonitor) + * @see IEngine#createCustomPlan(IProfile, Operand[], ProvisioningContext) + * @since 2.0 */ public class Operand { // marker class diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ProfileEvent.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProfileEvent.java index d96796f2f..064717d1a 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ProfileEvent.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProfileEvent.java @@ -8,12 +8,13 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; import java.util.EventObject; /** * @noextend This class is not intended to be subclassed by clients. + * @since 2.0 */ public class ProfileEvent extends EventObject { private static final long serialVersionUID = 3082402920617281765L; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ProfileScope.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProfileScope.java index 70d72d639..e0ab51a1a 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ProfileScope.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProfileScope.java @@ -8,13 +8,24 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; import org.eclipse.core.internal.preferences.PreferencesService; +import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; +import org.eclipse.equinox.internal.p2.engine.EngineActivator; +import org.eclipse.equinox.p2.core.IAgentLocation; +import org.eclipse.equinox.security.storage.EncodingUtils; +/** + * A profile scope contains the preferences associated with a particular profile + * in a provisioned system. + * @see IProfile + * @since 2.0 + */ public final class ProfileScope implements IScopeContext { /* @@ -25,15 +36,33 @@ public final class ProfileScope implements IScopeContext { private String profileId; - /* + private IAgentLocation location; + + /** * Create and return a new profile scope for the given profile. The given - * profile must not be null. + * profile id must not be null. The provisioning agent of the currently running + * system is used. + * @deprecated use {@link ProfileScope#ProfileScope(IAgentLocation, String)} instead */ public ProfileScope(String profileId) { + this(getDefaultAgent(), profileId); + } + + /** + * Creates and returns a profile scope for the given profile id and agent. + * @param agentLocation The location of the provisioning agent to obtain profile preferences for + * @param profileId The id of the profile to obtain preferences for + */ + public ProfileScope(IAgentLocation agentLocation, String profileId) { super(); - if (profileId == null) - throw new IllegalArgumentException(); + Assert.isNotNull(agentLocation); + Assert.isNotNull(profileId); this.profileId = profileId; + this.location = agentLocation; + } + + private static IAgentLocation getDefaultAgent() { + return (IAgentLocation) ServiceHelper.getService(EngineActivator.getContext(), IAgentLocation.SERVICE_NAME); } public IPath getLocation() { @@ -53,7 +82,9 @@ public final class ProfileScope implements IScopeContext { public IEclipsePreferences getNode(String qualifier) { if (qualifier == null) throw new IllegalArgumentException(); - return (IEclipsePreferences) PreferencesService.getDefault().getRootNode().node(getName()).node(profileId).node(qualifier); + String locationString = EncodingUtils.encodeSlashes(location.getRootLocation().toString()); + //format is /profile/{agentLocationURI}/{profileId}/qualifier + return (IEclipsePreferences) PreferencesService.getDefault().getRootNode().node(getName()).node(locationString).node(profileId).node(qualifier); } /* (non-Javadoc) diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/PropertyOperand.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/PropertyOperand.java index 24c536e66..3751abb39 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/PropertyOperand.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/PropertyOperand.java @@ -8,10 +8,13 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; import org.eclipse.core.runtime.Assert; +/** + * @since 2.0 + */ public class PropertyOperand extends Operand { private final Object first; private final Object second; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ProvisioningContext.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java index 5e021c3d6..bb08c51d9 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ProvisioningContext.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java @@ -9,17 +9,22 @@ * IBM Corporation - initial API and implementation * WindRiver - https://bugs.eclipse.org/bugs/show_bug.cgi?id=227372 *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; import java.net.URI; import java.util.*; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.IRequirement; +/** + * @since 2.0 + */ public class ProvisioningContext { private URI[] metadataRepositories; //metadata repositories to consult private URI[] artifactRepositories; //artifact repositories to consult - private Properties properties = new Properties(); - private List extraIUs = new ArrayList(); - private Collection additionalRequirements; + private Map<String, String> properties = new HashMap<String, String>(); + private List<IInstallableUnit> extraIUs = new ArrayList<IInstallableUnit>(); + private Collection<IRequirement> additionalRequirements; public ProvisioningContext() { // null repos means look at them all @@ -48,30 +53,30 @@ public class ProvisioningContext { } public String getProperty(String key) { - return properties.getProperty(key); + return properties.get(key); } public void setProperty(String key, String value) { - properties.setProperty(key, value); + properties.put(key, value); } - public Properties getProperties() { + public Map<String, String> getProperties() { return properties; } - public List getExtraIUs() { + public List<IInstallableUnit> getExtraIUs() { return extraIUs; } - public void setExtraIUs(List extraIUs) { + public void setExtraIUs(List<IInstallableUnit> extraIUs) { this.extraIUs = extraIUs; } - public void setAdditionalRequirements(Collection requirements) { + public void setAdditionalRequirements(Collection<IRequirement> requirements) { additionalRequirements = requirements; } - public Collection getAdditionalRequirements() { + public Collection<IRequirement> getAdditionalRequirements() { return additionalRequirements; } } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningPlan.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningPlan.java new file mode 100644 index 000000000..5ea81fb7b --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningPlan.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * Copyright (c) 2007, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.engine; + +import java.util.*; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.query.*; + +/** + * @since 2.0 + */ +public class ProvisioningPlan implements IProvisioningPlan { + IStatus status; + Operand[] operands; + Map<IInstallableUnit, IStatus> actualChangeRequest; + Map<IInstallableUnit, IStatus> sideEffectChanges; + IProvisioningPlan installerPlan; + IStatus globalRequestStatus; + IProfile profile; + IQueryable<IInstallableUnit> completeState; + private final ProvisioningContext context; + + public ProvisioningPlan(IProfile profile, Operand[] operands, ProvisioningContext context) { + this(Status.OK_STATUS, operands, null, Status.OK_STATUS, null, profile, null, context); + } + + public ProvisioningPlan(IStatus status, IProfile profile, IProvisioningPlan installerPlan, ProvisioningContext context) { + this(status, new Operand[0], null, null, installerPlan, profile, null, null); + } + + public ProvisioningPlan(IStatus status, Operand[] operands, Map<IInstallableUnit, IStatus>[] actualChangeRequest, IStatus globalStatus, IProvisioningPlan installerPlan, IProfile profile, IQueryable<IInstallableUnit> futureState, ProvisioningContext context) { + this.status = status; + this.operands = operands; + if (actualChangeRequest != null) { + this.actualChangeRequest = actualChangeRequest[0]; + this.sideEffectChanges = actualChangeRequest[1]; + } + this.globalRequestStatus = globalStatus; + this.installerPlan = installerPlan; + this.profile = profile; + if (futureState == null) { + futureState = new IQueryable<IInstallableUnit>() { + public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor) { + return Collector.emptyCollector(); + } + }; + } + completeState = futureState; + if (context == null) + context = new ProvisioningContext(); + this.context = context; + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.p2.engine.IProvisioningPlan#getStatus() + */ + public IStatus getStatus() { + return status; + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.p2.engine.IProvisioningPlan#getProfile() + */ + public IProfile getProfile() { + return profile; + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.p2.engine.IProvisioningPlan#getOperands() + */ + public Operand[] getOperands() { + return operands; + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.p2.engine.IProvisioningPlan#getRemovals() + */ + public IQueryable<IInstallableUnit> getRemovals() { + return new QueryablePlan(false); + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.p2.engine.IProvisioningPlan#getAdditions() + */ + public IQueryable<IInstallableUnit> getAdditions() { + return new QueryablePlan(true); + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.p2.engine.IProvisioningPlan#getRequestStatus(org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit) + */ + public IStatus getRequestStatus(IInstallableUnit iu) { + if (actualChangeRequest == null) + return null; + return actualChangeRequest.get(iu); + } + + public IStatus getRequestStatus() { + return globalRequestStatus; + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.p2.engine.IProvisioningPlan#getSideEffectChanges() + */ + public Map<IInstallableUnit, IStatus> getSideEffectChanges() { + if (sideEffectChanges == null) + return CollectionUtils.emptyMap(); + return sideEffectChanges; + } + + private class QueryablePlan implements IQueryable<IInstallableUnit> { + private boolean addition; + + public QueryablePlan(boolean add) { + this.addition = add; + } + + public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor) { + if (operands == null || status.getSeverity() == IStatus.ERROR) + return Collector.emptyCollector(); + Collection<IInstallableUnit> list = new ArrayList<IInstallableUnit>(); + for (int i = 0; i < operands.length; i++) { + if (!(operands[i] instanceof InstallableUnitOperand)) + continue; + InstallableUnitOperand op = ((InstallableUnitOperand) operands[i]); + IInstallableUnit iu = addition ? op.second() : op.first(); + if (iu != null) + list.add(iu); + } + return query.perform(list.iterator()); + } + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.p2.engine.IProvisioningPlan#getInstallerPlan() + */ + public IProvisioningPlan getInstallerPlan() { + return installerPlan; + } + + public ProvisioningContext getContext() { + return context; + } + + public void setInstallerPlan(IProvisioningPlan p) { + installerPlan = p; + } + + public IQueryable<IInstallableUnit> getCompleteState() { + return completeState; + } +} diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/RollbackOperationEvent.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/RollbackOperationEvent.java index 4d0032cba..e56813696 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/RollbackOperationEvent.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/RollbackOperationEvent.java @@ -8,10 +8,14 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.p2.engine.PhaseSet; +/** + * @since 2.0 + */ public class RollbackOperationEvent extends TransactionEvent { private static final long serialVersionUID = -2076492953949691215L; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/TransactionEvent.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/TransactionEvent.java index efb574f7d..2ce52a3b7 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/TransactionEvent.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/TransactionEvent.java @@ -8,10 +8,14 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine; import java.util.EventObject; +import org.eclipse.equinox.internal.p2.engine.PhaseSet; +/** + * @since 2.0 + */ public abstract class TransactionEvent extends EventObject { private static final long serialVersionUID = 6278706971855493984L; protected IProfile profile; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/package.html b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/package.html new file mode 100644 index 000000000..8cf851643 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/package.html @@ -0,0 +1,22 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <title>Package-level Javadoc</title> +</head> +<body> +Provides support for interacting with the p2 provisioning engine +<h2> +Package Specification</h2> +<p> +This package specifies API for interacting with the p2 provisioning engine. The engine +is a naive service that blindly performs a set of requested changes to a provisioned +system. No attempt is made to resolve dependencies or determine whether the +resulting system is valid or consistent. It is assumed that the engine client has +crafted a valid provisioning plan for the engine to perform, typically by using a planner +service. +<p> +@since 2.0 +<p> +</body> +</html> diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/IUProfilePropertyQuery.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/query/IUProfilePropertyQuery.java index 22afdac26..84437a6f6 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/IUProfilePropertyQuery.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/query/IUProfilePropertyQuery.java @@ -8,18 +8,23 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine.query; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.IUPropertyQuery; +import org.eclipse.equinox.internal.p2.metadata.query.IUPropertyQuery; +import org.eclipse.equinox.p2.engine.IProfile; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; /** * A query that searches for {@link IInstallableUnit} instances that have * a property associated with the specified profile, whose value matches the provided value. + * @since 2.0 */ public class IUProfilePropertyQuery extends IUPropertyQuery { private IProfile profile; + /** + * @noreference This method is not intended to be referenced by clients. + */ public void setProfile(IProfile profile) { this.profile = profile; } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/query/UserVisibleRootQuery.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/query/UserVisibleRootQuery.java new file mode 100644 index 000000000..20ea0d011 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/query/UserVisibleRootQuery.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.engine.query; + +import org.eclipse.equinox.p2.engine.IProfile; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; + + +/** + * A query matching all the {@link IInstallableUnit}s that are marked visible to the user. + * @since 2.0 + */ +public class UserVisibleRootQuery extends IUProfilePropertyQuery { + + public UserVisibleRootQuery() { + super(IProfile.PROP_PROFILE_ROOT_IU, Boolean.TRUE.toString()); + } + + /** + * Test if the {@link IInstallableUnit}, in the context of a {@link IProfile} is visible to the user + * @param iu the element being tested. + * @param profile the context in which the iu is tested + * @return <tt>true</tt> if the element is visible to the user. + */ + public static boolean isUserVisible(IInstallableUnit iu, IProfile profile) { + String value = profile.getInstallableUnitProperty(iu, IProfile.PROP_PROFILE_ROOT_IU); + if (value != null && (value.equals(Boolean.TRUE.toString()))) + return true; + return false; + } +} diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/Memento.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/Memento.java index eb4c15330..fdcb4dbb7 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/Memento.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/Memento.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,17 +8,20 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine.spi; import java.util.*; +/** + * @since 2.0 + */ public class Memento { private static final long serialVersionUID = 3257399736837461585L; - private static final Collection simples = Arrays.asList(new Class[] {String.class, Integer.class, Long.class, Float.class, Double.class, Byte.class, Short.class, Character.class, Boolean.class}); - private static final Collection simpleArrays = Arrays.asList(new Class[] {String[].class, Integer[].class, Long[].class, Float[].class, Double[].class, Byte[].class, Short[].class, Character[].class, Boolean[].class}); - private static final Collection primitiveArrays = Arrays.asList(new Class[] {long[].class, int[].class, short[].class, char[].class, byte[].class, double[].class, float[].class, boolean[].class}); + private static final Collection<Class<?>> simples = Arrays.<Class<?>> asList(String.class, Integer.class, Long.class, Float.class, Double.class, Byte.class, Short.class, Character.class, Boolean.class); + private static final Collection<Class<?>> simpleArrays = Arrays.<Class<?>> asList(String[].class, Integer[].class, Long[].class, Float[].class, Double[].class, Byte[].class, Short[].class, Character[].class, Boolean[].class); + private static final Collection<Class<?>> primitiveArrays = Arrays.<Class<?>> asList(long[].class, int[].class, short[].class, char[].class, byte[].class, double[].class, float[].class, boolean[].class); - Map mementoMap = new HashMap(); + Map<String, Object> mementoMap = new HashMap<String, Object>(); public Object remove(String key) { if (key == null) @@ -45,15 +48,15 @@ public class Memento { return mementoMap.get(key); } - public Enumeration getKeys() { - return new Enumeration() { - Iterator keysIterator = mementoMap.keySet().iterator(); + public Enumeration<String> getKeys() { + return new Enumeration<String>() { + Iterator<String> keysIterator = mementoMap.keySet().iterator(); public boolean hasMoreElements() { return keysIterator.hasNext(); } - public Object nextElement() { + public String nextElement() { return keysIterator.next(); } }; @@ -63,7 +66,7 @@ public class Memento { if (value == null) return; - Class clazz = value.getClass(); + Class<? extends Object> clazz = value.getClass(); if (simples.contains(clazz)) return; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ProvisioningAction.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/ProvisioningAction.java index dc1b05224..2154abcc1 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ProvisioningAction.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/ProvisioningAction.java @@ -8,11 +8,14 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine.spi; import java.util.Map; import org.eclipse.core.runtime.IStatus; +/** + * @since 2.0 + */ public abstract class ProvisioningAction { private Memento memento = new Memento(); @@ -22,9 +25,9 @@ public abstract class ProvisioningAction { return memento; } - public abstract IStatus execute(Map parameters); + public abstract IStatus execute(Map<String, Object> parameters); - public abstract IStatus undo(Map parameters); + public abstract IStatus undo(Map<String, Object> parameters); // TODO: these probably should not be visible public void setTouchpoint(Touchpoint touchpoint) { diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/Touchpoint.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/Touchpoint.java index 4cc43fbd7..bbcc51b60 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/Touchpoint.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/Touchpoint.java @@ -8,14 +8,18 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.engine; +package org.eclipse.equinox.p2.engine.spi; import java.util.Map; import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.engine.PhaseSet; +import org.eclipse.equinox.p2.engine.IProfile; +import org.eclipse.equinox.p2.engine.Operand; /** * A touchpoint is responsible for executing a given phase for a given * targeted system (eclipse, native). The order of phases is defined in the {@link PhaseSet}. + * @since 2.0 */ public abstract class Touchpoint { @@ -24,19 +28,19 @@ public abstract class Touchpoint { return actionId; } - public IStatus initializePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map touchpointParameters) { + public IStatus initializePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map<String, Object> touchpointParameters) { return Status.OK_STATUS; } - public IStatus completePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map touchpointParameters) { + public IStatus completePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map<String, Object> touchpointParameters) { return Status.OK_STATUS; } - public IStatus initializeOperand(IProfile profile, Operand operand, Map parameters) { + public IStatus initializeOperand(IProfile profile, Operand operand, Map<String, Object> parameters) { return Status.OK_STATUS; } - public IStatus completeOperand(IProfile profile, Operand operand, Map parameters) { + public IStatus completeOperand(IProfile profile, Operand operand, Map<String, Object> parameters) { return Status.OK_STATUS; } |