Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Arthorne2009-10-07 19:02:23 +0000
committerJohn Arthorne2009-10-07 19:02:23 +0000
commitcab6d9f76e4c91fcb27545c34d07a3bd0241e89a (patch)
tree2efa627288a016dcee8c5b3586fdfdfc8866b33b /bundles
parent21921252470b18ff8fb1cd7f832db14017b67131 (diff)
downloadrt.equinox.p2-cab6d9f76e4c91fcb27545c34d07a3bd0241e89a.tar.gz
rt.equinox.p2-cab6d9f76e4c91fcb27545c34d07a3bd0241e89a.tar.xz
rt.equinox.p2-cab6d9f76e4c91fcb27545c34d07a3bd0241e89a.zip
Bug 290207 - Support multiple p2 instances in a single VM
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF5
-rw-r--r--bundles/org.eclipse.equinox.p2.core/OSGI-INF/agentProvider.xml7
-rw-r--r--bundles/org.eclipse.equinox.p2.core/OSGI-INF/eventBus.xml4
-rw-r--r--bundles/org.eclipse.equinox.p2.core/build.properties15
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/DefaultAgentProvider.java35
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/EventBusComponent.java28
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/ProvisioningAgent.java85
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgent.java55
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgentProvider.java37
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/package.html22
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/spi/IAgentServiceFactory.java39
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/spi/package.html20
12 files changed, 339 insertions, 13 deletions
diff --git a/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF
index bcce949ef..1322f4e01 100644
--- a/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF
@@ -94,10 +94,13 @@ Export-Package: org.eclipse.equinox.internal.p2.core;x-friends:="org.eclipse.equ
org.eclipse.equinox.p2.metadata.repository,
org.eclipse.equinox.p2.director,
org.eclipse.equinox.p2.engine,
- org.eclipse.equinox.p2.touchpoint.eclipse"
+ org.eclipse.equinox.p2.touchpoint.eclipse",
+ org.eclipse.equinox.p2.core,
+ org.eclipse.equinox.p2.core.spi
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
J2SE-1.4
Bundle-Activator: org.eclipse.equinox.internal.p2.core.Activator
Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.5.0,4.0.0)"
+Service-Component: OSGI-INF/eventBus.xml
diff --git a/bundles/org.eclipse.equinox.p2.core/OSGI-INF/agentProvider.xml b/bundles/org.eclipse.equinox.p2.core/OSGI-INF/agentProvider.xml
new file mode 100644
index 000000000..adf24cc83
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/OSGI-INF/agentProvider.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.equinox.p2.di.agentProvider">
+ <implementation class="org.eclipse.equinox.internal.p2.core.DefaultAgentProvider"/>
+ <service>
+ <provide interface="org.eclipse.equinox.p2.core.IProvisioningAgentProvider"/>
+ </service>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.p2.core/OSGI-INF/eventBus.xml b/bundles/org.eclipse.equinox.p2.core/OSGI-INF/eventBus.xml
new file mode 100644
index 000000000..8f9978a3b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/OSGI-INF/eventBus.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.equinox.p2.core.eventbus">
+ <implementation class="org.eclipse.equinox.internal.p2.core.EventBusComponent"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.p2.core/build.properties b/bundles/org.eclipse.equinox.p2.core/build.properties
index a6b8330d2..209c80c29 100644
--- a/bundles/org.eclipse.equinox.p2.core/build.properties
+++ b/bundles/org.eclipse.equinox.p2.core/build.properties
@@ -1,17 +1,8 @@
-###############################################################################
-# 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
-###############################################################################
-source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
about.html,\
- plugin.properties
+ plugin.properties,\
+ OSGI-INF/eventBus.xml
src.includes = about.html
+source.. = src/
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/DefaultAgentProvider.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/DefaultAgentProvider.java
new file mode 100644
index 000000000..0f7b9b64e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/DefaultAgentProvider.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.core;
+
+import java.net.URI;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.core.IProvisioningAgentProvider;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Default implementation of {@link IProvisioningAgentProvider}.
+ */
+public class DefaultAgentProvider implements IProvisioningAgentProvider {
+ private BundleContext context;
+
+ public void activate(BundleContext aContext) {
+ this.context = aContext;
+ }
+
+ public IProvisioningAgent createAgent(URI location) throws Exception {
+ ProvisioningAgent result = new ProvisioningAgent();
+ result.setLocation(location);
+ result.setBundleContext(context);
+ return result;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/EventBusComponent.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/EventBusComponent.java
new file mode 100644
index 000000000..095efdee3
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/EventBusComponent.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.core;
+
+import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;
+
+/**
+ * Factory for creating {@link IProvisioningEventBus} instances.
+ */
+public class EventBusComponent implements IAgentServiceFactory {
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.p2.core.spi.IAgentServiceFactory#createService(org.eclipse.equinox.p2.core.IProvisioningAgent)
+ */
+ public Object createService(IProvisioningAgent agent) {
+ return new ProvisioningEventBus();
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/ProvisioningAgent.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/ProvisioningAgent.java
new file mode 100644
index 000000000..aef7146b5
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/ProvisioningAgent.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.core;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.util.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
+import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;
+import org.osgi.framework.*;
+
+/**
+ * Represents a p2 agent instance.
+ */
+public class ProvisioningAgent implements IProvisioningAgent {
+
+ private final Map agentServices = Collections.synchronizedMap(new HashMap());
+
+ private BundleContext context;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.p2.core.IProvisioningAgent#getService(java.lang.String)
+ */
+ public Object getService(String serviceName) {
+ Object service = agentServices.get(serviceName);
+ if (service != null)
+ return service;
+ //attempt to get factory service from service registry
+ ServiceReference[] refs;
+ try {
+ refs = context.getServiceReferences(IAgentServiceFactory.SERVICE_NAME, "(" + IAgentServiceFactory.PROP_CREATED_SERVICE_NAME + '=' + serviceName + ')'); //$NON-NLS-1$
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ return null;
+ }
+ if (refs == null || refs.length == 0)
+ return null;
+ IAgentServiceFactory factory = (IAgentServiceFactory) context.getService(refs[0]);
+ if (factory == null)
+ return null;
+ try {
+ service = factory.createService(this);
+ } finally {
+ context.ungetService(refs[0]);
+ }
+ if (service != null)
+ agentServices.put(serviceName, service);
+ return service;
+ }
+
+ public void registerService(String serviceName, Object service) {
+ agentServices.put(serviceName, service);
+ }
+
+ public void setBundleContext(BundleContext context) {
+ this.context = context;
+ }
+
+ public void setLocation(URI location) {
+ try {
+ AgentLocation agentLocation = new BasicLocation(URIUtil.toURL(location));
+ agentServices.put(AgentLocation.SERVICE_NAME, agentLocation);
+ } catch (MalformedURLException e) {
+ LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Invalid agent location", e)); //$NON-NLS-1$
+ }
+ }
+
+ public void unregisterService(String serviceName, Object service) {
+ synchronized (agentServices) {
+ if (agentServices.get(serviceName) == service)
+ agentServices.remove(serviceName);
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgent.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgent.java
new file mode 100644
index 000000000..6bcada44b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgent.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.core;
+
+import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;
+
+/**
+ * A provisioning agent is comprised of a modular, extensible set of related services.
+ * Each agent instance has its own separate instances of these services that are
+ * not shared with other agents. There is at most one instance of a given service
+ * tracked by an agent at any given time, which ensures all services that make
+ * up an agent instance share common service instances with each other.
+ * <p>
+ * Services are registered with an agent either directly, via the {@link #registerService(String, Object)}
+ * method, or indirectly by registering an {@link IAgentServiceFactory} in the OSGi
+ * service registry.
+ * </p>
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @noextend This interface is not intended to be extended by clients.
+ * @since 1.1
+ */
+public interface IProvisioningAgent {
+ /**
+ * Returns the service with the given service name, or <code>null</code>
+ * if no such service is available in this agent.
+ */
+ public Object getService(String serviceName);
+
+ /**
+ * Registers a service with this provisioning agent.
+ *
+ * @param serviceName The name of the service to register
+ * @param service The service implementation
+ */
+ public void registerService(String serviceName, Object service);
+
+ /**
+ * Unregisters a service that has previously been registered with this
+ * agent via {@link #registerService(String, Object)}. This method has
+ * no effect if no such service is registered with this agent.
+ *
+ * @param serviceName The name of the service to unregister
+ * @param service The service implementation to unregister.
+ */
+ public void unregisterService(String serviceName, Object service);
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgentProvider.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgentProvider.java
new file mode 100644
index 000000000..010f3bf29
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgentProvider.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.core;
+
+import java.net.URI;
+
+/**
+ * A service that is used to create or obtain instances of an
+ * {@link IProvisioningAgent}.
+ * @since 1.1
+ */
+public interface IProvisioningAgentProvider {
+ /**
+ * Creates a provisioning agent who metadata is stored at the given location.
+ * If a <code>null</code> location is provided, the provisioning agent for the
+ * currently running system is returned, if available. If a <code>null</code>
+ * location is provided and the currently running system has not been provisioned
+ * by any known agent, <code>null</code> is returned.
+ *
+ * @param location The location where the agent metadata is stored
+ * @return A provisioning agent, or <code>null</code> if a <code>null</code>
+ * parameter is provided an there is no currently running agent.
+ * @throws Exception If agent creation failed. Reasons include:
+ * <ul>
+ * <li>The location is not writeable.</li>
+ * </ul>
+ */
+ public IProvisioningAgent createAgent(URI location) throws Exception;
+}
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/package.html b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/package.html
new file mode 100644
index 000000000..ce702fae6
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/package.html
@@ -0,0 +1,22 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Package-level Javadoc</title>
+</head>
+<body>
+Provides core support for interacting with a p2-based provisioning system
+<h2>
+Package Specification</h2>
+<p>
+This package specifies API for creating, using, and extending a provisioning system.
+A provisioning agent ties together a set of related services that work together
+to implement a provisioning system. For end users of the provisioning system,
+they simply instantiate or obtain an agent and get the services they require from
+the agent. Extenders can register a factory for adding new services to the system,
+or add services directly to an agent.
+<p>
+@since 2.0
+<p>
+</body>
+</html>
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/spi/IAgentServiceFactory.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/spi/IAgentServiceFactory.java
new file mode 100644
index 000000000..8fd467b67
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/spi/IAgentServiceFactory.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.core.spi;
+
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+
+/**
+ * A factory for creating a service that forms part of a provisioning agent instance.
+ * Factories themselves are registered in the OSGi service registry so that they
+ * can be obtained by a provisioning agent.
+ * @since 1.1
+ */
+public interface IAgentServiceFactory {
+ /**
+ * The service name for the factory service.
+ */
+ public static final String SERVICE_NAME = IAgentServiceFactory.class.getName();
+
+ /**
+ * The service property specifying the name of the service created by this factory.
+ */
+ public static final String PROP_CREATED_SERVICE_NAME = "p2.agent.servicename"; //$NON-NLS-1$
+
+ /**
+ * Instantiates a service instance for the given provisioning agent.
+ *
+ * @param agent The agent this service will belong to
+ * @return The created service
+ */
+ public Object createService(IProvisioningAgent agent);
+}
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/spi/package.html b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/spi/package.html
new file mode 100644
index 000000000..70d3ca559
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/spi/package.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Package-level Javadoc</title>
+</head>
+<body>
+Provides API for customizing and extending a p2-based provisioning system
+<h2>
+Package Specification</h2>
+<p>
+This package specifies API for extending and customizing a provisioning system.
+A provisioning agent ties together a set of related services that work together
+to implement a provisioning system. Extenders can register a factory for adding new
+services to the system, or add services directly to an agent.
+<p>
+@since 2.0
+<p>
+</body>
+</html>

Back to the top