Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2012-12-13 08:21:31 -0500
committerPascal Rapicault2013-01-19 17:13:47 -0500
commit8020d416f36e13219978dca2e29ebb64e0c48454 (patch)
tree7a85724edcc6700976a63595db00595e14c44ac5 /bundles/org.eclipse.equinox.p2.engine/src
parent54a9cd05bd5edca233d7e589e3abf74752c643e5 (diff)
downloadrt.equinox.p2-8020d416f36e13219978dca2e29ebb64e0c48454.tar.gz
rt.equinox.p2-8020d416f36e13219978dca2e29ebb64e0c48454.tar.xz
rt.equinox.p2-8020d416f36e13219978dca2e29ebb64e0c48454.zip
bug 397183 - initial support for lastResult variablev20130119-221347
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.engine/src')
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/AssignVariableAction.java21
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ParameterizedProvisioningAction.java47
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Phase.java15
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/ProvisioningAction.java13
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/Value.java30
5 files changed, 112 insertions, 14 deletions
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/AssignVariableAction.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/AssignVariableAction.java
new file mode 100644
index 000000000..bcadf35f0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/AssignVariableAction.java
@@ -0,0 +1,21 @@
+package org.eclipse.equinox.internal.p2.engine;
+
+import java.util.Map;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
+
+public class AssignVariableAction extends ProvisioningAction {
+
+ @Override
+ public IStatus execute(Map<String, Object> parameters) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IStatus undo(Map<String, Object> parameters) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
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 8437cb324..eed4c31cf 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 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
@@ -7,19 +7,21 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Landmark Graphics Corporation - bug 397183
*******************************************************************************/
package org.eclipse.equinox.internal.p2.engine;
import java.util.*;
import java.util.Map.Entry;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
-import org.eclipse.equinox.p2.engine.spi.Touchpoint;
+import org.eclipse.equinox.p2.engine.spi.*;
public class ParameterizedProvisioningAction extends ProvisioningAction {
-
private ProvisioningAction action;
private Map<String, String> actionParameters;
+ //ActualParameter is used to keep values to which variables have been resolved.
+ //This is especially useful when undoing in the presence of variables that change (e.g. lastResult)
+ private Map<String, Object> actualParameters;
private String actionText;
public ParameterizedProvisioningAction(ProvisioningAction action, Map<String, String> actionParameters, String actionText) {
@@ -27,6 +29,7 @@ public class ParameterizedProvisioningAction extends ProvisioningAction {
throw new IllegalArgumentException(Messages.ParameterizedProvisioningAction_action_or_parameters_null);
this.action = action;
this.actionParameters = actionParameters;
+ this.actualParameters = new HashMap<String, Object>(actionParameters.size());
this.actionText = actionText;
}
@@ -44,14 +47,14 @@ public class ParameterizedProvisioningAction extends ProvisioningAction {
Map<String, Object> result = new HashMap<String, Object>(parameters);
for (Entry<String, String> entry : actionParameters.entrySet()) {
String name = entry.getKey();
- String value = processVariables(entry.getValue(), parameters);
+ Object value = processVariables(entry.getValue(), parameters, false);
result.put(name, value);
}
return Collections.unmodifiableMap(result);
}
- private String processVariables(String parameterValue, Map<String, Object> parameters) {
-
+ //allowInfixReplacement triggers the replacement of the variables found in the middle of a string (e.g. abc${var}def)
+ private Object processVariables(String parameterValue, Map<String, Object> parameters, boolean allowInfixReplacement) {
int variableBeginIndex = parameterValue.indexOf("${"); //$NON-NLS-1$
if (variableBeginIndex == -1)
return parameterValue;
@@ -62,7 +65,25 @@ public class ParameterizedProvisioningAction extends ProvisioningAction {
String preVariable = parameterValue.substring(0, variableBeginIndex);
String variableName = parameterValue.substring(variableBeginIndex + 2, variableEndIndex);
- Object value = parameters.get(variableName);
+
+ //replace the internal name by the user visible name
+ if (Phase.LAST_RESULT_PUBLIC_NAME.equals(variableName)) {
+ variableName = Phase.LAST_RESULT_INTERNAL_NAME;
+ }
+ Object valueUsed = actualParameters.get(variableName);
+ Object value = valueUsed == null ? parameters.get(variableName) : valueUsed;
+ actualParameters.put(variableName, value);
+
+ if (value instanceof Value) {
+ if (allowInfixReplacement == false && variableBeginIndex == 0 && variableEndIndex == parameterValue.length() - 1)
+ return value;
+
+ Value<?> result = (Value<?>) value;
+ if (result.getClazz() == String.class)
+ value = result.getValue();
+ else
+ throw new RuntimeException("The type of the variable is expected to be a String"); //$NON-NLS-1$
+ }
// try to replace this parameter with a character
if (value == null && variableName.charAt(0) == '#') {
@@ -75,8 +96,8 @@ public class ParameterizedProvisioningAction extends ProvisioningAction {
}
}
- String variableValue = value == null ? "" : value.toString(); //$NON-NLS-1$
- String postVariable = processVariables(parameterValue.substring(variableEndIndex + 1), parameters);
+ String variableValue = value == null ? "" : value.toString(); //$NON-NLS-1$ //TODO This is where we replace the values
+ String postVariable = (String) processVariables(parameterValue.substring(variableEndIndex + 1), parameters, true);
return preVariable + variableValue + postVariable;
}
@@ -99,4 +120,10 @@ public class ParameterizedProvisioningAction extends ProvisioningAction {
public void setTouchpoint(Touchpoint touchpoint) {
throw new UnsupportedOperationException();
}
+
+ @Override
+ public Value<?> getResult() {
+ return action.getResult();
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Phase.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Phase.java
index bcf912978..ccc05effb 100644
--- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Phase.java
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Phase.java
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Landmark Graphics Corporation - bug 397183
*******************************************************************************/
package org.eclipse.equinox.internal.p2.engine;
@@ -16,8 +17,7 @@ import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.ProvisioningContext;
-import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
-import org.eclipse.equinox.p2.engine.spi.Touchpoint;
+import org.eclipse.equinox.p2.engine.spi.*;
import org.eclipse.osgi.util.NLS;
public abstract class Phase {
@@ -32,6 +32,8 @@ public abstract class Phase {
protected static final String PARM_AGENT = "agent"; //$NON-NLS-1$
protected static final String PARM_FORCED = "forced"; //$NON-NLS-1$
protected static final String PARM_TOUCHPOINT = "touchpoint"; //$NON-NLS-1$
+ protected static final String LAST_RESULT_INTERNAL_NAME = "_p2_internal_last_result_variable_"; //$NON-NLS-1$ //
+ protected static final String LAST_RESULT_PUBLIC_NAME = "lastResult"; //$NON-NLS-1$
protected final String phaseId;
protected final int weight;
@@ -155,8 +157,8 @@ public abstract class Phase {
operandParameters = touchpointToTouchpointOperandParameters.get(operandTouchpoint);
}
- operandParameters = Collections.unmodifiableMap(operandParameters);
if (actions != null) {
+ Object lastResult = null;
for (int j = 0; j < actions.size(); j++) {
ProvisioningAction action = actions.get(j);
Map<String, Object> parameters = operandParameters;
@@ -168,10 +170,17 @@ public abstract class Phase {
parameters = touchpointToTouchpointOperandParameters.get(touchpoint);
}
+ if (lastResult != null && lastResult != Value.NO_VALUE) {
+ parameters = new HashMap<String, Object>(parameters);
+ parameters.put(LAST_RESULT_INTERNAL_NAME, lastResult);
+ }
+ parameters = Collections.unmodifiableMap(parameters);
+
IStatus actionStatus = null;
try {
session.recordActionExecute(action, parameters);
actionStatus = action.execute(parameters);
+ lastResult = action.getResult().getValue();
} catch (RuntimeException e) {
if (!forced)
throw e;
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/ProvisioningAction.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/ProvisioningAction.java
index e8d8716cd..fb80a02e1 100644
--- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/ProvisioningAction.java
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/ProvisioningAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Landmark Graphics Corporation - bug 397183
*******************************************************************************/
package org.eclipse.equinox.p2.engine.spi;
@@ -31,6 +32,16 @@ public abstract class ProvisioningAction {
public abstract IStatus undo(Map<String, Object> parameters);
+ /**
+ * This method is meant for provisioning actions that need to communicate the result of their execution
+ * to subsequent actions.
+ * This method is only invoked by p2 once execute() has been executed.
+ * @return the result of the action execution.
+ */
+ public Value<?> getResult() {
+ return Value.NO_VALUE;
+ }
+
// TODO: these probably should not be visible
public void setTouchpoint(Touchpoint touchpoint) {
this.touchpoint = touchpoint;
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/Value.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/Value.java
new file mode 100644
index 000000000..15ecf1599
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/spi/Value.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Landmark Graphics Corporation
+ * 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:
+ * Landmark Graphics Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.engine.spi;
+
+public class Value<T> {
+ public static final Value<Object> NO_VALUE = new Value<Object>(null);
+ private T value;
+ private Class<T> clazz;
+
+ public Value(T val) {
+ value = val;
+ }
+
+ public T getValue() {
+ return value;
+ }
+
+ public Class<T> getClazz() {
+ return clazz;
+ }
+
+}

Back to the top