diff options
47 files changed, 1183 insertions, 495 deletions
diff --git a/bundles/org.eclipse.equinox.p2.engine/plugin.xml b/bundles/org.eclipse.equinox.p2.engine/plugin.xml index db37a584d..725810951 100644 --- a/bundles/org.eclipse.equinox.p2.engine/plugin.xml +++ b/bundles/org.eclipse.equinox.p2.engine/plugin.xml @@ -1,16 +1,24 @@ <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.2"?> <plugin> -<extension-point - id="touchpoints" - name="Touchpoints" - schema="schema/touchpoints.exsd"/> +<extension-point id="touchpoints" name="Touchpoints" schema="schema/touchpoints.exsd"/> + <extension-point id="actions" name="Actions" schema="schema/actions.exsd"/> - - <extension point="org.eclipse.equinox.p2.engine.touchpoints" id="null" name="Null Touchpoint"> - <touchpoint - type="null" - class="org.eclipse.equinox.internal.p2.engine.NullTouchpoint" - version="1.0.0"/> - </extension> + +<extension point="org.eclipse.equinox.p2.engine.touchpoints" id="null" name="Null Touchpoint"> + <touchpoint + class="org.eclipse.equinox.internal.p2.engine.NullTouchpoint" + type="null" + version="1.0.0"/> +</extension> + +<extension point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.engine.NullAction" + name="null" + touchpointType="null" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> +</extension> </plugin> diff --git a/bundles/org.eclipse.equinox.p2.engine/schema/actions.exsd b/bundles/org.eclipse.equinox.p2.engine/schema/actions.exsd index 95021ec36..05b25cc0c 100644 --- a/bundles/org.eclipse.equinox.p2.engine/schema/actions.exsd +++ b/bundles/org.eclipse.equinox.p2.engine/schema/actions.exsd @@ -49,7 +49,14 @@ <element name="action"> <complexType> - <attribute name="id" type="string" use="required"> + <attribute name="name" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="version" type="string" use="required"> <annotation> <documentation> @@ -66,6 +73,27 @@ </appinfo> </annotation> </attribute> + <attribute name="touchpointType" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="touchpointVersion" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="description" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> </complexType> </element> diff --git a/bundles/org.eclipse.equinox.p2.engine/schema/touchpoints.exsd b/bundles/org.eclipse.equinox.p2.engine/schema/touchpoints.exsd index 1748a815e..12534af9c 100644 --- a/bundles/org.eclipse.equinox.p2.engine/schema/touchpoints.exsd +++ b/bundles/org.eclipse.equinox.p2.engine/schema/touchpoints.exsd @@ -1,20 +1,24 @@ <?xml version='1.0' encoding='UTF-8'?> <!-- Schema file written by PDE --> -<schema targetNamespace="org.eclipse.equinox.p2.engine"> +<schema targetNamespace="org.eclipse.equinox.p2.engine" xmlns="http://www.w3.org/2001/XMLSchema"> <annotation> - <appInfo> + <appinfo> <meta.schema plugin="org.eclipse.equinox.p2.engine" id="touchpoints" name="Touchpoints"/> - </appInfo> + </appinfo> <documentation> [Enter description of this extension point.] </documentation> </annotation> <element name="extension"> + <annotation> + <appinfo> + <meta.element /> + </appinfo> + </annotation> <complexType> <sequence> <element ref="touchpoint" minOccurs="0" maxOccurs="1"/> - <element ref="data" minOccurs="0" maxOccurs="unbounded"/> </sequence> <attribute name="point" type="string" use="required"> <annotation> @@ -35,9 +39,9 @@ <documentation> </documentation> - <appInfo> + <appinfo> <meta.attribute translatable="true"/> - </appInfo> + </appinfo> </annotation> </attribute> </complexType> @@ -52,16 +56,6 @@ </documentation> </annotation> </attribute> - <attribute name="class" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - <appInfo> - <meta.attribute kind="java" basedOn="org.eclipse.equinox.p2.engine.ITouchpoint"/> - </appInfo> - </annotation> - </attribute> <attribute name="version" type="string" use="required"> <annotation> <documentation> @@ -69,23 +63,14 @@ </documentation> </annotation> </attribute> - </complexType> - </element> - - <element name="data"> - <complexType> - <attribute name="name" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - </annotation> - </attribute> - <attribute name="type" type="string"> + <attribute name="class" type="string" use="required"> <annotation> <documentation> </documentation> + <appinfo> + <meta.attribute kind="java" basedOn="org.eclipse.equinox.p2.engine.ITouchpoint"/> + </appinfo> </annotation> </attribute> <attribute name="description" type="string"> @@ -93,27 +78,24 @@ <documentation> </documentation> - <appInfo> - <meta.attribute translatable="true"/> - </appInfo> </annotation> </attribute> </complexType> </element> <annotation> - <appInfo> + <appinfo> <meta.section type="since"/> - </appInfo> + </appinfo> <documentation> [Enter the first release in which this extension point appears.] </documentation> </annotation> <annotation> - <appInfo> + <appinfo> <meta.section type="examples"/> - </appInfo> + </appinfo> <documentation> <p> <pre> @@ -129,30 +111,22 @@ </annotation> <annotation> - <appInfo> + <appinfo> <meta.section type="apiInfo"/> - </appInfo> + </appinfo> <documentation> [Enter API information here.] </documentation> </annotation> <annotation> - <appInfo> + <appinfo> <meta.section type="implementation"/> - </appInfo> + </appinfo> <documentation> [Enter information about supplied implementation of this extension point.] </documentation> </annotation> - <annotation> - <appInfo> - <meta.section type="copyright"/> - </appInfo> - <documentation> - - </documentation> - </annotation> </schema> 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 9cdcf843d..f38fdbc4f 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 @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2008 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.p2.engine; import java.util.HashMap; @@ -5,13 +15,18 @@ 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.osgi.service.resolver.VersionRange; +import org.eclipse.osgi.util.NLS; public class ActionManager implements IRegistryChangeListener { private static final String PT_ACTIONS = "actions"; //$NON-NLS-1$ private static final String ELEMENT_ACTION = "action"; //$NON-NLS-1$ private static final String ATTRIBUTE_CLASS = "class"; //$NON-NLS-1$ - private static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$ + 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$ private static ActionManager instance; @@ -25,23 +40,40 @@ public class ActionManager implements IRegistryChangeListener { private HashMap actionMap; private ActionManager() { - RegistryFactory.getRegistry().addRegistryChangeListener(this); + RegistryFactory.getRegistry().addRegistryChangeListener(this, EngineActivator.ID); } public ProvisioningAction getAction(String actionId) { + return getAction(actionId, null); + } + + public ProvisioningAction getAction(String actionId, VersionRange versionRange) { IConfigurationElement actionElement = (IConfigurationElement) getActionMap().get(actionId); if (actionElement != null && actionElement.isValid()) { try { - return (ProvisioningAction) actionElement.createExecutableExtension(ATTRIBUTE_CLASS); + ProvisioningAction action = (ProvisioningAction) actionElement.createExecutableExtension(ATTRIBUTE_CLASS); + + String touchpointType = actionElement.getAttribute(TOUCHPOINT_TYPE); + if (touchpointType != null) { + String touchpointVersion = actionElement.getAttribute(TOUCHPOINT_VERSION); + Touchpoint touchpoint = TouchpointManager.getInstance().getTouchpoint(touchpointType, touchpointVersion); + if (touchpoint == null) { + reportError(NLS.bind(Messages.ActionManager_Required_Touchpoint_Not_Found, touchpointType, actionId)); + return null; + } + action.setTouchpoint(touchpoint); + } + return action; } catch (CoreException e) { - //TODO: create Message - LogHelper.log(new Status(IStatus.ERROR, EngineActivator.ID, "Error creating action with id=" + actionId)); + reportError(NLS.bind(Messages.ActionManager_Exception_Creating_Action_Extension, actionId)); } } return null; } private synchronized Map getActionMap() { + if (actionMap != null) + return actionMap; IExtensionPoint point = RegistryFactory.getRegistry().getExtensionPoint(EngineActivator.ID, PT_ACTIONS); IExtension[] extensions = point.getExtensions(); actionMap = new HashMap(extensions.length); @@ -52,7 +84,7 @@ public class ActionManager implements IRegistryChangeListener { if (!actionElement.getName().equals(ELEMENT_ACTION)) continue; - String actionId = actionElement.getAttribute(ATTRIBUTE_ID); + String actionId = actionElement.getAttribute(ATTRIBUTE_NAME); if (actionId == null) continue; @@ -68,4 +100,10 @@ public class ActionManager implements IRegistryChangeListener { public synchronized void registryChanged(IRegistryChangeEvent event) { actionMap = null; } + + static void reportError(String errorMsg) { + Status errorStatus = new Status(IStatus.ERROR, EngineActivator.ID, 1, errorMsg, null); + LogHelper.log(errorStatus); + } + } 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 d45857429..dc505a6bf 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 @@ -13,37 +13,74 @@ package org.eclipse.equinox.internal.p2.engine; import java.util.*; import org.eclipse.core.runtime.Assert; import org.eclipse.equinox.internal.provisional.p2.engine.*; +import org.eclipse.equinox.internal.provisional.p2.metadata.TouchpointInstruction; +import org.eclipse.osgi.service.resolver.VersionRange; import org.eclipse.osgi.util.NLS; public class InstructionParser { + public class ActionEntry { + + protected final VersionRange versionRange; + protected final String actionId; + + public ActionEntry(String actionId, VersionRange versionRange) { + this.actionId = actionId; + this.versionRange = versionRange; + } + } + + private static final String VERSION_EQUALS = "version="; //$NON-NLS-1$ InstallableUnitPhase phase; - Touchpoint touchpoint; + Touchpoint defaultTouchpoint; - public InstructionParser(InstallableUnitPhase phase, Touchpoint touchpoint) { + public InstructionParser(InstallableUnitPhase phase, Touchpoint defaultTouchpoint) { Assert.isNotNull(phase); - Assert.isNotNull(touchpoint); + Assert.isNotNull(defaultTouchpoint); this.phase = phase; - this.touchpoint = touchpoint; + this.defaultTouchpoint = defaultTouchpoint; } - public ProvisioningAction[] parseActions(String instruction) { + public ProvisioningAction[] parseActions(TouchpointInstruction instruction) { List actions = new ArrayList(); - StringTokenizer tokenizer = new StringTokenizer(instruction, ";"); //$NON-NLS-1$ + Map importMap = parseImportAttribute(instruction.getImportAttribute()); + StringTokenizer tokenizer = new StringTokenizer(instruction.getBody(), ";"); //$NON-NLS-1$ while (tokenizer.hasMoreTokens()) { - actions.add(parseAction(tokenizer.nextToken())); + actions.add(parseAction(tokenizer.nextToken(), importMap)); } return (ProvisioningAction[]) actions.toArray(new ProvisioningAction[actions.size()]); } - private ProvisioningAction parseAction(String statement) { + private Map parseImportAttribute(String importAttribute) { + if (importAttribute == null) + return Collections.EMPTY_MAP; + + Map result = new HashMap(); + StringTokenizer tokenizer = new StringTokenizer(importAttribute, ","); //$NON-NLS-1$ + while (tokenizer.hasMoreTokens()) { + StringTokenizer actionTokenizer = new StringTokenizer(tokenizer.nextToken(), ";"); //$NON-NLS-1$ + String actionId = actionTokenizer.nextToken().trim(); + int lastDot = actionId.lastIndexOf('.'); + String actionKey = (lastDot == -1) ? actionId : actionId.substring(lastDot + 1); + VersionRange actionVersionRange = null; + while (actionTokenizer.hasMoreTokens()) { + String actionAttribute = actionTokenizer.nextToken().trim(); + if (actionAttribute.startsWith(VERSION_EQUALS)) + actionVersionRange = new VersionRange(actionAttribute.substring(VERSION_EQUALS.length() + 1)); + } + result.put(actionKey, new ActionEntry(actionId, actionVersionRange)); + } + return result; + } + + private ProvisioningAction parseAction(String statement, Map qualifier) { int openBracket = statement.indexOf('('); int closeBracket = statement.lastIndexOf(')'); if (openBracket == -1 || closeBracket == -1 || openBracket > closeBracket) throw new IllegalArgumentException(statement); String actionName = statement.substring(0, openBracket).trim(); - ProvisioningAction action = lookupAction(actionName); + ProvisioningAction action = lookupAction(actionName, qualifier); String nameValuePairs = statement.substring(openBracket + 1, closeBracket); if (nameValuePairs.length() == 0) @@ -63,10 +100,17 @@ public class InstructionParser { return new ParameterizedProvisioningAction(action, parameters); } - private ProvisioningAction lookupAction(String actionId) { - ProvisioningAction action = touchpoint.getAction(actionId); - if (action == null) - action = ActionManager.getInstance().getAction(actionId); + private ProvisioningAction lookupAction(String actionId, Map importMap) { + VersionRange versionRange = null; + if (actionId.indexOf('.') == -1) { + ActionEntry actionEntry = (ActionEntry) importMap.get(actionId); + if (actionEntry != null) { + actionId = actionEntry.actionId; + versionRange = actionEntry.versionRange; + } else + actionId = defaultTouchpoint.qualifyAction(actionId); + } + ProvisioningAction action = ActionManager.getInstance().getAction(actionId, versionRange); if (action == null) throw new IllegalArgumentException(NLS.bind(Messages.action_not_found, actionId)); 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 ff04105af..c896dae0e 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 @@ -15,6 +15,9 @@ 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 static String ActionManager_Exception_Creating_Action_Extension; + public static String ActionManager_Required_Touchpoint_Not_Found; + public static String action_not_found; public static String download_artifact; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/NullAction.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/NullAction.java new file mode 100644 index 000000000..272fef1c3 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/NullAction.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2008 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.p2.engine; + +import java.util.Map; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction; + +public class NullAction extends ProvisioningAction { + + public IStatus execute(Map parameters) { + return Status.OK_STATUS; + } + + public IStatus undo(Map parameters) { + return Status.OK_STATUS; + } + +} diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/NullTouchpoint.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/NullTouchpoint.java index 3ede1f48a..aa0ec3043 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/NullTouchpoint.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/NullTouchpoint.java @@ -10,10 +10,6 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.engine; -import java.util.Map; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -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.TouchpointType; @@ -40,15 +36,7 @@ public class NullTouchpoint extends Touchpoint { return false; } - public ProvisioningAction getAction(String actionId) { - return new ProvisioningAction() { - public IStatus execute(Map parameters) { - return Status.OK_STATUS; - } - - public IStatus undo(Map parameters) { - return Status.OK_STATUS; - } - }; + public String qualifyAction(String actionId) { + return EngineActivator.ID + ".null"; //$NON-NLS-1$ } } 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 f2110177b..269f69e1f 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 @@ -14,6 +14,7 @@ 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; public class ParameterizedProvisioningAction extends ProvisioningAction { @@ -77,4 +78,20 @@ public class ParameterizedProvisioningAction extends ProvisioningAction { String postVariable = processVariables(parameterValue.substring(variableEndIndex + 1), parameters); return preVariable + variableValue + postVariable; } + + public ProvisioningAction getAction() { + return action; + } + + public Map getParameters() { + return actionParameters; + } + + public Touchpoint getTouchpoint() { + return action.getTouchpoint(); + } + + public void setTouchpoint(Touchpoint touchpoint) { + throw new UnsupportedOperationException(); + } } 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 2988ab625..c4ba969dd 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 @@ -16,7 +16,9 @@ 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.TouchpointType; +import org.eclipse.osgi.service.resolver.VersionRange; import org.eclipse.osgi.util.NLS; +import org.osgi.framework.Version; //TODO This needs to support multiple version of each touchpoint and have a lookup that supports version semantics public class TouchpointManager implements IRegistryChangeListener { @@ -32,9 +34,9 @@ public class TouchpointManager implements IRegistryChangeListener { private static final String PT_TOUCHPOINTS = "touchpoints"; //$NON-NLS-1$ private static final String ELEMENT_TOUCHPOINT = "touchpoint"; //$NON-NLS-1$ - private static final String ELEMENT_TOUCHPOINT_DATA = "data"; //$NON-NLS-1$ private static final String ATTRIBUTE_CLASS = "class"; //$NON-NLS-1$ private static final String ATTRIBUTE_TYPE = "type"; //$NON-NLS-1$ + private static final String ATTRIBUTE_VERSION = "version"; //$NON-NLS-1$ private class TouchpointEntry { @@ -48,12 +50,12 @@ public class TouchpointManager implements IRegistryChangeListener { public Touchpoint getTouchpoint() { if (!createdExtension) { - String id = element.getAttribute(ATTRIBUTE_TYPE); + String id = getType(); try { Touchpoint touchpointInstance = (Touchpoint) element.createExecutableExtension(ATTRIBUTE_CLASS); if (touchpointInstance != null) { if (!id.equals(touchpointInstance.getTouchpointType().getId())) { - reportError(NLS.bind(Messages.TouchpointManager_Touchpoint_Type_Mismatch, id, touchpointInstance.getTouchpointType().getId()), null); + reportError(NLS.bind(Messages.TouchpointManager_Touchpoint_Type_Mismatch, id, touchpointInstance.getTouchpointType().getId())); } this.touchpoint = touchpointInstance; } else { @@ -72,6 +74,14 @@ public class TouchpointManager implements IRegistryChangeListener { return this.touchpoint; } + public Version getVersion() { + return new Version(element.getAttribute(ATTRIBUTE_VERSION)); + } + + public String getType() { + return element.getAttribute(ATTRIBUTE_TYPE); + } + public String toString() { StringBuffer result = new StringBuffer(element.toString()); if (createdExtension) { @@ -92,69 +102,77 @@ public class TouchpointManager implements IRegistryChangeListener { } /* - * Return the touchpoint which is registered for the given id, + * Return the touchpoint which is registered for the given type, + * or <code>null</code> if none are registered. + */ + public synchronized Touchpoint getTouchpoint(TouchpointType type) { + if (type == null) + throw new IllegalArgumentException(Messages.TouchpointManager_Null_Touchpoint_Type_Argument); + return getTouchpoint(type.getId(), type.getVersion().toString()); + } + + /* + * Return the touchpoint which is registered for the given type and optionally version, * or <code>null</code> if none are registered. */ - public Touchpoint getTouchpoint(TouchpointType id) { - if (id == null || "".equals(id.getId())) //$NON-NLS-1$ + public Touchpoint getTouchpoint(String typeId, String versionRange) { + if (typeId == null || typeId.length() == 0) throw new IllegalArgumentException(Messages.TouchpointManager_Null_Touchpoint_Type_Argument); - if (touchpointEntries == null) { - initializeTouchpoints(); + + TouchpointEntry entry = (TouchpointEntry) getTouchpointEntries().get(typeId); + if (entry == null) + return null; + if (versionRange != null) { + VersionRange range = new VersionRange(versionRange); + if (!range.isIncluded(entry.getVersion())) + return null; } - TouchpointEntry entry = (TouchpointEntry) touchpointEntries.get(id.getId()); - return entry == null ? null : entry.getTouchpoint(); + + return entry.getTouchpoint(); } /* * Construct a map of the extensions that implement the touchpoints extension point. */ - private MultiStatus initializeTouchpoints() { - MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); - IExtensionPoint point = RegistryFactory.getRegistry().getExtensionPoint(EngineActivator.ID, PT_TOUCHPOINTS); - if (point == null) { - reportError(NLS.bind(Messages.TouchpointManager_No_Extension_Point, EngineActivator.ID, PT_TOUCHPOINTS), status); - touchpointEntries = new HashMap(0); - return status; - } + private synchronized Map getTouchpointEntries() { + if (touchpointEntries != null) + return touchpointEntries; + IExtensionPoint point = RegistryFactory.getRegistry().getExtensionPoint(EngineActivator.ID, PT_TOUCHPOINTS); IExtension[] extensions = point.getExtensions(); touchpointEntries = new HashMap(extensions.length); for (int i = 0; i < extensions.length; i++) { IConfigurationElement[] elements = extensions[i].getConfigurationElements(); for (int j = 0; j < elements.length; j++) { String elementName = elements[j].getName(); - if (!ELEMENT_TOUCHPOINT.equalsIgnoreCase(elements[j].getName())) { - if (!ELEMENT_TOUCHPOINT_DATA.equals(elementName)) { // TODO: are 'data' elements still needed? - reportError(NLS.bind(Messages.TouchpointManager_Incorrectly_Named_Extension, elements[j].getName(), ELEMENT_TOUCHPOINT), status); - } + if (!ELEMENT_TOUCHPOINT.equalsIgnoreCase(elementName)) { + reportError(NLS.bind(Messages.TouchpointManager_Incorrectly_Named_Extension, elements[j].getName(), ELEMENT_TOUCHPOINT)); continue; } String id = elements[j].getAttribute(ATTRIBUTE_TYPE); if (id == null) { - reportError(NLS.bind(Messages.TouchpointManager_Attribute_Not_Specified, ATTRIBUTE_TYPE), status); + reportError(NLS.bind(Messages.TouchpointManager_Attribute_Not_Specified, ATTRIBUTE_TYPE)); continue; } if (touchpointEntries.get(id) == null) { touchpointEntries.put(id, new TouchpointEntry(elements[j])); } else { - reportError(NLS.bind(Messages.TouchpointManager_Conflicting_Touchpoint_Types, ATTRIBUTE_TYPE, id), status); + reportError(NLS.bind(Messages.TouchpointManager_Conflicting_Touchpoint_Types, ATTRIBUTE_TYPE, id)); } } } - return status; + return touchpointEntries; } - static void reportError(String errorMsg, MultiStatus status) { + static void reportError(String errorMsg) { Status errorStatus = new Status(IStatus.ERROR, EngineActivator.ID, 1, errorMsg, null); - if (status != null && !status.isOK()) - status.add(errorStatus); LogHelper.log(errorStatus); } /* (non-Javadoc) * @see org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.eclipse.core.runtime.IRegistryChangeEvent) */ - public void registryChanged(IRegistryChangeEvent event) { + public synchronized void registryChanged(IRegistryChangeEvent event) { // just flush the cache when something changed. It will be recomputed on demand. touchpointEntries = null; } 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 94cf94296..0dfd21fe2 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 @@ -9,6 +9,8 @@ # IBM Corporation - initial API and implementation ############################################################################### +ActionManager_Exception_Creating_Action_Extension=Error creating action with id: {0}. +ActionManager_Required_Touchpoint_Not_Found=The required {0} touchpoint for the {1} action is not included in the installation manager configuration. action_not_found=No action found for: {0}. download_artifact=Downloading artifacts download_no_repository=No artifact repository available. 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/internal/provisional/p2/engine/InstallableUnitEvent.java index 38fd92ae5..13f988922 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/internal/provisional/p2/engine/InstallableUnitEvent.java @@ -33,7 +33,7 @@ public class InstallableUnitEvent extends EventObject { } public InstallableUnitEvent(String phaseId, boolean prePhase, IProfile profile, InstallableUnitOperand operand, int type, Touchpoint touchpoint, IStatus result) { - super(touchpoint); //TODO not sure if the touchpoint should be the source + super(profile); this.phaseId = phaseId; this.prePhase = prePhase; this.profile = profile; @@ -42,6 +42,7 @@ public class InstallableUnitEvent extends EventObject { throw new IllegalArgumentException(Messages.InstallableUnitEvent_type_not_install_or_uninstall); this.type = type; this.result = result; + this.touchpoint = touchpoint; } 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/provisional/p2/engine/InstallableUnitPhase.java index 804108945..aa801f6a6 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/provisional/p2/engine/InstallableUnitPhase.java @@ -12,7 +12,6 @@ package org.eclipse.equinox.internal.provisional.p2.engine; import java.util.*; -import java.util.Map.Entry; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.engine.*; import org.eclipse.equinox.internal.provisional.p2.metadata.*; @@ -24,92 +23,36 @@ public abstract class InstallableUnitPhase extends Phase { protected static final String PARM_IU = "iu"; //$NON-NLS-1$ protected static final String PARM_TOUCHPOINT = "touchpoint"; //$NON-NLS-1$ - protected ProvisioningContext provContext = null; - private Map touchpointToTouchpointParameters; - protected InstallableUnitPhase(String phaseId, int weight) { super(phaseId, weight); } - void perform(MultiStatus status, EngineSession session, IProfile profile, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor) { - provContext = context; - touchpointToTouchpointParameters = new HashMap(); - for (int i = 0; i < operands.length; i++) { - if (!(operands[i] instanceof InstallableUnitOperand)) - continue; - - InstallableUnitOperand iuOperand = (InstallableUnitOperand) operands[i]; - TouchpointType type = getTouchpointType(iuOperand); - Touchpoint touchpoint = TouchpointManager.getInstance().getTouchpoint(type); - //abort the entire phase if any required touchpoint is missing - if (touchpoint == null) { - status.add(new Status(IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.required_touchpoint_not_found, type), null)); - return; - } - if (!touchpointToTouchpointParameters.containsKey(touchpoint)) { - touchpointToTouchpointParameters.put(touchpoint, null); - } - } - super.perform(status, session, profile, operands, context, monitor); - } - - protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { - MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); - mergeStatus(status, initializeInstallableUnitPhase(monitor, profile, parameters)); - for (Iterator it = touchpointToTouchpointParameters.entrySet().iterator(); it.hasNext();) { - Entry entry = (Entry) it.next(); - Touchpoint touchpoint = (Touchpoint) entry.getKey(); - Map touchpointParameters = new HashMap(parameters); - touchpointParameters.put(PARM_TOUCHPOINT, touchpoint); - mergeStatus(status, touchpoint.initializePhase(monitor, profile, phaseId, touchpointParameters)); - entry.setValue(touchpointParameters); - } - return status; - } - - protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { - MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); - for (Iterator it = touchpointToTouchpointParameters.entrySet().iterator(); it.hasNext();) { - Entry entry = (Entry) it.next(); - Touchpoint touchpoint = (Touchpoint) entry.getKey(); - Map touchpointParameters = (Map) entry.getValue(); - mergeStatus(status, touchpoint.completePhase(monitor, profile, phaseId, touchpointParameters)); - entry.setValue(null); - } - mergeStatus(status, completeInstallableUnitPhase(monitor, profile, parameters)); - return status; - } - protected IStatus initializeOperand(IProfile profile, Operand operand, Map parameters, IProgressMonitor monitor) { - if (!(operand instanceof InstallableUnitOperand)) - return null; - InstallableUnitOperand iuOperand = (InstallableUnitOperand) operand; - MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); mergeStatus(status, initializeOperand(profile, iuOperand, parameters, monitor)); - Touchpoint touchpoint = getTouchpoint(iuOperand); - Map touchpointParameters = (Map) touchpointToTouchpointParameters.get(touchpoint); - if (touchpointParameters != null) - parameters.putAll(touchpointParameters); - mergeStatus(status, touchpoint.initializeOperand(profile, phaseId, iuOperand, parameters)); + mergeStatus(status, super.initializeOperand(profile, operand, parameters, monitor)); return status; } - protected IStatus completeOperand(IProfile profile, Operand operand, Map parameters, IProgressMonitor monitor) { - if (!(operand instanceof InstallableUnitOperand)) - return null; + protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) { + return Status.OK_STATUS; + } + protected IStatus completeOperand(IProfile profile, Operand operand, Map parameters, IProgressMonitor monitor) { InstallableUnitOperand iuOperand = (InstallableUnitOperand) operand; MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); - Touchpoint touchpoint = getTouchpoint(iuOperand); - mergeStatus(status, touchpoint.completeOperand(profile, phaseId, iuOperand, parameters)); + mergeStatus(status, super.completeOperand(profile, iuOperand, parameters, monitor)); mergeStatus(status, completeOperand(profile, iuOperand, parameters, monitor)); return status; } - protected ProvisioningAction[] getActions(Operand operand) { + protected IStatus completeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) { + return Status.OK_STATUS; + } + + final protected ProvisioningAction[] getActions(Operand operand) { if (!(operand instanceof InstallableUnitOperand)) return null; @@ -117,7 +60,9 @@ public abstract class InstallableUnitPhase extends Phase { return getActions(iuOperand); } - protected boolean isApplicable(Operand operand) { + protected abstract ProvisioningAction[] getActions(InstallableUnitOperand operand); + + final protected boolean isApplicable(Operand operand) { if (!(operand instanceof InstallableUnitOperand)) return false; @@ -125,6 +70,10 @@ public abstract class InstallableUnitPhase extends Phase { return isApplicable(iuOperand); } + protected boolean isApplicable(InstallableUnitOperand operand) { + return true; + } + /** * Returns the touchpoint corresponding to the operand, or null if no corresponding * touchpoint is available. @@ -140,7 +89,7 @@ public abstract class InstallableUnitPhase extends Phase { /** * Returns the touchpoint type corresponding to the operand. Never returns null. */ - protected final static TouchpointType getTouchpointType(InstallableUnitOperand operand) { + private final static TouchpointType getTouchpointType(InstallableUnitOperand operand) { IInstallableUnit unit = operand.second(); if (unit == null) unit = operand.first(); @@ -148,13 +97,14 @@ public abstract class InstallableUnitPhase extends Phase { } protected final ProvisioningAction[] getActions(IInstallableUnit unit, String key) { - String[] instructions = getInstructions(unit, key); + TouchpointInstruction[] instructions = getInstructions(unit, key); if (instructions == null || instructions.length == 0) return null; Touchpoint touchpoint = getTouchpoint(unit); - //TODO Likely need to propagate an exception if the touchpoint is not present - if (touchpoint == null) - return null; + //TODO Need to propagate an exception if the touchpoint is not present + if (touchpoint == null) { + throw new IllegalStateException(NLS.bind(Messages.required_touchpoint_not_found, unit.getTouchpointType())); + } InstructionParser parser = new InstructionParser(this, touchpoint); List actions = new ArrayList(); for (int i = 0; i < instructions.length; i++) { @@ -163,45 +113,19 @@ public abstract class InstallableUnitPhase extends Phase { return (ProvisioningAction[]) actions.toArray(new ProvisioningAction[actions.size()]); } - private final static String[] getInstructions(IInstallableUnit unit, String key) { + private final static TouchpointInstruction[] getInstructions(IInstallableUnit unit, String key) { TouchpointData[] data = unit.getTouchpointData(); if (data == null) return null; - String[] matches = new String[data.length]; - int count = 0; + ArrayList matches = new ArrayList(data.length); for (int i = 0; i < data.length; i++) { - matches[count] = data[i].getInstructions(key); - if (matches[count] != null) - count++; + TouchpointInstruction instructions = data[i].getInstructions(key); + if (instructions != null) + matches.add(instructions); } - if (count == data.length) - return matches; - String[] result = new String[count]; - System.arraycopy(matches, 0, result, 0, count); - return result; - } - - protected abstract ProvisioningAction[] getActions(InstallableUnitOperand operand); - - protected boolean isApplicable(InstallableUnitOperand operand) { - return true; - } - protected IStatus initializeInstallableUnitPhase(IProgressMonitor monitor, IProfile profile, Map parameters) { - return Status.OK_STATUS; - } - - protected IStatus completeInstallableUnitPhase(IProgressMonitor monitor, IProfile profile, Map parameters) { - return Status.OK_STATUS; - } - - protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) { - return Status.OK_STATUS; - } - - protected IStatus completeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) { - return Status.OK_STATUS; + TouchpointInstruction[] result = (TouchpointInstruction[]) matches.toArray(new TouchpointInstruction[matches.size()]); + return result; } - } 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/provisional/p2/engine/Phase.java index 4e9d17a81..c90b0d825 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/provisional/p2/engine/Phase.java @@ -11,6 +11,7 @@ package org.eclipse.equinox.internal.provisional.p2.engine; import java.util.*; +import java.util.Map.Entry; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.engine.EngineActivator; @@ -25,7 +26,9 @@ public abstract class Phase { protected int prePerformWork = 1000; protected int mainPerformWork = 10000; protected int postPerformWork = 1000; - private Map phaseParameters; + private Map phaseParameters = new HashMap(); + private Map touchpointToTouchpointPhaseParameters = new HashMap(); + private Map touchpointToTouchpointOperandParameters = new HashMap(); protected Phase(String phaseId, int weight) { if (phaseId == null || phaseId.length() == 0) @@ -90,7 +93,6 @@ public abstract class Phase { } void prePerform(MultiStatus status, IProfile profile, ProvisioningContext context, IProgressMonitor monitor) { - phaseParameters = new HashMap(); phaseParameters.put(PARM_PROFILE, profile); phaseParameters.put(PARM_CONTEXT, context); phaseParameters.put(PARM_PHASE_ID, phaseId); @@ -109,28 +111,61 @@ public abstract class Phase { continue; ProvisioningAction[] actions = getActions(operand); - Map parameters = new HashMap(phaseParameters); - parameters.put(PARM_OPERAND, operand); - mergeStatus(status, initializeOperand(profile, operand, parameters, subMonitor)); + Map operandParameters = new HashMap(phaseParameters); + operandParameters.put(PARM_OPERAND, operand); + mergeStatus(status, initializeOperand(profile, operand, operandParameters, subMonitor)); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; - parameters = Collections.unmodifiableMap(parameters); + + operandParameters = Collections.unmodifiableMap(operandParameters); if (actions != null) { for (int j = 0; j < actions.length; j++) { ProvisioningAction action = actions[j]; + Map parameters = operandParameters; + Touchpoint touchpoint = action.getTouchpoint(); + if (touchpoint != null) { + mergeStatus(status, initializeTouchpointParameters(profile, operand, operandParameters, touchpoint, subMonitor)); + if (status.matches(IStatus.ERROR | IStatus.CANCEL)) + return; + + parameters = (Map) touchpointToTouchpointOperandParameters.get(touchpoint); + } session.recordAction(action, operand); mergeStatus(status, action.execute(parameters)); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; } } - mergeStatus(status, completeOperand(profile, operand, parameters, subMonitor)); + + mergeStatus(status, completeOperand(profile, operand, operandParameters, subMonitor)); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; subMonitor.worked(1); } } + private IStatus initializeTouchpointParameters(IProfile profile, Operand operand, Map operandParameters, Touchpoint touchpoint, IProgressMonitor monitor) { + if (touchpointToTouchpointOperandParameters.containsKey(touchpoint)) + return Status.OK_STATUS; + + Map touchpointPhaseParameters = (Map) touchpointToTouchpointPhaseParameters.get(touchpoint); + if (touchpointPhaseParameters == null) { + touchpointPhaseParameters = new HashMap(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); + touchpointOperandParameters.putAll(operandParameters); + IStatus status = touchpoint.initializeOperand(profile, operand, touchpointPhaseParameters); + if (status != null && status.matches(IStatus.ERROR | IStatus.CANCEL)) + return status; + touchpointToTouchpointOperandParameters.put(touchpoint, touchpointOperandParameters); + return Status.OK_STATUS; + } + /** * Merges a given IStatus into a MultiStatus */ @@ -141,20 +176,29 @@ public abstract class Phase { void postPerform(MultiStatus status, IProfile profile, ProvisioningContext context, IProgressMonitor monitor) { mergeStatus(status, completePhase(monitor, profile, phaseParameters)); - phaseParameters = null; + phaseParameters.clear(); } void undo(MultiStatus status, EngineSession session, IProfile profile, Operand operand, ProvisioningAction[] actions, ProvisioningContext context) { - Map parameters = new HashMap(phaseParameters); - parameters.put(PARM_OPERAND, operand); - mergeStatus(status, initializeOperand(profile, operand, parameters, new NullProgressMonitor())); - parameters = Collections.unmodifiableMap(parameters); + Map operandParameters = new HashMap(phaseParameters); + operandParameters.put(PARM_OPERAND, operand); + mergeStatus(status, initializeOperand(profile, operand, operandParameters, new NullProgressMonitor())); + operandParameters = Collections.unmodifiableMap(operandParameters); for (int j = 0; j < actions.length; j++) { ProvisioningAction action = actions[j]; + Map parameters = operandParameters; + Touchpoint touchpoint = action.getTouchpoint(); + if (touchpoint != null) { + mergeStatus(status, initializeTouchpointParameters(profile, operand, operandParameters, touchpoint, new NullProgressMonitor())); + if (status.matches(IStatus.ERROR | IStatus.CANCEL)) + return; + + parameters = (Map) touchpointToTouchpointOperandParameters.get(touchpoint); + } mergeStatus(status, action.undo(parameters)); // TODO: session.removeAction(...) } - mergeStatus(status, completeOperand(profile, operand, parameters, new NullProgressMonitor())); + mergeStatus(status, completeOperand(profile, operand, operandParameters, new NullProgressMonitor())); } protected boolean isApplicable(Operand operand) { @@ -166,11 +210,33 @@ public abstract class Phase { } protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { - return Status.OK_STATUS; + if (touchpointToTouchpointPhaseParameters == null) + 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(); + mergeStatus(status, touchpoint.completePhase(monitor, profile, phaseId, touchpointParameters)); + } + touchpointToTouchpointPhaseParameters.clear(); + return status; } protected IStatus completeOperand(IProfile profile, Operand operand, Map parameters, IProgressMonitor monitor) { - return Status.OK_STATUS; + if (touchpointToTouchpointOperandParameters == null) + 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(); + mergeStatus(status, touchpoint.completeOperand(profile, operand, touchpointParameters)); + } + touchpointToTouchpointOperandParameters.clear(); + return status; } protected IStatus initializeOperand(IProfile profile, Operand operand, Map parameters, IProgressMonitor monitor) { 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/internal/provisional/p2/engine/ProvisioningAction.java index 15d013bea..dc80ec364 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/internal/provisional/p2/engine/ProvisioningAction.java @@ -16,6 +16,7 @@ import org.eclipse.core.runtime.IStatus; public abstract class ProvisioningAction { private Memento memento = new Memento(); + private Touchpoint touchpoint; protected Memento getMemento() { return memento; @@ -24,4 +25,12 @@ public abstract class ProvisioningAction { public abstract IStatus execute(Map parameters); public abstract IStatus undo(Map parameters); + + public void setTouchpoint(Touchpoint touchpoint) { + this.touchpoint = touchpoint; + } + + public Touchpoint getTouchpoint() { + return 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/internal/provisional/p2/engine/Touchpoint.java index 59ef151b2..5729e00c1 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/internal/provisional/p2/engine/Touchpoint.java @@ -22,7 +22,10 @@ public abstract class Touchpoint { public abstract TouchpointType getTouchpointType(); - public abstract ProvisioningAction getAction(String actionId); + /** NOT API -- this is for backwards compatibility only */ + public String qualifyAction(String actionId) { + return actionId; + } public IStatus initializePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map touchpointParameters) { return Status.OK_STATUS; @@ -32,11 +35,11 @@ public abstract class Touchpoint { return Status.OK_STATUS; } - public IStatus initializeOperand(IProfile profile, String phaseId, InstallableUnitOperand operand, Map parameters) { + public IStatus initializeOperand(IProfile profile, Operand operand, Map parameters) { return Status.OK_STATUS; } - public IStatus completeOperand(IProfile profile, String phaseId, InstallableUnitOperand operand, Map parameters) { + public IStatus completeOperand(IProfile profile, Operand operand, Map parameters) { return Status.OK_STATUS; } } 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/provisional/p2/engine/phases/CheckTrust.java index 5ef06f258..6b8be6064 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/provisional/p2/engine/phases/CheckTrust.java @@ -13,6 +13,7 @@ package org.eclipse.equinox.internal.provisional.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.ActionManager; import org.eclipse.equinox.internal.provisional.p2.engine.*; import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; @@ -40,7 +41,8 @@ public class CheckTrust extends InstallableUnitPhase { } protected ProvisioningAction[] getActions(InstallableUnitOperand currentOperand) { - ProvisioningAction action = getTouchpoint(currentOperand).getAction(phaseId); + String actionId = getTouchpoint(currentOperand).qualifyAction(phaseId); + ProvisioningAction action = ActionManager.getInstance().getAction(actionId); if (action == null) { return null; } 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/provisional/p2/engine/phases/Collect.java index 680ba686a..23727e375 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/provisional/p2/engine/phases/Collect.java @@ -14,9 +14,11 @@ package org.eclipse.equinox.internal.provisional.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.ActionManager; 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.osgi.util.NLS; /** * The goal of the collect phase is to ask the touchpoints if the artifacts associated with an IU need to be downloaded. @@ -37,7 +39,11 @@ public class Collect extends InstallableUnitPhase { } protected ProvisioningAction[] getActions(InstallableUnitOperand currentOperand) { - ProvisioningAction action = getTouchpoint(currentOperand).getAction(phaseId); + String actionId = getTouchpoint(currentOperand).qualifyAction(phaseId); + ProvisioningAction action = ActionManager.getInstance().getAction(actionId); + if (action == null) { + throw new IllegalArgumentException(NLS.bind(Messages.action_not_found, actionId)); + } return new ProvisioningAction[] {action}; } @@ -45,10 +51,11 @@ public class Collect extends InstallableUnitPhase { return Messages.Phase_Collect_Error; } - protected IStatus completeInstallableUnitPhase(IProgressMonitor monitor, IProfile profile, Map parameters) { + protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { List artifactRequests = (List) parameters.get(PARM_ARTIFACT_REQUESTS); + ProvisioningContext context = (ProvisioningContext) parameters.get(PARM_CONTEXT); - DownloadManager dm = new DownloadManager(provContext); + DownloadManager dm = new DownloadManager(context); for (Iterator it = artifactRequests.iterator(); it.hasNext();) { IArtifactRequest[] requests = (IArtifactRequest[]) it.next(); dm.add(requests); @@ -56,7 +63,7 @@ public class Collect extends InstallableUnitPhase { return dm.start(monitor); } - protected IStatus initializeInstallableUnitPhase(IProgressMonitor monitor, IProfile profile, Map parameters) { + protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { parameters.put(PARM_ARTIFACT_REQUESTS, new ArrayList()); return null; } 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 index 0241c5d4b..be2d03e41 100644 --- 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 @@ -15,6 +15,7 @@ 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 action_not_found; public static String Phase_Collect_Error; public static String Phase_Install_Error; public static String Phase_Configure_Error; 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/provisional/p2/engine/phases/Sizing.java index 853c0de0e..d216ceff6 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/provisional/p2/engine/phases/Sizing.java @@ -14,10 +14,12 @@ 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.ActionManager; 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.osgi.util.NLS; public class Sizing extends InstallableUnitPhase { private static final String PHASE_ID = "collect"; //$NON-NLS-1$ @@ -42,7 +44,12 @@ public class Sizing extends InstallableUnitPhase { } protected ProvisioningAction[] getActions(InstallableUnitOperand currentOperand) { - ProvisioningAction action = getTouchpoint(currentOperand).getAction("collect"); //$NON-NLS-1$ + String actionId = getTouchpoint(currentOperand).qualifyAction("collect"); //$NON-NLS-1$ + + ProvisioningAction action = ActionManager.getInstance().getAction(actionId); + if (action == null) { + throw new IllegalArgumentException(NLS.bind(Messages.action_not_found, actionId)); + } return new ProvisioningAction[] {action}; } @@ -50,8 +57,10 @@ public class Sizing extends InstallableUnitPhase { return Messages.Phase_Sizing_Error; } - protected IStatus completeInstallableUnitPhase(IProgressMonitor monitor, IProfile profile, Map parameters) { + protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { List artifactRequests = (List) parameters.get("artifactRequests"); //$NON-NLS-1$ + ProvisioningContext context = (ProvisioningContext) parameters.get(PARM_CONTEXT); + Set artifactsToObtain = new HashSet(artifactRequests.size()); for (Iterator it = artifactRequests.iterator(); it.hasNext();) { @@ -68,10 +77,10 @@ public class Sizing extends InstallableUnitPhase { IArtifactRepositoryManager repoMgr = (IArtifactRepositoryManager) ServiceHelper.getService(EngineActivator.getContext(), IArtifactRepositoryManager.class.getName()); URI[] repositories = null; - if (provContext == null || provContext.getArtifactRepositories() == null) + if (context == null || context.getArtifactRepositories() == null) repositories = repoMgr.getKnownRepositories(IArtifactRepositoryManager.REPOSITORIES_ALL); else - repositories = provContext.getArtifactRepositories(); + repositories = context.getArtifactRepositories(); for (Iterator iterator = artifactsToObtain.iterator(); iterator.hasNext() && !monitor.isCanceled();) { IArtifactRequest artifactRequest = (IArtifactRequest) iterator.next(); @@ -97,7 +106,7 @@ public class Sizing extends InstallableUnitPhase { return null; } - protected IStatus initializeInstallableUnitPhase(IProgressMonitor monitor, IProfile profile, Map parameters) { + protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { parameters.put(PARM_ARTIFACT_REQUESTS, new ArrayList()); return null; } 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 index 2d12c8bdf..5ab0fa1b3 100644 --- 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 @@ -17,3 +17,4 @@ Phase_Install_Task=Installing {0} Phase_Sizing_Error=An error occurred while computing the size of the items to be installed Phase_Unconfigure_Error=An error occurred while unconfiguring the items to uninstall Phase_Uninstall_Error=An error occurred while uninstalling +action_not_found=No action found for: {0}.
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataParser.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataParser.java index 8164d8482..592aa6fc7 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataParser.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataParser.java @@ -713,20 +713,24 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { protected class TouchpointInstructionHandler extends TextHandler { private final String[] required = new String[] {TOUCHPOINT_DATA_INSTRUCTION_KEY_ATTRIBUTE}; + private final String[] optional = new String[] {TOUCHPOINT_DATA_INSTRUCTION_IMPORT_ATTRIBUTE}; Map instructions = null; String key = null; + String qualifier = null; public TouchpointInstructionHandler(AbstractHandler parentHandler, Attributes attributes, Map instructions) { super(parentHandler, TOUCHPOINT_DATA_INSTRUCTION_ELEMENT); - key = parseRequiredAttributes(attributes, required)[0]; + String[] values = parseAttributes(attributes, required, optional); + key = values[0]; + qualifier = values[1]; this.instructions = instructions; } protected void finished() { if (isValidXML()) { if (key != null) { - instructions.put(key, getText()); + instructions.put(key, MetadataFactory.createTouchpointInstruction(getText(), qualifier)); } } } diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java index 75379a448..8b725b839 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java @@ -228,7 +228,10 @@ public abstract class MetadataWriter extends XMLWriter implements XMLConstants { Map.Entry entry = (Map.Entry) iter.next(); start(TOUCHPOINT_DATA_INSTRUCTION_ELEMENT); attribute(TOUCHPOINT_DATA_INSTRUCTION_KEY_ATTRIBUTE, entry.getKey()); - cdata((String) entry.getValue(), true); + TouchpointInstruction instruction = (TouchpointInstruction) entry.getValue(); + if (instruction.getImportAttribute() != null) + attribute(TOUCHPOINT_DATA_INSTRUCTION_IMPORT_ATTRIBUTE, instruction.getImportAttribute()); + cdata(instruction.getBody(), true); end(TOUCHPOINT_DATA_INSTRUCTION_ELEMENT); } } diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/XMLConstants.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/XMLConstants.java index e7031c4ea..70d9eaf34 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/XMLConstants.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/XMLConstants.java @@ -77,6 +77,7 @@ public interface XMLConstants extends org.eclipse.equinox.internal.p2.persistenc // Constants for attributes of an a touchpoint data instruction element public static final String TOUCHPOINT_DATA_INSTRUCTION_KEY_ATTRIBUTE = "key"; //$NON-NLS-1$ + public static final String TOUCHPOINT_DATA_INSTRUCTION_IMPORT_ATTRIBUTE = "import"; //$NON-NLS-1$ // Constants for attributes of an update descriptor public static final String UPDATE_DESCRIPTOR_SEVERITY = "severity"; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/MetadataFactory.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/MetadataFactory.java index bdbf67bdc..a821506d4 100644 --- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/MetadataFactory.java +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/MetadataFactory.java @@ -12,6 +12,7 @@ package org.eclipse.equinox.internal.provisional.p2.metadata; import java.util.*; +import java.util.Map.Entry; import org.eclipse.core.runtime.Assert; import org.eclipse.equinox.internal.p2.metadata.*; import org.eclipse.osgi.service.resolver.VersionRange; @@ -284,7 +285,19 @@ public class MetadataFactory { public static TouchpointData createTouchpointData(Map instructions) { Assert.isNotNull(instructions); //copy the map to protect against subsequent change by caller - return instructions.isEmpty() ? EMPTY_TOUCHPOINT_DATA : new TouchpointData(new LinkedHashMap(instructions)); + if (instructions.isEmpty()) + return EMPTY_TOUCHPOINT_DATA; + + Map result = new LinkedHashMap(instructions.size()); + for (Iterator iterator = instructions.entrySet().iterator(); iterator.hasNext();) { + Entry entry = (Entry) iterator.next(); + Object value = entry.getValue(); + if (value == null || value instanceof String) + value = createTouchpointInstruction((String) value, null); + + result.put(entry.getKey(), value); + } + return new TouchpointData(result); } /** @@ -324,4 +337,8 @@ public class MetadataFactory { public static IUpdateDescriptor createUpdateDescriptor(String id, VersionRange range, int severity, String description) { return new UpdateDescriptor(id, range, severity, description); } + + public static TouchpointInstruction createTouchpointInstruction(String body, String importAttribute) { + return new TouchpointInstruction(body, importAttribute); + } } diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/TouchpointData.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/TouchpointData.java index 1a7eb1119..2240f720a 100644 --- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/TouchpointData.java +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/TouchpointData.java @@ -49,8 +49,8 @@ public class TouchpointData { this.instructions = instructions; } - public String getInstructions(String instructionKey) { - return (String) instructions.get(instructionKey); + public TouchpointInstruction getInstructions(String instructionKey) { + return (TouchpointInstruction) instructions.get(instructionKey); } // Return an unmodifiable collection of the instructions diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/TouchpointInstruction.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/TouchpointInstruction.java new file mode 100644 index 000000000..eb9b93a92 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/TouchpointInstruction.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2008 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.metadata; + +public class TouchpointInstruction { + + private final String body; + private final String importAttribute; + + TouchpointInstruction(String body) { + this(body, null); + } + + TouchpointInstruction(String body, String importAttribute) { + this.body = body; + this.importAttribute = importAttribute; + } + + public String getBody() { + return body; + } + + public String getImportAttribute() { + return importAttribute; + } + + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((body == null) ? 0 : body.hashCode()); + result = prime * result + ((importAttribute == null) ? 0 : importAttribute.hashCode()); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TouchpointInstruction other = (TouchpointInstruction) obj; + if (body == null) { + if (other.body != null) + return false; + } else if (!body.equals(other.body)) + return false; + if (importAttribute == null) { + if (other.importAttribute != null) + return false; + } else if (!importAttribute.equals(other.importAttribute)) + return false; + return true; + } +} diff --git a/bundles/org.eclipse.equinox.p2.tests/plugin.xml b/bundles/org.eclipse.equinox.p2.tests/plugin.xml index 145d09118..a40be5d18 100644 --- a/bundles/org.eclipse.equinox.p2.tests/plugin.xml +++ b/bundles/org.eclipse.equinox.p2.tests/plugin.xml @@ -40,7 +40,16 @@ point="org.eclipse.equinox.p2.engine.actions"> <action class="org.eclipse.equinox.p2.tests.engine.InstructionParserTest$TestAction" - id="org.eclipse.equinox.p2.tests.engine.test"> + name="org.eclipse.equinox.p2.tests.engine.test" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.p2.tests.engine.PhaseTest$TestAction" + name="phasetest.test" + version="1"> </action> </extension> diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/AllTests.java index ce2736065..9f8f2d222 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/AllTests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/AllTests.java @@ -29,6 +29,7 @@ public class AllTests extends TestCase { suite.addTestSuite(ProfileTest.class); suite.addTestSuite(ProfileRegistryTest.class); suite.addTestSuite(SurrogateProfileHandlerTest.class); + suite.addTestSuite(TouchpointManagerTest.class); suite.addTestSuite(TouchpointTest.class); return suite; } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/InstructionParserTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/InstructionParserTest.java index fe7ea3edf..6f3ff2f8f 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/InstructionParserTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/InstructionParserTest.java @@ -19,10 +19,6 @@ public class InstructionParserTest extends AbstractProvisioningTest { public static class NullActionTouchpoint extends Touchpoint { private static final TouchpointType TOUCHPOINT_TYPE = MetadataFactory.createTouchpointType("NullActionTouchpoint", new Version("1.0")); //$NON-NLS-1$ //$NON-NLS-2$ - public ProvisioningAction getAction(String actionId) { - return null; - } - public TouchpointType getTouchpointType() { return TOUCHPOINT_TYPE; } @@ -62,32 +58,70 @@ public class InstructionParserTest extends AbstractProvisioningTest { public void testGoodAction() { InstructionParser parser = new InstructionParser(new Collect(1), new NullTouchpoint()); - ProvisioningAction[] actions = parser.parseActions("goodAction()"); + ProvisioningAction[] actions = parser.parseActions(MetadataFactory.createTouchpointInstruction("goodAction()", null)); + assertEquals(1, actions.length); + } + + public void testGoodActionFullyQualified() { + InstructionParser parser = new InstructionParser(new Collect(1), new NullActionTouchpoint()); + ProvisioningAction[] actions = parser.parseActions(MetadataFactory.createTouchpointInstruction("phasetest.test()", null)); + assertEquals(1, actions.length); + } + + public void testBadActionFullyQualified() { + InstructionParser parser = new InstructionParser(new Collect(1), new NullActionTouchpoint()); + try { + ProvisioningAction[] actions = parser.parseActions(MetadataFactory.createTouchpointInstruction("bad.phasetest.test()", null)); + } catch (IllegalArgumentException e) { + return; + } + fail(); + } + + public void testGoodActionFromImport() { + InstructionParser parser = new InstructionParser(new Collect(1), new NullActionTouchpoint()); + ProvisioningAction[] actions = parser.parseActions(MetadataFactory.createTouchpointInstruction("test()", "phasetest.test")); assertEquals(1, actions.length); } + public void testGoodActionFromImportWithVersionRange() { + InstructionParser parser = new InstructionParser(new Collect(1), new NullActionTouchpoint()); + ProvisioningAction[] actions = parser.parseActions(MetadataFactory.createTouchpointInstruction("test()", "phasetest.test;version=[1.0,2.0)")); + assertEquals(1, actions.length); + } + + public void testBadActionFromImport() { + InstructionParser parser = new InstructionParser(new Collect(1), new NullActionTouchpoint()); + try { + ProvisioningAction[] actions = parser.parseActions(MetadataFactory.createTouchpointInstruction("test()", "bad.phasetest.test")); + } catch (IllegalArgumentException e) { + return; + } + fail(); + } + public void testGoodActions() { InstructionParser parser = new InstructionParser(new Collect(1), new NullTouchpoint()); - ProvisioningAction[] actions = parser.parseActions("goodAction1(); goodAction2()"); + ProvisioningAction[] actions = parser.parseActions(MetadataFactory.createTouchpointInstruction("goodAction1(); goodAction2()", null)); assertEquals(2, actions.length); } public void testGoodParameter() { InstructionParser parser = new InstructionParser(new Collect(1), new NullTouchpoint()); - ProvisioningAction[] actions = parser.parseActions("goodAction(a:1)"); + ProvisioningAction[] actions = parser.parseActions(MetadataFactory.createTouchpointInstruction("goodAction(a:1)", null)); assertEquals(1, actions.length); } public void testGoodParameters() { InstructionParser parser = new InstructionParser(new Collect(1), new NullTouchpoint()); - ProvisioningAction[] actions = parser.parseActions("goodAction(a:1, b:2)"); + ProvisioningAction[] actions = parser.parseActions(MetadataFactory.createTouchpointInstruction("goodAction(a:1, b:2)", null)); assertEquals(1, actions.length); } public void testBadParameter() { InstructionParser parser = new InstructionParser(new Collect(1), new NullTouchpoint()); try { - parser.parseActions("goodAction(badParameter)"); + parser.parseActions(MetadataFactory.createTouchpointInstruction("goodAction(badParameter)", null)); } catch (IllegalArgumentException e) { return; } @@ -97,7 +131,7 @@ public class InstructionParserTest extends AbstractProvisioningTest { public void testGoodParamterBadParameter() { InstructionParser parser = new InstructionParser(new Collect(1), new NullTouchpoint()); try { - parser.parseActions("goodAction(a:1, badParameter)"); + parser.parseActions(MetadataFactory.createTouchpointInstruction("goodAction(a:1, badParameter)", null)); } catch (IllegalArgumentException e) { return; } @@ -107,7 +141,7 @@ public class InstructionParserTest extends AbstractProvisioningTest { public void testBadAction() { InstructionParser parser = new InstructionParser(new Collect(1), new NullTouchpoint()); try { - parser.parseActions("badAction"); + parser.parseActions(MetadataFactory.createTouchpointInstruction("badAction", null)); } catch (IllegalArgumentException e) { return; } @@ -117,7 +151,7 @@ public class InstructionParserTest extends AbstractProvisioningTest { public void testGoodActionBadAction() { InstructionParser parser = new InstructionParser(new Collect(1), new NullTouchpoint()); try { - parser.parseActions("goodAction(); badAction"); + parser.parseActions(MetadataFactory.createTouchpointInstruction("goodAction(); badAction", null)); } catch (IllegalArgumentException e) { return; } @@ -128,7 +162,7 @@ public class InstructionParserTest extends AbstractProvisioningTest { Touchpoint empty = new NullActionTouchpoint(); InstructionParser parser = new InstructionParser(new Collect(1), empty); try { - parser.parseActions("notfoundaction()"); + parser.parseActions(MetadataFactory.createTouchpointInstruction("notfoundaction()", null)); } catch (IllegalArgumentException e) { return; } @@ -138,7 +172,7 @@ public class InstructionParserTest extends AbstractProvisioningTest { public void testActionManagerActionFound() { Touchpoint empty = new NullActionTouchpoint(); InstructionParser parser = new InstructionParser(new Collect(1), empty); - ProvisioningAction[] actions = parser.parseActions("org.eclipse.equinox.p2.tests.engine.test(a:1, b:2)"); + ProvisioningAction[] actions = parser.parseActions(MetadataFactory.createTouchpointInstruction("org.eclipse.equinox.p2.tests.engine.test(a:1, b:2)", null)); assertEquals(1, actions.length); } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/NullTouchpointTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/NullTouchpointTest.java index 65099a104..bacbdcaf0 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/NullTouchpointTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/NullTouchpointTest.java @@ -3,6 +3,7 @@ package org.eclipse.equinox.p2.tests.engine; import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.p2.engine.ActionManager; import org.eclipse.equinox.internal.p2.engine.NullTouchpoint; import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction; import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; @@ -12,9 +13,10 @@ public class NullTouchpointTest extends AbstractProvisioningTest { return new TestSuite(NullTouchpointTest.class); } - public void testGetAction() { + public void testQualifyAction() { NullTouchpoint touchpoint = new NullTouchpoint(); - ProvisioningAction action = touchpoint.getAction(""); + String actionId = touchpoint.qualifyAction(""); + ProvisioningAction action = ActionManager.getInstance().getAction(actionId); assertEquals(IStatus.OK, action.execute(null).getSeverity()); assertEquals(IStatus.OK, action.undo(null).getSeverity()); } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseTest.java index cabd2f4e3..1d79fe6a2 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseTest.java @@ -10,13 +10,16 @@ *******************************************************************************/ package org.eclipse.equinox.p2.tests.engine; -import java.util.Map; +import java.util.*; import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.engine.NullAction; +import org.eclipse.equinox.internal.p2.engine.ParameterizedProvisioningAction; 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.*; import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; import org.eclipse.equinox.p2.tests.TestActivator; import org.osgi.framework.ServiceReference; +import org.osgi.framework.Version; /** * Simple test of the engine API. @@ -63,18 +66,32 @@ public class PhaseTest extends AbstractProvisioningTest { return super.initializeOperand(profile, operand, parameters, monitor); } - protected IStatus completeInstallableUnitPhase(IProgressMonitor monitor, IProfile profile, Map parameters) { + protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { completePhase = true; - return super.completeInstallableUnitPhase(monitor, profile, parameters); + return super.completePhase(monitor, profile, parameters); } - protected IStatus initializeInstallableUnitPhase(IProgressMonitor monitor, IProfile profile, Map parameters) { + protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { initializePhase = true; - return super.initializeInstallableUnitPhase(monitor, profile, parameters); + return super.initializePhase(monitor, profile, parameters); } protected ProvisioningAction[] getActions(InstallableUnitOperand operand) { - return null; + final Touchpoint touchpoint = getTouchpoint(operand); + ProvisioningAction action = new ProvisioningAction() { + public IStatus execute(Map parameters) { + return null; + } + + public IStatus undo(Map parameters) { + return null; + } + + public Touchpoint getTouchpoint() { + return touchpoint; + } + }; + return new ProvisioningAction[] {action}; } } @@ -137,7 +154,7 @@ public class PhaseTest extends AbstractProvisioningTest { } public void testPerform() { - PhaseSet phaseSet = new TestPhaseSet(); + PhaseSet phaseSet = new TestPhaseSet(new TestPhase()); IProfile profile = createProfile("PhaseTest"); engine.perform(profile, phaseSet, new InstallableUnitOperand[0], null, new NullProgressMonitor()); @@ -199,4 +216,52 @@ public class PhaseTest extends AbstractProvisioningTest { assertTrue(phase.initializeOperand); assertTrue(phase.completeOperand); } + + public static class TestAction extends ProvisioningAction { + + public IStatus execute(Map parameters) { + return null; + } + + public IStatus undo(Map parameters) { + return null; + } + } + + public void testGetAction() { + final ArrayList actionsList1 = new ArrayList(); + InstallableUnitPhase phase1 = new InstallableUnitPhase("test", 1) { + protected ProvisioningAction[] getActions(InstallableUnitOperand operand) { + ProvisioningAction[] actions = getActions(operand.second(), "test1"); + actionsList1.addAll(Arrays.asList(actions)); + return actions; + } + }; + final ArrayList actionsList2 = new ArrayList(); + InstallableUnitPhase phase2 = new InstallableUnitPhase("test", 1) { + protected ProvisioningAction[] getActions(InstallableUnitOperand operand) { + ProvisioningAction[] actions = getActions(operand.second(), "test2"); + actionsList2.addAll(Arrays.asList(actions)); + return actions; + } + }; + + PhaseSet phaseSet = new TestPhaseSet(new Phase[] {phase1, phase2}); + IProfile profile = createProfile("PhaseTest"); + + Map instructions = new HashMap(); + instructions.put("test1", MetadataFactory.createTouchpointInstruction("phasetest.test()", null)); + instructions.put("test2", MetadataFactory.createTouchpointInstruction("test()", null)); + TouchpointData touchpointData = MetadataFactory.createTouchpointData(instructions); + IInstallableUnit unit = createIU("test", new Version("1.0.0"), null, NO_REQUIRES, new ProvidedCapability[0], NO_PROPERTIES, TouchpointType.NONE, touchpointData, false); + IStatus status = engine.perform(profile, phaseSet, new InstallableUnitOperand[] {new InstallableUnitOperand(null, unit)}, null, new NullProgressMonitor()); + if (!status.isOK()) { + System.out.println(status); + fail(); + } + + assertEquals(TestAction.class, ((ParameterizedProvisioningAction) actionsList1.get(0)).getAction().getClass()); + assertEquals(NullAction.class, ((ParameterizedProvisioningAction) actionsList2.get(0)).getAction().getClass()); + } + } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/TouchpointManagerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/TouchpointManagerTest.java new file mode 100644 index 000000000..0132c32c9 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/TouchpointManagerTest.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2008 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.tests.engine; + +import org.eclipse.equinox.internal.p2.engine.TouchpointManager; +import org.eclipse.equinox.internal.provisional.p2.metadata.TouchpointType; +import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; + +/** + * Simple test of the engine API. + */ +public class TouchpointManagerTest extends AbstractProvisioningTest { + + public TouchpointManagerTest(String name) { + super(name); + } + + public TouchpointManagerTest() { + super(""); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + public void testGetTouchpointByType() { + TouchpointManager manager = TouchpointManager.getInstance(); + assertNotNull(manager.getTouchpoint(TouchpointType.NONE)); + } + + public void testGetTouchpointByIdWithVersion() { + TouchpointManager manager = TouchpointManager.getInstance(); + assertNotNull(manager.getTouchpoint("phaseTest", "1.0.0")); + } + + public void testGetTouchpointByIdWithNullVersion() { + TouchpointManager manager = TouchpointManager.getInstance(); + assertNotNull(manager.getTouchpoint("phaseTest", null)); + } +} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/TouchpointTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/TouchpointTest.java index 34bed86b2..a0b4a70c8 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/TouchpointTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/TouchpointTest.java @@ -38,9 +38,9 @@ public class TouchpointTest extends AbstractProvisioningTest { testTouchpoint = this; } - public IStatus completeOperand(IProfile profile, String phaseId, InstallableUnitOperand operand, Map parameters) { + public IStatus completeOperand(IProfile profile, Operand operand, Map parameters) { completeOperand++; - return super.completeOperand(profile, phaseId, operand, parameters); + return super.completeOperand(profile, operand, parameters); } public IStatus completePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map touchpointParameters) { @@ -48,9 +48,9 @@ public class TouchpointTest extends AbstractProvisioningTest { return super.completePhase(monitor, profile, phaseId, touchpointParameters); } - public IStatus initializeOperand(IProfile profile, String phaseId, InstallableUnitOperand operand, Map parameters) { + public IStatus initializeOperand(IProfile profile, Operand operand, Map parameters) { initializeOperand++; - return super.initializeOperand(profile, phaseId, operand, parameters); + return super.initializeOperand(profile, operand, parameters); } public IStatus initializePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map touchpointParameters) { @@ -58,29 +58,25 @@ public class TouchpointTest extends AbstractProvisioningTest { return super.initializePhase(monitor, profile, phaseId, touchpointParameters); } - public ProvisioningAction getAction(String actionId) { - return null; - } - public TouchpointType getTouchpointType() { return MetadataFactory.createTouchpointType("test", new Version("1.0.0")); } } public static class OperandTestTouchpoint extends TestTouchpoint { - public IStatus completeOperand(IProfile profile, String phaseId, InstallableUnitOperand operand, Map parameters) { + public IStatus completeOperand(IProfile profile, Operand operand, Map parameters) { assertEquals(1, initializeOperand); assertEquals(0, completeOperand); - super.completeOperand(profile, phaseId, operand, parameters); + super.completeOperand(profile, operand, parameters); assertEquals(1, initializeOperand); assertEquals(1, completeOperand); return null; } - public IStatus initializeOperand(IProfile profile, String phaseId, InstallableUnitOperand operand, Map parameters) { + public IStatus initializeOperand(IProfile profile, Operand operand, Map parameters) { assertEquals(0, initializeOperand); assertEquals(0, completeOperand); - super.initializeOperand(profile, phaseId, operand, parameters); + super.initializeOperand(profile, operand, parameters); assertEquals(1, initializeOperand); assertEquals(0, completeOperand); return null; diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/FeaturesActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/FeaturesActionTest.java index d474f80f5..5af3f5882 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/FeaturesActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/FeaturesActionTest.java @@ -78,7 +78,7 @@ public class FeaturesActionTest extends ActionTest { assertTrue(foo.getTouchpointType().getVersion().equals(fooVersion)); //zipped=true - String fooValue = (String) foo.getTouchpointData()[0].getInstructions().get("zipped"); //$NON-NLS-1$ + String fooValue = (String) ((TouchpointInstruction) foo.getTouchpointData()[0].getInstructions().get("zipped")).getBody(); //$NON-NLS-1$ assertTrue(fooValue.equalsIgnoreCase("true")); //$NON-NLS-1$ RequiredCapability[] fooRequiredCapabilities = foo.getRequiredCapabilities(); @@ -105,7 +105,7 @@ public class FeaturesActionTest extends ActionTest { assertTrue(bar.isSingleton()); //check zipped=true in touchpointData - String barValue = (String) bar.getTouchpointData()[0].getInstructions().get("zipped"); //$NON-NLS-1$ + String barValue = (String) ((TouchpointInstruction) bar.getTouchpointData()[0].getInstructions().get("zipped")).getBody(); //$NON-NLS-1$ assertTrue(barValue.equalsIgnoreCase("true")); //$NON-NLS-1$ //check touchpointType diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java index 2f59e55ce..8c39e0d53 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java @@ -90,8 +90,8 @@ public class JREActionTest extends ActionTest { IInstallableUnit bar = (IInstallableUnit) barIUs.get(0); Map instructions = bar.getTouchpointData()[0].getInstructions(); - assertTrue(instructions.get("install").equals("unzip(source:@artifact, target:${installFolder});")); //$NON-NLS-1$//$NON-NLS-2$ - assertTrue(instructions.get("uninstall").equals("cleanupzip(source:@artifact, target:${installFolder});")); //$NON-NLS-1$ //$NON-NLS-2$ + assertTrue(((TouchpointInstruction) instructions.get("install")).getBody().equals("unzip(source:@artifact, target:${installFolder});")); //$NON-NLS-1$//$NON-NLS-2$ + assertTrue(((TouchpointInstruction) instructions.get("uninstall")).getBody().equals("cleanupzip(source:@artifact, target:${installFolder});")); //$NON-NLS-1$ //$NON-NLS-2$ RequiredCapability[] requiredCapability = bar.getRequiredCapabilities(); verifyRequiredCapability(requiredCapability, IInstallableUnit.NAMESPACE_IU_ID, "a.jre", new VersionRange(JREVersion, true, new Version(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE), true)); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java index f60a778cf..6ee13c6b9 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java @@ -474,7 +474,7 @@ public class UpdateSiteTest extends AbstractProvisioningTest { assertEquals("1.1", 1, data.length); Map instructions = data[0].getInstructions(); assertEquals("1.2", 1, instructions.size()); - assertEquals("1.3", "true", instructions.get("zipped")); + assertEquals("1.3", "true", ((TouchpointInstruction) instructions.get("zipped")).getBody()); } public void testMirrors() { diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml index 7719695d1..cd5d7887a 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml @@ -5,10 +5,230 @@ class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint" version="1.0.0"/> </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.AddJVMArgumentAction" + name="addJvmArg" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.AddProgramArgumentAction" + name="addProgramArg" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.AddSourceBundleAction" + name="addSourceBundle" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.CheckTrustAction" + name="checkTrust" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.ChmodAction" + name="chmod" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.CollectAction" + name="collect" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction" + name="installBundle" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallFeatureAction" + name="installFeature" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.LinkAction" + name="link" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.MarkStartedAction" + name="markStarted" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.MkdirAction" + name="mkdir" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.RemoveJVMArgumentAction" + name="removeJvmArg" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.RemoveProgramArgumentAction" + name="removeProgramArg" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.RemoveSourceBundleAction" + name="removeSourceBundle" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.RmdirAction" + name="rmdir" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.SetFrameworkDependentPropertyAction" + name="setFrameworkDependentProperty" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.SetFrameworkIndependentPropertyAction" + name="setFrameworkIndependentProperty" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.SetLauncherNameAction" + name="setLauncherName" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.SetProgramPropertyAction" + name="setProgramProperty" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.SetStartLevelAction" + name="setStartLevel" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> <extension point="org.eclipse.equinox.p2.garbagecollector.marksetproviders" id="EclipseTouchpoint"> <run class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.MarkSetProvider"/> </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.UninstallBundleAction" + name="uninstallBundle" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.UninstallFeatureAction" + name="uninstallFeature" + touchpointType="org.eclipse.equinox.p2.osgi" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> </plugin> diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java index 315695d8c..0f42fed8f 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java @@ -16,7 +16,6 @@ import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.ActionFactory; import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdminRuntimeException; import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; @@ -72,8 +71,8 @@ public class EclipseTouchpoint extends Touchpoint { return Status.OK_STATUS; } - public ProvisioningAction getAction(String actionId) { - return ActionFactory.create(actionId); + public String qualifyAction(String actionId) { + return Activator.ID + "." + actionId; //$NON-NLS-1$ } public TouchpointType getTouchpointType() { @@ -92,7 +91,7 @@ public class EclipseTouchpoint extends Touchpoint { return null; } - public IStatus initializeOperand(IProfile profile, String phaseId, InstallableUnitOperand operand, Map parameters) { + public IStatus initializeOperand(IProfile profile, Operand operand, Map parameters) { IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU); if (iu != null && Boolean.valueOf(iu.getProperty(IInstallableUnit.PROP_PARTIAL_IU)).booleanValue()) { IInstallableUnit preparedIU = prepareIU(iu, profile); diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java index d17c5b6db..780ce1b3e 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java @@ -292,7 +292,8 @@ public class Util { public static String getManifest(TouchpointData[] data) { for (int i = 0; i < data.length; i++) { - String manifest = data[i].getInstructions("manifest"); //$NON-NLS-1$ + TouchpointInstruction manifestInstructions = data[i].getInstructions("manifest"); //$NON-NLS-1$ + String manifest = manifestInstructions.getBody(); if (manifest != null && manifest.length() > 0) return manifest; } diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/ActionFactory.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/ActionFactory.java deleted file mode 100644 index 44e9dec72..000000000 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/ActionFactory.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.p2.touchpoint.eclipse.actions; - -import java.util.HashMap; -import java.util.Map; -import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util; -import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction; -import org.eclipse.osgi.util.NLS; - -public class ActionFactory { - - private static Map actions; - - static { - actions = new HashMap(); - actions.put(CollectAction.ID, CollectAction.class); - actions.put(InstallBundleAction.ID, InstallBundleAction.class); - actions.put(UninstallBundleAction.ID, UninstallBundleAction.class); - actions.put(AddSourceBundleAction.ID, AddSourceBundleAction.class); - actions.put(RemoveSourceBundleAction.ID, RemoveSourceBundleAction.class); - actions.put(InstallFeatureAction.ID, InstallFeatureAction.class); - actions.put(UninstallFeatureAction.ID, UninstallFeatureAction.class); - actions.put(SetLauncherNameAction.ID, SetLauncherNameAction.class); - actions.put(AddProgramArgumentAction.ID, AddProgramArgumentAction.class); - actions.put(RemoveProgramArgumentAction.ID, RemoveProgramArgumentAction.class); - actions.put(SetStartLevelAction.ID, SetStartLevelAction.class); - actions.put(MarkStartedAction.ID, MarkStartedAction.class); - actions.put(SetFrameworkDependentPropertyAction.ID, SetFrameworkDependentPropertyAction.class); - actions.put(SetFrameworkIndependentPropertyAction.ID, SetFrameworkIndependentPropertyAction.class); - actions.put(SetProgramPropertyAction.ID, SetProgramPropertyAction.class); - actions.put(AddJVMArgumentAction.ID, AddJVMArgumentAction.class); - actions.put(RemoveJVMArgumentAction.ID, RemoveJVMArgumentAction.class); - actions.put(MkdirAction.ID, MkdirAction.class); - actions.put(RmdirAction.ID, RmdirAction.class); - actions.put(LinkAction.ID, LinkAction.class); - actions.put(ChmodAction.ID, ChmodAction.class); - actions.put(CheckTrustAction.ID, CheckTrustAction.class); - } - - public static ProvisioningAction create(String actionId) { - Class clazz = (Class) actions.get(actionId); - if (clazz != null) { - try { - return (ProvisioningAction) clazz.newInstance(); - } catch (InstantiationException e) { - LogHelper.log(Util.createError(NLS.bind(Messages.action_not_instantiated, actionId), e)); - return null; - } catch (IllegalAccessException e) { - LogHelper.log(Util.createError(NLS.bind(Messages.action_not_instantiated, actionId), e)); - return null; - } - } - return null; - } -} diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml b/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml index 8aa8e3ebf..c7ac11bef 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml @@ -5,4 +5,54 @@ class="org.eclipse.equinox.internal.p2.touchpoint.natives.NativeTouchpoint" version="1.0.0"/> </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.natives.actions.ChmodAction" + name="chmod" + touchpointType="org.eclipse.equinox.p2.native" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.natives.actions.CleanupzipAction" + name="cleanupzip" + touchpointType="org.eclipse.equinox.p2.native" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.natives.actions.CollectAction" + name="collect" + touchpointType="org.eclipse.equinox.p2.native" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.natives.actions.LinkAction" + name="link" + touchpointType="org.eclipse.equinox.p2.native" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.natives.actions.UnzipAction" + name="unzip" + touchpointType="org.eclipse.equinox.p2.native" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> </plugin> diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java index 48f772c2c..601c1b552 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java @@ -16,139 +16,44 @@ import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.engine.Profile; -import org.eclipse.equinox.internal.p2.touchpoint.natives.actions.LinkAction; 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.core.location.AgentLocation; import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository; -import org.eclipse.equinox.internal.provisional.p2.engine.*; +import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; +import org.eclipse.equinox.internal.provisional.p2.engine.Touchpoint; import org.eclipse.equinox.internal.provisional.p2.metadata.*; import org.eclipse.osgi.util.NLS; import org.osgi.framework.Version; public class NativeTouchpoint extends Touchpoint { - private static final String PARM_TARGET_FILE = "targetFile"; //$NON-NLS-1$ - private static final String PARM_PERMISSIONS = "permissions"; //$NON-NLS-1$ - private static final String PARM_TARGET_DIR = "targetDir"; //$NON-NLS-1$ - private static final String PARM_TARGET = "target"; //$NON-NLS-1$ - private static final String ACTION_CHMOD = "chmod"; //$NON-NLS-1$ - private static final String PARM_IU = "iu"; //$NON-NLS-1$ - private static final String PIPE = "|"; //$NON-NLS-1$ - private static final String PARM_SOURCE = "source"; //$NON-NLS-1$ - private static final String PARM_ARTIFACT = "@artifact"; //$NON-NLS-1$ - private static final String PARM_INSTALL_FOLDER = "installFolder"; //$NON-NLS-1$ - private static final String NATIVE_TOUCHPOINT_TYPE = "org.eclipse.equinox.p2.native"; //$NON-NLS-1$ - private static final String ACTION_CLEANUPZIP = "cleanupzip"; //$NON-NLS-1$ - private static final String ACTION_UNZIP = "unzip"; //$NON-NLS-1$ - private static final String PARM_ARTIFACT_REQUESTS = "artifactRequests"; //$NON-NLS-1$ - private static final String PARM_OPERAND = "operand"; //$NON-NLS-1$ - private static final String PARM_PROFILE = "profile"; //$NON-NLS-1$ - private static final String ACTION_COLLECT = "collect"; //$NON-NLS-1$ - private static final String ID = "org.eclipse.equinox.p2.touchpoint.natives"; //$NON-NLS-1$ - - protected static IStatus createError(String message) { + public static final String PARM_TARGET_FILE = "targetFile"; //$NON-NLS-1$ + public static final String PARM_PERMISSIONS = "permissions"; //$NON-NLS-1$ + public static final String PARM_TARGET_DIR = "targetDir"; //$NON-NLS-1$ + public static final String PARM_TARGET = "target"; //$NON-NLS-1$ + public static final String ACTION_CHMOD = "chmod"; //$NON-NLS-1$ + public static final String PARM_IU = "iu"; //$NON-NLS-1$ + public static final String PIPE = "|"; //$NON-NLS-1$ + public static final String PARM_SOURCE = "source"; //$NON-NLS-1$ + public static final String PARM_ARTIFACT = "@artifact"; //$NON-NLS-1$ + public static final String PARM_INSTALL_FOLDER = "installFolder"; //$NON-NLS-1$ + public static final String NATIVE_TOUCHPOINT_TYPE = "org.eclipse.equinox.p2.native"; //$NON-NLS-1$ + public static final String ACTION_CLEANUPZIP = "cleanupzip"; //$NON-NLS-1$ + public static final String ACTION_UNZIP = "unzip"; //$NON-NLS-1$ + public static final String PARM_ARTIFACT_REQUESTS = "artifactRequests"; //$NON-NLS-1$ + public static final String PARM_OPERAND = "operand"; //$NON-NLS-1$ + public static final String PARM_PROFILE = "profile"; //$NON-NLS-1$ + public static final String ACTION_COLLECT = "collect"; //$NON-NLS-1$ + public static final String ID = "org.eclipse.equinox.p2.touchpoint.natives"; //$NON-NLS-1$ + + public static IStatus createError(String message) { return new Status(IStatus.ERROR, ID, message); } - public ProvisioningAction getAction(String actionId) { - if (actionId.equals(ACTION_COLLECT)) { - return new ProvisioningAction() { - public IStatus execute(Map parameters) { - IProfile profile = (IProfile) parameters.get(PARM_PROFILE); - InstallableUnitOperand operand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); - try { - IArtifactRequest[] requests = collect(operand.second(), profile); - Collection artifactRequests = (Collection) parameters.get(PARM_ARTIFACT_REQUESTS); - artifactRequests.add(requests); - } catch (ProvisionException e) { - return e.getStatus(); - } - return Status.OK_STATUS; - } - - public IStatus undo(Map parameters) { - // nothing to do for now - return Status.OK_STATUS; - } - }; - } - - if (actionId.equals(ACTION_UNZIP)) { - return new ProvisioningAction() { - public IStatus execute(Map parameters) { - return unzip(parameters); - } - - public IStatus undo(Map parameters) { - return cleanupzip(parameters); - } - }; - } - if (actionId.equals(ACTION_CLEANUPZIP)) { - return new ProvisioningAction() { - public IStatus execute(Map parameters) { - return cleanupzip(parameters); - } - - public IStatus undo(Map parameters) { - return unzip(parameters); - } - }; - } - - if (actionId.equals(ACTION_CHMOD)) { - return new ProvisioningAction() { - public IStatus execute(Map parameters) { - String targetDir = (String) parameters.get(PARM_TARGET_DIR); - if (targetDir == null) - return createError(NLS.bind(Messages.param_not_set, PARM_TARGET_DIR, ACTION_CHMOD)); - String targetFile = (String) parameters.get(PARM_TARGET_FILE); - if (targetFile == null) - return createError(NLS.bind(Messages.param_not_set, PARM_TARGET_FILE, ACTION_CHMOD)); - String permissions = (String) parameters.get(PARM_PERMISSIONS); - if (permissions == null) - return createError(NLS.bind(Messages.param_not_set, PARM_PERMISSIONS, ACTION_CHMOD)); - - new Permissions().chmod(targetDir, targetFile, permissions); - return Status.OK_STATUS; - } - - public IStatus undo(Map parameters) { - //TODO: implement undo ?? - return Status.OK_STATUS; - } - }; - } - - if (actionId.equals(LinkAction.ID)) { - return new LinkAction(); - } - return null; - } - public TouchpointType getTouchpointType() { return MetadataFactory.createTouchpointType(NATIVE_TOUCHPOINT_TYPE, new Version(1, 0, 0)); } - IArtifactRequest[] collect(IInstallableUnit installableUnit, IProfile profile) throws ProvisionException { - IArtifactKey[] toDownload = installableUnit.getArtifacts(); - if (toDownload == null) - return new IArtifactRequest[0]; - IArtifactRepository destination = getDownloadCacheRepo(); - IArtifactRequest[] requests = new IArtifactRequest[toDownload.length]; - int count = 0; - for (int i = 0; i < toDownload.length; i++) { - //TODO Here there are cases where the download is not necessary again because what needs to be done is just a configuration step - requests[count++] = getArtifactRepositoryManager().createMirrorRequest(toDownload[i], destination, null, null); - } - - if (requests.length == count) - return requests; - IArtifactRequest[] result = new IArtifactRequest[count]; - System.arraycopy(requests, 0, result, 0, count); - return result; - } - private String getInstallFolder(IProfile profile) { return profile.getProperty(IProfile.PROP_INSTALL_FOLDER); } @@ -157,11 +62,11 @@ public class NativeTouchpoint extends Touchpoint { return (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName()); } - static private IArtifactRepositoryManager getArtifactRepositoryManager() { + public static IArtifactRepositoryManager getArtifactRepositoryManager() { return (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); } - static private IFileArtifactRepository getDownloadCacheRepo() throws ProvisionException { + static public IFileArtifactRepository getDownloadCacheRepo() throws ProvisionException { URI location = getDownloadCacheLocation(); if (location == null) throw new IllegalStateException(Messages.could_not_obtain_download_cache); @@ -195,7 +100,7 @@ public class NativeTouchpoint extends Touchpoint { return null; } - IStatus unzip(Map parameters) { + public static IStatus unzip(Map parameters) { String source = (String) parameters.get(PARM_SOURCE); if (source == null) return createError(NLS.bind(Messages.param_not_set, PARM_SOURCE, ACTION_UNZIP)); @@ -237,7 +142,7 @@ public class NativeTouchpoint extends Touchpoint { return Status.OK_STATUS; } - protected IStatus cleanupzip(Map parameters) { + public static IStatus cleanupzip(Map parameters) { String source = (String) parameters.get(PARM_SOURCE); if (source == null) return createError(NLS.bind(Messages.param_not_set, PARM_SOURCE, ACTION_CLEANUPZIP)); @@ -274,4 +179,8 @@ public class NativeTouchpoint extends Touchpoint { return Status.OK_STATUS; } + + public String qualifyAction(String actionId) { + return ID + "." + actionId; //$NON-NLS-1$ + } } diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java new file mode 100644 index 000000000..eab30c987 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2008 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.p2.touchpoint.natives.actions; + +import java.util.Map; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.equinox.internal.p2.touchpoint.natives.*; +import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction; +import org.eclipse.osgi.util.NLS; + +public class ChmodAction extends ProvisioningAction { + public IStatus execute(Map parameters) { + String targetDir = (String) parameters.get(NativeTouchpoint.PARM_TARGET_DIR); + if (targetDir == null) + return NativeTouchpoint.createError(NLS.bind(Messages.param_not_set, NativeTouchpoint.PARM_TARGET_DIR, NativeTouchpoint.ACTION_CHMOD)); + String targetFile = (String) parameters.get(NativeTouchpoint.PARM_TARGET_FILE); + if (targetFile == null) + return NativeTouchpoint.createError(NLS.bind(Messages.param_not_set, NativeTouchpoint.PARM_TARGET_FILE, NativeTouchpoint.ACTION_CHMOD)); + String permissions = (String) parameters.get(NativeTouchpoint.PARM_PERMISSIONS); + if (permissions == null) + return NativeTouchpoint.createError(NLS.bind(Messages.param_not_set, NativeTouchpoint.PARM_PERMISSIONS, NativeTouchpoint.ACTION_CHMOD)); + + new Permissions().chmod(targetDir, targetFile, permissions); + return Status.OK_STATUS; + } + + public IStatus undo(Map parameters) { + //TODO: implement undo ?? + return Status.OK_STATUS; + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupzipAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupzipAction.java new file mode 100644 index 000000000..7373df20c --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupzipAction.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2008 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.p2.touchpoint.natives.actions; + +import java.util.Map; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.p2.touchpoint.natives.NativeTouchpoint; +import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction; + +public class CleanupzipAction extends ProvisioningAction { + public IStatus execute(Map parameters) { + return NativeTouchpoint.cleanupzip(parameters); + } + + public IStatus undo(Map parameters) { + return NativeTouchpoint.unzip(parameters); + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CollectAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CollectAction.java new file mode 100644 index 000000000..7d22719d0 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CollectAction.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2008 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.p2.touchpoint.natives.actions; + +import java.util.Collection; +import java.util.Map; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.equinox.internal.p2.touchpoint.natives.NativeTouchpoint; +import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; +import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRequest; +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.IArtifactKey; +import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; + +public class CollectAction extends ProvisioningAction { + + public IStatus execute(Map parameters) { + IProfile profile = (IProfile) parameters.get(NativeTouchpoint.PARM_PROFILE); + InstallableUnitOperand operand = (InstallableUnitOperand) parameters.get(NativeTouchpoint.PARM_OPERAND); + try { + IArtifactRequest[] requests = collect(operand.second(), profile); + Collection artifactRequests = (Collection) parameters.get(NativeTouchpoint.PARM_ARTIFACT_REQUESTS); + artifactRequests.add(requests); + } catch (ProvisionException e) { + return e.getStatus(); + } + return Status.OK_STATUS; + } + + public IStatus undo(Map parameters) { + // nothing to do for now + return Status.OK_STATUS; + } + + IArtifactRequest[] collect(IInstallableUnit installableUnit, IProfile profile) throws ProvisionException { + IArtifactKey[] toDownload = installableUnit.getArtifacts(); + if (toDownload == null) + return new IArtifactRequest[0]; + IArtifactRepository destination = NativeTouchpoint.getDownloadCacheRepo(); + IArtifactRequest[] requests = new IArtifactRequest[toDownload.length]; + int count = 0; + for (int i = 0; i < toDownload.length; i++) { + //TODO Here there are cases where the download is not necessary again because what needs to be done is just a configuration step + requests[count++] = NativeTouchpoint.getArtifactRepositoryManager().createMirrorRequest(toDownload[i], destination, null, null); + } + + if (requests.length == count) + return requests; + IArtifactRequest[] result = new IArtifactRequest[count]; + System.arraycopy(requests, 0, result, 0, count); + return result; + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/UnzipAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/UnzipAction.java new file mode 100644 index 000000000..183f82ba4 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/UnzipAction.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2008 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.p2.touchpoint.natives.actions; + +import java.util.Map; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.p2.touchpoint.natives.NativeTouchpoint; +import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction; + +public class UnzipAction extends ProvisioningAction { + + public IStatus execute(Map parameters) { + return NativeTouchpoint.unzip(parameters); + } + + public IStatus undo(Map parameters) { + return NativeTouchpoint.cleanupzip(parameters); + } +}
\ No newline at end of file |