felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1564308 - in /felix/trunk: ./ bundlerepository.osgi-ct/ bundlerepository.osgi-ct/src/ bundlerepository.osgi-ct/src/main/ bundlerepository.osgi-ct/src/main/java/ bundlerepository.osgi-ct/src/main/java/org/ bundlerepository.osgi-ct/src/main/...
Date Tue, 04 Feb 2014 14:13:45 GMT
Author: davidb
Date: Tue Feb  4 14:13:44 2014
New Revision: 1564308

URL: http://svn.apache.org/r1564308
Log:
[FELIX-4371] Integration bundle needed to work with the OSGi Repository CT

Added:
    felix/trunk/bundlerepository.osgi-ct/
    felix/trunk/bundlerepository.osgi-ct/pom.xml
    felix/trunk/bundlerepository.osgi-ct/src/
    felix/trunk/bundlerepository.osgi-ct/src/main/
    felix/trunk/bundlerepository.osgi-ct/src/main/java/
    felix/trunk/bundlerepository.osgi-ct/src/main/java/org/
    felix/trunk/bundlerepository.osgi-ct/src/main/java/org/apache/
    felix/trunk/bundlerepository.osgi-ct/src/main/java/org/apache/felix/
    felix/trunk/bundlerepository.osgi-ct/src/main/java/org/apache/felix/bundlerepository/
    felix/trunk/bundlerepository.osgi-ct/src/main/java/org/apache/felix/bundlerepository/osgict/
    felix/trunk/bundlerepository.osgi-ct/src/main/java/org/apache/felix/bundlerepository/osgict/Activator.java
Modified:
    felix/trunk/pom.xml

Added: felix/trunk/bundlerepository.osgi-ct/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository.osgi-ct/pom.xml?rev=1564308&view=auto
==============================================================================
--- felix/trunk/bundlerepository.osgi-ct/pom.xml (added)
+++ felix/trunk/bundlerepository.osgi-ct/pom.xml Tue Feb  4 14:13:44 2014
@@ -0,0 +1,101 @@
+<!--
+ 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">
+  <parent>
+    <groupId>org.apache.felix</groupId>
+    <artifactId>felix-parent</artifactId>
+    <version>2.1</version>
+    <relativePath>../../pom/pom.xml</relativePath>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <name>Apache Felix Bundle Repository - OSGi CT integration</name>
+  <description>
+    Bundle repository service OSGi CT integration. To run a Repository implementation in
the 
+    OSGi CT, a small integration layer needs to be provided by the implementation that knows
+    how to prime the repository with the provided repository xml file.
+  </description>
+  <artifactId>org.apache.felix.bundlerepository.osgi-ct</artifactId>
+  <version>1.7.0-SNAPSHOT</version>
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/felix/trunk/bundlerepository.osgi-ct</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/felix/trunk/bundlerepository.osgi-ct</developerConnection>
+    <url>http://svn.apache.org/repos/asf/felix/trunk/bundlerepository.osgi-ct</url>
+  </scm>
+  <dependencies>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>5.0.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <version>5.0.0</version>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>org.apache.felix.bundlerepository</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <target>1.5</target>
+          <source>1.5</source>
+        </configuration>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>2.3.4</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Export-Package></Export-Package>
+            <Private-Package>org.apache.felix.bundlerepository.osgict</Private-Package>
+            <Bundle-Activator>org.apache.felix.bundlerepository.osgict.Activator</Bundle-Activator>
+            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+            <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
+          </instructions>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.rat</groupId>
+        <artifactId>apache-rat-plugin</artifactId>
+        <configuration>
+          <excludeSubProjects>false</excludeSubProjects>
+          <useEclipseDefaultExcludes>true</useEclipseDefaultExcludes>
+          <useMavenDefaultExcludes>true</useMavenDefaultExcludes>
+          <excludes>
+            <param>doc/*</param>
+            <param>maven-eclipse.xml</param>
+            <param>.checkstyle</param>
+            <param>.externalToolBuilders/*</param>
+          </excludes>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: felix/trunk/bundlerepository.osgi-ct/src/main/java/org/apache/felix/bundlerepository/osgict/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository.osgi-ct/src/main/java/org/apache/felix/bundlerepository/osgict/Activator.java?rev=1564308&view=auto
==============================================================================
--- felix/trunk/bundlerepository.osgi-ct/src/main/java/org/apache/felix/bundlerepository/osgict/Activator.java
(added)
+++ felix/trunk/bundlerepository.osgi-ct/src/main/java/org/apache/felix/bundlerepository/osgict/Activator.java
Tue Feb  4 14:13:44 2014
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+package org.apache.felix.bundlerepository.osgict;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * This Activator implements the required glue between an OSGi Repository implementation
and the
+ * OSGi CT. It is needed to prime the repository with the data needed by the CT and works
as
+ * follows:
+ * <ul>
+ * <li>The CT registers a String service with as property {@code repository-xml}. This
service is
+ * literally the repository XML needed by the test, and must be fed to the repository implementation.
+ * <li>When that's done this glue code registers another service with as property
+ * {@code repository-populated} to signal to the CT that the priming is done.
+ * </ul>
+ */
+public class Activator implements BundleActivator
+{
+    private BundleContext bundleContext;
+    private ServiceTracker<String, String> repoXMLTracker;
+    private ServiceTracker<RepositoryAdmin, RepositoryAdmin> repoTracker;
+
+    public void start(BundleContext context) throws Exception
+    {
+        bundleContext = context;
+        Filter f = context.createFilter("(&(objectClass=java.lang.String)(repository-xml=*))");
+        repoXMLTracker = new ServiceTracker<String, String>(context, f, null) {
+            @Override
+            public String addingService(ServiceReference<String> reference)
+            {
+                try
+                {
+                    String xml = super.addingService(reference);
+                    handleRepositoryXML(reference, xml);
+                    return xml;
+                }
+                catch (Exception e)
+                {
+                    throw new RuntimeException(e);
+                }
+            }
+        };
+        repoXMLTracker.open();
+    }
+
+    public void stop(BundleContext context) throws Exception
+    {
+        repoXMLTracker.close();
+        if (repoTracker != null)
+            repoTracker.close();
+    }
+
+    private void handleRepositoryXML(ServiceReference<String> reference, String xml)
throws Exception
+    {
+        File tempXMLFile = bundleContext.getDataFile("repo-" + reference.getProperty("repository-xml")
+ ".xml");
+        writeXMLToFile(tempXMLFile, xml);
+
+        repoTracker = new ServiceTracker<RepositoryAdmin, RepositoryAdmin>(bundleContext,
RepositoryAdmin.class, null);
+        repoTracker.open();
+        RepositoryAdmin repo = repoTracker.waitForService(30000);
+        repo.addRepository(tempXMLFile.toURI().toURL());
+        tempXMLFile.delete();
+
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("repository-populated", reference.getProperty("repository-xml"));
+        bundleContext.registerService(String.class, "", props);
+    }
+
+    private void writeXMLToFile(File tempXMLFile, String xml) throws IOException
+    {
+        FileOutputStream fos = new FileOutputStream(tempXMLFile);
+        try
+        {
+            fos.write(xml.getBytes());
+        }
+        finally
+        {
+            fos.close();
+        }
+    }
+}

Modified: felix/trunk/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/pom.xml?rev=1564308&r1=1564307&r2=1564308&view=diff
==============================================================================
--- felix/trunk/pom.xml (original)
+++ felix/trunk/pom.xml Tue Feb  4 14:13:44 2014
@@ -64,6 +64,7 @@
       <modules>
         <module>utils</module>
         <module>bundlerepository</module>
+        <module>bundlerepository.osgi-ct</module>
      </modules>
    </profile>
 



Mime
View raw message