You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by de...@apache.org on 2011/01/01 18:41:56 UTC

svn commit: r1054263 - in /maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin: announcement/AnnouncementMojo.java jira/JiraMojo.java jira/JiraXML.java

Author: dennisl
Date: Sat Jan  1 17:41:56 2011
New Revision: 1054263

URL: http://svn.apache.org/viewvc?rev=1054263&view=rev
Log:
[MCHANGES-144] Add configuration if the encoding of JIRA xml file is not UTF-8.

Modified:
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraXML.java

Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java?rev=1054263&r1=1054262&r2=1054263&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java (original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java Sat Jan  1 17:41:56 2011
@@ -247,7 +247,7 @@ public class AnnouncementMojo
     private String resolutionIds;
 
     /**
-     * The path of the XML file of JIRA-announcements to be parsed.
+     * Path to the JIRA XML file, which will be parsed.
      *
      * @parameter expression="${project.build.directory}/jira-announcement.xml"
      * @required
@@ -256,6 +256,15 @@ public class AnnouncementMojo
     private File jiraXML;
 
     /**
+     * The encoding used in the JIRA XML file. You only need to change this if
+     * your JIRA server is returning responses in an encoding other than UTF-8.
+     *
+     * @parameter default-value="UTF-8" expression="${changes.jiraXmlEncoding}"
+     * @since 2.4
+     */
+    private String jiraXmlEncoding;
+
+    /**
      * The maximum number of issues to fetch from JIRA.
      * <p>
      * <b>Note:</b> In versions 2.0-beta-3 and earlier this parameter was
@@ -607,7 +616,7 @@ public class AnnouncementMojo
 
             if ( jiraXMLFile.exists() )
             {
-                JiraXML jiraParser = new JiraXML( jiraXMLFile );
+                JiraXML jiraParser = new JiraXML( jiraXMLFile, jiraXmlEncoding );
 
                 List issues = jiraParser.getIssueList();
 

Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java?rev=1054263&r1=1054262&r2=1054263&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java (original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java Sat Jan  1 17:41:56 2011
@@ -42,13 +42,22 @@ public class JiraMojo
     /**
      * Path to the JIRA XML file, which will be parsed.
      *
-     * @parameter expression="${project.build.directory}/jira-results.xml "
+     * @parameter expression="${project.build.directory}/jira-results.xml"
      * @required
      * @readonly
      */
     private File jiraXmlPath;
 
     /**
+     * The encoding used in the JIRA XML file. You only need to change this if
+     * your JIRA server is returning responses in an encoding other than UTF-8.
+     *
+     * @parameter default-value="UTF-8" expression="${changes.jiraXmlEncoding}"
+     * @since 2.4
+     */
+    private String jiraXmlEncoding;
+
+    /**
      * Settings XML configuration.
      *
      * @parameter expression="${settings}"
@@ -248,7 +257,7 @@ public class JiraMojo
 
             if ( jiraXmlPath.isFile() )
             {
-                JiraXML jira = new JiraXML( jiraXmlPath );
+                JiraXML jira = new JiraXML( jiraXmlPath, jiraXmlEncoding );
                 List issueList = jira.getIssueList();
 
                 report = new JiraReportGenerator( columnNames );

Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraXML.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraXML.java?rev=1054263&r1=1054262&r2=1054263&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraXML.java (original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraXML.java Sat Jan  1 17:41:56 2011
@@ -20,18 +20,16 @@ package org.apache.maven.plugin.jira;
  */
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
-import org.apache.maven.plugins.changes.model.Action;
-import org.apache.maven.plugins.changes.model.Release;
 import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
 
@@ -53,9 +51,10 @@ public class JiraXML
 
     private JiraIssue issue;
 
-    public JiraXML( File xmlPath )
+    public JiraXML( File xmlPath, String encoding )
     {
         SAXParserFactory factory = SAXParserFactory.newInstance();
+        FileInputStream fis = null;
 
         issueList = new ArrayList();
 
@@ -63,12 +62,30 @@ public class JiraXML
         {
             SAXParser saxParser = factory.newSAXParser();
 
-            saxParser.parse( xmlPath, this );
+            fis = new FileInputStream( xmlPath );
+            InputSource inputSource = new InputSource( fis );
+            inputSource.setEncoding( encoding );
+
+            saxParser.parse( inputSource, this );
         }
         catch ( Throwable t )
         {
             t.printStackTrace();
         }
+        finally
+        {
+            if ( fis != null )
+            {
+                try
+                {
+                    fis.close();
+                }
+                catch ( IOException e )
+                {
+                    // Ignore
+                }
+            }
+        }
     }
 
     public void startElement( String namespaceURI, String sName, String qName, Attributes attrs )



Re: svn commit: r1054263 - in /maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin: announcement/AnnouncementMojo.java jira/JiraMojo.java jira/JiraXML.java

Posted by Hervé BOUTEMY <he...@free.fr>.
I had a look both at the code and examples.

IMHO, the bug was in the way the Jira response was stored to the file using 
platform encoding, hence the different result when file.encoding value was set.
r1054373 is a fix for this problem.
I'm not absolutely sure if Jira content was properly generated, or if it was 
really generated with an encoding different from UTF-8 (yes, the HTTP header 
can't be trusted in this case), we'll need to wait for a real world test

Regards,

Hervé

Le samedi 1 janvier 2011, Dennis Lundberg a écrit :
> On 2011-01-01 19:52, Hervé BOUTEMY wrote:
> > Hi Dennis,
> > 
> > Like Benjamin wrote in the issue, a new parameter should not be necessary
> > since XML is declaring encoding: you just have tu use
> > ReaderFactory.newXmlReader() to avoid relying on the parser to detect
> > encoding.
> 
> Yes, I read Benjamin's comment.
> 
> > Such an argument is usefull only if Jira generates wrong XML, with
> > content not consistent with encoding declared in its prolog: such a case
> > would be a bug in Jira.
> 
> Unfortunately the RSS-feed files that the plugin downloads from JIRA
> doesn't have an XML prolog. They are encoded using the platform encoding
> of the JIRA server.
> 
> After doing some reading about file encoding, again, I came to the
> conclusion that it wasn't possible to establish the encoding of the
> downloaded files. See the two example files that are attached to the
> issue. If my assumption was wrong please let me know.
> 
> > Don't hesitate to ping me if this isn't clear (I know, encoding stays
> > bizarre for a lot of people :) )
> 
> It sure is, but I'll hopefully get it some of these days... Thanks
> 
> > Regards,
> > 
> > Hervé
> > 
> > Le samedi 1 janvier 2011, dennisl@apache.org a écrit :
> >> Author: dennisl
> >> Date: Sat Jan  1 17:41:56 2011
> >> New Revision: 1054263
> >> 
> >> URL: http://svn.apache.org/viewvc?rev=1054263&view=rev
> >> Log:
> >> [MCHANGES-144] Add configuration if the encoding of JIRA xml file is not
> >> UTF-8.
> >> 
> >> Modified:
> >> 
> >> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/
> >> pl ugin/announcement/AnnouncementMojo.java
> >> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/
> >> pl ugin/jira/JiraMojo.java
> >> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/
> >> pl ugin/jira/JiraXML.java
> >> 
> >> Modified:
> >> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/
> >> pl ugin/announcement/AnnouncementMojo.java URL:
> >> http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/sr
> >> c/
> >> main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java?re
> >> v=10 54263&r1=1054262&r2=1054263&view=diff
> >> ========================================================================
> >> == ==== ---
> >> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/
> >> pl ugin/announcement/AnnouncementMojo.java (original) +++
> >> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/
> >> pl ugin/announcement/AnnouncementMojo.java Sat Jan  1 17:41:56 2011 @@
> >> -247,7 +247,7 @@ public class AnnouncementMojo
> >> 
> >>      private String resolutionIds;
> >>      
> >>      /**
> >> 
> >> -     * The path of the XML file of JIRA-announcements to be parsed.
> >> +     * Path to the JIRA XML file, which will be parsed.
> >> 
> >>       *
> >>       * @parameter
> >> 
> >> expression="${project.build.directory}/jira-announcement.xml" *
> >> @required @@ -256,6 +256,15 @@ public class AnnouncementMojo
> >> 
> >>      private File jiraXML;
> >>      
> >>      /**
> >> 
> >> +     * The encoding used in the JIRA XML file. You only need to change
> >> this if +     * your JIRA server is returning responses in an encoding
> >> other than UTF-8. +     *
> >> +     * @parameter default-value="UTF-8"
> >> expression="${changes.jiraXmlEncoding}" +     * @since 2.4
> >> +     */
> >> +    private String jiraXmlEncoding;
> >> +
> >> +    /**
> >> 
> >>       * The maximum number of issues to fetch from JIRA.
> >>       * <p>
> >>       * <b>Note:</b> In versions 2.0-beta-3 and earlier this parameter
> >>       was
> >> 
> >> @@ -607,7 +616,7 @@ public class AnnouncementMojo
> >> 
> >>              if ( jiraXMLFile.exists() )
> >>              {
> >> 
> >> -                JiraXML jiraParser = new JiraXML( jiraXMLFile );
> >> +                JiraXML jiraParser = new JiraXML( jiraXMLFile,
> >> jiraXmlEncoding );
> >> 
> >>                  List issues = jiraParser.getIssueList();
> >> 
> >> Modified:
> >> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/
> >> pl ugin/jira/JiraMojo.java URL:
> >> http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/sr
> >> c/
> >> main/java/org/apache/maven/plugin/jira/JiraMojo.java?rev=1054263&r1=105
> >> 4262 &r2=1054263&view=diff
> >> ========================================================================
> >> == ==== ---
> >> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/
> >> pl ugin/jira/JiraMojo.java (original) +++
> >> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/
> >> pl ugin/jira/JiraMojo.java Sat Jan  1 17:41:56 2011 @@ -42,13 +42,22 @@
> >> public class JiraMojo
> >> 
> >>      /**
> >>      
> >>       * Path to the JIRA XML file, which will be parsed.
> >>       *
> >> 
> >> -     * @parameter
> >> expression="${project.build.directory}/jira-results.xml " +     *
> >> @parameter
> >> expression="${project.build.directory}/jira-results.xml" * @required
> >> 
> >>       * @readonly
> >>       */
> >>      
> >>      private File jiraXmlPath;
> >>      
> >>      /**
> >> 
> >> +     * The encoding used in the JIRA XML file. You only need to change
> >> this if +     * your JIRA server is returning responses in an encoding
> >> other than UTF-8. +     *
> >> +     * @parameter default-value="UTF-8"
> >> expression="${changes.jiraXmlEncoding}" +     * @since 2.4
> >> +     */
> >> +    private String jiraXmlEncoding;
> >> +
> >> +    /**
> >> 
> >>       * Settings XML configuration.
> >>       *
> >>       * @parameter expression="${settings}"
> >> 
> >> @@ -248,7 +257,7 @@ public class JiraMojo
> >> 
> >>              if ( jiraXmlPath.isFile() )
> >>              {
> >> 
> >> -                JiraXML jira = new JiraXML( jiraXmlPath );
> >> +                JiraXML jira = new JiraXML( jiraXmlPath,
> >> jiraXmlEncoding ); List issueList = jira.getIssueList();
> >> 
> >>                  report = new JiraReportGenerator( columnNames );
> >> 
> >> Modified:
> >> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/
> >> pl ugin/jira/JiraXML.java URL:
> >> http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/sr
> >> c/
> >> main/java/org/apache/maven/plugin/jira/JiraXML.java?rev=1054263&r1=1054
> >> 262& r2=1054263&view=diff
> >> ========================================================================
> >> == ==== ---
> >> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/
> >> pl ugin/jira/JiraXML.java (original) +++
> >> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/
> >> pl ugin/jira/JiraXML.java Sat Jan  1 17:41:56 2011 @@ -20,18 +20,16 @@
> >> package org.apache.maven.plugin.jira;
> >> 
> >>   */
> >>  
> >>  import java.io.File;
> >> 
> >> +import java.io.FileInputStream;
> >> +import java.io.IOException;
> >> 
> >>  import java.util.ArrayList;
> >> 
> >> -import java.util.HashMap;
> >> -import java.util.Iterator;
> >> 
> >>  import java.util.List;
> >> 
> >> -import java.util.Map;
> >> 
> >>  import javax.xml.parsers.SAXParser;
> >>  import javax.xml.parsers.SAXParserFactory;
> >> 
> >> -import org.apache.maven.plugins.changes.model.Action;
> >> -import org.apache.maven.plugins.changes.model.Release;
> >> 
> >>  import org.xml.sax.Attributes;
> >> 
> >> +import org.xml.sax.InputSource;
> >> 
> >>  import org.xml.sax.SAXException;
> >>  import org.xml.sax.helpers.DefaultHandler;
> >> 
> >> @@ -53,9 +51,10 @@ public class JiraXML
> >> 
> >>      private JiraIssue issue;
> >> 
> >> -    public JiraXML( File xmlPath )
> >> +    public JiraXML( File xmlPath, String encoding )
> >> 
> >>      {
> >>      
> >>          SAXParserFactory factory = SAXParserFactory.newInstance();
> >> 
> >> +        FileInputStream fis = null;
> >> 
> >>          issueList = new ArrayList();
> >> 
> >> @@ -63,12 +62,30 @@ public class JiraXML
> >> 
> >>          {
> >>          
> >>              SAXParser saxParser = factory.newSAXParser();
> >> 
> >> -            saxParser.parse( xmlPath, this );
> >> +            fis = new FileInputStream( xmlPath );
> >> +            InputSource inputSource = new InputSource( fis );
> >> +            inputSource.setEncoding( encoding );
> >> +
> >> +            saxParser.parse( inputSource, this );
> >> 
> >>          }
> >>          catch ( Throwable t )
> >>          {
> >>          
> >>              t.printStackTrace();
> >>          
> >>          }
> >> 
> >> +        finally
> >> +        {
> >> +            if ( fis != null )
> >> +            {
> >> +                try
> >> +                {
> >> +                    fis.close();
> >> +                }
> >> +                catch ( IOException e )
> >> +                {
> >> +                    // Ignore
> >> +                }
> >> +            }
> >> +        }
> >> 
> >>      }
> >>      
> >>      public void startElement( String namespaceURI, String sName, String
> >> 
> >> qName, Attributes attrs )
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> > For additional commands, e-mail: dev-help@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: svn commit: r1054263 - in /maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin: announcement/AnnouncementMojo.java jira/JiraMojo.java jira/JiraXML.java

Posted by Dennis Lundberg <de...@apache.org>.
On 2011-01-01 19:52, Hervé BOUTEMY wrote:
> Hi Dennis,
> 
> Like Benjamin wrote in the issue, a new parameter should not be necessary 
> since XML is declaring encoding: you just have tu use 
> ReaderFactory.newXmlReader() to avoid relying on the parser to detect 
> encoding.

Yes, I read Benjamin's comment.

> Such an argument is usefull only if Jira generates wrong XML, with content not 
> consistent with encoding declared in its prolog: such a case would be a bug in 
> Jira.

Unfortunately the RSS-feed files that the plugin downloads from JIRA
doesn't have an XML prolog. They are encoded using the platform encoding
of the JIRA server.

After doing some reading about file encoding, again, I came to the
conclusion that it wasn't possible to establish the encoding of the
downloaded files. See the two example files that are attached to the
issue. If my assumption was wrong please let me know.

> Don't hesitate to ping me if this isn't clear (I know, encoding stays bizarre 
> for a lot of people :) )

It sure is, but I'll hopefully get it some of these days... Thanks

> Regards,
> 
> Hervé
> 
> Le samedi 1 janvier 2011, dennisl@apache.org a écrit :
>> Author: dennisl
>> Date: Sat Jan  1 17:41:56 2011
>> New Revision: 1054263
>>
>> URL: http://svn.apache.org/viewvc?rev=1054263&view=rev
>> Log:
>> [MCHANGES-144] Add configuration if the encoding of JIRA xml file is not
>> UTF-8.
>>
>> Modified:
>>    
>> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
>> ugin/announcement/AnnouncementMojo.java
>> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
>> ugin/jira/JiraMojo.java
>> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
>> ugin/jira/JiraXML.java
>>
>> Modified:
>> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
>> ugin/announcement/AnnouncementMojo.java URL:
>> http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/
>> main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java?rev=10
>> 54263&r1=1054262&r2=1054263&view=diff
>> ==========================================================================
>> ==== ---
>> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
>> ugin/announcement/AnnouncementMojo.java (original) +++
>> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
>> ugin/announcement/AnnouncementMojo.java Sat Jan  1 17:41:56 2011 @@ -247,7
>> +247,7 @@ public class AnnouncementMojo
>>      private String resolutionIds;
>>
>>      /**
>> -     * The path of the XML file of JIRA-announcements to be parsed.
>> +     * Path to the JIRA XML file, which will be parsed.
>>       *
>>       * @parameter
>> expression="${project.build.directory}/jira-announcement.xml" * @required
>> @@ -256,6 +256,15 @@ public class AnnouncementMojo
>>      private File jiraXML;
>>
>>      /**
>> +     * The encoding used in the JIRA XML file. You only need to change
>> this if +     * your JIRA server is returning responses in an encoding
>> other than UTF-8. +     *
>> +     * @parameter default-value="UTF-8"
>> expression="${changes.jiraXmlEncoding}" +     * @since 2.4
>> +     */
>> +    private String jiraXmlEncoding;
>> +
>> +    /**
>>       * The maximum number of issues to fetch from JIRA.
>>       * <p>
>>       * <b>Note:</b> In versions 2.0-beta-3 and earlier this parameter was
>> @@ -607,7 +616,7 @@ public class AnnouncementMojo
>>
>>              if ( jiraXMLFile.exists() )
>>              {
>> -                JiraXML jiraParser = new JiraXML( jiraXMLFile );
>> +                JiraXML jiraParser = new JiraXML( jiraXMLFile,
>> jiraXmlEncoding );
>>
>>                  List issues = jiraParser.getIssueList();
>>
>>
>> Modified:
>> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
>> ugin/jira/JiraMojo.java URL:
>> http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/
>> main/java/org/apache/maven/plugin/jira/JiraMojo.java?rev=1054263&r1=1054262
>> &r2=1054263&view=diff
>> ==========================================================================
>> ==== ---
>> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
>> ugin/jira/JiraMojo.java (original) +++
>> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
>> ugin/jira/JiraMojo.java Sat Jan  1 17:41:56 2011 @@ -42,13 +42,22 @@ public
>> class JiraMojo
>>      /**
>>       * Path to the JIRA XML file, which will be parsed.
>>       *
>> -     * @parameter expression="${project.build.directory}/jira-results.xml
>> " +     * @parameter
>> expression="${project.build.directory}/jira-results.xml" * @required
>>       * @readonly
>>       */
>>      private File jiraXmlPath;
>>
>>      /**
>> +     * The encoding used in the JIRA XML file. You only need to change
>> this if +     * your JIRA server is returning responses in an encoding
>> other than UTF-8. +     *
>> +     * @parameter default-value="UTF-8"
>> expression="${changes.jiraXmlEncoding}" +     * @since 2.4
>> +     */
>> +    private String jiraXmlEncoding;
>> +
>> +    /**
>>       * Settings XML configuration.
>>       *
>>       * @parameter expression="${settings}"
>> @@ -248,7 +257,7 @@ public class JiraMojo
>>
>>              if ( jiraXmlPath.isFile() )
>>              {
>> -                JiraXML jira = new JiraXML( jiraXmlPath );
>> +                JiraXML jira = new JiraXML( jiraXmlPath, jiraXmlEncoding
>> ); List issueList = jira.getIssueList();
>>
>>                  report = new JiraReportGenerator( columnNames );
>>
>> Modified:
>> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
>> ugin/jira/JiraXML.java URL:
>> http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/
>> main/java/org/apache/maven/plugin/jira/JiraXML.java?rev=1054263&r1=1054262&
>> r2=1054263&view=diff
>> ==========================================================================
>> ==== ---
>> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
>> ugin/jira/JiraXML.java (original) +++
>> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
>> ugin/jira/JiraXML.java Sat Jan  1 17:41:56 2011 @@ -20,18 +20,16 @@ package
>> org.apache.maven.plugin.jira;
>>   */
>>
>>  import java.io.File;
>> +import java.io.FileInputStream;
>> +import java.io.IOException;
>>  import java.util.ArrayList;
>> -import java.util.HashMap;
>> -import java.util.Iterator;
>>  import java.util.List;
>> -import java.util.Map;
>>
>>  import javax.xml.parsers.SAXParser;
>>  import javax.xml.parsers.SAXParserFactory;
>>
>> -import org.apache.maven.plugins.changes.model.Action;
>> -import org.apache.maven.plugins.changes.model.Release;
>>  import org.xml.sax.Attributes;
>> +import org.xml.sax.InputSource;
>>  import org.xml.sax.SAXException;
>>  import org.xml.sax.helpers.DefaultHandler;
>>
>> @@ -53,9 +51,10 @@ public class JiraXML
>>
>>      private JiraIssue issue;
>>
>> -    public JiraXML( File xmlPath )
>> +    public JiraXML( File xmlPath, String encoding )
>>      {
>>          SAXParserFactory factory = SAXParserFactory.newInstance();
>> +        FileInputStream fis = null;
>>
>>          issueList = new ArrayList();
>>
>> @@ -63,12 +62,30 @@ public class JiraXML
>>          {
>>              SAXParser saxParser = factory.newSAXParser();
>>
>> -            saxParser.parse( xmlPath, this );
>> +            fis = new FileInputStream( xmlPath );
>> +            InputSource inputSource = new InputSource( fis );
>> +            inputSource.setEncoding( encoding );
>> +
>> +            saxParser.parse( inputSource, this );
>>          }
>>          catch ( Throwable t )
>>          {
>>              t.printStackTrace();
>>          }
>> +        finally
>> +        {
>> +            if ( fis != null )
>> +            {
>> +                try
>> +                {
>> +                    fis.close();
>> +                }
>> +                catch ( IOException e )
>> +                {
>> +                    // Ignore
>> +                }
>> +            }
>> +        }
>>      }
>>
>>      public void startElement( String namespaceURI, String sName, String
>> qName, Attributes attrs )
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
> 
> 


-- 
Dennis Lundberg

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: svn commit: r1054263 - in /maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin: announcement/AnnouncementMojo.java jira/JiraMojo.java jira/JiraXML.java

Posted by Hervé BOUTEMY <he...@free.fr>.
Hi Dennis,

Like Benjamin wrote in the issue, a new parameter should not be necessary 
since XML is declaring encoding: you just have tu use 
ReaderFactory.newXmlReader() to avoid relying on the parser to detect 
encoding.

Such an argument is usefull only if Jira generates wrong XML, with content not 
consistent with encoding declared in its prolog: such a case would be a bug in 
Jira.

Don't hesitate to ping me if this isn't clear (I know, encoding stays bizarre 
for a lot of people :) )

Regards,

Hervé

Le samedi 1 janvier 2011, dennisl@apache.org a écrit :
> Author: dennisl
> Date: Sat Jan  1 17:41:56 2011
> New Revision: 1054263
> 
> URL: http://svn.apache.org/viewvc?rev=1054263&view=rev
> Log:
> [MCHANGES-144] Add configuration if the encoding of JIRA xml file is not
> UTF-8.
> 
> Modified:
>    
> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
> ugin/announcement/AnnouncementMojo.java
> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
> ugin/jira/JiraMojo.java
> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
> ugin/jira/JiraXML.java
> 
> Modified:
> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
> ugin/announcement/AnnouncementMojo.java URL:
> http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/
> main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java?rev=10
> 54263&r1=1054262&r2=1054263&view=diff
> ==========================================================================
> ==== ---
> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
> ugin/announcement/AnnouncementMojo.java (original) +++
> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
> ugin/announcement/AnnouncementMojo.java Sat Jan  1 17:41:56 2011 @@ -247,7
> +247,7 @@ public class AnnouncementMojo
>      private String resolutionIds;
> 
>      /**
> -     * The path of the XML file of JIRA-announcements to be parsed.
> +     * Path to the JIRA XML file, which will be parsed.
>       *
>       * @parameter
> expression="${project.build.directory}/jira-announcement.xml" * @required
> @@ -256,6 +256,15 @@ public class AnnouncementMojo
>      private File jiraXML;
> 
>      /**
> +     * The encoding used in the JIRA XML file. You only need to change
> this if +     * your JIRA server is returning responses in an encoding
> other than UTF-8. +     *
> +     * @parameter default-value="UTF-8"
> expression="${changes.jiraXmlEncoding}" +     * @since 2.4
> +     */
> +    private String jiraXmlEncoding;
> +
> +    /**
>       * The maximum number of issues to fetch from JIRA.
>       * <p>
>       * <b>Note:</b> In versions 2.0-beta-3 and earlier this parameter was
> @@ -607,7 +616,7 @@ public class AnnouncementMojo
> 
>              if ( jiraXMLFile.exists() )
>              {
> -                JiraXML jiraParser = new JiraXML( jiraXMLFile );
> +                JiraXML jiraParser = new JiraXML( jiraXMLFile,
> jiraXmlEncoding );
> 
>                  List issues = jiraParser.getIssueList();
> 
> 
> Modified:
> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
> ugin/jira/JiraMojo.java URL:
> http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/
> main/java/org/apache/maven/plugin/jira/JiraMojo.java?rev=1054263&r1=1054262
> &r2=1054263&view=diff
> ==========================================================================
> ==== ---
> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
> ugin/jira/JiraMojo.java (original) +++
> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
> ugin/jira/JiraMojo.java Sat Jan  1 17:41:56 2011 @@ -42,13 +42,22 @@ public
> class JiraMojo
>      /**
>       * Path to the JIRA XML file, which will be parsed.
>       *
> -     * @parameter expression="${project.build.directory}/jira-results.xml
> " +     * @parameter
> expression="${project.build.directory}/jira-results.xml" * @required
>       * @readonly
>       */
>      private File jiraXmlPath;
> 
>      /**
> +     * The encoding used in the JIRA XML file. You only need to change
> this if +     * your JIRA server is returning responses in an encoding
> other than UTF-8. +     *
> +     * @parameter default-value="UTF-8"
> expression="${changes.jiraXmlEncoding}" +     * @since 2.4
> +     */
> +    private String jiraXmlEncoding;
> +
> +    /**
>       * Settings XML configuration.
>       *
>       * @parameter expression="${settings}"
> @@ -248,7 +257,7 @@ public class JiraMojo
> 
>              if ( jiraXmlPath.isFile() )
>              {
> -                JiraXML jira = new JiraXML( jiraXmlPath );
> +                JiraXML jira = new JiraXML( jiraXmlPath, jiraXmlEncoding
> ); List issueList = jira.getIssueList();
> 
>                  report = new JiraReportGenerator( columnNames );
> 
> Modified:
> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
> ugin/jira/JiraXML.java URL:
> http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/
> main/java/org/apache/maven/plugin/jira/JiraXML.java?rev=1054263&r1=1054262&
> r2=1054263&view=diff
> ==========================================================================
> ==== ---
> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
> ugin/jira/JiraXML.java (original) +++
> maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/pl
> ugin/jira/JiraXML.java Sat Jan  1 17:41:56 2011 @@ -20,18 +20,16 @@ package
> org.apache.maven.plugin.jira;
>   */
> 
>  import java.io.File;
> +import java.io.FileInputStream;
> +import java.io.IOException;
>  import java.util.ArrayList;
> -import java.util.HashMap;
> -import java.util.Iterator;
>  import java.util.List;
> -import java.util.Map;
> 
>  import javax.xml.parsers.SAXParser;
>  import javax.xml.parsers.SAXParserFactory;
> 
> -import org.apache.maven.plugins.changes.model.Action;
> -import org.apache.maven.plugins.changes.model.Release;
>  import org.xml.sax.Attributes;
> +import org.xml.sax.InputSource;
>  import org.xml.sax.SAXException;
>  import org.xml.sax.helpers.DefaultHandler;
> 
> @@ -53,9 +51,10 @@ public class JiraXML
> 
>      private JiraIssue issue;
> 
> -    public JiraXML( File xmlPath )
> +    public JiraXML( File xmlPath, String encoding )
>      {
>          SAXParserFactory factory = SAXParserFactory.newInstance();
> +        FileInputStream fis = null;
> 
>          issueList = new ArrayList();
> 
> @@ -63,12 +62,30 @@ public class JiraXML
>          {
>              SAXParser saxParser = factory.newSAXParser();
> 
> -            saxParser.parse( xmlPath, this );
> +            fis = new FileInputStream( xmlPath );
> +            InputSource inputSource = new InputSource( fis );
> +            inputSource.setEncoding( encoding );
> +
> +            saxParser.parse( inputSource, this );
>          }
>          catch ( Throwable t )
>          {
>              t.printStackTrace();
>          }
> +        finally
> +        {
> +            if ( fis != null )
> +            {
> +                try
> +                {
> +                    fis.close();
> +                }
> +                catch ( IOException e )
> +                {
> +                    // Ignore
> +                }
> +            }
> +        }
>      }
> 
>      public void startElement( String namespaceURI, String sName, String
> qName, Attributes attrs )


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org