aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1157844 - in /aries/trunk/subsystem/subsystem-core: ./ src/main/java/org/apache/aries/subsystem/core/ src/main/java/org/apache/aries/subsystem/core/internal/ src/main/java/org/apache/aries/subsystem/core/obr/ src/main/java/org/eclipse/equi...
Date Mon, 15 Aug 2011 13:42:58 GMT
Author: jwross
Date: Mon Aug 15 13:42:57 2011
New Revision: 1157844

URL: http://svn.apache.org/viewvc?rev=1157844&view=rev
Log:
ARIES-728: Check in initial baseline for subsystems implementation based on latest RFCs.

org.apache.aries.subsystem.core

Removed:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceProcessor.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/DictionaryAsMap.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/DictionaryBuilder.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/FileUtils.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/NoOpResolver.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceImpl.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RootSubsystem.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemEventDispatcher.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemImpl.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/BundleInfoImpl.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/ContentImpl.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/Manve2Repository.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/RepositoryDescriptorGenerator.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/eclipse/equinox/
Modified:
    aries/trunk/subsystem/subsystem-core/pom.xml
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceConverter.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceResolver.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/SubsystemEvent.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceResolverImpl.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceFactory.java
    aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/ResourceResolverTest.java

Modified: aries/trunk/subsystem/subsystem-core/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/pom.xml?rev=1157844&r1=1157843&r2=1157844&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/pom.xml (original)
+++ aries/trunk/subsystem/subsystem-core/pom.xml Mon Aug 15 13:42:57 2011
@@ -55,23 +55,9 @@
 
     <dependencies>
     	<dependency>
-    		<groupId>org.eclipse.equinox</groupId>
-    		<artifactId>coordinator</artifactId>
-    		<version>1.0.0.v20110314</version>
-    	</dependency>
-        <dependency>
             <groupId>org.apache.aries.subsystem</groupId>
             <artifactId>org.apache.aries.subsystem.api</artifactId>
             <version>0.1-SNAPSHOT</version>
-        </dependency>
-       <dependency>
-            <groupId>org.eclipse.equinox</groupId>
-            <artifactId>region</artifactId>
-            <version>1.0.0.v20110506</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.aries.application</groupId>
-            <artifactId>org.apache.aries.application.api</artifactId>
             <exclusions>
             	<exclusion>
             		<groupId>org.osgi</groupId>
@@ -80,8 +66,9 @@
             </exclusions>
         </dependency>
         <dependency>
-            <groupId>org.apache.aries.application</groupId>
-            <artifactId>org.apache.aries.application.utils</artifactId>
+            <groupId>org.apache.aries</groupId>
+            <artifactId>org.apache.aries.util</artifactId>
+            <version>0.4-SNAPSHOT</version>
             <exclusions>
             	<exclusion>
             		<groupId>org.osgi</groupId>
@@ -90,9 +77,9 @@
             </exclusions>
         </dependency>
         <dependency>
-            <groupId>org.apache.aries.testsupport</groupId>
-            <artifactId>org.apache.aries.testsupport.unit</artifactId>
-            <scope>test</scope>
+            <groupId>org.apache.aries.application</groupId>
+            <artifactId>org.apache.aries.application.api</artifactId>
+            <version>0.3.1-SNAPSHOT</version>
             <exclusions>
             	<exclusion>
             		<groupId>org.osgi</groupId>
@@ -100,21 +87,21 @@
             	</exclusion>
             </exclusions>
         </dependency>
-        <dependency>
+    	<dependency>
             <groupId>org.eclipse</groupId>
             <artifactId>osgi</artifactId>
-            <version>3.7.0.v20110221</version>
+            <version>3.8.0-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-simple</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-api</artifactId>
-            <scope>provided</scope>
+    	<dependency>
+    		<groupId>org.eclipse.equinox</groupId>
+    		<artifactId>coordinator</artifactId>
+    		<version>1.0.0.v20110314</version>
+    	</dependency>
+    	<dependency>
+            <groupId>org.eclipse.equinox</groupId>
+            <artifactId>region</artifactId>
+            <version>1.0.0.v20110506</version>
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
@@ -128,16 +115,6 @@
             </exclusions>
         </dependency>
         <dependency>
-            <groupId>org.apache.aries.application</groupId>
-            <artifactId>org.apache.aries.application.api</artifactId>
-            <version>0.3</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.aries.application</groupId>
-            <artifactId>org.apache.aries.application.utils</artifactId>
-            <version>0.3</version>
-        </dependency>
-        <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.bundlerepository</artifactId>
             <version>1.6.4</version>
@@ -149,15 +126,30 @@
             </exclusions>
         </dependency>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
+            <groupId>org.apache.aries.testsupport</groupId>
+            <artifactId>org.apache.aries.testsupport.unit</artifactId>
+            <version>0.4-SNAPSHOT</version>
+            <scope>test</scope>
+            <exclusions>
+            	<exclusion>
+            		<groupId>org.osgi</groupId>
+            		<artifactId>org.osgi.core</artifactId>
+            	</exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.aries.testsupport</groupId>
-            <artifactId>org.apache.aries.testsupport.unit</artifactId>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
             <scope>test</scope>
-            <version>0.3</version>
         </dependency>
     </dependencies>
 

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceConverter.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceConverter.java?rev=1157844&r1=1157843&r2=1157844&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceConverter.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceConverter.java
Mon Aug 15 13:42:57 2011
@@ -13,8 +13,8 @@
  */
 package org.apache.aries.subsystem.core;
 
-import org.apache.aries.subsystem.SubsystemException;
-import org.apache.aries.subsystem.spi.Resource;
+import org.osgi.framework.wiring.Resource;
+import org.osgi.service.subsystem.SubsystemException;
 
 /**
  * ResourceConverters are used to transform resources into another kind of

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceResolver.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceResolver.java?rev=1157844&r1=1157843&r2=1157844&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceResolver.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceResolver.java
Mon Aug 15 13:42:57 2011
@@ -15,8 +15,8 @@ package org.apache.aries.subsystem.core;
 
 import java.util.List;
 
-import org.apache.aries.subsystem.SubsystemException;
-import org.apache.aries.subsystem.spi.Resource;
+import org.osgi.framework.wiring.Resource;
+import org.osgi.service.subsystem.SubsystemException;
 
 /**
  * The ResourceResolver object is used by the SubsystemAdmin to locate

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/SubsystemEvent.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/SubsystemEvent.java?rev=1157844&r1=1157843&r2=1157844&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/SubsystemEvent.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/SubsystemEvent.java
Mon Aug 15 13:42:57 2011
@@ -13,7 +13,7 @@
  */
 package org.apache.aries.subsystem.core;
 
-import org.apache.aries.subsystem.Subsystem;
+import org.osgi.service.subsystem.Subsystem;
 
 /**
  * Event sent to listeners when an operation has been performed on a subsystem.
@@ -31,6 +31,7 @@ public class SubsystemEvent {
          * Event type used to indicate a subsystem has been installed.
          */
         INSTALLED,
+        INSTALLING,
 
         /**
          * Event type used to indicate a subsystem has been started.

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java?rev=1157844&r1=1157843&r2=1157844&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
Mon Aug 15 13:42:57 2011
@@ -14,119 +14,198 @@
 package org.apache.aries.subsystem.core.internal;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Executor;
 
-import org.apache.aries.subsystem.Subsystem;
-import org.apache.aries.subsystem.SubsystemConstants;
-import org.apache.aries.subsystem.core.ResourceResolver;
-import org.apache.aries.subsystem.spi.ResourceProcessor;
+import org.apache.aries.subsystem.core.obr.felix.FelixResourceAdapter;
+import org.apache.aries.subsystem.core.obr.felix.OsgiResourceAdapter;
+import org.apache.felix.bundlerepository.Reason;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
 import org.eclipse.equinox.region.RegionDigraph;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.hooks.resolver.ResolverHookFactory;
+import org.osgi.framework.wiring.Capability;
+import org.osgi.framework.wiring.FrameworkWiring;
+import org.osgi.framework.wiring.Requirement;
+import org.osgi.framework.wiring.Resource;
+import org.osgi.framework.wiring.Wire;
 import org.osgi.service.coordinator.Coordinator;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+import org.osgi.service.repository.Repository;
+import org.osgi.service.resolver.Environment;
+import org.osgi.service.resolver.ResolutionException;
+import org.osgi.service.resolver.Resolver;
+import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.SubsystemException;
 import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * The bundle activator for the this bundle.
- * When the bundle is starting, this activator will create
- * and register the SubsystemAdmin service.
+ * The bundle activator for the this bundle. When the bundle is starting, this
+ * activator will create and register the SubsystemAdmin service.
  */
 public class Activator implements BundleActivator {
-    private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
-    
-    static Coordinator getCoordinator() {
-    	return context.getService(context.getServiceReference(Coordinator.class));
-    }
-    
-    private static BundleContext context;
-    private List<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>();
-    private static SubsystemEventDispatcher eventDispatcher;
-    
-    private ServiceTracker scopeServiceTracker;
-    
-    public void start(final BundleContext context) throws Exception {
-        if (LOGGER.isDebugEnabled()) {
-            LOGGER.debug("subsystem activator starting");
-        }
-        Activator.context = context;
-        Activator.eventDispatcher = new SubsystemEventDispatcher(context);   
-        register(ResourceResolver.class,
-                 new NoOpResolver(),
-                 DictionaryBuilder.build(Constants.SERVICE_RANKING, Integer.MIN_VALUE));
-        register(ResourceResolver.class,
-                new ResourceResolverImpl(context),
-                DictionaryBuilder.build(Constants.SERVICE_RANKING, 0));
-        register(ResourceProcessor.class,
-                new BundleResourceProcessor(context),
-                DictionaryBuilder.build(SubsystemConstants.SERVICE_RESOURCE_TYPE, SubsystemConstants.RESOURCE_TYPE_BUNDLE));
-        register(ResourceProcessor.class,
-                new SubsystemResourceProcessor(context),
-                DictionaryBuilder.build(SubsystemConstants.SERVICE_RESOURCE_TYPE, SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM));
-        scopeServiceTracker = new ServiceTracker(
-        		context,
-        		RegionDigraph.class.getName(),
-        		new ServiceTrackerCustomizer() {
-        			private ServiceReference<?> scopeRef;
-        			private ServiceRegistration<?> subsystemReg;
-        			
-					public synchronized Object addingService(ServiceReference reference) {
-						if (subsystemReg != null) return null;
-						RegionDigraph digraph = (RegionDigraph)context.getService(reference);
-						if (digraph == null) return null;
-						subsystemReg = context.registerService(Subsystem.class.getName(), new SubsystemServiceFactory(digraph.getRegion(context.getBundle())),
null);
-						return digraph;
-					}
-
-					public void modifiedService(ServiceReference reference, Object service) {
-						// Do nothing.
-					}
-
-					public synchronized void removedService(ServiceReference reference, Object service)
{
-						if (reference != scopeRef) return;
-						subsystemReg.unregister();
-						subsystemReg = null;
-						// TODO Look for another service?
-					}
-        		});
-        scopeServiceTracker.open();
-    }
-
-    protected <T> void register(Class<T> clazz, T service, Dictionary props)
{
-         registrations.add(context.registerService(clazz.getName(), service, props));
-    }
-
-    protected <T> void register(Class<T> clazz, ServiceFactory factory, Dictionary
props) {
-         registrations.add(context.registerService(clazz.getName(), factory, props));
-    }
-
-    public void stop(BundleContext context) throws Exception {
-        if (LOGGER.isDebugEnabled()) {
-            LOGGER.debug("subsystem activator stopping");
-        }
-        scopeServiceTracker.close();
-        for (ServiceRegistration<?> r : registrations) {
-            try {
-                r.unregister();
-            } catch (Exception e) {
-                LOGGER.warn("Subsystem Activator shut down", e);
-            }
-        }
-        eventDispatcher.destroy();
-    }
-    
-    public static BundleContext getBundleContext() {
-        return context;
-    }
-    
-    public static SubsystemEventDispatcher getEventDispatcher() {
-        return eventDispatcher;
-    }
+	private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
+	private static BundleContext context;
+	private static SubsystemManager subsystemManager = new SubsystemManager();
+	
+	public static BundleContext getBundleContext() {
+		return context;
+	}
+	
+	public static Coordinator getCoordinator() {
+		return context.getService(context.getServiceReference(Coordinator.class));
+	}
+	
+	public static EventAdmin getEventAdmin() {
+		ServiceReference<EventAdmin> ref = context.getServiceReference(EventAdmin.class);
+		if (ref == null) return null;
+		return context.getService(ref);
+	}
+	
+	public static Executor getExecutor() {
+		return context.getService(context.getServiceReference(Executor.class));
+	}
+	
+	public static FrameworkWiring getFrameworkWiring() {
+		return context.getBundle(0).adapt(FrameworkWiring.class);
+	}
+	
+	public static RegionDigraph getRegionDigraph() {
+		return context.getService(context.getServiceReference(RegionDigraph.class));
+	}
+	
+	public static Collection<Repository> getRepositories() {
+		Collection<ServiceReference<Repository>> references;
+		try {
+			references = context.getServiceReferences(Repository.class, null);
+		}
+		catch (InvalidSyntaxException e) {
+			// This should never happen, but I don't want to cover it up. Nor do I want to force clients
to handle it.
+			throw new RuntimeException(e);
+		}
+		ArrayList<Repository> repositories = new ArrayList<Repository>(references.size());
+		for (ServiceReference<Repository> reference : references) {
+			Repository repository = context.getService(reference);
+			if (repository != null)
+				repositories.add(repository);
+		}
+		repositories.trimToSize();
+		return repositories;
+	}
+	
+	public static RepositoryAdmin getRepositoryAdmin() {
+		ServiceTracker st = new ServiceTracker(context, RepositoryAdmin.class.getName(), null);
+		try {
+			st.open();
+			return (RepositoryAdmin)st.waitForService(5000);
+		}
+		catch (InterruptedException e) {
+			Thread.currentThread().interrupt();
+			return null;
+		}
+		finally {
+			st.close();
+		}
+	}
+	
+	/*
+	 * TODO
+	 * A naive implementation serving as a placeholder until a real Resolver comes along.
+	 */
+	public static Resolver getResolver() {
+		return new Resolver() {
+			@Override
+			public Map<Resource, List<Wire>> resolve(Environment environment, Requirement...
requirements) throws ResolutionException {
+				Collection<Capability> capabilities = new ArrayList<Capability>();
+				for (Requirement requirement : requirements)
+					capabilities.addAll(environment.findProviders(requirement));
+				List<Resource> resources = new ArrayList<Resource>(capabilities.size());
+				for (Capability capability : capabilities)
+					resources.add(capability.getResource());
+				org.apache.felix.bundlerepository.Resolver resolver = getRepositoryAdmin().resolver();
+		        for (Resource resource : resources)
+		            resolver.add(new OsgiResourceAdapter(resource));
+		        if (resolver.resolve()) {
+		        	for (org.apache.felix.bundlerepository.Resource resource : resolver.getRequiredResources())
+		            	resources.add(new FelixResourceAdapter(resource));
+		        	for (org.apache.felix.bundlerepository.Resource resource : resolver.getOptionalResources())
+		        		resources.add(new FelixResourceAdapter(resource));
+		        }
+		        else {
+		            Reason[] reasons = resolver.getUnsatisfiedRequirements();
+		            StringBuilder builder = new StringBuilder("Failed to resolve subsystem").append(System.getProperty("line.separator"));
+		            for (Reason reason : reasons)
+		                builder
+		                	.append("resource = ")
+		                	.append(reason.getResource().getSymbolicName())
+		                	.append(", requirement = ")
+		                	.append(reason.getRequirement().getName())
+		                	.append(System.getProperty("line.separator"));
+		            throw new SubsystemException(builder.toString());
+		        }
+		        Map<Resource, List<Wire>> result = new HashMap<Resource, List<Wire>>(resources.size());
+				for (Resource resource : resources)
+					result.put(resource, Collections.EMPTY_LIST);
+				return result;
+			}
+		};
+	}
+	
+	public static SubsystemManager getSubsystemManager() {
+		return subsystemManager;
+	}
+	
+	private final BundleListener bundleListener = new SubsystemSynchronousBundleListener();
+	private final List<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
+	
+	public void start(final BundleContext context) throws Exception {
+		if (LOGGER.isDebugEnabled()) {
+			LOGGER.debug("subsystem activator starting");
+		}
+		Activator.context = context;
+		register(Subsystem.class.getName(), new SubsystemServiceFactory(), null);
+		register(ResolverHookFactory.class, new SubsystemResolverHookFactory(), null);
+		context.getBundle(0).getBundleContext().addBundleListener(bundleListener);
+		Dictionary<String, Object> properties = new Hashtable<String, Object>();
+		properties.put(EventConstants.EVENT_TOPIC, new String[]{"org/osgi/framework/BundleEvent/*"});
+		register(EventHandler.class, new BundleEventHandler(), properties);
+	}
+
+	public void stop(BundleContext context) throws Exception {
+		if (LOGGER.isDebugEnabled()) {
+			LOGGER.debug("subsystem activator stopping");
+		}
+		context.getBundle(0).getBundleContext().removeBundleListener(bundleListener);
+		for (ServiceRegistration<?> r : registrations) {
+			try {
+				r.unregister();
+			} catch (Exception e) {
+				LOGGER.warn("Subsystem Activator shut down", e);
+			}
+		}
+	}
+
+	private <T> void register(Class<T> clazz, T service, Dictionary<String, ?>
props) {
+		registrations.add(context.registerService(clazz.getName(), service, props));
+	}
+	
+	private <T> void register(String clazz, T service, Dictionary<String, ?> props)
{
+		registrations.add(context.registerService(clazz, service, props));
+	}
 }

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceResolverImpl.java?rev=1157844&r1=1157843&r2=1157844&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceResolverImpl.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceResolverImpl.java
Mon Aug 15 13:42:57 2011
@@ -11,12 +11,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.aries.subsystem.core.internal;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -29,21 +30,26 @@ import javax.xml.transform.stream.Stream
 
 import org.apache.aries.application.Content;
 import org.apache.aries.application.management.BundleInfo;
-import org.apache.aries.subsystem.SubsystemConstants;
-import org.apache.aries.subsystem.SubsystemException;
+import org.apache.aries.subsystem.core.BundleInfoImpl;
+import org.apache.aries.subsystem.core.ContentImpl;
+import org.apache.aries.subsystem.core.Manve2Repository;
+import org.apache.aries.subsystem.core.RepositoryDescriptorGenerator;
 import org.apache.aries.subsystem.core.ResourceResolver;
-import org.apache.aries.subsystem.core.obr.BundleInfoImpl;
-import org.apache.aries.subsystem.core.obr.ContentImpl;
-import org.apache.aries.subsystem.core.obr.Manve2Repository;
-import org.apache.aries.subsystem.core.obr.RepositoryDescriptorGenerator;
-import org.apache.aries.subsystem.spi.Resource;
+import org.apache.aries.subsystem.core.obr.felix.FelixResourceAdapter;
+import org.apache.aries.subsystem.core.obr.felix.OsgiResourceAdapter;
+import org.apache.felix.bundlerepository.Capability;
+import org.apache.felix.bundlerepository.Property;
 import org.apache.felix.bundlerepository.Reason;
 import org.apache.felix.bundlerepository.Repository;
 import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.apache.felix.bundlerepository.Requirement;
 import org.apache.felix.bundlerepository.Resolver;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.Version;
+import org.osgi.framework.wiring.Resource;
+import org.osgi.service.subsystem.SubsystemConstants;
+import org.osgi.service.subsystem.SubsystemException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -177,12 +183,14 @@ public class ResourceResolverImpl implem
                 if (resources[i].getSymbolicName().equals(symbolicName)) {
                     if (resources[i].getVersion().compareTo(new Version(version)) == 0) {
                         res = resources[i];
+                        break;
                     }
                 }
             }
         }
         if (res == null) {
-            throw new SubsystemException("unable to find the resource " + resource);
+//            throw new SubsystemException("unable to find the resource " + resource);
+        	return null;
         }
         
         Map props = res.getProperties();
@@ -190,16 +198,16 @@ public class ResourceResolverImpl implem
 
         Object type = props.get(SubsystemConstants.RESOURCE_TYPE_ATTRIBUTE);
 
-        return new ResourceImpl(symbolicName, res.getVersion(), type == null ? SubsystemConstants.RESOURCE_TYPE_BUNDLE
: (String)type, res.getURI() , props);
+        return new FelixResourceAdapter(res);
     }
     
     /**
      * the format of resource is like bundlesymbolicname;version=1.0.0, for example com.ibm.ws.eba.example.blog.api;version=1.0.0,
      */
     private org.apache.felix.bundlerepository.Resource findOBRResource(Resource resource)
throws SubsystemException {
-        String symbolicName = String.valueOf(resource.getAttributes().get(Resource.SYMBOLIC_NAME_ATTRIBUTE));
+        String symbolicName = ResourceHelper.getSymbolicNameAttribute(resource);
         // this version could possibly be a range
-        Version version = (Version)resource.getAttributes().get(Resource.VERSION_ATTRIBUTE);
+        Version version = ResourceHelper.getVersionAttribute(resource);
 
         //org.apache.felix.bundlerepository.Resource[] res = this.repositoryAdmin.discoverResources(filterString.toString());
         Repository[] repos = this.repositoryAdmin.listRepositories();
@@ -230,7 +238,7 @@ public class ResourceResolverImpl implem
 
         Object type = props.get(SubsystemConstants.RESOURCE_TYPE_ATTRIBUTE);
 
-        return new ResourceImpl(resource.getSymbolicName(), resource.getVersion(), type ==
null ? SubsystemConstants.RESOURCE_TYPE_BUNDLE : (String)type, resource.getURI() , props);
+        return new FelixResourceAdapter(resource);
     }
     
     public List<Resource> resolve(List<Resource> subsystemContent,
@@ -243,38 +251,116 @@ public class ResourceResolverImpl implem
         
         // add subsystem content to the resolver
         for (Resource res : subsystemContent) {
-            org.apache.felix.bundlerepository.Resource obrRes = findOBRResource(res);
-            obrResolver.add(obrRes);
+//            org.apache.felix.bundlerepository.Resource obrRes = findOBRResource(res);
+//            obrResolver.add(obrRes);
+            obrResolver.add(new OsgiResourceAdapter(res));
         }
         
         // add subsystem resource to the resolver
         for (Resource res : subsystemResources) {
-            org.apache.felix.bundlerepository.Resource obrRes = findOBRResource(res);
-            obrResolver.add(obrRes);
+//            org.apache.felix.bundlerepository.Resource obrRes = findOBRResource(res);
+//            obrResolver.add(obrRes);
+        	obrResolver.add(new OsgiResourceAdapter(res));
         }
         
         // Question: do we need to create the repository.xml for the subsystem and add the
repo to RepoAdmin?
         List<Resource> resources = new ArrayList<Resource>();
         if (obrResolver.resolve()) {
             for (org.apache.felix.bundlerepository.Resource res : obrResolver.getRequiredResources())
{
-                resources.add(toResource(res));
+//                resources.add(toResource(res));
+            	resources.add(new FelixResourceAdapter(res));
             }
             
             // Question: should we handle optional resource differently?
             for (org.apache.felix.bundlerepository.Resource res : obrResolver.getOptionalResources())
{
-                resources.add(toResource(res));
+//                resources.add(toResource(res));
+            	resources.add(new FelixResourceAdapter(res));
             }
         } else {
             // log the unsatisfied requirement
             Reason[] reasons = obrResolver.getUnsatisfiedRequirements();
+            StringBuilder builder = new StringBuilder("Failed to resolve subsystem").append(System.getProperty("line.separator"));
             for (Reason reason : reasons) {
                 LOGGER.warn("Unable to resolve subsystem content {} subsystem resource {}
because of unsatisfied requirement {}", 
                         new Object[] {subsystemContent.toString(), subsystemResources.toString(),
reason.getRequirement().getName()});
+                builder
+                	.append("resource = ")
+                	.append(reason.getResource().getSymbolicName())
+                	.append(", requirement = ")
+                	.append(reason.getRequirement().getName())
+                	.append(System.getProperty("line.separator"));
             }
-
+            throw new SubsystemException(builder.toString());
         }
-        
         return resources;
     }
+    
+    private org.apache.felix.bundlerepository.Resource convert(final Resource resource) {
+    	return new org.apache.felix.bundlerepository.Resource() {
+			public Capability[] getCapabilities() {
+				Collection<Capability> result = new ArrayList<Capability>(resource.getCapabilities(null).size());
+				for (org.osgi.framework.wiring.Capability capability : resource.getCapabilities(null))
{
+					result.add(new Capability() {
+						public String getName() {
+							// TODO Auto-generated method stub
+							return null;
+						}
+
+						public Property[] getProperties() {
+							// TODO Auto-generated method stub
+							return null;
+						}
+
+						public Map getPropertiesAsMap() {
+							// TODO Auto-generated method stub
+							return null;
+						}
+					});
+				}
+				return null;
+			}
+
+			public String[] getCategories() {
+				return new String[0];
+			}
+
+			public String getId() {
+				return getSymbolicName() + ";version=" + getVersion();
+			}
+
+			public String getPresentationName() {
+				return getSymbolicName();
+			}
+
+			public Map getProperties() {
+				return Collections.EMPTY_MAP;
+			}
+
+			public Requirement[] getRequirements() {
+				// TODO Auto-generated method stub
+				return null;
+			}
+
+			public Long getSize() {
+				return 0L;
+			}
+
+			public String getSymbolicName() {
+				return ResourceHelper.getSymbolicNameAttribute(resource);
+			}
+
+			public String getURI() {
+				return ResourceHelper.getContentAttribute(resource);
+			}
+
+			public Version getVersion() {
+				return ResourceHelper.getVersionAttribute(resource);
+			}
+
+			public boolean isLocal() {
+				return false;
+			}
+    	};
+    }
 
 }

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceFactory.java?rev=1157844&r1=1157843&r2=1157844&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceFactory.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceFactory.java
Mon Aug 15 13:42:57 2011
@@ -1,32 +1,53 @@
-package org.apache.aries.subsystem.core.internal;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.aries.subsystem.Subsystem;
-import org.eclipse.equinox.region.Region;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceRegistration;
-
-public class SubsystemServiceFactory implements ServiceFactory<Subsystem> {
-	private final Map<Bundle, Subsystem> bundlesToSubsystems = new HashMap<Bundle,
Subsystem>();
-	private final Subsystem rootSubsystem;
-	
-	public SubsystemServiceFactory(Region region) {
-		rootSubsystem = new RootSubsystem(region);
-	}
-	
-	public Subsystem getService(Bundle bundle, ServiceRegistration<Subsystem> registration)
{
-		Subsystem result = bundlesToSubsystems.get(bundle);
-		if (result == null) {
-			result = rootSubsystem;
-			bundlesToSubsystems.put(bundle, result);
-		}
-		return result;
-	}
-
-	public void ungetService(Bundle bundle, ServiceRegistration<Subsystem> registration,
Subsystem service) {
-		bundlesToSubsystems.remove(bundle);
-	}
-}
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.subsystem.core.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.equinox.region.Region;
+import org.eclipse.equinox.region.RegionDigraph;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.subsystem.Subsystem;
+
+public class SubsystemServiceFactory implements ServiceFactory<Subsystem> {
+	private final Map<Region, Subsystem> regionsToSubsystems = new HashMap<Region,
Subsystem>();
+	
+	private final AriesSubsystem rootSubsystem;
+	
+	public SubsystemServiceFactory() throws Exception {
+		rootSubsystem = new AriesSubsystem();
+		Region region = Activator.getRegionDigraph().getRegion(Activator.getBundleContext().getBundle());
+		regionsToSubsystems.put(region, rootSubsystem);
+	}
+	
+	public Subsystem getService(Bundle bundle, ServiceRegistration<Subsystem> registration)
{
+		RegionDigraph digraph = Activator.getRegionDigraph();
+		Region region = digraph.getRegion(bundle);
+		Subsystem subsystem = regionsToSubsystems.get(region);
+		if (subsystem == null) {
+			subsystem = rootSubsystem;
+			regionsToSubsystems.put(region, subsystem);
+		}
+		return subsystem;
+	}
+
+	public void ungetService(Bundle bundle, ServiceRegistration<Subsystem> registration,
Subsystem service) {
+		RegionDigraph digraph = Activator.getRegionDigraph();
+		Region region = digraph.getRegion(bundle);
+		regionsToSubsystems.remove(region);
+	}
+}

Modified: aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/ResourceResolverTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/ResourceResolverTest.java?rev=1157844&r1=1157843&r2=1157844&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/ResourceResolverTest.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/ResourceResolverTest.java
Mon Aug 15 13:42:57 2011
@@ -20,10 +20,10 @@ import java.io.File;
 import org.apache.aries.mocks.BundleContextMock;
 import org.apache.aries.subsystem.core.internal.ResourceResolverImpl;
 import org.apache.aries.unittest.mocks.Skeleton;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
 import org.junit.Before;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
-import org.apache.felix.bundlerepository.RepositoryAdmin;
 
 public class ResourceResolverTest {
 



Mime
View raw message