servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccust...@apache.org
Subject svn commit: r959208 - in /servicemix/maven-plugins/jbi-maven-plugin/trunk/src: main/java/org/apache/servicemix/maven/plugin/jbi/ test/java/org/apache/servicemix/maven/plugin/jbi/ test/resources/
Date Wed, 30 Jun 2010 06:14:28 GMT
Author: ccustine
Date: Wed Jun 30 06:14:28 2010
New Revision: 959208

URL: http://svn.apache.org/viewvc?rev=959208&view=rev
Log:
SM-1943 - jbi-maven-plugin does not process a jbi-services.xml file that has a comment node
as the first root node

Added:
    servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzerTest.java
    servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/resources/jbi-services.xml
Modified:
    servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java

Modified: servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java?rev=959208&r1=959207&r2=959208&view=diff
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java
(original)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java
Wed Jun 30 06:14:28 2010
@@ -1,111 +1,118 @@
-/*
- * 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.servicemix.maven.plugin.jbi;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.servicemix.common.packaging.Consumes;
-import org.apache.servicemix.common.packaging.Provides;
-import org.apache.servicemix.common.packaging.ServiceUnitAnalyzer;
-
-/**
- * A dummy implementation of the ServiceUnitAnalyzer that allows you to generate
- * the consumes and provides from a simple XML file
- * 
- */
-public class JbiServiceFileAnalyzer implements ServiceUnitAnalyzer {
-
-    public static final String JBI_NAMESPACE = "http://java.sun.com/xml/ns/jbi";
-
-    private List consumes = new ArrayList();
-
-    private List provides = new ArrayList();
-
-    public List getConsumes() {
-        return consumes;
-    }
-
-    public List getProvides() {
-        return provides;
-    }
-
-    public void init(File explodedServiceUnitRoot) {
-
-    }
-
-    public void setJbiServicesFile(File jbiServicesFile) throws MojoExecutionException {
-        parseXml(jbiServicesFile);
-    }
-
-    private void parseXml(File jbiServicesFile) throws MojoExecutionException {
-        try {
-            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-            dbf.setNamespaceAware(true);
-            DocumentBuilder db = dbf.newDocumentBuilder();
-            Document doc = db.parse(jbiServicesFile);
-
-            Node servicesNode = doc.getFirstChild();
-            if (XmlDescriptorHelper.isElement(servicesNode, JBI_NAMESPACE,
-                    "services")) {
-                // We will process the children
-                Element servicesElement = (Element) servicesNode;
-                NodeList children = servicesElement.getChildNodes();
-                for (int i = 0; i < children.getLength(); i++) {
-                    if (children.item(i) instanceof Element) {
-                        Element childElement = (Element) children.item(i);
-                        if (XmlDescriptorHelper.isElement(childElement,
-                                JBI_NAMESPACE, "consumes")) {
-                            Consumes newConsumes = new Consumes();
-                            newConsumes.setEndpointName(XmlDescriptorHelper
-                                    .getEndpointName(childElement));
-                            newConsumes.setInterfaceName(XmlDescriptorHelper
-                                    .getInterfaceName(childElement));
-                            newConsumes.setServiceName(XmlDescriptorHelper
-                                    .getServiceName(childElement));
-                            consumes.add(newConsumes);
-                        } else if (XmlDescriptorHelper.isElement(childElement,
-                                JBI_NAMESPACE, "provides")) {
-                            Provides newProvides = new Provides();
-                            newProvides.setEndpointName(XmlDescriptorHelper
-                                    .getEndpointName(childElement));
-                            newProvides.setInterfaceName(XmlDescriptorHelper
-                                    .getInterfaceName(childElement));
-                            newProvides.setServiceName(XmlDescriptorHelper
-                                    .getServiceName(childElement));
-                            provides.add(newProvides);
-                        }
-                    }
-                }
-            }
-
-        } catch (Exception e) {
-            throw new MojoExecutionException("Unable to parse "
-                    + jbiServicesFile.getAbsolutePath());
-        }
-    }
-}
+/*
+ * 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.servicemix.maven.plugin.jbi;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.servicemix.common.packaging.Consumes;
+import org.apache.servicemix.common.packaging.Provides;
+import org.apache.servicemix.common.packaging.ServiceUnitAnalyzer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * A dummy implementation of the ServiceUnitAnalyzer that allows you to generate
+ * the consumes and provides from a simple XML file
+ *
+ */
+public class JbiServiceFileAnalyzer implements ServiceUnitAnalyzer {
+
+    public static final String JBI_NAMESPACE = "http://java.sun.com/xml/ns/jbi";
+
+    private final List consumes = new ArrayList();
+
+    private final List provides = new ArrayList();
+
+    public List getConsumes() {
+        return consumes;
+    }
+
+    public List getProvides() {
+        return provides;
+    }
+
+    public void init(File explodedServiceUnitRoot) {
+
+    }
+
+    public void setJbiServicesFile(File jbiServicesFile) throws MojoExecutionException {
+        parseXml(jbiServicesFile);
+    }
+
+    private void parseXml(File jbiServicesFile) throws MojoExecutionException {
+        try {
+            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+            dbf.setNamespaceAware(true);
+            DocumentBuilder db = dbf.newDocumentBuilder();
+            Document doc = db.parse(jbiServicesFile);
+
+            // Stop at first services child node that is found
+            NodeList childNodes = doc.getChildNodes();
+            Node servicesNode = null;
+            for (int i = 0; i < childNodes.getLength(); i++) {
+                if (XmlDescriptorHelper.isElement(childNodes.item(i), JBI_NAMESPACE,
+                    "services")) {
+                    servicesNode = childNodes.item(i);
+                    break;
+                }
+            }
+            if (servicesNode != null) {
+                // We will process the children
+                Element servicesElement = (Element) servicesNode;
+                NodeList children = servicesElement.getChildNodes();
+                for (int i = 0; i < children.getLength(); i++) {
+                    if (children.item(i) instanceof Element) {
+                        Element childElement = (Element) children.item(i);
+                        if (XmlDescriptorHelper.isElement(childElement,
+                                JBI_NAMESPACE, "consumes")) {
+                            Consumes newConsumes = new Consumes();
+                            newConsumes.setEndpointName(XmlDescriptorHelper
+                                    .getEndpointName(childElement));
+                            newConsumes.setInterfaceName(XmlDescriptorHelper
+                                    .getInterfaceName(childElement));
+                            newConsumes.setServiceName(XmlDescriptorHelper
+                                    .getServiceName(childElement));
+                            consumes.add(newConsumes);
+                        } else if (XmlDescriptorHelper.isElement(childElement,
+                                JBI_NAMESPACE, "provides")) {
+                            Provides newProvides = new Provides();
+                            newProvides.setEndpointName(XmlDescriptorHelper
+                                    .getEndpointName(childElement));
+                            newProvides.setInterfaceName(XmlDescriptorHelper
+                                    .getInterfaceName(childElement));
+                            newProvides.setServiceName(XmlDescriptorHelper
+                                    .getServiceName(childElement));
+                            provides.add(newProvides);
+                        }
+                    }
+                }
+            }
+
+        } catch (Exception e) {
+            throw new MojoExecutionException("Unable to parse "
+                    + jbiServicesFile.getAbsolutePath());
+        }
+    }
+}

Added: servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzerTest.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzerTest.java?rev=959208&view=auto
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzerTest.java
(added)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzerTest.java
Wed Jun 30 06:14:28 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.servicemix.maven.plugin.jbi;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.common.packaging.Consumes;
+import org.apache.servicemix.common.packaging.Provides;
+
+/**
+ * Test case to exercise the default service file analyzer which uses a
+ * service.xml file.
+ */
+public class JbiServiceFileAnalyzerTest extends TestCase
+{
+    private static final File SERVICES_FILE = new File("./src/test/resources/jbi-services.xml");
+
+    /**
+     * Simple test to retrieve and parse a jbi-services.xml file
+     * @throws Exception
+     */
+    @SuppressWarnings("unchecked")
+    public void testParseServicesXml() throws Exception {
+        JbiServiceFileAnalyzer analyzer = new JbiServiceFileAnalyzer();
+        assertNotNull("analyzer should not be null", analyzer);
+
+        analyzer.setJbiServicesFile(SERVICES_FILE);
+        List<Consumes> consumes = analyzer.getConsumes();
+        List<Provides> provides = analyzer.getProvides();
+        assertNotNull("Consumes List should not be null", consumes);
+        assertNotNull("Provides List should not be null", provides);
+        assertTrue("Should be Empty consumes list", consumes.isEmpty());
+        assertFalse("Provides List should not be empty", provides.isEmpty());
+    }
+}

Added: servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/resources/jbi-services.xml
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/resources/jbi-services.xml?rev=959208&view=auto
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/resources/jbi-services.xml (added)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/resources/jbi-services.xml Wed
Jun 30 06:14:28 2010
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+          xmlns="http://java.sun.com/xml/ns/jbi"
+          xmlns:wf="http://www.novell.com/provisioning/service">
+<!--
+ ========================================================================
+
+ Test Copyright (c) 2010 blah blah blah
+
+ ========================================================================
+-->
+  <provides service-name="wf:ProvisioningService"
+            interface-name="wf:Provisioning"
+            endpoint-name="ServiceEngine_JBIPort" />
+</services>
+ 



Mime
View raw message