You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2011/12/03 11:23:24 UTC
svn commit: r1209881 - in /felix/trunk/ipojo: ./ core/
core/src/main/java/org/apache/felix/ipojo/ core/src/main/resources/
online-manipulator/ tests/online-manipulator/
tests/online-manipulator/src/test/java/org/apache/felix/ipojo/online/manipulator/test/
Author: clement
Date: Sat Dec 3 10:23:24 2011
New Revision: 1209881
URL: http://svn.apache.org/viewvc?rev=1209881&view=rev
Log:
Fix FELIX-3252
Embeds the iPOJO online manipulator into the iPOJO Core bundle
Added:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPOJOURLHandler.java
Removed:
felix/trunk/ipojo/online-manipulator/
Modified:
felix/trunk/ipojo/core/pom.xml
felix/trunk/ipojo/core/src/main/resources/metadata.xml
felix/trunk/ipojo/pom.xml
felix/trunk/ipojo/tests/online-manipulator/pom.xml
felix/trunk/ipojo/tests/online-manipulator/src/test/java/org/apache/felix/ipojo/online/manipulator/test/OnlineManipulatorTest.java
Modified: felix/trunk/ipojo/core/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/pom.xml?rev=1209881&r1=1209880&r2=1209881&view=diff
==============================================================================
--- felix/trunk/ipojo/core/pom.xml (original)
+++ felix/trunk/ipojo/core/pom.xml Sat Dec 3 10:23:24 2011
@@ -36,6 +36,9 @@
* change in the Factory interface (FELIX-3190)
-->
<ipojo.package.version>1.8.1</ipojo.package.version>
+
+ <!-- Embedded manipulator version -->
+ <ipojo.manipulator.version>1.8.0</ipojo.manipulator.version>
</properties>
<description>
@@ -61,6 +64,11 @@
<artifactId>org.apache.felix.ipojo.metadata</artifactId>
<version>1.5.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.manipulator</artifactId>
+ <version>${ipojo.manipulator.version}</version>
+ </dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-all</artifactId>
@@ -107,7 +115,19 @@
org.osgi.framework;version=1.3, <!-- To support KF 2 -->
org.osgi.service.cm,
org.osgi.service.log,
- !net.sourceforge.cobertura.* <!-- To support code coverage -->
+ !org.objectweb.asm.tree,
+ !sun.io,
+ !net.sourceforge.cobertura.*, <!-- To support code coverage -->
+
+ <!--
+ Packages used for the online-manipulator.
+ They are optionals
+ -->
+ javax.xml.parsers;resolution:=optional,
+ org.osgi.service.url;resolution:=optional,
+ org.w3c.dom;resolution:=optional,
+ org.xml.sax;resolution:=optional,
+ org.xml.sax.helpers;resolution:=optional
</Import-Package>
<Private-Package>
org.apache.felix.ipojo.handlers.architecture,
@@ -124,9 +144,17 @@
org.apache.felix.ipojo.handlers.providedservice.*; version="${ipojo.package.version}",
org.apache.felix.ipojo.handlers.configuration; version="${ipojo.package.version}",
org.apache.felix.ipojo.context; version="${ipojo.package.version}",
+ <!-- Embedded manipulator -->
+ org.apache.felix.ipojo.manipulator; version="${ipojo.manipulator.version}",
+ org.apache.felix.ipojo.xml.parser; version="${ipojo.manipulator.version}",
+ org.apache.felix.ipojo.*; version="${ipojo.manipulator.version}",
+ <!-- Compendium packages -->
org.osgi.service.cm,
org.osgi.service.log,
- org.objectweb.asm; version=3.3.1
+ <!-- ASM (Manipulator dependencies -->
+ org.objectweb.asm.commons;version=3.3.1,
+ org.objectweb.asm.signature;version=3.3.1,
+ org.objectweb.asm;version=3.3.1
</Export-Package>
<Include-Resource>
META-INF/LICENSE=LICENSE,
Added: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPOJOURLHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPOJOURLHandler.java?rev=1209881&view=auto
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPOJOURLHandler.java (added)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPOJOURLHandler.java Sat Dec 3 10:23:24 2011
@@ -0,0 +1,239 @@
+/*
+ * 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.ipojo;
+
+import org.apache.felix.ipojo.manipulator.Pojoization;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.url.URLStreamHandlerService;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+* iPOJO URL Handler allowing installation time manipulation.
+* When a bundle is installed with the <code>ipojo:</code> URL
+* prefix, the bundle is downloaded and manipulated by this
+* handler.
+* The metadata.xml file can either be provided inside the bundle (root,
+* or in META-INF) or given in the URL:
+* ipojo:URL_BUNDLE!URL_METADATA.
+* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+*/
+public class IPOJOURLHandler extends org.osgi.service.url.AbstractURLStreamHandlerService implements URLStreamHandlerService {
+
+ /**
+ * The bundle context.
+ */
+ private BundleContext m_context;
+
+ /**
+ * The directory storing bundles.
+ */
+ private File m_temp;
+
+ /**
+ * Creates a IPOJOURLHandler.
+ * Gets the bundle context and create the working
+ * directory.
+ * @param bc the bundle context
+ */
+ public IPOJOURLHandler(BundleContext bc) {
+ m_context = bc;
+ m_temp = m_context.getDataFile("temp");
+ if (! m_temp.exists()) {
+ m_temp.mkdir();
+ }
+ }
+
+ /**
+ * Stops the URL handler:
+ * Deletes the working directory.
+ */
+ public void stop() {
+ File[] files = m_temp.listFiles();
+ if (files != null) {
+ for (int i = 0; i < files.length; i++) {
+ files[i].delete();
+ }
+ }
+ m_temp.delete();
+ }
+
+ /**
+ * Opens a connection using the ipojo url handler.
+ * This methods parses the URL and manipulate the given bundle.
+ * @param url the url.
+ * @return the URL connection on the manipulated bundle
+ * @throws java.io.IOException occurs when the bundle cannot be either downloaded, or manipulated or
+ * installed correctly.
+ * @see org.osgi.service.url.AbstractURLStreamHandlerService#openConnection(java.net.URL)
+ */
+ public URLConnection openConnection(URL url) throws IOException {
+ System.out.println("Processing URL : " + url);
+
+ // Parse the url:
+ String full = url.toExternalForm();
+ // Remote ipojo://
+ if (full.startsWith("ipojo:")) {
+ full = full.substring(6);
+ }
+ // Remove '/' or '//'
+ while (full.startsWith("/")) {
+ full = full.substring(1);
+ }
+
+ full = full.trim();
+
+ // Now full is like : URL,URL or URL
+ String[] urls = full.split("!");
+ URL bundleURL = null;
+ URL metadataURL = null;
+ if (urls.length == 1) {
+ // URL form
+ System.out.println("Extracted URL : " + urls[0]);
+ bundleURL = new URL(urls[0]);
+ } else if (urls.length == 2) {
+ // URL,URL form
+ bundleURL = new URL(urls[0]);
+ metadataURL = new URL(urls[1]);
+ } else {
+ throw new MalformedURLException("The iPOJO url is not formatted correctly, ipojo:bundle_url[!metadata_url] expected");
+ }
+
+ File bundle = File.createTempFile("ipojo_", ".jar", m_temp);
+ save(bundleURL, bundle);
+ File metadata = null;
+ if (metadataURL != null) {
+ metadata = File.createTempFile("ipojo_", ".xml", m_temp);
+ save(metadataURL, metadata);
+ } else {
+ // Check that the metadata are in the jar file
+ JarFile jar = new JarFile(bundle);
+ metadata = findMetadata(jar);
+ }
+
+ // Pojoization
+ Pojoization pojoizator = new Pojoization();
+ File out = new File(m_temp, bundle.getName() + "-ipojo.jar");
+ System.out.println("Pojoization " + bundle.exists() + " - " + metadata.exists());
+ try {
+ pojoizator.pojoization(bundle, out, metadata);
+ } catch (Exception e) {
+ if (! pojoizator.getErrors().isEmpty()) {
+ throw new IOException("Errors occured during the manipulation : " + pojoizator.getErrors());
+ }
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+
+ if (! pojoizator.getErrors().isEmpty()) {
+ throw new IOException("Errors occured during the manipulation : " + pojoizator.getErrors());
+ }
+ if (! pojoizator.getWarnings().isEmpty()) {
+ System.err.println("Warnings occured during the manipulation : " + pojoizator.getWarnings());
+ }
+
+ System.out.println("Manipulation done : " + out.exists());
+
+ // Cleanup
+ bundle.delete();
+ if (metadata != null) {
+ metadata.delete();
+ }
+ out.deleteOnExit();
+ // Returns the URL Connection
+ return out.toURI().toURL().openConnection();
+
+
+ }
+
+ /**
+ * Downloads the content pointed by the given url to
+ * the given file.
+ * @param url the url
+ * @param file the file
+ * @throws java.io.IOException occurs if the content cannot be read
+ * and save inside the file
+ */
+ private void save(URL url, File file) throws IOException {
+ InputStream is = url.openStream();
+ save(is, file);
+ }
+
+ /**
+ * Saves the content of the input stream to the given file.
+ * @param is the input stream to read
+ * @param file the file
+ * @throws java.io.IOException occurs if the content cannot be read
+ * and save inside the file
+ */
+ private void save(InputStream is, File file) throws IOException {
+ FileOutputStream writer = new FileOutputStream(file);
+ int cc = 0;
+ do {
+ int i = is.read();
+ if (i == -1) {
+ break;
+ }
+ cc++;
+ writer.write(i);
+ } while (true);
+ System.out.println(cc + " bytes copied");
+ is.close();
+ writer.close();
+ }
+
+ /**
+ * Looks for the metadata.xml file in the jar file.
+ * Two locations are checked:
+ * <ol>
+ * <li>the root of the jar file</li>
+ * <li>the META-INF directory</li>
+ * </ol>
+ * @param jar the jar file
+ * @return the founded file or <code>null</code> if not found.
+ * @throws java.io.IOException occurs when the Jar file cannot be read.
+ */
+ private File findMetadata(JarFile jar) throws IOException {
+ JarEntry je = jar.getJarEntry("metadata.xml");
+ if (je == null) {
+ je = jar.getJarEntry("META-INF/metadata.xml");
+ }
+
+ if (je == null) {
+ System.out.println("Metadata file not found, use annotations only.");
+ return null; // Not Found, use annotation only
+ } else {
+ System.out.println("Metadata file found: " + je.getName());
+ File metadata = File.createTempFile("ipojo_", ".xml", m_temp);
+ save(jar.getInputStream(je), metadata);
+ System.out.println("Metadata file saved to " + metadata.getAbsolutePath());
+ return metadata;
+ }
+
+ }
+
+}
Modified: felix/trunk/ipojo/core/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/resources/metadata.xml?rev=1209881&r1=1209880&r2=1209881&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/resources/metadata.xml (original)
+++ felix/trunk/ipojo/core/src/main/resources/metadata.xml Sat Dec 3 10:23:24 2011
@@ -17,31 +17,41 @@
under the License.
-->
<ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/CURRENT/core.xsd"
- xmlns="org.apache.felix.ipojo">
- <!-- Primitives handler -->
- <handler
- classname="org.apache.felix.ipojo.handlers.lifecycle.controller.ControllerHandler"
- name="controller" architecture="false"/>
- <handler
- classname="org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler"
- name="callback" level="2" architecture="false" />
- <handler
- classname="org.apache.felix.ipojo.handlers.dependency.DependencyHandler"
- name="requires" level="0" architecture="false">
- <!-- <controller field="m_state"/> -->
- </handler>
- <handler
- classname="org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler"
- name="provides" level="3" architecture="false" />
- <handler
- classname="org.apache.felix.ipojo.handlers.configuration.ConfigurationHandler"
- name="properties" level="1" architecture="false" />
- <handler
- classname="org.apache.felix.ipojo.handlers.architecture.ArchitectureHandler"
- name="architecture" architecture="false">
- <provides specifications="org.apache.felix.ipojo.architecture.Architecture">
- <property field="m_name" name="architecture.instance"/>
- </provides>
- </handler>
+ xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/CURRENT/core.xsd"
+ xmlns="org.apache.felix.ipojo">
+ <!-- Primitives handler -->
+ <handler
+ classname="org.apache.felix.ipojo.handlers.lifecycle.controller.ControllerHandler"
+ name="controller" architecture="false"/>
+ <handler
+ classname="org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler"
+ name="callback" level="2" architecture="false"/>
+ <handler
+ classname="org.apache.felix.ipojo.handlers.dependency.DependencyHandler"
+ name="requires" level="0" architecture="false">
+ <!-- <controller field="m_state"/> -->
+ </handler>
+ <handler
+ classname="org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler"
+ name="provides" level="3" architecture="false"/>
+ <handler
+ classname="org.apache.felix.ipojo.handlers.configuration.ConfigurationHandler"
+ name="properties" level="1" architecture="false"/>
+ <handler
+ classname="org.apache.felix.ipojo.handlers.architecture.ArchitectureHandler"
+ name="architecture" architecture="false">
+ <provides specifications="org.apache.felix.ipojo.architecture.Architecture">
+ <property field="m_name" name="architecture.instance"/>
+ </provides>
+ </handler>
+ <!-- iPOJO Online Manipulator -->
+ <component classname="org.apache.felix.ipojo.IPOJOURLHandler"
+ public="false"
+ immediate="true">
+ <provides>
+ <property name="url.handler.protocol" type="java.lang.String" value="ipojo"/>
+ </provides>
+ <callback transition="invalidate" method="stop"/>
+ </component>
+ <instance component="org.apache.felix.ipojo.IPOJOURLHandler"/>
</ipojo>
\ No newline at end of file
Modified: felix/trunk/ipojo/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/pom.xml?rev=1209881&r1=1209880&r2=1209881&view=diff
==============================================================================
--- felix/trunk/ipojo/pom.xml (original)
+++ felix/trunk/ipojo/pom.xml Sat Dec 3 10:23:24 2011
@@ -42,7 +42,6 @@
<module>handler/eventadmin</module>
<module>handler/whiteboard</module>
<module>api</module>
- <module>online-manipulator</module>
<!-- remove junit4osgi during the release process
<module>junit4osgi</module> -->
</modules>
Modified: felix/trunk/ipojo/tests/online-manipulator/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/online-manipulator/pom.xml?rev=1209881&r1=1209880&r2=1209881&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/online-manipulator/pom.xml (original)
+++ felix/trunk/ipojo/tests/online-manipulator/pom.xml Sat Dec 3 10:23:24 2011
@@ -1,112 +1,106 @@
<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>
+ 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>ipojo.tests</groupId>
- <artifactId>ipojo.tests</artifactId>
- <version>1.5.0-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
+ <parent>
+ <groupId>ipojo.tests</groupId>
+ <artifactId>ipojo.tests</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo.online.manipulator.test</artifactId>
- <version>1.7.0-SNAPSHOT</version>
- <name>Online Manipulator Test</name>
- <packaging>jar</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.servicemix.tooling</groupId>
- <artifactId>depends-maven-plugin</artifactId>
- <version>1.2</version>
- <executions>
- <execution>
- <id>generate-depends-file</id>
- <goals>
- <goal>generate-depends-file</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- </dependency>
-
- <!--
- Pax Exam API:
- -->
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam</artifactId>
- <version>1.2.0</version>
- </dependency>
- <!--
- During runtime Pax Exam will discover the OSGi container to use by
- searching metadata available into classpath. Pax Exam comes with a
- default container that uses [Pax Runner] for implementing the
- container requirements:
- -->
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-container-default
- </artifactId>
- <version>1.2.0</version>
- </dependency>
- <!--
- If your test code is based on JUnit you will have to have the Junit
- support artifact:
- -->
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-junit</artifactId>
- <version>1.2.0</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.5</version>
- <type>jar</type>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.ops4j.pax.swissbox</groupId>
- <artifactId>pax-swissbox-tinybundles</artifactId>
- <version>1.2.0</version>
- </dependency>
- <dependency>
- <groupId>xerces</groupId>
- <artifactId>xercesImpl</artifactId>
- <version>2.4.0</version>
- </dependency>
- <dependency>
<groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo.annotations</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo</artifactId>
- <version>${ipojo.core.snapshot}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo.online.manipulator</artifactId>
+ <artifactId>org.apache.felix.ipojo.online.manipulator.test</artifactId>
<version>1.7.0-SNAPSHOT</version>
- </dependency>
-
- </dependencies>
+ <name>Online Manipulator Test</name>
+ <packaging>jar</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ <version>1.2</version>
+ <executions>
+ <execution>
+ <id>generate-depends-file</id>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+
+ <!--
+ Pax Exam API:
+ -->
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam</artifactId>
+ <version>1.2.0</version>
+ </dependency>
+ <!--
+ During runtime Pax Exam will discover the OSGi container to use by
+ searching metadata available into classpath. Pax Exam comes with a
+ default container that uses [Pax Runner] for implementing the
+ container requirements:
+ -->
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-default
+ </artifactId>
+ <version>1.2.0</version>
+ </dependency>
+ <!--
+ If your test code is based on JUnit you will have to have the Junit
+ support artifact:
+ -->
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit</artifactId>
+ <version>1.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.5</version>
+ <type>jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.swissbox</groupId>
+ <artifactId>pax-swissbox-tinybundles</artifactId>
+ <version>1.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ <version>${ipojo.core.snapshot}</version>
+ </dependency>
+ </dependencies>
</project>
Modified: felix/trunk/ipojo/tests/online-manipulator/src/test/java/org/apache/felix/ipojo/online/manipulator/test/OnlineManipulatorTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/online-manipulator/src/test/java/org/apache/felix/ipojo/online/manipulator/test/OnlineManipulatorTest.java?rev=1209881&r1=1209880&r2=1209881&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/online-manipulator/src/test/java/org/apache/felix/ipojo/online/manipulator/test/OnlineManipulatorTest.java (original)
+++ felix/trunk/ipojo/tests/online-manipulator/src/test/java/org/apache/felix/ipojo/online/manipulator/test/OnlineManipulatorTest.java Sat Dec 3 10:23:24 2011
@@ -1,13 +1,7 @@
package org.apache.felix.ipojo.online.manipulator.test;
-import static org.ops4j.pax.exam.CoreOptions.equinox;
-import static org.ops4j.pax.exam.CoreOptions.felix;
-import static org.ops4j.pax.exam.CoreOptions.frameworks;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.provision;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.CoreOptions.*;
import static org.ops4j.pax.exam.MavenUtils.asInProject;
import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
@@ -42,7 +36,7 @@ import org.osgi.framework.InvalidSyntaxE
import org.osgi.framework.ServiceReference;
-@RunWith( JUnit4TestRunner.class )
+@RunWith(JUnit4TestRunner.class)
public class OnlineManipulatorTest {
@@ -62,63 +56,51 @@ public class OnlineManipulatorTest {
*/
@Configuration
- public static Option[] configure() throws IOException
- {
-
+ public static Option[] configure() throws IOException {
String providerWithMetadata = providerWithMetadata();
String providerWithMetadataInMetaInf = providerWithMetadataInMetaInf();
String providerWithoutMetadata = providerWithoutMetadata();
- String consumerWithMetadata = consumerWithMetadata();
+ String consumerWithMetadata = consumerWithMetadata();
String consumerWithoutMetadata = consumerWithoutMetadata();
return options(
frameworks(
felix(),
- equinox()
- // knopflerfish() KF does not export an XML parser.
- ),
- provision(
- mavenBundle()
- .groupId("org.apache.felix")
- .artifactId("org.apache.felix.ipojo")
- .version(asInProject())
- ),
-
- provision(
- mavenBundle()
- .groupId("org.apache.felix")
- .artifactId("org.apache.felix.ipojo.online.manipulator")
- .version(asInProject())
- ),
- provision(
- newBundle()
- .add( Hello.class )
- .set(Constants.BUNDLE_SYMBOLICNAME,"ServiceInterface")
- .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.online.manipulator.test.service")
- .build()
- ),
- systemProperty( "providerWithMetadata" ).value( providerWithMetadata ),
- systemProperty( "providerWithMetadataInMetaInf" ).value( providerWithMetadataInMetaInf ),
- systemProperty( "providerWithoutMetadata" ).value( providerWithoutMetadata ),
- systemProperty( "consumerWithMetadata").value(consumerWithMetadata),
- systemProperty( "consumerWithoutMetadata").value(consumerWithoutMetadata),
-
- new Customizer() {
- @Override
- public InputStream customizeTestProbe( InputStream testProbe )
- {
- return TinyBundles.modifyBundle(testProbe).set(Constants.IMPORT_PACKAGE,
- "org.apache.felix.ipojo.online.manipulator.test.service")
- .build();
- }
+ equinox(),
+ knopflerfish() //KF does not export an XML parser.
+ ),
+ provision(
+ mavenBundle()
+ .groupId("org.apache.felix")
+ .artifactId("org.apache.felix.ipojo")
+ .version(asInProject())
+ ),
+
+ provision(
+ newBundle()
+ .add(Hello.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "ServiceInterface")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.online.manipulator.test.service")
+ .build()
+ ),
+ systemProperty("providerWithMetadata").value(providerWithMetadata),
+ systemProperty("providerWithMetadataInMetaInf").value(providerWithMetadataInMetaInf),
+ systemProperty("providerWithoutMetadata").value(providerWithoutMetadata),
+ systemProperty("consumerWithMetadata").value(consumerWithMetadata),
+ systemProperty("consumerWithoutMetadata").value(consumerWithoutMetadata),
+
+ new Customizer() {
+ @Override
+ public InputStream customizeTestProbe(InputStream testProbe) {
+ return TinyBundles.modifyBundle(testProbe).set(Constants.IMPORT_PACKAGE,
+ "org.apache.felix.ipojo.online.manipulator.test.service")
+ .build();
+ }
}
- );
-
-
-
+ );
}
@@ -133,7 +115,7 @@ public class OnlineManipulatorTest {
}
private static File getTemporaryFile(String name) throws IOException {
- if (! TMP.exists()) {
+ if (!TMP.exists()) {
TMP.mkdirs();
TMP.deleteOnExit();
}
@@ -150,7 +132,7 @@ public class OnlineManipulatorTest {
public void installProviderWithMetadata1() throws BundleException, InvalidSyntaxException, Exception {
String url = context.getProperty("providerWithMetadata");
Assert.assertNotNull(url);
- Bundle bundle = context.installBundle("ipojo:"+url);
+ Bundle bundle = context.installBundle("ipojo:" + url);
bundle.start();
assertBundle("Provider");
@@ -161,12 +143,11 @@ public class OnlineManipulatorTest {
}
-
@Test
public void installProviderWithMetadata2() throws BundleException, InvalidSyntaxException, IOException {
String url = context.getProperty("providerWithMetadataInMetaInf");
Assert.assertNotNull(url);
- context.installBundle("ipojo:"+url).start();
+ context.installBundle("ipojo:" + url).start();
assertBundle("Provider");
helper.waitForService(Hello.class.getName(), null, 5000);
assertValidity();
@@ -177,7 +158,7 @@ public class OnlineManipulatorTest {
public void installProviderWithoutMetadata() throws BundleException, InvalidSyntaxException, IOException {
String url = context.getProperty("providerWithoutMetadata");
Assert.assertNotNull(url);
- context.installBundle("ipojo:"+url).start();
+ context.installBundle("ipojo:" + url).start();
assertBundle("Provider");
helper.waitForService(Hello.class.getName(), null, 5000);
assertValidity();
@@ -188,12 +169,12 @@ public class OnlineManipulatorTest {
public void installConsumerWithMetadata() throws BundleException, InvalidSyntaxException, IOException {
String url = context.getProperty("providerWithoutMetadata");
Assert.assertNotNull(url);
- context.installBundle("ipojo:"+url).start();
+ context.installBundle("ipojo:" + url).start();
assertBundle("Provider");
String url2 = context.getProperty("consumerWithMetadata");
Assert.assertNotNull(url);
- context.installBundle("ipojo:"+url2).start();
+ context.installBundle("ipojo:" + url2).start();
assertBundle("Consumer");
helper.waitForService(Hello.class.getName(), null, 5000);
// Wait for activation.
@@ -210,13 +191,13 @@ public class OnlineManipulatorTest {
public void installConsumerWithoutMetadata() throws BundleException, InvalidSyntaxException, IOException {
String url = context.getProperty("providerWithMetadataInMetaInf");
Assert.assertNotNull(url);
- context.installBundle("ipojo:"+url).start();
+ context.installBundle("ipojo:" + url).start();
assertBundle("Provider");
helper.waitForService(Hello.class.getName(), null, 5000);
String url2 = context.getProperty("consumerWithoutMetadata");
Assert.assertNotNull(url);
- context.installBundle("ipojo:"+url2).start();
+ context.installBundle("ipojo:" + url2).start();
assertBundle("Consumer");
// Wait for activation.
try {
@@ -230,16 +211,17 @@ public class OnlineManipulatorTest {
/**
* Gets a regular bundle containing metadata file
+ *
* @return the url of the bundle
* @throws IOException
*/
public static String providerWithMetadata() throws IOException {
InputStream is = newBundle()
- .add("metadata.xml", OnlineManipulatorTest.class.getClassLoader().getResource("provider.xml"))
- .add(MyProvider.class)
- .set(Constants.BUNDLE_SYMBOLICNAME,"Provider")
- .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.online.manipulator.test.service")
- .build();
+ .add("metadata.xml", OnlineManipulatorTest.class.getClassLoader().getResource("provider.xml"))
+ .add(MyProvider.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Provider")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.online.manipulator.test.service")
+ .build();
File out = getTemporaryFile("providerWithMetadata");
StreamUtils.copyStream(is, new FileOutputStream(out), true);
@@ -248,16 +230,17 @@ public class OnlineManipulatorTest {
/**
* Gets a regular bundle containing metadata file in the META-INF directory
+ *
* @return the url of the bundle
* @throws IOException
*/
public static String providerWithMetadataInMetaInf() throws IOException {
InputStream is = newBundle()
- .add("META-INF/metadata.xml", OnlineManipulatorTest.class.getClassLoader().getResource("provider.xml"))
- .add(MyProvider.class)
- .set(Constants.BUNDLE_SYMBOLICNAME,"Provider")
- .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.online.manipulator.test.service")
- .build();
+ .add("META-INF/metadata.xml", OnlineManipulatorTest.class.getClassLoader().getResource("provider.xml"))
+ .add(MyProvider.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Provider")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.online.manipulator.test.service")
+ .build();
File out = getTemporaryFile("providerWithMetadataInMetaInf");
StreamUtils.copyStream(is, new FileOutputStream(out), true);
@@ -266,37 +249,39 @@ public class OnlineManipulatorTest {
/**
* Gets a provider bundle which does not contain the metadata file.
+ *
* @return the url of the bundle + metadata
* @throws IOException
*/
public static String providerWithoutMetadata() throws IOException {
- InputStream is = newBundle()
- //.addResource("metadata.xml", this.getClass().getClassLoader().getResource("provider.xml"))
- .add(MyProvider.class)
- .set(Constants.BUNDLE_SYMBOLICNAME,"Provider")
- .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.online.manipulator.test.service")
- .build();
+ InputStream is = newBundle()
+ //.addResource("metadata.xml", this.getClass().getClassLoader().getResource("provider.xml"))
+ .add(MyProvider.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Provider")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.online.manipulator.test.service")
+ .build();
- File out = getTemporaryFile("providerWithoutMetadata");
+ File out = getTemporaryFile("providerWithoutMetadata");
StreamUtils.copyStream(is, new FileOutputStream(out), true);
String url = out.toURI().toURL().toExternalForm();
- return url + "!" +OnlineManipulatorTest.class.getClassLoader().getResource("provider.xml");
+ return url + "!" + OnlineManipulatorTest.class.getClassLoader().getResource("provider.xml");
}
/**
* Gets a consumer bundle using annotation containing the instance
* declaration in the metadata.
+ *
* @return the url of the bundle
* @throws IOException
*/
public static String consumerWithMetadata() throws IOException {
InputStream is = newBundle()
- .add("metadata.xml", OnlineManipulatorTest.class.getClassLoader().getResource("consumer.xml"))
- .add(Consumer.class)
- .set(Constants.BUNDLE_SYMBOLICNAME, "Consumer")
- .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.online.manipulator.test.service")
- .build();
+ .add("metadata.xml", OnlineManipulatorTest.class.getClassLoader().getResource("consumer.xml"))
+ .add(Consumer.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Consumer")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.online.manipulator.test.service")
+ .build();
File out = getTemporaryFile("consumerWithMetadata");
StreamUtils.copyStream(is, new FileOutputStream(out), true);
@@ -306,15 +291,16 @@ public class OnlineManipulatorTest {
/**
* Gets a consumer bundle using annotation that does not contain
* metadata
+ *
* @return the url of the bundle + metadata
* @throws IOException
*/
public static String consumerWithoutMetadata() throws IOException {
InputStream is = newBundle()
- .add(Consumer.class)
- .set(Constants.BUNDLE_SYMBOLICNAME, "Consumer")
- .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.online.manipulator.test.service")
- .build();
+ .add(Consumer.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Consumer")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.online.manipulator.test.service")
+ .build();
File out = getTemporaryFile("consumerWithoutMetadata");
StreamUtils.copyStream(is, new FileOutputStream(out), true);
@@ -324,7 +310,6 @@ public class OnlineManipulatorTest {
}
-
public void dumpServices() throws InvalidSyntaxException {
ServiceReference[] refs = context.getAllServiceReferences(null, null);
System.out.println(" === Services === ");
@@ -339,14 +324,14 @@ public class OnlineManipulatorTest {
Bundle[] bundles = context.getBundles();
System.out.println(" === Bundles === ");
for (Bundle bundle : bundles) {
- String sn = bundle.getSymbolicName();
+ String sn = bundle.getSymbolicName();
System.out.println(sn);
}
System.out.println("====");
}
private void assertBundle(String sn) {
- for (Bundle bundle :context.getBundles()) {
+ for (Bundle bundle : context.getBundles()) {
if (bundle.getSymbolicName().equals(sn)
&& bundle.getState() == Bundle.ACTIVE) {
return;
@@ -372,5 +357,4 @@ public class OnlineManipulatorTest {
}
-
}