ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gscok...@apache.org
Subject svn commit: r661275 - in /ant/ivy/core/trunk: CHANGES.txt src/java/org/apache/ivy/plugins/report/XmlReportWriter.java test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java test/repositories/1/special-encoding-root-ivy.xml
Date Thu, 29 May 2008 09:55:27 GMT
Author: gscokart
Date: Thu May 29 02:55:26 2008
New Revision: 661275

URL: http://svn.apache.org/viewvc?rev=661275&view=rev
Log:
Fix the encoding used in XML reports (IVY-816)

Added:
    ant/ivy/core/trunk/test/repositories/1/special-encoding-root-ivy.xml   (with props)
Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=661275&r1=661274&r2=661275&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Thu May 29 02:55:26 2008
@@ -123,6 +123,7 @@
 - FIX: Classpath issues with vfs ftp while being used as a bundle (IVY-785)
 - FIX: Relative include in a settings must be evaluated relatively to the settings file (IVY-372)
 - FIX: The Bundle-Version is 0.0.0 in the build artifacts (IVY-802)
+- FIX: Fix the encoding used in XML reports (IVY-816)
 
 - DOCUMENTATION: Broken link in documentation in Ivy files section, info element page (IVY-788)
 - DOCUMENTATION: Add new cache information to resolver doc (IVY-772) (thanks to Carlton Brown)

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java?rev=661275&r1=661274&r2=661275&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java Thu May
29 02:55:26 2008
@@ -17,8 +17,11 @@
  */
 package org.apache.ivy.plugins.report;
 
+import java.io.BufferedWriter;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
@@ -46,6 +49,8 @@
  * XmlReportWriter allows to write ResolveReport in an xml format. 
  */
 public class XmlReportWriter {
+    
+    static final String REPORT_ENCODING = "ISO-8859-1";
 
     public void output(ConfigurationResolveReport report, OutputStream stream) {
         output(report, new String[] {report.getConfiguration()}, stream);
@@ -53,9 +58,16 @@
 
     public void output(
             ConfigurationResolveReport report, String[] confs, OutputStream stream) {
-        PrintWriter out = new PrintWriter(stream);
+        OutputStreamWriter encodedOutStream;
+        try {
+            encodedOutStream = new OutputStreamWriter(stream , REPORT_ENCODING);
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(REPORT_ENCODING + " is not known on your jvm" , e);
+        }
+        PrintWriter out = new PrintWriter(new BufferedWriter(encodedOutStream));
         ModuleRevisionId mrid = report.getModuleDescriptor().getModuleRevisionId();
-        out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
+        //out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
+        out.println("<?xml version=\"1.0\" encoding=\"" + REPORT_ENCODING + "\"?>");
         out.println("<?xml-stylesheet type=\"text/xsl\" href=\"ivy-report.xsl\"?>");
         out.println("<ivy-report version=\"1.0\">");
         out.println("\t<info");

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java?rev=661275&r1=661274&r2=661275&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java Thu
May 29 02:55:26 2008
@@ -17,6 +17,7 @@
  */
 package org.apache.ivy.plugins.report;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 
@@ -27,6 +28,8 @@
 import org.apache.ivy.core.report.ResolveReport;
 import org.apache.ivy.core.resolve.ResolveOptions;
 import org.apache.ivy.util.CacheCleaner;
+import org.apache.ivy.util.XMLHelper;
+import org.xml.sax.helpers.DefaultHandler;
 
 public class XmlReportWriterTest extends TestCase {
     private Ivy _ivy;
@@ -54,7 +57,7 @@
 
     public void testWriteOrigin() throws Exception {
         ResolveReport report = _ivy.resolve(new File(
-                "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
+                "test/repositories/1/special-encoding-root-ivy.xml").toURL(),
             getResolveOptions(new String[] {"default"}));
         assertNotNull(report);
 
@@ -62,17 +65,24 @@
         XmlReportWriter writer = new XmlReportWriter();
         writer.output(report.getConfigurationReport("default"), buffer);
         buffer.flush();
-        String xml = buffer.toString();
+        String xml = buffer.toString(XmlReportWriter.REPORT_ENCODING);
 
         String expectedLocation = "location=\""
                 + new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").getAbsolutePath()
                 + "\"";
         String expectedIsLocal = "is-local=\"true\"";
+        String expectedOrg = "organisation=\"spécial\"";
 
         assertTrue("XML doesn't contain artifact location attribute",
             xml.indexOf(expectedLocation) != -1);
         assertTrue("XML doesn't contain artifact is-local attribute",
             xml.indexOf(expectedIsLocal) != -1);
+        assertTrue("XML doesn't contain the organisation",
+            xml.indexOf(expectedOrg) != -1);
+        
+        //check that the XML is valid
+        XMLHelper.parse(new ByteArrayInputStream(buffer.toByteArray()), null,
+            new DefaultHandler(), null);
     }
 
     public void testEscapeXml() throws Exception {

Added: ant/ivy/core/trunk/test/repositories/1/special-encoding-root-ivy.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/repositories/1/special-encoding-root-ivy.xml?rev=661275&view=auto
==============================================================================
--- ant/ivy/core/trunk/test/repositories/1/special-encoding-root-ivy.xml (added)
+++ ant/ivy/core/trunk/test/repositories/1/special-encoding-root-ivy.xml Thu May 29 02:55:26
2008
@@ -0,0 +1,32 @@
+<?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.    
+-->
+<ivy-module version="1.0">
+	<info organisation="spécial"
+	       module="accünt"
+	       revision="1.0"
+	       status="integration"
+	       publication="20041101110000"
+	>
+		<description>éà</description>		
+	</info>
+	<dependencies>
+		<dependency org="org1" name="mod1.2" rev="2.0"/>
+	</dependencies>
+</ivy-module>

Propchange: ant/ivy/core/trunk/test/repositories/1/special-encoding-root-ivy.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message