Return-Path: X-Original-To: apmail-aries-commits-archive@www.apache.org Delivered-To: apmail-aries-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C0BFF18BA9 for ; Tue, 12 Jan 2016 13:42:47 +0000 (UTC) Received: (qmail 85444 invoked by uid 500); 12 Jan 2016 13:42:47 -0000 Delivered-To: apmail-aries-commits-archive@aries.apache.org Received: (qmail 85376 invoked by uid 500); 12 Jan 2016 13:42:47 -0000 Mailing-List: contact commits-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list commits@aries.apache.org Received: (qmail 85365 invoked by uid 99); 12 Jan 2016 13:42:47 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jan 2016 13:42:47 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 1C60FC16B3 for ; Tue, 12 Jan 2016 13:42:47 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.246 X-Spam-Level: * X-Spam-Status: No, score=1.246 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.554] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id cq0FkU1z8hiI for ; Tue, 12 Jan 2016 13:42:44 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTP id C86FF258C7 for ; Tue, 12 Jan 2016 13:42:43 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id E41E0E0361 for ; Tue, 12 Jan 2016 13:42:42 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id E34033A0176 for ; Tue, 12 Jan 2016 13:42:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1724231 - in /aries/trunk/blueprint/blueprint-maven-plugin/src: main/java/org/apache/aries/blueprint/plugin/ test/java/org/apache/aries/blueprint/plugin/ test/java/org/apache/aries/blueprint/plugin/test/ Date: Tue, 12 Jan 2016 13:42:42 -0000 To: commits@aries.apache.org From: cschneider@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160112134242.E34033A0176@svn01-us-west.apache.org> Author: cschneider Date: Tue Jan 12 13:42:42 2016 New Revision: 1724231 URL: http://svn.apache.org/viewvc?rev=1724231&view=rev Log: [ARIES-1476] Support 0 or multiple OsgiServiceProvider#classes. - 0 classes adds auto-export="interfaces" to the service element - multiple classes adds the interfaces (e.g. A and B) to the interfaces element: A B Added: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceABImpl.java aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceAImpl3.java Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceProviderWriter.java aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceProviderWriter.java URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceProviderWriter.java?rev=1724231&r1=1724230&r2=1724231&view=diff ============================================================================== --- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceProviderWriter.java (original) +++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceProviderWriter.java Tue Jan 12 13:42:42 2016 @@ -19,6 +19,7 @@ package org.apache.aries.blueprint.plugin; import java.util.Collection; +import java.util.List; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; @@ -28,6 +29,9 @@ import org.ops4j.pax.cdi.api.OsgiService import org.ops4j.pax.cdi.api.Properties; import org.ops4j.pax.cdi.api.Property; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + public class OsgiServiceProviderWriter { private XMLStreamWriter writer; @@ -40,30 +44,64 @@ public class OsgiServiceProviderWriter { write(bean); } } - + public void write(Bean bean) throws XMLStreamException { OsgiServiceProvider serviceProvider = bean.clazz.getAnnotation(OsgiServiceProvider.class); if (serviceProvider == null) { return; } - if (serviceProvider.classes().length == 0) { - throw new IllegalArgumentException("Need to provide the interface class in the @OsgiServiceProvider(classes={...}) annotation on " + bean.clazz); - } + Properties properties = bean.clazz.getAnnotation(Properties.class); - if (properties == null) { + List interfaceNames = Lists.newArrayList(); + for (Class serviceIf : serviceProvider.classes()) { + interfaceNames.add(serviceIf.getName()); + } + + // If there are no properties to write and only one service attribute (either + // interface="MyServiceInterface" or auto-export="interfaces") then create an + // empty element + boolean writeEmptyElement = properties == null && interfaceNames.size() < 2; + if (writeEmptyElement) { writer.writeEmptyElement("service"); } else { writer.writeStartElement("service"); } writer.writeAttribute("ref", bean.id); - Class serviceIf = serviceProvider.classes()[0]; - writer.writeAttribute("interface", serviceIf.getName()); + + if (interfaceNames.size() == 0) { + writer.writeAttribute("auto-export", "interfaces"); + } else if (interfaceNames.size() == 1) { + writer.writeAttribute("interface", Iterables.getOnlyElement(interfaceNames)); + } else { + writeInterfacesElement(interfaceNames); + } + writer.writeCharacters("\n"); if (properties != null) { writeProperties(properties); + } + + if (!writeEmptyElement) { + writer.writeEndElement(); + writer.writeCharacters("\n"); + } + } + + private void writeInterfacesElement(Iterable interfaceNames) throws XMLStreamException + { + writer.writeCharacters("\n"); + writer.writeCharacters(" "); + writer.writeStartElement("interfaces"); + writer.writeCharacters("\n"); + for (String interfaceName : interfaceNames) { + writer.writeCharacters(" "); + writer.writeStartElement("value"); + writer.writeCharacters(interfaceName); writer.writeEndElement(); writer.writeCharacters("\n"); } + writer.writeCharacters(" "); + writer.writeEndElement(); } private void writeProperties(Properties properties) throws XMLStreamException { Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java?rev=1724231&r1=1724230&r2=1724231&view=diff ============================================================================== --- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java (original) +++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java Tue Jan 12 13:42:42 2016 @@ -38,6 +38,8 @@ import javax.xml.xpath.XPathFactory; import org.apache.aries.blueprint.plugin.model.Context; import org.apache.aries.blueprint.plugin.model.TransactionalDef; import org.apache.aries.blueprint.plugin.test.MyBean1; +import org.apache.aries.blueprint.plugin.test.ServiceA; +import org.apache.aries.blueprint.plugin.test.ServiceB; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.xbean.finder.ClassFinder; import org.junit.Assert; @@ -105,6 +107,31 @@ public class GeneratorTest { // @Autowired Assert.assertEquals("my1", xpath.evaluate("property[@name='bean2']/@ref", bean1)); + // Service with 1 interface + Node serviceAImpl2 = (Node) xpath.evaluate("/blueprint/service[@ref='my2']", document, XPathConstants.NODE); + Assert.assertEquals(ServiceA.class.getName(), xpath.evaluate("@interface", serviceAImpl2)); + Assert.assertEquals("", xpath.evaluate("@auto-export", serviceAImpl2)); + Assert.assertEquals("", xpath.evaluate("interfaces", serviceAImpl2)); + + // Service with 0 interfaces (using auto-export=interfaces instead) + Node serviceAImpl3 = (Node) xpath.evaluate("/blueprint/service[@ref='serviceAImpl3']", document, XPathConstants.NODE); + Assert.assertEquals("", xpath.evaluate("@interface", serviceAImpl3)); + Assert.assertEquals("interfaces", xpath.evaluate("@auto-export", serviceAImpl3)); + Assert.assertEquals("", xpath.evaluate("interfaces", serviceAImpl3)); + + // Service with 2 interfaces (using ServiceAServiceB + Node serviceABImpl = (Node) xpath.evaluate("/blueprint/service[@ref='serviceABImpl']", document, XPathConstants.NODE); + Assert.assertEquals("", xpath.evaluate("@interface", serviceABImpl)); + Assert.assertEquals("", xpath.evaluate("@auto-export", serviceABImpl)); + + NodeList interfaceValues = (NodeList) xpath.evaluate("interfaces/value", serviceABImpl, XPathConstants.NODESET); + Set interfaceNames = new HashSet(); + for (int i = 0; i < interfaceValues.getLength(); ++i) { + Node interfaceValue = interfaceValues.item(i); + interfaceNames.add(interfaceValue.getTextContent()); + } + Assert.assertEquals(Sets.newHashSet(ServiceA.class.getName(), ServiceB.class.getName()), + interfaceNames); } private Document readToDocument(ByteArrayOutputStream os) throws ParserConfigurationException, Added: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceABImpl.java URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceABImpl.java?rev=1724231&view=auto ============================================================================== --- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceABImpl.java (added) +++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceABImpl.java Tue Jan 12 13:42:42 2016 @@ -0,0 +1,29 @@ +/** + * 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.aries.blueprint.plugin.test; + +import javax.inject.Singleton; + +import org.ops4j.pax.cdi.api.OsgiServiceProvider; + +@Singleton +@OsgiServiceProvider(classes = {ServiceA.class, ServiceB.class}) +public class ServiceABImpl implements ServiceA, ServiceB +{ +} Added: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceAImpl3.java URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceAImpl3.java?rev=1724231&view=auto ============================================================================== --- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceAImpl3.java (added) +++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceAImpl3.java Tue Jan 12 13:42:42 2016 @@ -0,0 +1,29 @@ +/** + * 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.aries.blueprint.plugin.test; + +import javax.inject.Singleton; + +import org.ops4j.pax.cdi.api.OsgiServiceProvider; + +@Singleton +@OsgiServiceProvider +public class ServiceAImpl3 implements ServiceA +{ +}