db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r547982 - in /db/derby/code/trunk/java/build/org/apache/derbyBuild: ReleaseNoteReader.java ReleaseNotesGenerator.java
Date Sat, 16 Jun 2007 21:06:07 GMT
Author: rhillegas
Date: Sat Jun 16 14:06:07 2007
New Revision: 547982

URL: http://svn.apache.org/viewvc?view=rev&rev=547982
Log:
DERBY-2570: Create a lint tool which people can use to satisfy themselves that their release
notes can be digested by the release note generator.

Added:
    db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNoteReader.java   (with props)
Modified:
    db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNotesGenerator.java

Added: db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNoteReader.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNoteReader.java?view=auto&rev=547982
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNoteReader.java (added)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNoteReader.java Sat Jun 16
14:06:07 2007
@@ -0,0 +1,223 @@
+/*
+
+   Derby - Class org.apache.derbyBuild.ReleaseNoteReader
+
+   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.derbyBuild;
+
+import java.io.*;
+import java.net.URL;
+import java.util.ArrayList;
+import javax.xml.parsers.*;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.*;
+import javax.xml.transform.stream.*;
+import org.w3c.dom.*;
+
+/**
+ * <p>
+ * This tool reads a release note from a stream. When run standalone, this is
+ * a file stream. When run from the ReleaseNoteGenerator, the stream is opened
+ * on the URL of a release note stored in JIRA. The purpose of this class it to
+ * help people verify that their release notes can be digested by the ReleaseNoteGenerator.
+ * </p>
+ */
+public class ReleaseNoteReader
+{
+    /////////////////////////////////////////////////////////////////////////
+    //
+    //  CONSTANTS
+    //
+    /////////////////////////////////////////////////////////////////////////
+    
+    private static  final   String  USAGE =
+        "Usage:\n" +
+        "\n" +
+        "  java org.apache.derbyBuild.ReleaseNoteReader RELEASE_NOTE_FILE\n" +
+        "\n" +
+        "    where\n" +
+        "                  RELEASE_NOTE_FILE is the name of the file which holds the release
note\n";
+
+    private static  final   String  PARAGRAPH = "p";
+    private static  final   String  BODY = "body";
+
+    /////////////////////////////////////////////////////////////////////////
+    //
+    //  STATE
+    //
+    /////////////////////////////////////////////////////////////////////////
+
+    private DocumentBuilder _documentBuilder;
+
+    /////////////////////////////////////////////////////////////////////////
+    //
+    //  CONSTRUCTORS
+    //
+    /////////////////////////////////////////////////////////////////////////
+
+    public ReleaseNoteReader( DocumentBuilder documentBuilder )
+    {
+        _documentBuilder = documentBuilder;
+    }
+        
+    /////////////////////////////////////////////////////////////////////////
+    //
+    //  MAIN
+    //
+    /////////////////////////////////////////////////////////////////////////
+
+   /**
+    * The program entry point exercises all of the checks which
+    * would be performed by the ReleaseNoteGenerator on this
+    * particular release note. Takes one argument, the name of
+    * the file which holds the release note.
+    */
+    public  static void main( String[] args )
+        throws Exception
+    {
+        if ( (args == null) || (args.length != 1) )
+        {
+            println( USAGE );
+            System.exit(1);
+        }
+
+        String                                  fileName = args[ 0 ];
+        FileInputStream                 fis = new FileInputStream( fileName );
+        DocumentBuilderFactory  factory = DocumentBuilderFactory.newInstance();
+        DocumentBuilder              builder = factory.newDocumentBuilder();
+        ReleaseNoteReader           me = new ReleaseNoteReader( builder );
+
+        // here are the checks we perform
+        Document                        doc = me.getReleaseNote( fis );
+        String                              summary = me.getReleaseNoteSummary( doc );
+        Element                         details = me.getReleaseNoteDetails( doc );
+
+        // if you get this far, then everything worked
+
+        println( "\n" + fileName + " passes the currently known checks performed by the release
note generator.\n" );
+    }
+    
+    /////////////////////////////////////////////////////////////////////////
+    //
+    //  BEHAVIOR CALLED BY ReleaseNoteGenerator
+    //
+    /////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * Get the release note for an issue.
+     * </p>
+     */
+    public Document   getReleaseNote( InputStream is )
+        throws Exception
+    {
+        Document        doc = _documentBuilder.parse( is );
+
+        is.close();
+        
+        return doc;
+    }
+
+    /**
+     * <p>
+     * Get the summary for a release note
+     * </p>
+     */
+    public String   getReleaseNoteSummary( Document releaseNote )
+        throws Exception
+    {
+        //
+        // The release note has the following structure:
+        //
+        // <h4>Summary of Change</h4>
+        // <p>
+        //  Summary text
+        // </p>
+        //
+        Element     root = releaseNote.getDocumentElement();
+        Element     summaryParagraph = getFirstChild( root, PARAGRAPH );
+        String          summaryText = squeezeText( summaryParagraph );
+
+        return summaryText;
+    }
+ 
+    /**
+     * <p>
+     * Get the detail section for a release note
+     * </p>
+     */
+    public Element   getReleaseNoteDetails( Document releaseNote )
+        throws Exception
+    {
+        Element     root = releaseNote.getDocumentElement();
+        Element     details = getFirstChild( root, BODY );
+
+        return details;
+    }
+
+    ////////////////////////////////////////////////////////
+    //
+    // XML MINIONS
+    //
+    ////////////////////////////////////////////////////////
+
+    private Element getFirstChild( Element node, String childName )
+        throws Exception
+    {
+        Element retval = getOptionalChild( node, childName );
+
+        if ( retval == null )
+        {
+            throw new Exception( "Could not find child element '" + childName + "' in parent
element '" + node.getNodeName() + "'." );
+        }
+
+        return retval;
+    }
+
+    private Element getOptionalChild( Element node, String childName )
+        throws Exception
+    {
+        return (Element) node.getElementsByTagName( childName ).item( 0 );
+    }
+
+    /**
+     * <p>
+     * Squeeze the text out of an Element.
+     * </p>
+     */
+    private String squeezeText( Element node )
+        throws Exception
+    {
+        Node        textChild = node.getFirstChild();
+        String      text = textChild.getNodeValue();
+
+        return text;
+    }
+
+   ////////////////////////////////////////////////////////
+    //
+    // MISC MINIONS
+    //
+    ////////////////////////////////////////////////////////
+
+    private  static void    println( String text )
+    {
+        System.out.println( text );
+    }
+}

Propchange: db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNoteReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNotesGenerator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNotesGenerator.java?view=diff&rev=547982&r1=547981&r2=547982
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNotesGenerator.java (original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNotesGenerator.java Sat Jun
16 14:06:07 2007
@@ -214,6 +214,7 @@
         private Document    _summary;
         private Document    _bugList;
         private Document    _releaseNotesList;
+        private ReleaseNoteReader   _releaseNoteReader;
 
         private ArrayList       _missingReleaseNotes;
         private ArrayList       _errors;
@@ -235,6 +236,8 @@
 
             _missingReleaseNotes = new ArrayList();
             _errors = new ArrayList();
+
+            _releaseNoteReader = new ReleaseNoteReader( documentBuilder );
         }
 
         public  void    addMissingReleaseNote( JiraIssue issue )
@@ -252,6 +255,7 @@
         public  Document    getSummary() { return _summary; }
         public  Document    getBugList() { return _bugList; }
         public  Document    getReleaseNotesList() { return _releaseNotesList; }
+        public  ReleaseNoteReader   getReleaseNoteReader() { return _releaseNoteReader; }
         
         public  JiraIssue[]     getMissingReleaseNotes()
         {
@@ -621,6 +625,7 @@
         Document    pamphlet = gs.getPamphlet();
         Element     issuesSection = getSection( pamphlet, MAIN_SECTION_LEVEL, ISSUES_SECTION
);
         Document    issuesList = gs.getReleaseNotesList();
+        ReleaseNoteReader   releaseNoteReader = gs.getReleaseNoteReader();
         JiraIssue[]    bugs = getJiraIssues( issuesList );
         int                 count = bugs.length;
         String          releaseID = getReleaseID( gs );
@@ -638,7 +643,15 @@
         {
             JiraIssue       issue = bugs[ i ];
             
-            Document    releaseNote = getReleaseNote( gs, issue );
+            Document    releaseNote = null;
+
+            try {
+                releaseNote = getReleaseNote( gs, issue );
+            }
+            catch (Throwable t)
+            {
+                gs.addError( formatError( "Unable to read or parse release note for " + issue.getKey(),
t ) );
+            }
 
             // skip this note if we were unable to read it
             if ( releaseNote == null )
@@ -648,7 +661,17 @@
             }
             
             String          key = "Note for " + issue.getKey();
-            String          summary = getReleaseNoteSummary( gs, issue, releaseNote );
+            String          summary = null;
+
+            try {
+                summary = releaseNoteReader.getReleaseNoteSummary( releaseNote );
+            }
+            catch (Throwable t)
+            {
+                gs.addError( formatError( "Badly formatted summary for " + issue.getKey(),
t ) );
+                summary = "Unreadable summary line";
+            }
+            
             String          tocEntry = key + ": " + summary;
 
             insertLine( issuesSection );
@@ -656,8 +679,7 @@
             Element     issueSection = createSection( issuesSection, ISSUE_DETAIL_LEVEL,
toc, key, tocEntry );
 
             try {
-                Element     root = releaseNote.getDocumentElement();
-                Element     details = getFirstChild( root, BODY );
+                Element     details = releaseNoteReader.getReleaseNoteDetails( releaseNote
);
 
                 // copy the details out of the release note into this section of the
                 // pamphlet
@@ -671,6 +693,7 @@
         }
     }
     
+    
     /**
      * <p>
      * Get the release note for an issue.
@@ -681,60 +704,24 @@
     {
         if ( issue.hasReleaseNote() )
         {
-            URL                                 url = new URL( issue.getReleaseNoteAddress()
);
-
+            URL             url = null;
+            InputStream is = null;
+            
             try {
-                InputStream                     is = url.openStream();
-                Document        doc = gs.getDocumentBuilder().parse( is );
-
-                is.close();
-
-                return doc;
+                url = new URL( issue.getReleaseNoteAddress() );
+                is = url.openStream();
             }
-            catch (Exception e)
+            catch (Throwable t)
             {
-                processThrowable( e );
-
-                gs.addError( formatError( "Unable to read or parse release note for " + issue.getKey(),
e ) );
-
+                processThrowable( t );
                 return null;
             }
-        }
-        else { return null; }
-    }
 
-    /**
-     * <p>
-     * Get the summary for a release note
-     * </p>
-     */
-    private String   getReleaseNoteSummary( GeneratorState gs, JiraIssue issue, Document
releaseNote )
-        throws Exception
-    {
-        if ( releaseNote != null )
-        {
-            //
-            // The release note has the following structure:
-            //
-            // <h4>Summary of Change</h4>
-            // <p>
-            //  Summary text
-            // </p>
-            //
-            try {
-                Element     root = releaseNote.getDocumentElement();
-                Element     summaryParagraph = getFirstChild( root, PARAGRAPH );
-                String          summaryText = squeezeText( summaryParagraph );
+            Document        doc = gs.getReleaseNoteReader().getReleaseNote( is );
 
-                return summaryText;
-            }
-            catch (Throwable t)
-            {
-                gs.addError( formatError( "Badly formatted summary for " + issue.getKey(),
t ) );
-                return "Unreadable summary line";
-            }
+            return doc;
         }
-        else { return "???"; }
+        else { return null; }
     }
 
     //////////////////////////////////



Mime
View raw message