FELIX-2175: Improve the Blueprint component to parse / introspect blueprint configuration files and generate OBR service requirements / capabilities accordingly
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@921470 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/test/java/org/apache/felix/bnd/BlueprintComponentTest.java b/bundleplugin/src/test/java/org/apache/felix/bnd/BlueprintComponentTest.java
deleted file mode 100644
index 014610e..0000000
--- a/bundleplugin/src/test/java/org/apache/felix/bnd/BlueprintComponentTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.bnd;
-
-import java.util.Set;
-
-import aQute.lib.spring.XMLType;
-import junit.framework.TestCase;
-
-public class BlueprintComponentTest extends TestCase {
-
- public void testPackages() throws Exception {
- XMLType t = new XMLType(getClass().getResource("blueprint.xsl"), null, ".*\\.xml");
- Set<String> s = t.analyze(getClass().getResourceAsStream("bp.xml"));
- assertEquals(14, s.size());
- assertTrue(s.contains("java.lang"));
- for (int i = 1; i <= 13; i++) {
- assertTrue(s.contains("p" + i));
- }
- }
-}
diff --git a/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java
new file mode 100644
index 0000000..8c9ac37
--- /dev/null
+++ b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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.bundleplugin;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.jar.Manifest;
+
+import aQute.lib.osgi.Builder;
+import aQute.lib.spring.XMLType;
+import junit.framework.TestCase;
+import org.apache.felix.bundleplugin.ManifestPlugin;
+import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.osgi.framework.Constants;
+
+public class BlueprintComponentTest extends TestCase {
+
+ public void testBlueprint() throws Exception
+ {
+
+ MavenProjectStub project = new MavenProjectStub() {
+ private final List resources = new ArrayList();
+ @Override
+ public void addResource(Resource resource) {
+ resources.add(resource);
+ }
+
+ @Override
+ public List getResources() {
+ return resources;
+ }
+ };
+ project.setGroupId( "group" );
+ project.setArtifactId( "artifact" );
+ project.setVersion( "1.1.0.0" );
+ Resource r = new Resource();
+ r.setDirectory(new File("src/test/resources").getAbsoluteFile().getCanonicalPath());
+ r.setIncludes(Arrays.asList("**/*.*"));
+ project.addResource(r);
+ project.addCompileSourceRoot(new File("src/test/resources").getAbsoluteFile().getCanonicalPath());
+
+ ManifestPlugin plugin = new ManifestPlugin();
+ plugin.setBasedir(new File("target/tmp/basedir"));
+ plugin.setBuildDirectory("target/tmp/basedir/target");
+ plugin.setOutputDirectory(new File("target/tmp/basedir/target/classes"));
+
+ Map instructions = new HashMap();
+ instructions.put("Test", "Foo");
+
+ instructions.put("nsh_interface", "foo.bar.Namespace");
+ instructions.put("nsh_namespace", "ns");
+
+ Properties props = new Properties();
+ Builder builder = plugin.buildOSGiBundle(project, instructions, props, plugin.getClasspath(project));
+
+ Manifest manifest = builder.getJar().getManifest();
+ String expSvc = manifest.getMainAttributes().getValue(Constants.EXPORT_SERVICE);
+ String impSvc = manifest.getMainAttributes().getValue(Constants.IMPORT_SERVICE);
+ assertNotNull(expSvc);
+ assertNotNull(impSvc);
+
+ String impPkg = manifest.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
+ List<String> pkgs = Arrays.asList(impPkg.split(","));
+ for (int i = 1; i <= 13; i++) {
+ assertTrue(pkgs.contains("p" + i));
+ }
+ }
+
+}
diff --git a/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
index 581b28f..c9748e8 100644
--- a/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
+++ b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
@@ -21,10 +21,21 @@
*/
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.Properties;
+import java.util.jar.Manifest;
+import org.apache.maven.model.Resource;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter;
@@ -33,6 +44,9 @@
import aQute.lib.osgi.Analyzer;
import aQute.lib.osgi.Builder;
import aQute.lib.osgi.Jar;
+import org.osgi.framework.Constants;
+import org.osgi.impl.bundle.obr.resource.RepositoryImpl;
+import org.osgi.impl.bundle.obr.resource.BundleInfo;
/**
@@ -59,6 +73,10 @@
public void testConvertVersionToOsgi()
{
+ try {
+ new BundleInfo(new RepositoryImpl(new URL("file:.")), new File("/Users/gnodet/.m2/repository/org/apache/felix/karaf/webconsole/org.apache.felix.karaf.webconsole.branding/1.5.0-SNAPSHOT/org.apache.felix.karaf.webconsole.branding-1.5.0-SNAPSHOT.jar")).build();
+ } catch(Exception e ) {}
+
String osgiVersion;
osgiVersion = plugin.convertVersionToOsgi( "2.1.0-SNAPSHOT" );
@@ -195,4 +213,5 @@
String cleanupVersion = Builder.cleanupVersion( "0.0.0.4aug2000r7-dev" );
assertEquals( "0.0.0.4aug2000r7-dev", cleanupVersion );
}
+
}
diff --git a/bundleplugin/src/test/resources/OSGI-INF/blueprint/bp.xml b/bundleplugin/src/test/resources/OSGI-INF/blueprint/bp.xml
new file mode 100644
index 0000000..fe8d4f3
--- /dev/null
+++ b/bundleplugin/src/test/resources/OSGI-INF/blueprint/bp.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:tx="http://foo.bar/tx"
+ xmlns:t2="http://foo.bar/t2">
+
+ <type-converters>
+ <bean class="p1.Foo" t2:a="b">
+ <argument type="java.lang.Integer[]" value="0 1"/>
+ </bean>
+ </type-converters>
+
+ <bean class="p2.Foo">
+ <tx:transaction method="*" value="NotSupported"/>
+ <property name="bar">
+ <bean class="p3.Foo"/>
+ </property>
+ </bean>
+
+ <reference interface="p4.Foo" availability="optional"/>
+
+ <reference-list interface="p5.Foo">
+ </reference-list>
+
+ <service interface="p6.Foo">
+ <service-properties>
+ <entry key="k" value="v" />
+ </service-properties>
+ </service>
+
+ <service>
+ <interfaces>
+ <value>p7.Foo</value>
+ </interfaces>
+ <bean class="p8.Foo">
+ <argument type="p9.Foo[][]"><null/></argument>
+ <property name="bar">
+ <list value-type="p10.Foo">
+ <map key-type="p11.Foo" value-type="p12.Foo">
+ </map>
+ <set value-type="p13.Foo[]"/>
+ </list>
+ </property>
+ </bean>
+ </service>
+
+</blueprint>
diff --git a/bundleplugin/src/test/resources/org/apache/felix/bnd/bp.xml b/bundleplugin/src/test/resources/org/apache/felix/bnd/bp.xml
deleted file mode 100644
index ec74f7d..0000000
--- a/bundleplugin/src/test/resources/org/apache/felix/bnd/bp.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
- <type-converters>
- <bean class="p1.Foo">
- <argument type="java.lang.Integer[]" value="0 1"/>
- </bean>
- </type-converters>
-
- <bean class="p2.Foo">
- <property name="bar">
- <bean class="p3.Foo"/>
- </property>
- </bean>
-
- <reference interface="p4.Foo" />
-
- <reference-list interface="p5.Foo">
- </reference-list>
-
- <service interface="p6.Foo">
- </service>
-
- <service>
- <interfaces>
- <value>p7.Foo</value>
- </interfaces>
- <bean class="p8.Foo">
- <argument type="p9.Foo[][]"><null/></argument>
- <property name="bar">
- <list value-type="p10.Foo">
- <map key-type="p11.Foo" value-type="p12.Foo">
- </map>
- <set value-type="p13.Foo[]"/>
- </list>
- </property>
- </bean>
- </service>
-
-</blueprint>
\ No newline at end of file