From fad4a1858eac6e6aacf59709751c16a7358ba989 Mon Sep 17 00:00:00 2001 From: DJ Houghton Date: Wed, 2 Feb 2011 21:14:45 +0000 Subject: Bug 329784 - Touchpoint instruction for incremental changes to program properties --- .../eclipse/AddProgramPropertyActionTest.java | 80 +++++++++++++++++++ .../p2/tests/touchpoint/eclipse/AllTests.java | 4 +- .../eclipse/RemoveProgramPropertyActionTest.java | 78 +++++++++++++++++++ .../META-INF/MANIFEST.MF | 2 +- .../plugin.xml | 20 +++++ .../eclipse/actions/AddProgramPropertyAction.java | 90 ++++++++++++++++++++++ .../actions/RemoveProgramPropertyAction.java | 73 ++++++++++++++++++ 7 files changed, 345 insertions(+), 2 deletions(-) create mode 100644 bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddProgramPropertyActionTest.java create mode 100644 bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/RemoveProgramPropertyActionTest.java create mode 100644 bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/AddProgramPropertyAction.java create mode 100644 bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RemoveProgramPropertyAction.java 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 @@ -27,6 +27,16 @@ version="1.0.0"> + + + + + + + + convertToList(String value) { + List result = new ArrayList(); + 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 list) { + StringBuffer buffer = new StringBuffer(); + for (Iterator 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 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 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 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 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 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; + } + +} -- cgit v1.2.3