You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2016/04/14 16:18:26 UTC
svn commit: r1739118 - in /felix/trunk/tools/maven-bundle-plugin: pom.xml
src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
src/main/java/org/apache/felix/bundleplugin/JpaPlugin.java
src/main/resources/org/apache/felix/bundleplugin/jpa.xsl
Author: gnodet
Date: Thu Apr 14 14:18:26 2016
New Revision: 1739118
URL: http://svn.apache.org/viewvc?rev=1739118&view=rev
Log:
Merge branch 'maven-jpa' into trunk
Added:
felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/JpaPlugin.java
felix/trunk/tools/maven-bundle-plugin/src/main/resources/org/apache/felix/bundleplugin/jpa.xsl
Modified:
felix/trunk/tools/maven-bundle-plugin/pom.xml
felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
Modified: felix/trunk/tools/maven-bundle-plugin/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven-bundle-plugin/pom.xml?rev=1739118&r1=1739117&r2=1739118&view=diff
==============================================================================
--- felix/trunk/tools/maven-bundle-plugin/pom.xml (original)
+++ felix/trunk/tools/maven-bundle-plugin/pom.xml Thu Apr 14 14:18:26 2016
@@ -28,7 +28,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-bundle-plugin</artifactId>
- <version>3.0.2-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>Maven Bundle Plugin</name>
@@ -127,6 +127,7 @@
</excludes>
</configuration>
</plugin>
+ <!--
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>2.0.0</version>
@@ -148,6 +149,7 @@
</execution>
</executions>
</plugin>
+ -->
</plugins>
</build>
Modified: felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java?rev=1739118&r1=1739117&r2=1739118&view=diff
==============================================================================
--- felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java (original)
+++ felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java Thu Apr 14 14:18:26 2016
@@ -1838,7 +1838,8 @@ public class BundlePlugin extends Abstra
// Add default plugins
header( properties, Analyzer.PLUGIN, BlueprintPlugin.class.getName() + ","
- + SpringXMLType.class.getName() );
+ + SpringXMLType.class.getName() + ","
+ + JpaPlugin.class.getName() );
return properties;
}
Added: felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/JpaPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/JpaPlugin.java?rev=1739118&view=auto
==============================================================================
--- felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/JpaPlugin.java (added)
+++ felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/JpaPlugin.java Thu Apr 14 14:18:26 2016
@@ -0,0 +1,175 @@
+/*
+ * 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 javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import aQute.bnd.header.Attrs;
+import aQute.bnd.osgi.Analyzer;
+import aQute.bnd.osgi.Descriptors.PackageRef;
+import aQute.bnd.osgi.Jar;
+import aQute.bnd.osgi.Processor;
+import aQute.bnd.osgi.Resource;
+import aQute.bnd.service.AnalyzerPlugin;
+import aQute.libg.generics.Create;
+import org.apache.felix.utils.manifest.Attribute;
+import org.apache.felix.utils.manifest.Clause;
+import org.osgi.framework.Constants;
+
+import static org.apache.felix.utils.manifest.Parser.parseHeader;
+
+
+public class JpaPlugin implements AnalyzerPlugin
+{
+
+ Transformer transformer;
+
+
+ public JpaPlugin() throws Exception
+ {
+ transformer = getTransformer( getClass().getResource( "jpa.xsl" ) );
+ }
+
+
+ public boolean analyzeJar( Analyzer analyzer ) throws Exception
+ {
+ Set<String> headers = Create.set();
+
+ String mpHeader = analyzer.getProperty( "Meta-Persistence" );
+
+ transformer.setParameter( "jpa-enable", analyzer.getProperty( "jpa-enable", "true" ) );
+ transformer.setParameter( "jpa-implementation", analyzer.getProperty( "jpa-implementation", "aries" ) );
+ transformer.setParameter( "jpa-datasource-req", analyzer.getProperty( "jpa-datasource-req", "true" ) );
+
+ Map<String, ? extends Map<String, String>> map = Processor.parseHeader( mpHeader, null );
+ for ( String root : map.keySet() )
+ {
+ Resource resource = analyzer.getJar().getResource(root);
+ if ( resource != null ) {
+ process(analyzer, root, resource, headers);
+ }
+ }
+
+ // Group and analyze
+ for ( String str : headers )
+ {
+ int idx = str.indexOf( ':' );
+ if ( idx < 0 )
+ {
+ analyzer.warning( ( new StringBuilder( "Error analyzing services in scr resource: " ) ).append( str ).toString() );
+ continue;
+ }
+ String h = str.substring( 0, idx ).trim();
+ String v = str.substring( idx + 1 ).trim();
+
+ StringBuilder sb = new StringBuilder();
+ String header = analyzer.getProperty( h );
+ if (header != null && !header.isEmpty())
+ {
+ sb.append(header);
+ sb.append(",");
+ }
+ sb.append( v );
+ analyzer.setProperty(h, sb.toString());
+ }
+ return false;
+ }
+
+
+ private void process( Analyzer analyzer, String path, Resource resource, Set<String> headers )
+ {
+ InputStream in = null;
+ try
+ {
+ in = resource.openInputStream();
+
+ // Retrieve headers
+ Set<String> set = analyze( in );
+System.err.println("Output: " + set.toString());
+ headers.addAll( set );
+ }
+ catch ( Exception e )
+ {
+ analyzer.error( ( new StringBuilder( "Unexpected exception in processing spring resources(" ) )
+ .append( path ).append( "): " ).append( e ).toString() );
+ }
+ finally
+ {
+ try
+ {
+ if ( in != null )
+ {
+ in.close();
+ }
+ }
+ catch ( IOException e )
+ {
+ }
+ }
+ }
+
+
+ public Set<String> analyze( InputStream in ) throws Exception
+ {
+ Set<String> refers = new HashSet<String>();
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ javax.xml.transform.Result r = new StreamResult( bout );
+ javax.xml.transform.Source s = new StreamSource( in );
+ transformer.transform( s, r );
+ ByteArrayInputStream bin = new ByteArrayInputStream( bout.toByteArray() );
+ bout.close();
+ BufferedReader br = new BufferedReader( new InputStreamReader( bin ) );
+ for ( String line = br.readLine(); line != null; line = br.readLine() )
+ {
+ line = line.trim();
+ if ( line.length() > 0 )
+ {
+ refers.add( line );
+ }
+ }
+
+ br.close();
+ return refers;
+ }
+
+
+ protected Transformer getTransformer( URL url ) throws Exception
+ {
+ TransformerFactory tf = TransformerFactory.newInstance();
+ javax.xml.transform.Source source = new StreamSource( url.openStream() );
+ return tf.newTransformer( source );
+ }
+
+}
Added: felix/trunk/tools/maven-bundle-plugin/src/main/resources/org/apache/felix/bundleplugin/jpa.xsl
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven-bundle-plugin/src/main/resources/org/apache/felix/bundleplugin/jpa.xsl?rev=1739118&view=auto
==============================================================================
--- felix/trunk/tools/maven-bundle-plugin/src/main/resources/org/apache/felix/bundleplugin/jpa.xsl (added)
+++ felix/trunk/tools/maven-bundle-plugin/src/main/resources/org/apache/felix/bundleplugin/jpa.xsl Thu Apr 14 14:18:26 2016
@@ -0,0 +1,151 @@
+<?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.
+
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:jpa="http://java.sun.com/xml/ns/persistence">
+
+ <xsl:output method="text" />
+
+ <!-- Transformer properties -->
+ <xsl:param name="jpa-enable"/>
+ <xsl:param name="jpa-implementation"/>
+ <xsl:param name="jpa-datasource-req"/>
+
+ <xsl:variable name="nl">
+ <xsl:text>
</xsl:text>
+ </xsl:variable>
+
+ <xsl:template match="/">
+ <xsl:if test="$jpa-enable = 'true'">
+
+ <xsl:for-each select="//jpa:persistence-unit">
+ <xsl:variable name="attrs" select="concat('osgi.unit.name="', @name, '"')"/>
+ <!-- Standard interfaces -->
+ <xsl:call-template name="service-capability">
+ <xsl:with-param name="interface" select="'javax.persistence.EntityManager'"/>
+ <xsl:with-param name="attributes" select="$attrs"/>
+ </xsl:call-template>
+ <xsl:call-template name="service-capability">
+ <xsl:with-param name="interface" select="'javax.persistence.EntityManagerFactory'"/>
+ <xsl:with-param name="attributes" select="$attrs"/>
+ </xsl:call-template>
+ <!-- Aries JPA specific interfaces -->
+ <xsl:if test="$jpa-implementation = 'aries'">
+ <xsl:call-template name="service-capability">
+ <xsl:with-param name="interface" select="'org.apache.aries.jpa.template.JpaTemplate'"/>
+ <xsl:with-param name="attributes" select="$attrs"/>
+ </xsl:call-template>
+ <xsl:call-template name="service-capability">
+ <xsl:with-param name="interface" select="'org.apache.aries.jpa.supplier.EmSupplier'"/>
+ <xsl:with-param name="attributes" select="$attrs"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:for-each>
+
+ <xsl:if test="$jpa-implementation = 'aries'">
+ <xsl:text>
+ Require-Capability: osgi.extender;osgi.extender=aries.jpa
+ </xsl:text>
+ </xsl:if>
+
+ <!-- Service requirement for the provider -->
+ <xsl:for-each select="//jpa:persistence-unit/jpa:provider">
+ <xsl:call-template name="service-requirement">
+ <xsl:with-param name="interface" select="'javax.persistence.spi.PersistenceProvider'"/>
+ <xsl:with-param name="attributes" select="concat('javax.persistence.provider=', text())"/>
+ </xsl:call-template>
+ </xsl:for-each>
+
+ <xsl:if test="//jpa:persistence-unit/jpa:provider[text()='org.hibernate.jpa.HibernatePersistenceProvider']">
+ <xsl:text>
+ Import-Package: org.hibernate.proxy;javassist.util.proxy;resolution:=optional
+ DynamicImport-Package: org.hibernate.proxy;javassist.util.proxy
+ </xsl:text>
+ </xsl:if>
+
+ <xsl:if test="//jpa:persistence-unit[@transaction-type='JTA']">
+ <xsl:call-template name="service-requirement">
+ <xsl:with-param name="interface" select="'javax.transaction.TransactionManager'"/>
+ </xsl:call-template>
+ </xsl:if>
+
+ <!-- DataSource requirement -->
+ <xsl:if test="$jpa-datasource-req = 'true'">
+ <xsl:for-each select="//jpa:persistence-unit[@transaction-type='JTA']/jpa:jta-data-source">
+ <xsl:if test="starts-with(text(), 'osgi:service/')">
+ <xsl:variable name="rem1" select="substring-after(text(), '/')"/>
+ <xsl:variable name="rem2" select="substring-before($rem1, '/')"/>
+ <xsl:variable name="rem3" select="substring-after($rem1, '/')"/>
+ <xsl:call-template name="service-requirement">
+ <xsl:with-param name="interface" select="$rem2" />
+ <xsl:with-param name="attributes">
+ <xsl:if test="string-length($rem3) > 0">
+ <xsl:value-of select="concat('filter:="', $rem3, '"')"/>
+ </xsl:if>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:for-each select="//jpa:persistence-unit[@transaction-type='RESOURCE_LOCAL']/jpa:non-jta-data-source">
+ <xsl:if test="starts-with(text(), 'osgi:service/')">
+ <xsl:variable name="rem1" select="substring-after(text(), '/')"/>
+ <xsl:variable name="rem2" select="substring-before($rem1, '/')"/>
+ <xsl:variable name="rem3" select="substring-after($rem1, '/')"/>
+ <xsl:call-template name="service-requirement">
+ <xsl:with-param name="interface" select="$rem2" />
+ <xsl:with-param name="attributes">
+ <xsl:if test="string-length($rem3) > 0">
+ <xsl:value-of select="concat('filter:="', $rem3, '"')"/>
+ </xsl:if>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:for-each select="//jpa:persistence-unit[count(jpa:jta-data-source) + count(jpa:non-jta-data-source) = 0]/jpa:properties/jpa:property[@name='javax.persistence.jdbc.driver']">
+ <xsl:call-template name="service-requirement">
+ <xsl:with-param name="interface" select="'org.osgi.service.jdbc.DataSourceFactory'" />
+ <xsl:with-param name="attributes">
+ <xsl:value-of select="concat('osgi.jdbc.driver.class=', @value)"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:if>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template name="service-capability">
+ <xsl:param name="interface"/>
+ <xsl:param name="attributes" select="''"/>
+ <xsl:value-of select="concat('Provide-Capability: osgi.service;effective:=active;',
+ 'objectClass=', $interface, ';',
+ $attributes,
+ $nl)"/>
+ </xsl:template>
+
+ <xsl:template name="service-requirement">
+ <xsl:param name="interface"/>
+ <xsl:param name="attributes" select="''"/>
+ <xsl:value-of select="concat('Require-Capability: osgi.service;effective:=active;',
+ 'objectClass=', $interface, ';',
+ $attributes,
+ $nl)"/>
+ </xsl:template>
+
+</xsl:stylesheet>
+