diff options
author | DJ Houghton | 2011-02-02 21:14:45 +0000 |
---|---|---|
committer | DJ Houghton | 2011-02-02 21:14:45 +0000 |
commit | fad4a1858eac6e6aacf59709751c16a7358ba989 (patch) | |
tree | cc45d1150ef95b8a3fb31d8b67d4435d26c56060 /bundles/org.eclipse.equinox.p2.touchpoint.eclipse | |
parent | 84324fdd00154afb3f875b322d07a5590888299b (diff) | |
download | rt.equinox.p2-fad4a1858eac6e6aacf59709751c16a7358ba989.tar.gz rt.equinox.p2-fad4a1858eac6e6aacf59709751c16a7358ba989.tar.xz rt.equinox.p2-fad4a1858eac6e6aacf59709751c16a7358ba989.zip |
Bug 329784 - Touchpoint instruction for incremental changes to program properties
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.touchpoint.eclipse')
4 files changed, 184 insertions, 1 deletions
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; + } + +} |