You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2007/02/14 18:36:00 UTC
svn commit: r507635 - in
/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src:
main/java/org/apache/servicemix/maven/plugin/jbi/ test/ test/java/
test/java/org/ test/java/org/apache/ test/java/org/apache/servicemix/
test/java/org/apache/servicemix/...
Author: gnodet
Date: Wed Feb 14 09:35:54 2007
New Revision: 507635
URL: http://svn.apache.org/viewvc?view=rev&rev=507635
Log:
SM-829: Incorrect file encoding of create jbi.xml
Added:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/apache/
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/apache/servicemix/
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/apache/servicemix/maven/
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/apache/servicemix/maven/plugin/
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/apache/servicemix/maven/plugin/jbi/
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriterTest.java (with props)
Modified:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceAssemblyDescriptorWriter.java
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriter.java
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiSharedLibraryDescriptorWriter.java
Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java?view=diff&rev=507635&r1=507634&r2=507635
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java (original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java Wed Feb 14 09:35:54 2007
@@ -17,8 +17,8 @@
package org.apache.servicemix.maven.plugin.jbi;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
+import java.io.PrintWriter;
import java.io.Writer;
import java.util.Iterator;
import java.util.List;
@@ -39,9 +39,9 @@
String componentClassLoaderDelegation, String bootstrapClassLoaderDelegation,
List uris)
throws JbiPluginException {
- FileWriter w;
+ PrintWriter w;
try {
- w = new FileWriter(descriptor);
+ w = new PrintWriter(descriptor, encoding);
} catch (IOException ex) {
throw new JbiPluginException("Exception while opening file["
+ descriptor.getAbsolutePath() + "]", ex);
Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceAssemblyDescriptorWriter.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceAssemblyDescriptorWriter.java?view=diff&rev=507635&r1=507634&r2=507635
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceAssemblyDescriptorWriter.java (original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceAssemblyDescriptorWriter.java Wed Feb 14 09:35:54 2007
@@ -17,8 +17,8 @@
package org.apache.servicemix.maven.plugin.jbi;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
+import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
@@ -44,9 +44,9 @@
public void write(File descriptor, String name, String description,
List uris, List connections) throws JbiPluginException {
- FileWriter w;
+ PrintWriter w;
try {
- w = new FileWriter(descriptor);
+ w = new PrintWriter(descriptor, encoding);
} catch (IOException ex) {
throw new JbiPluginException("Exception while opening file["
+ descriptor.getAbsolutePath() + "]", ex);
Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriter.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriter.java?view=diff&rev=507635&r1=507634&r2=507635
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriter.java (original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriter.java Wed Feb 14 09:35:54 2007
@@ -17,8 +17,8 @@
package org.apache.servicemix.maven.plugin.jbi;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
+import java.io.PrintWriter;
import java.io.Writer;
import java.util.Iterator;
import java.util.List;
@@ -43,9 +43,9 @@
public void write(File descriptor, boolean bc, String name, String description,
List uris, List consumes, List provides) throws JbiPluginException {
- FileWriter w;
+ PrintWriter w;
try {
- w = new FileWriter(descriptor);
+ w = new PrintWriter(descriptor, encoding);
} catch (IOException ex) {
throw new JbiPluginException("Exception while opening file["
+ descriptor.getAbsolutePath() + "]", ex);
Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiSharedLibraryDescriptorWriter.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiSharedLibraryDescriptorWriter.java?view=diff&rev=507635&r1=507634&r2=507635
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiSharedLibraryDescriptorWriter.java (original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiSharedLibraryDescriptorWriter.java Wed Feb 14 09:35:54 2007
@@ -17,8 +17,8 @@
package org.apache.servicemix.maven.plugin.jbi;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
+import java.io.PrintWriter;
import java.io.Writer;
import java.util.Iterator;
import java.util.List;
@@ -41,9 +41,9 @@
public void write(File descriptor, String name, String description,
String version, String classLoaderDelegation, List uris)
throws JbiPluginException {
- FileWriter w;
+ PrintWriter w;
try {
- w = new FileWriter(descriptor);
+ w = new PrintWriter(descriptor, encoding);
} catch (IOException ex) {
throw new JbiPluginException("Exception while opening file["
+ descriptor.getAbsolutePath() + "]", ex);
Added: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriterTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriterTest.java?view=auto&rev=507635
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriterTest.java (added)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriterTest.java Wed Feb 14 09:35:54 2007
@@ -0,0 +1,183 @@
+/*
+ * 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.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.common.packaging.Consumes;
+import org.apache.servicemix.common.packaging.Provides;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class JbiServiceUnitDescriptorWriterTest extends TestCase {
+
+ private static final String ENCODING_UTF8 = "UTF-8";
+ private static final String ENCODING_ISO88591 = "ISO-8859-1";
+ private static final String JBI_NAMESPACE = "http://java.sun.com/xml/ns/jbi";
+
+ //TODO: how to fetch the build directory ('./target') from Maven property?
+ private String generatedDescriptorLocation = "./target/test-outputs";
+
+ private File outputDir;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.outputDir = new File(generatedDescriptorLocation);
+ if (!this.outputDir.exists()) {
+ this.outputDir.mkdirs();
+ }
+ }
+
+ public void testUTF8EncodingWrite()
+ throws Exception {
+ File descriptor = new File(outputDir, "jbi-su-UTF8.xml");
+
+ String xmlEncoding = ENCODING_UTF8;
+ writeDescriptor(descriptor, xmlEncoding);
+ verifyDescriptor(descriptor, xmlEncoding);
+ }
+
+ public void testISO88591EncodingWrite()
+ throws Exception {
+ File descriptor = new File(outputDir, "jbi-su-ISO88591.xml");
+
+ String xmlEncoding = ENCODING_ISO88591;
+ writeDescriptor(descriptor, xmlEncoding);
+ verifyDescriptor(descriptor, xmlEncoding);
+ }
+
+ private void writeDescriptor(File descriptor, String encoding)
+ throws JbiPluginException {
+ List consumes = new ArrayList();
+ List provides = new ArrayList();
+
+ QName serviceName = new QName("http://test.com/encoding", "abcåäö");
+
+ Consumes newConsumes = new Consumes();
+ newConsumes.setServiceName(serviceName);
+ newConsumes.setEndpointName("consumeråäö");
+ consumes.add(newConsumes);
+
+ Provides newProvides = new Provides();
+ newProvides.setServiceName(serviceName);
+ newProvides.setEndpointName("provideråäö");
+ provides.add(newProvides);
+
+ JbiServiceUnitDescriptorWriter writer = new JbiServiceUnitDescriptorWriter(
+ encoding);
+ writer.write(descriptor, false, "name", "description", new ArrayList(), consumes,
+ provides);
+ }
+
+ private void verifyDescriptor(File descriptor, String expectedXmlEncoding) throws Exception {
+ Document doc = getDocument(descriptor);
+ assertEquals(doc.getXmlEncoding(), expectedXmlEncoding);
+
+ Element serviceElement = getServicesElement(doc);
+
+ List consumes = getConsumes(serviceElement);
+ Consumes con = (Consumes) consumes.get(0);
+ assertEquals(con.getServiceName().getLocalPart(), "abcåäö");
+ assertEquals(con.getEndpointName(), "consumeråäö");
+
+ List provides = getProvides(serviceElement);
+ Provides prov = (Provides) provides.get(0);
+ assertEquals(prov.getServiceName().getLocalPart(), "abcåäö");
+ assertEquals(prov.getEndpointName(), "provideråäö");
+ }
+
+ private Document getDocument(File jbiServicesFile) throws Exception {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document doc = db.parse(jbiServicesFile);
+
+ return doc;
+ }
+
+ private Element getServicesElement(Document doc) throws Exception {
+ Node jbiNode = doc.getFirstChild();
+ assertTrue(XmlDescriptorHelper.isElement(jbiNode, JBI_NAMESPACE, "jbi"));
+ Node tmpNode = jbiNode.getFirstChild();
+ while (true) {
+ assertNotNull(tmpNode);
+ if (XmlDescriptorHelper.isElement(tmpNode, JBI_NAMESPACE,
+ "services")) {
+ return (Element) tmpNode;
+ } else {
+ tmpNode = tmpNode.getNextSibling();
+ }
+ }
+ }
+
+ private List getConsumes(Element servicesElement) throws Exception {
+ List consumes = new ArrayList();
+ 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);
+ }
+ }
+ }
+
+ return consumes;
+ }
+
+ private List getProvides(Element servicesElement) throws Exception {
+ List provides = new ArrayList();
+ 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,
+ "provides")) {
+ Provides newProvides = new Provides();
+ newProvides.setEndpointName(XmlDescriptorHelper
+ .getEndpointName(childElement));
+ newProvides.setInterfaceName(XmlDescriptorHelper
+ .getInterfaceName(childElement));
+ newProvides.setServiceName(XmlDescriptorHelper
+ .getServiceName(childElement));
+ provides.add(newProvides);
+ }
+ }
+ }
+
+ return provides;
+ }
+}
Propchange: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriterTest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriterTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain