diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov')
6 files changed, 466 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/CommonDef.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/CommonDef.java new file mode 100644 index 000000000..e24937a7f --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/CommonDef.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007 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.prov.engine; + +/* + * This interface contains global constant definitions. + * + * Use this interface to define constants that are likely to be used + * widely in different contexts with share a common intended meaning. + * + */ +public interface CommonDef { + + public static final String EmptyString = ""; //$NON-NLS-1$ + public static final String SpaceString = " "; //$NON-NLS-1$ + public static final String Underscore = "_"; //$NON-NLS-1$ + public static final String Dot = "."; //$NON-NLS-1$ + public static final String DotDot = ".."; //$NON-NLS-1$ + + public static final String EncodedSpaceString = "%20"; //$NON-NLS-1$ + + public static final String UncPrefix = "\\\\"; //$NON-NLS-1$ + public static final char ColonChar = ':'; + + /* + * Strings used as the type for the native and eclipse touchpoints, + * including the type in the touchpoints extension point. + */ + public static final String NativeTouchpoint = "native"; //$NON-NLS-1$ + public static final String EclipseTouchpoint = "eclipse"; //$NON-NLS-1$ + + public static final int MaxPathLength_Win32 = 256; + public static final int MaxPathLength_Linux = 1024; + // + // /* + // * Different protocols + // */ + // public interface Protocols { + // public static final String File = "file"; //$NON-NLS-1$ + // public static final String Http = "http"; //$NON-NLS-1$ + // public static final String Https = "https"; //$NON-NLS-1$ + // public static final String Ftp = "ftp"; //$NON-NLS-1$ + // public static final String Socks = "SOCKS"; //$NON-NLS-1$ + // } + // + // /* + // * File name extensions. + // */ + // public interface Extensions { + // public static final String Xml = ".xml"; //$NON-NLS-1$ + // public static final String Zip = ".zip"; //$NON-NLS-1$ + // public static final String Jar = ".jar"; //$NON-NLS-1$ + // public static final String Properties = ".properties"; //$NON-NLS-1$ + // } +} diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/EngineActivator.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/EngineActivator.java new file mode 100644 index 000000000..ee0b3eeac --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/EngineActivator.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2007 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.prov.engine; + +import org.osgi.framework.*; +import org.osgi.util.tracker.ServiceTracker; +import org.osgi.util.tracker.ServiceTrackerCustomizer; +import org.eclipse.equinox.prov.core.eventbus.ProvisioningEventBus; +import org.eclipse.equinox.prov.engine.Engine; + +public class EngineActivator implements BundleActivator, ServiceTrackerCustomizer { + private static BundleContext context; + public static final String ID = "org.eclipse.equinox.prov.engine"; + + public static BundleContext getContext() { + return context; + } + + private ServiceRegistration registration; + private ServiceTracker tracker; + + public void start(BundleContext context) throws Exception { + EngineActivator.context = context; + tracker = new ServiceTracker(context, ProvisioningEventBus.class.getName(), this); + tracker.open(); + } + + public void stop(BundleContext context) throws Exception { + tracker.close(); + tracker = null; + + EngineActivator.context = null; + } + + public Object addingService(ServiceReference reference) { + if (registration == null) { + ProvisioningEventBus eventBus = (ProvisioningEventBus) context.getService(reference); + registration = context.registerService(Engine.class.getName(), new Engine(eventBus), null); + return eventBus; + } + return null; + } + + public void modifiedService(ServiceReference reference, Object service) { + // TODO Auto-generated method stub + + } + + public void removedService(ServiceReference reference, Object service) { + if (registration != null) { + registration.unregister(); + registration = null; + } + } + +} diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/Messages.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/Messages.java new file mode 100644 index 000000000..c1dcd38fe --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/Messages.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2007 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.prov.engine; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.prov.engine.messages"; //$NON-NLS-1$ + + static { + // initialize resource bundles + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + // Do not instantiate + } + + public static String Engine_Error_During_Phase; + public static String Engine_Operation_Canceled_By_User; + public static String Profile_Not_Named_Self; + public static String Profile_Duplicate_Profile_Id; + public static String TouchpointManager_Null_Touchpoint_Type_Argument; + public static String TouchpointManager_Required_Touchpoint_Not_Found; + public static String TouchpointManager_No_Extension_Point; + public static String TouchpointManager_Incorrectly_Named_Extension; + public static String TouchpointManager_Attribute_Not_Specified; + public static String TouchpointManager_Conflicting_Touchpoint_Types; + public static String TouchpointManager_Touchpoint_Type_Mismatch; + public static String TouchpointManager_Exception_Creating_Touchpoint_Extension; + public static String TouchpointManager_Null_Creating_Touchpoint_Extension; + public static String Install_Operand_Description; + public static String Update_Operand_Description; + public static String Uninstall_Operand_Description; + +} diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/NullTouchpoint.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/NullTouchpoint.java new file mode 100644 index 000000000..2b8795770 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/NullTouchpoint.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007 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.prov.engine; + +import org.eclipse.equinox.prov.engine.*; +import org.eclipse.equinox.prov.metadata.TouchpointType; + +/** + * A touchpoint that performs no processing. + */ +public class NullTouchpoint implements ITouchpoint { + public static final ITouchpoint INSTANCE = new NullTouchpoint(); + + /** + * Public constructor only intended to be called by extension registry. + */ + public NullTouchpoint() { + super(); + } + + public TouchpointType getTouchpointType() { + return TouchpointType.NONE; + } + + public boolean supports(String phaseId) { + if (phaseId.equals("install") || phaseId.equals("uninstall")) + return true; + return false; + } + + public ITouchpointAction[] getActions(String phaseID, Profile profile, Operand operand) { + return new ITouchpointAction[] {}; + } + +} diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/TouchpointManager.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/TouchpointManager.java new file mode 100644 index 000000000..ec2cf09a5 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/TouchpointManager.java @@ -0,0 +1,223 @@ +/******************************************************************************* + * Copyright (c) 2007 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.prov.engine; + +import java.util.*; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.prov.core.helpers.LogHelper; +import org.eclipse.equinox.prov.core.helpers.MultiStatus; +import org.eclipse.equinox.prov.engine.ITouchpoint; +import org.eclipse.equinox.prov.metadata.TouchpointType; +import org.eclipse.osgi.util.NLS; + +//TODO This needs to support multiple version of each touchpoint and have a lookup that supports version semantics +public class TouchpointManager implements IRegistryChangeListener { + + private static TouchpointManager instance; + + public static TouchpointManager getInstance() { + if (instance == null) { + instance = new TouchpointManager(); + } + return instance; + } + + 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 class TouchpointEntry { + + private IConfigurationElement element; + private boolean createdExtension; + private ITouchpoint touchpoint; + + public TouchpointEntry(IConfigurationElement element) { + super(); + this.element = element; + this.touchpoint = null; + this.createdExtension = false; + } + + public TouchpointEntry(IConfigurationElement element, ITouchpoint touchpoint) { + super(); + this.element = element; + this.touchpoint = touchpoint; + this.createdExtension = (touchpoint != null ? true : false); + } + + public boolean hasTouchpoint() { + return (this.touchpoint != null); + } + + public ITouchpoint getTouchpoint() { + if (!createdExtension) { + String id = element.getAttribute(ATTRIBUTE_TYPE); + try { + ITouchpoint touchpoint = (ITouchpoint) element.createExecutableExtension(ATTRIBUTE_CLASS); + if (touchpoint != null) { + if (!id.equals(touchpoint.getTouchpointType().getId())) { + reportError(NLS.bind(Messages.TouchpointManager_Touchpoint_Type_Mismatch, id, touchpoint.getTouchpointType().getId()), null); + } + this.touchpoint = touchpoint; + } else { + String errorMsg = NLS.bind(Messages.TouchpointManager_Null_Creating_Touchpoint_Extension, id); + throw new CoreException(new Status(IStatus.ERROR, EngineActivator.ID, 1, errorMsg, null)); + } + } catch (CoreException cexcpt) { + LogHelper.log(new Status(IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.TouchpointManager_Exception_Creating_Touchpoint_Extension, id), cexcpt)); + } catch (ClassCastException ccexcpt) { + LogHelper.log(new Status(IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.TouchpointManager_Exception_Creating_Touchpoint_Extension, id), ccexcpt)); + } + // Mark as created even in error cases, + // so exceptions are not logged multiple times + createdExtension = true; + } + return this.touchpoint; + } + + public String toString() { + StringBuffer result = new StringBuffer(element.toString()); + if (createdExtension) { + String touchpointString = touchpoint != null ? touchpoint.toString() : "not created"; //$NON-NLS-1$ + result.append(" => " + touchpointString); //$NON-NLS-1$ + } + return result.toString(); + } + } + + // TODO: Do we really want to store the touchpoints? The danger is + // that if two installations are performed simultaneously, then... + // TODO: Figure out locking, concurrency requirements for touchpoints. + private Map touchpointEntries; + + private TouchpointManager() { + RegistryFactory.getRegistry().addRegistryChangeListener(this, EngineActivator.ID); + } + + /* + * Return the touchpoint which is registered for the given id, + * or <code>null</code> if none are registered. + */ + public ITouchpoint getTouchpoint(TouchpointType id) { + if (id == null || CommonDef.EmptyString.equals(id.getId())) + throw new IllegalArgumentException(Messages.TouchpointManager_Null_Touchpoint_Type_Argument); + if (touchpointEntries == null) { + initializeTouchpoints(); + } + TouchpointEntry entry = (TouchpointEntry) touchpointEntries.get(id.getId()); + return entry == null ? null : entry.getTouchpoint(); + } + + public ITouchpoint[] getAllTouchpoints() { + if (touchpointEntries == null) { + initializeTouchpoints(); + } + Collection adapters = touchpointEntries.values(); + + ArrayList touchpoints = new ArrayList(adapters.size()); + for (Iterator iter = adapters.iterator(); iter.hasNext();) { + TouchpointEntry entry = (TouchpointEntry) iter.next(); + ITouchpoint touchpoint = entry.getTouchpoint(); + if (touchpoint != null) { + touchpoints.add(touchpoint); + } + } + return (ITouchpoint[]) touchpoints.toArray(new ITouchpoint[touchpoints.size()]); + } + + public ITouchpoint[] getCreatedTouchpoints() { + if (touchpointEntries == null) + return new ITouchpoint[0]; + Collection adapters = touchpointEntries.values(); + + ArrayList touchpoints = new ArrayList(adapters.size()); + for (Iterator iter = adapters.iterator(); iter.hasNext();) { + TouchpointEntry entry = (TouchpointEntry) iter.next(); + if (entry.hasTouchpoint()) { + ITouchpoint touchpoint = entry.getTouchpoint(); + if (touchpoint != null) { + touchpoints.add(touchpoint); + } + } + } + return (ITouchpoint[]) touchpoints.toArray(new ITouchpoint[touchpoints.size()]); + } + + public IStatus validateTouchpoints(String[] requiredTypes) { + MultiStatus status = (touchpointEntries == null ? initializeTouchpoints() : new MultiStatus()); + + for (int i = 0; i < requiredTypes.length; i++) { + TouchpointEntry entry = (TouchpointEntry) touchpointEntries.get(requiredTypes[i]); + if (entry == null) { + reportError(NLS.bind(Messages.TouchpointManager_Required_Touchpoint_Not_Found, requiredTypes[i]), status); + } + } + return status; + } + + /* + * Construct a map of the extensions that implement the touchpoints extension point. + */ + private MultiStatus initializeTouchpoints() { + MultiStatus status = new MultiStatus(); + 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; + } + + 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); + } + continue; + } + String id = elements[j].getAttribute(ATTRIBUTE_TYPE); + if (id == null) { + reportError(NLS.bind(Messages.TouchpointManager_Attribute_Not_Specified, ATTRIBUTE_TYPE), status); + 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); + } + } + } + return status; + } + + private static void reportError(String errorMsg, MultiStatus status) { + Status errorStatus = new Status(IStatus.ERROR, EngineActivator.ID, 1, errorMsg, null); + if (status != null) { + 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) { + // 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/prov/engine/messages.properties b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/messages.properties new file mode 100644 index 000000000..9b10bd1cb --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/prov/engine/messages.properties @@ -0,0 +1,29 @@ +############################################################################### +# Copyright (c) 2007 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 +############################################################################### + +Engine_Error_During_Phase=Error during phase: {0}. +Engine_Operation_Canceled_By_User=Operation canceled by the user. + +Profile_Duplicate_Profile_Id=Adding profile with duplicate id: {0}. +Profile_Not_Named_Self=Can't have a profile named: {0}. +TouchpointManager_Null_Touchpoint_Type_Argument=A null or empty string was passed as the type of a touchpoint. +TouchpointManager_Required_Touchpoint_Not_Found=The required {0} touchpoint is not included in the installation manager configuration. +TouchpointManager_No_Extension_Point=The extension point {0}.{1} was not found in the platform extension registry. +TouchpointManager_Incorrectly_Named_Extension=A touchpoint extension is incorrectly named {0} instead of {1}. +TouchpointManager_Attribute_Not_Specified=The required attribute {0} is not specified for the touchpoints extension point. +TouchpointManager_Conflicting_Touchpoint_Types=Two or more touchpoint extensions of type {0} are defined. +TouchpointManager_Touchpoint_Type_Mismatch=The touchpoint registered for type {0} reports its type as {1}. +TouchpointManager_Exception_Creating_Touchpoint_Extension=An exception was thrown and caught when creating the extension point instance for the {0} touchpoint. +TouchpointManager_Null_Creating_Touchpoint_Extension=A null object was returned when creating the extension point instance for the {0} touchpoint. + +Install_Operand_Description=Installing unit {0}. +Update_Operand_Description=Updating unit {0} with unit {1}. +Uninstall_Operand_Description=Removing unit {0}. |