You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gn...@apache.org on 2010/04/15 14:26:58 UTC
svn commit: r934386 - in /incubator/aries/trunk/subsystem: ./ subsystem-obr/
subsystem-obr/src/ subsystem-obr/src/main/ subsystem-obr/src/main/java/
subsystem-obr/src/main/java/org/ subsystem-obr/src/main/java/org/apache/
subsystem-obr/src/main/java/or...
Author: gnodet
Date: Thu Apr 15 12:26:57 2010
New Revision: 934386
URL: http://svn.apache.org/viewvc?rev=934386&view=rev
Log:
ARIES-283: check in another possible way to use obr from subsystems
Added:
incubator/aries/trunk/subsystem/subsystem-obr/
incubator/aries/trunk/subsystem/subsystem-obr/pom.xml
incubator/aries/trunk/subsystem/subsystem-obr/src/
incubator/aries/trunk/subsystem/subsystem-obr/src/main/
incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/
incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/
incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/
incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/
incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/
incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/
incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/
incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/Activator.java
incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceImpl.java
incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceResolver.java
incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceImpl.java
Modified:
incubator/aries/trunk/subsystem/pom.xml
Modified: incubator/aries/trunk/subsystem/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/subsystem/pom.xml?rev=934386&r1=934385&r2=934386&view=diff
==============================================================================
--- incubator/aries/trunk/subsystem/pom.xml (original)
+++ incubator/aries/trunk/subsystem/pom.xml Thu Apr 15 12:26:57 2010
@@ -104,7 +104,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.bundlerepository</artifactId>
- <version>1.4.3</version>
+ <version>1.6.1-SNAPSHOT</version>
</dependency>
@@ -114,6 +114,7 @@
<modules>
<module>subsystem-api</module>
<module>subsystem-core</module>
+ <module>subsystem-obr</module>
<module>subsystem-install</module>
<module>subsystem-itests</module>
</modules>
Added: incubator/aries/trunk/subsystem/subsystem-obr/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/subsystem/subsystem-obr/pom.xml?rev=934386&view=auto
==============================================================================
--- incubator/aries/trunk/subsystem/subsystem-obr/pom.xml (added)
+++ incubator/aries/trunk/subsystem/subsystem-obr/pom.xml Thu Apr 15 12:26:57 2010
@@ -0,0 +1,79 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.aries.subsystem</groupId>
+ <artifactId>subsystem</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>org.apache.aries.subsystem.obr</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Aries Subsystem OBR</name>
+ <description>
+ Subsystems OBR support.
+ </description>
+
+ <properties>
+ <aries.osgi.activator>
+ org.apache.aries.subsystem.obr.internal.Activator
+ </aries.osgi.activator>
+ <aries.osgi.private.pkg>
+ org.apache.aries.subsystem.obr.internal
+ </aries.osgi.private.pkg>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.subsystem</groupId>
+ <artifactId>org.apache.aries.subsystem.api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.bundlerepository</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/Activator.java?rev=934386&view=auto
==============================================================================
--- incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/Activator.java (added)
+++ incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/Activator.java Thu Apr 15 12:26:57 2010
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 WARRANTIESOR 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.obr.internal;
+
+import org.apache.aries.subsystem.spi.ResourceResolver;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class Activator implements BundleActivator {
+
+ private BundleContext bundleContext;
+ private ServiceRegistration registration;
+ private ServiceTracker repositoryAdminTracker;
+
+ public void start(BundleContext context) throws Exception {
+ bundleContext = context;
+ repositoryAdminTracker = new ServiceTracker(bundleContext,
+ RepositoryAdmin.class.getName(),
+ null) {
+ public Object addingService(ServiceReference reference) {
+ registration = bundleContext.registerService(ResourceResolver.class.getName(),
+ new ObrResourceResolver(repositoryAdminTracker),
+ null);
+ return super.addingService(reference);
+ }
+ };
+ repositoryAdminTracker.open();
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ registration.unregister();
+ repositoryAdminTracker.close();
+ }
+}
Added: incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceImpl.java?rev=934386&view=auto
==============================================================================
--- incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceImpl.java (added)
+++ incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceImpl.java Thu Apr 15 12:26:57 2010
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 WARRANTIESOR 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.obr.internal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Map;
+
+import org.apache.aries.subsystem.spi.Resource;
+import org.osgi.framework.Version;
+
+public class ObrResourceImpl implements Resource {
+
+ private final org.apache.felix.bundlerepository.Resource resource;
+ private final String type;
+ private final Map<String,String> attributes;
+
+ public ObrResourceImpl(org.apache.felix.bundlerepository.Resource resource, String type, Map<String,String> attributes) {
+ this.resource = resource;
+ this.type = type;
+ this.attributes = attributes;
+ }
+
+ public String getSymbolicName() {
+ return resource.getSymbolicName();
+ }
+
+ public Version getVersion() {
+ return resource.getVersion();
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getLocation() {
+ return resource.getURI();
+ }
+
+ public Map<String, String> getAttributes() {
+ return attributes;
+ }
+
+ public InputStream open() throws IOException {
+ return new URL(getLocation()).openStream();
+ }
+}
Added: incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceResolver.java?rev=934386&view=auto
==============================================================================
--- incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceResolver.java (added)
+++ incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceResolver.java Thu Apr 15 12:26:57 2010
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 WARRANTIESOR 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.obr.internal;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.aries.subsystem.SubsystemConstants;
+import org.apache.aries.subsystem.SubsystemException;
+import org.apache.aries.subsystem.spi.Resource;
+import org.apache.aries.subsystem.spi.ResourceResolver;
+import org.apache.felix.bundlerepository.Capability;
+import org.apache.felix.bundlerepository.Repository;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.apache.felix.bundlerepository.Resolver;
+import org.apache.felix.utils.manifest.Attribute;
+import org.apache.felix.utils.manifest.Clause;
+import org.apache.felix.utils.manifest.Parser;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.Version;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class ObrResourceResolver implements ResourceResolver
+{
+
+ private static final long TIMEOUT = 30000L;
+
+ private final ServiceTracker repositoryAdminTracker;
+
+ public ObrResourceResolver(ServiceTracker repositoryAdminTracker)
+ {
+ this.repositoryAdminTracker = repositoryAdminTracker;
+ }
+
+ protected RepositoryAdmin getRepositoryAdmin()
+ {
+ try {
+ RepositoryAdmin admin = (RepositoryAdmin) repositoryAdminTracker.waitForService(TIMEOUT);
+ if (admin == null) {
+ throw new SubsystemException("RepositoryAdmin service not available");
+ }
+ return admin;
+ } catch (InterruptedException e) {
+ throw new SubsystemException("RepositoryAdmin service not available", e);
+ }
+ }
+
+ public Resource find(String resource) throws SubsystemException {
+ Clause[] clauses = Parser.parseHeader(resource);
+ if (clauses.length != 1) {
+ throw new SubsystemException("Unsupported resource: " + resource);
+ }
+
+ String bsn = clauses[0].getName();
+ String ver = clauses[0].getAttribute(Constants.VERSION_ATTRIBUTE);
+ String typ = clauses[0].getAttribute(SubsystemConstants.RESOURCE_TYPE_ATTRIBUTE);
+ String loc = clauses[0].getAttribute(SubsystemConstants.RESOURCE_LOCATION_ATTRIBUTE);
+ Map<String,String> attributes = new HashMap<String,String>();
+ for (Attribute a : clauses[0].getAttributes()) {
+ String name = a.getName();
+ if (!Constants.VERSION_ATTRIBUTE.equals(name)
+ && !SubsystemConstants.RESOURCE_TYPE_ATTRIBUTE.equals(name)
+ && !SubsystemConstants.RESOURCE_LOCATION_ATTRIBUTE.equals(name))
+ {
+ attributes.put(name, a.getValue());
+ }
+ }
+ if (loc != null) {
+ return new ResourceImpl(
+ bsn,
+ ver != null ? new Version(ver) : Version.emptyVersion,
+ typ != null ? typ : SubsystemConstants.RESOURCE_TYPE_BUNDLE,
+ loc,
+ attributes
+ );
+ } else {
+ try {
+ RepositoryAdmin repo = getRepositoryAdmin();
+ org.apache.felix.bundlerepository.Resource[] resources =
+ repo.discoverResources("(&(symbolicname=" + bsn + ")" + (ver != null ? "(version=" + ver + ")" : "") + ")");
+ if (resources.length == 0) {
+ throw new SubsystemException("Unable to find a matching resource: " + resource);
+ }
+ return new ObrResourceImpl(resources[0],
+ typ != null ? typ : SubsystemConstants.RESOURCE_TYPE_BUNDLE,
+ attributes);
+ } catch (InvalidSyntaxException e) {
+ throw new SubsystemException("Invalid resource definition: " + resource, e);
+ }
+ }
+ }
+
+ public List<Resource> resolve(List<Resource> subsystemContent, List<Resource> subsystemResources) throws SubsystemException {
+ RepositoryAdmin admin = getRepositoryAdmin();
+ List<org.apache.felix.bundlerepository.Resource> obrResources = new ArrayList<org.apache.felix.bundlerepository.Resource>();
+ for (Resource res : subsystemResources)
+ {
+ if (res.getType().equals(SubsystemConstants.RESOURCE_TYPE_BUNDLE)) {
+ try
+ {
+ obrResources.add(admin.getHelper().createResource(new URL(res.getLocation())));
+ }
+ catch (Exception e) {
+ // TODO: log exception
+ }
+ }
+ }
+ Repository repository = admin.getHelper().repository(obrResources.toArray(new org.apache.felix.bundlerepository.Resource[obrResources.size()]));
+ List<Repository> repos = new ArrayList<Repository>();
+ repos.add(admin.getSystemRepository());
+ repos.add(admin.getLocalRepository());
+ repos.add(repository);
+ repos.addAll(Arrays.asList(admin.listRepositories()));
+ Resolver resolver = admin.resolver(repos.toArray(new Repository[repos.size()]));
+
+ for (Resource res : subsystemContent)
+ {
+ if (res.getType().equals(SubsystemConstants.RESOURCE_TYPE_BUNDLE)) {
+ resolver.add(admin.getHelper().requirement(Capability.BUNDLE, "(&(symbolicname=" + res.getSymbolicName() + ")" + (res.getVersion() != null ? "(version=" + res.getVersion() + ")" : "") + ")"));
+ }
+ }
+ if (!resolver.resolve(Resolver.NO_OPTIONAL_RESOURCES)) {
+ throw new SubsystemException("Can not resolve subsystem");
+ }
+
+ List<Resource> resolved = new ArrayList<Resource>();
+ for (org.apache.felix.bundlerepository.Resource res : resolver.getRequiredResources()) {
+ resolved.add(new ObrResourceImpl(res, SubsystemConstants.RESOURCE_TYPE_BUNDLE, new HashMap<String,String>()));
+ }
+ return resolved;
+ }
+
+}
Added: incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceImpl.java?rev=934386&view=auto
==============================================================================
--- incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceImpl.java (added)
+++ incubator/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceImpl.java Thu Apr 15 12:26:57 2010
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 WARRANTIESOR 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.obr.internal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Map;
+
+import org.apache.aries.subsystem.spi.Resource;
+import org.osgi.framework.Version;
+
+public class ResourceImpl implements Resource {
+
+ private final String symbolicName;
+ private final Version version;
+ private final String type;
+ private final String location;
+ private final Map<String,String> attributes;
+
+ public ResourceImpl(String symbolicName, Version version, String type, String location, Map<String,String> attributes) {
+ this.symbolicName = symbolicName;
+ this.version = version;
+ this.type = type;
+ this.location = location;
+ this.attributes = attributes;
+ }
+
+ public String getSymbolicName() {
+ return symbolicName;
+ }
+
+ public Version getVersion() {
+ return version;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public Map<String, String> getAttributes() {
+ return attributes;
+ }
+
+ public InputStream open() throws IOException {
+ return new URL(getLocation()).openStream();
+ }
+
+}