felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1813543 - in /felix/trunk/tools/maven-bundle-plugin/src: main/resources/org/apache/felix/bundleplugin/jpa.xsl test/java/org/apache/felix/bundleplugin/JpaPluginTest.java
Date Fri, 27 Oct 2017 15:19:35 GMT
Author: gnodet
Date: Fri Oct 27 15:19:34 2017
New Revision: 1813543

URL: http://svn.apache.org/viewvc?rev=1813543&view=rev
Log:
[FELIX-5734] The plugin generates wrong service requirements when using a jndi name in jpa

Added:
    felix/trunk/tools/maven-bundle-plugin/src/test/java/org/apache/felix/bundleplugin/JpaPluginTest.java
Modified:
    felix/trunk/tools/maven-bundle-plugin/src/main/resources/org/apache/felix/bundleplugin/jpa.xsl

Modified: 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=1813543&r1=1813542&r2=1813543&view=diff
==============================================================================
--- felix/trunk/tools/maven-bundle-plugin/src/main/resources/org/apache/felix/bundleplugin/jpa.xsl
(original)
+++ felix/trunk/tools/maven-bundle-plugin/src/main/resources/org/apache/felix/bundleplugin/jpa.xsl
Fri Oct 27 15:19:34 2017
@@ -92,14 +92,16 @@
                         <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:=&quot;',
$rem3, '&quot;')"/>
-                                </xsl:if>
-                            </xsl:with-param>
-                        </xsl:call-template>
+                        <xsl:if test="true or contains($rem2, '.')">
+                            <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:=&quot;',
$rem3, '&quot;')"/>
+                                    </xsl:if>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:if>
                     </xsl:if>
                 </xsl:for-each>
                 <xsl:for-each select="//jpa:persistence-unit[@transaction-type='RESOURCE_LOCAL']/jpa:non-jta-data-source">
@@ -107,14 +109,16 @@
                         <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:=&quot;',
$rem3, '&quot;')"/>
-                                </xsl:if>
-                            </xsl:with-param>
-                        </xsl:call-template>
+                        <xsl:if test="true or contains($rem2, '.')">
+                            <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:=&quot;',
$rem3, '&quot;')"/>
+                                    </xsl:if>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:if>
                     </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']">

Added: felix/trunk/tools/maven-bundle-plugin/src/test/java/org/apache/felix/bundleplugin/JpaPluginTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven-bundle-plugin/src/test/java/org/apache/felix/bundleplugin/JpaPluginTest.java?rev=1813543&view=auto
==============================================================================
--- felix/trunk/tools/maven-bundle-plugin/src/test/java/org/apache/felix/bundleplugin/JpaPluginTest.java
(added)
+++ felix/trunk/tools/maven-bundle-plugin/src/test/java/org/apache/felix/bundleplugin/JpaPluginTest.java
Fri Oct 27 15:19:34 2017
@@ -0,0 +1,72 @@
+/*
+ * 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 aQute.bnd.osgi.AbstractResource;
+import aQute.bnd.osgi.Analyzer;
+import aQute.bnd.osgi.Jar;
+import aQute.bnd.osgi.Resource;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class JpaPluginTest {
+
+    @Test
+    public void testNamedJndi() throws Exception {
+        String xmlStr = "<persistence xmlns='http://java.sun.com/xml/ns/persistence'>\n"
+
+                        "    <persistence-unit name='the-unit' transaction-type='JTA'>\n"
+
+                        "        <jta-data-source>osgi:service/jdbc/h2DS</jta-data-source>\n"
+
+                        "    </persistence-unit>\n" +
+                        "</persistence>";
+        String expectedReqs = "osgi.extender;osgi.extender=aries.jpa,osgi.service;effective:=active;objectClass=javax.transaction.TransactionManager;";
+        assertTransformation(xmlStr, expectedReqs);
+    }
+
+    @Test
+    public void testService() throws Exception {
+        String xmlStr = "<persistence xmlns='http://java.sun.com/xml/ns/persistence'>\n"
+
+                        "    <persistence-unit name='the-unit' transaction-type='JTA'>\n"
+
+                        "        <jta-data-source>osgi:service/javax.sql.DataSource/(&amp;(db=mydb)(version=3.1))</jta-data-source>\n"
+
+                        "    </persistence-unit>\n" +
+                        "</persistence>";
+        String expectedReqs = "osgi.extender;osgi.extender=aries.jpa,osgi.service;effective:=active;objectClass=javax.sql.DataSource;filter:=\"(&(db=mydb)(version=3.1))\",osgi.service;effective:=active;objectClass=javax.transaction.TransactionManager;";
+        assertTransformation(xmlStr, expectedReqs);
+    }
+
+    private void assertTransformation(final String xmlStr, String expectedReqs) throws Exception
{
+        Analyzer analyzer = new Analyzer();
+        Jar jar = new Jar("the-jar");
+        Resource xml = new AbstractResource(0) {
+            @Override
+            protected byte[] getBytes() throws Exception {
+                return xmlStr.getBytes();
+            }
+        };
+        JpaPlugin plugin = new JpaPlugin();
+
+        jar.putResource("the-persistence-xml", xml);
+        analyzer.setJar(jar);
+        analyzer.setProperty("Meta-Persistence", "the-persistence-xml");
+
+        plugin.analyzeJar(analyzer);
+
+        assertEquals(expectedReqs, analyzer.getProperty("Require-Capability"));
+    }
+}



Mime
View raw message