Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddProgramPropertyActionTest.java80
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AllTests.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/RemoveProgramPropertyActionTest.java78
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml20
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/AddProgramPropertyAction.java90
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RemoveProgramPropertyAction.java73
7 files changed, 345 insertions, 2 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddProgramPropertyActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddProgramPropertyActionTest.java
new file mode 100644
index 000000000..74a62eecc
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddProgramPropertyActionTest.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.touchpoint.eclipse;
+
+import java.util.*;
+import org.eclipse.equinox.internal.p2.engine.InstallableUnitOperand;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.ActionConstants;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.AddProgramPropertyAction;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.ConfigData;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+
+public class AddProgramPropertyActionTest extends AbstractProvisioningTest {
+
+ public AddProgramPropertyActionTest(String name) {
+ super(name);
+ }
+
+ public AddProgramPropertyActionTest() {
+ super("");
+ }
+
+ public void testExecuteUndo() {
+ // setup
+ Map parameters = new HashMap();
+ parameters.put(ActionConstants.PARM_AGENT, getAgent());
+ EclipseTouchpoint touchpoint = new EclipseTouchpoint();
+ Properties profileProperties = new Properties();
+ profileProperties.setProperty(IProfile.PROP_INSTALL_FOLDER, getTempFolder().toString());
+ IProfile profile = createProfile("test", profileProperties);
+ InstallableUnitOperand operand = new InstallableUnitOperand(null, createIU("test"));
+ touchpoint.initializePhase(null, profile, "test", parameters);
+ parameters.put("iu", operand.second());
+ touchpoint.initializeOperand(profile, parameters);
+ Manipulator manipulator = (Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR);
+ assertNotNull(manipulator);
+ ConfigData data = manipulator.getConfigData();
+
+ String key = getUniqueString();
+ String value1 = "foo";
+ String value2 = "bar";
+ assertNull(data.getProperty(key));
+ parameters.put(ActionConstants.PARM_PROP_NAME, key);
+ parameters.put(ActionConstants.PARM_PROP_VALUE, value1);
+
+ // execute the action and check the values
+ AddProgramPropertyAction action = new AddProgramPropertyAction();
+ action.execute(parameters);
+ String current = data.getProperty(key);
+ assertNotNull(current);
+ assertEquals(value1, current);
+
+ // add another value. expecting a comma-separated list of values
+ parameters.put(ActionConstants.PARM_PROP_VALUE, value2);
+ action.execute(parameters);
+ current = data.getProperty(key);
+ assertNotNull(current);
+ assertEquals(value1 + "," + value2, current);
+
+ // remove a value
+ parameters.put(ActionConstants.PARM_PROP_VALUE, value2);
+ action.undo(parameters);
+ current = data.getProperty(key);
+ assertNotNull(current);
+ assertEquals(value1, current);
+
+ // cleanup
+ data.setProperty(key, null);
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AllTests.java
index 5f4c9399a..eae364c24 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AllTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AllTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 2011 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
@@ -22,6 +22,7 @@ public class AllTests extends TestCase {
suite.addTestSuite(EclipseTouchpointTest.class);
suite.addTestSuite(AddJVMArgumentActionTest.class);
suite.addTestSuite(AddProgramArgumentActionTest.class);
+ suite.addTestSuite(AddProgramPropertyActionTest.class);
suite.addTestSuite(AddRepositoryActionTest.class);
suite.addTestSuite(AddSourceBundleActionTest.class);
suite.addTestSuite(CheckTrustActionTest.class);
@@ -35,6 +36,7 @@ public class AllTests extends TestCase {
suite.addTestSuite(PathUtilTest.class);
suite.addTestSuite(RemoveJVMArgumentActionTest.class);
suite.addTestSuite(RemoveProgramArgumentActionTest.class);
+ suite.addTestSuite(RemoveProgramPropertyActionTest.class);
suite.addTestSuite(RemoveRepositoryActionTest.class);
suite.addTestSuite(RemoveSourceBundleActionTest.class);
suite.addTestSuite(SetFrameworkDependentPropertyActionTest.class);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/RemoveProgramPropertyActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/RemoveProgramPropertyActionTest.java
new file mode 100644
index 000000000..10587b926
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/RemoveProgramPropertyActionTest.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.touchpoint.eclipse;
+
+import java.util.*;
+import org.eclipse.equinox.internal.p2.engine.InstallableUnitOperand;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.ActionConstants;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.RemoveProgramPropertyAction;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.ConfigData;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+
+public class RemoveProgramPropertyActionTest extends AbstractProvisioningTest {
+
+ public RemoveProgramPropertyActionTest(String name) {
+ super(name);
+ }
+
+ public RemoveProgramPropertyActionTest() {
+ super("");
+ }
+
+ public void testExecuteUndo() {
+ // setup
+ Map parameters = new HashMap();
+ parameters.put(ActionConstants.PARM_AGENT, getAgent());
+ EclipseTouchpoint touchpoint = new EclipseTouchpoint();
+ Properties profileProperties = new Properties();
+ profileProperties.setProperty(IProfile.PROP_INSTALL_FOLDER, getTempFolder().toString());
+ IProfile profile = createProfile("test", profileProperties);
+ InstallableUnitOperand operand = new InstallableUnitOperand(null, createIU("test"));
+ touchpoint.initializePhase(null, profile, "test", parameters);
+ parameters.put("iu", operand.second());
+ touchpoint.initializeOperand(profile, parameters);
+ Manipulator manipulator = (Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR);
+ assertNotNull(manipulator);
+ ConfigData data = manipulator.getConfigData();
+
+ String key = getUniqueString();
+ String value1 = "foo";
+ String value2 = "bar";
+ String value3 = "quux";
+ String initial = value1 + "," + value2 + "," + value3;
+ assertNull(data.getProperty(key));
+ data.setProperty(key, initial);
+
+ // set the parms
+ parameters.put(ActionConstants.PARM_PROP_NAME, key);
+ parameters.put(ActionConstants.PARM_PROP_VALUE, value2);
+
+ // execute the action and check the values
+ RemoveProgramPropertyAction action = new RemoveProgramPropertyAction();
+ action.execute(parameters);
+ String current = data.getProperty(key);
+ assertNotNull(current);
+ assertEquals(value1 + "," + value3, current);
+
+ // undo action
+ action.undo(parameters);
+ current = data.getProperty(key);
+ assertNotNull(current);
+ assertEquals(initial, current);
+
+ // cleanup
+ data.setProperty(key, null);
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/META-INF/MANIFEST.MF
index de43a8c3e..bac57f564 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.p2.touchpoint.eclipse;singleton:=true
-Bundle-Version: 2.0.100.qualifier
+Bundle-Version: 2.1.0.qualifier
Bundle-Activator: org.eclipse.equinox.internal.p2.touchpoint.eclipse.Activator
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml
index ab256c131..08abb6d26 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml
@@ -30,6 +30,16 @@
<extension
point="org.eclipse.equinox.p2.engine.actions">
<action
+ class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.AddProgramPropertyAction"
+ name="addProgramProperty"
+ 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.AddRepositoryAction"
name="addRepository"
touchpointType="org.eclipse.equinox.p2.osgi"
@@ -140,6 +150,16 @@
<extension
point="org.eclipse.equinox.p2.engine.actions">
<action
+ class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.RemoveProgramPropertyAction"
+ name="removeProgramProperty"
+ 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.RemoveRepositoryAction"
name="removeRepository"
touchpointType="org.eclipse.equinox.p2.osgi"
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/AddProgramPropertyAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/AddProgramPropertyAction.java
new file mode 100644
index 000000000..48d9ba9ef
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/AddProgramPropertyAction.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.ConfigData;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator;
+import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
+import org.eclipse.osgi.util.NLS;
+
+public class AddProgramPropertyAction extends ProvisioningAction {
+ public static final String ID = "addProgramProperty"; //$NON-NLS-1$
+
+ // treat the given string as a comma-separated list and parse and
+ // convert it to a real list
+ protected static List<String> convertToList(String value) {
+ List<String> result = new ArrayList<String>();
+ for (StringTokenizer tokenizer = new StringTokenizer(value, ","); tokenizer.hasMoreTokens();) //$NON-NLS-1$
+ result.add(tokenizer.nextToken());
+ return result;
+ }
+
+ // convert the given list to a comma-separated string
+ protected static String convertToString(List<String> list) {
+ StringBuffer buffer = new StringBuffer();
+ for (Iterator<String> iter = list.iterator(); iter.hasNext();) {
+ buffer.append(iter.next());
+ if (iter.hasNext())
+ buffer.append(',');
+ }
+ return buffer.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.p2.engine.spi.ProvisioningAction#execute(java.util.Map)
+ */
+ public IStatus execute(Map<String, Object> parameters) {
+ Manipulator manipulator = (Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR);
+ String propName = (String) parameters.get(ActionConstants.PARM_PROP_NAME);
+ if (propName == null)
+ return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_PROP_NAME, ID));
+ String propValue = (String) parameters.get(ActionConstants.PARM_PROP_VALUE);
+ if (propValue == null)
+ return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_PROP_VALUE, ID));
+ if (propValue != null && propValue.equals(ActionConstants.PARM_AT_ARTIFACT)) {
+ try {
+ propValue = Util.resolveArtifactParam(parameters);
+ } catch (CoreException e) {
+ return e.getStatus();
+ }
+ }
+
+ // if there was no value previously, then just set our key/value pair and return.
+ // otherwise we have to merge.
+ ConfigData data = manipulator.getConfigData();
+ String previous = data.getProperty(propName);
+ // make a backup - even if it is null
+ getMemento().put(ActionConstants.PARM_PREVIOUS_VALUE, previous);
+ // assume the value is a comma-separated list and just add ourselves to the end
+ if (previous != null)
+ propValue = previous + ',' + propValue;
+ data.setProperty(propName, propValue);
+ return Status.OK_STATUS;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.p2.engine.spi.ProvisioningAction#undo(java.util.Map)
+ */
+ public IStatus undo(Map<String, Object> parameters) {
+ Manipulator manipulator = (Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR);
+ String propName = (String) parameters.get(ActionConstants.PARM_PROP_NAME);
+ if (propName == null)
+ return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_PROP_NAME, ID));
+ String previous = (String) getMemento().get(ActionConstants.PARM_PREVIOUS_VALUE);
+ manipulator.getConfigData().setProperty(propName, previous);
+ return Status.OK_STATUS;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RemoveProgramPropertyAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RemoveProgramPropertyAction.java
new file mode 100644
index 000000000..18b3a67ef
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RemoveProgramPropertyAction.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.List;
+import java.util.Map;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.ConfigData;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator;
+import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
+import org.eclipse.osgi.util.NLS;
+
+public class RemoveProgramPropertyAction extends ProvisioningAction {
+ public static final String ID = "removeProgramProperty"; //$NON-NLS-1$
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.p2.engine.spi.ProvisioningAction#execute(java.util.Map)
+ */
+ public IStatus execute(Map<String, Object> parameters) {
+ Manipulator manipulator = (Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR);
+ String propName = (String) parameters.get(ActionConstants.PARM_PROP_NAME);
+ if (propName == null)
+ return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_PROP_NAME, ID));
+ String propValue = (String) parameters.get(ActionConstants.PARM_PROP_VALUE);
+
+ ConfigData data = manipulator.getConfigData();
+ String previous = data.getProperty(propName);
+ if (previous == null)
+ return Status.OK_STATUS;
+ // make a backup - even if it is null
+ getMemento().put(ActionConstants.PARM_PREVIOUS_VALUE, previous);
+ // if the value is null, remove the key/value pair.
+ if (propValue == null) {
+ data.setProperty(propName, null);
+ return Status.OK_STATUS;
+ }
+ // Otherwise treat the current value as a comma-separated list and remove
+ // just the one value that was specified.
+ List<String> list = AddProgramPropertyAction.convertToList(previous);
+ // if the value wasn't in the list, then just return
+ if (!list.remove(propValue))
+ return Status.OK_STATUS;
+ // otherwise set the property to the new value, or remove it if it is now empty
+ propValue = list.isEmpty() ? null : AddProgramPropertyAction.convertToString(list);
+ data.setProperty(propName, propValue);
+ return Status.OK_STATUS;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.p2.engine.spi.ProvisioningAction#undo(java.util.Map)
+ */
+ public IStatus undo(Map<String, Object> parameters) {
+ Manipulator manipulator = (Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR);
+ String propName = (String) parameters.get(ActionConstants.PARM_PROP_NAME);
+ if (propName == null)
+ return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_PROP_NAME, ID));
+ String previous = (String) getMemento().get(ActionConstants.PARM_PREVIOUS_VALUE);
+ manipulator.getConfigData().setProperty(propName, previous);
+ return Status.OK_STATUS;
+ }
+
+}

Back to the top