Coverage Report - org.apache.maven.plugin.announcement.JiraAnnouncementParser
 
Classes in this File Line Coverage Branch Coverage Complexity
JiraAnnouncementParser
0% 
0% 
3.5
 
 1  
 package org.apache.maven.plugin.announcement;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2006 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.io.File;
 20  
 import java.util.ArrayList;
 21  
 import java.util.List;
 22  
 
 23  
 import javax.xml.parsers.SAXParser;
 24  
 import javax.xml.parsers.SAXParserFactory;
 25  
 
 26  
 import org.apache.maven.plugin.changes.Action;
 27  
 import org.apache.maven.plugin.changes.Release;
 28  
 import org.xml.sax.Attributes;
 29  
 import org.xml.sax.SAXException;
 30  
 import org.xml.sax.helpers.DefaultHandler;
 31  
 
 32  
 /**
 33  
  * XML Parser for <code>JiraAnnouncement</code>s.
 34  
  *
 35  
  * @author aramirez@exist.com
 36  
  * @version $Id: org.apache.maven.plugin.announcement.JiraAnnouncementParser.html 816584 2012-05-08 12:33:35Z hboutemy $
 37  
  */
 38  
 public class JiraAnnouncementParser
 39  
     extends DefaultHandler
 40  
 {
 41  
     private String elementValue;
 42  
 
 43  0
     private String parentElement = "";
 44  
 
 45  
     private JiraAnnouncement issue;
 46  
 
 47  0
     private List issues = new ArrayList();
 48  
 
 49  
     public JiraAnnouncementParser( String xmlPath )
 50  0
     {
 51  0
         File xml = new File( xmlPath );
 52  
 
 53  0
         parseJira( xml );
 54  0
     }
 55  
 
 56  
     public JiraAnnouncementParser( File xmlPath )
 57  0
     {
 58  0
         parseJira( xmlPath );
 59  0
     }
 60  
 
 61  
     public void parseJira( File xml )
 62  
     {
 63  0
         SAXParserFactory factory = SAXParserFactory.newInstance();
 64  
 
 65  
         try
 66  
         {
 67  0
             SAXParser parser = factory.newSAXParser();
 68  
 
 69  0
             parser.parse( xml, this );
 70  
         }
 71  0
         catch ( Throwable t )
 72  
         {
 73  0
             t.printStackTrace();
 74  0
         }
 75  0
     }
 76  
 
 77  
     public void startElement( String namespaceURI, String sName, String qName, Attributes attrs )
 78  
         throws SAXException
 79  
     {
 80  0
         if ( qName.equals( "item" ) )
 81  
         {
 82  0
             issue = new JiraAnnouncement();
 83  
 
 84  0
             parentElement = "item";
 85  
         }
 86  0
     }
 87  
 
 88  
     public void endElement( String namespaceURI, String sName, String qName )
 89  
         throws SAXException
 90  
     {
 91  0
         if ( qName.equals( "item" ) )
 92  
         {
 93  0
             issues.add( issue );
 94  
 
 95  0
             parentElement = "";
 96  0
         }
 97  0
         else if ( qName.equals( "title" ) && parentElement.equals( "item" ) )
 98  
         {
 99  0
             issue.setTitle( elementValue );
 100  0
         }
 101  0
         else if ( qName.equals( "key" ) )
 102  
         {
 103  0
             issue.setKey( elementValue );
 104  0
         }
 105  0
         else if ( qName.equals( "link" ) && parentElement.equals( "item" ) )
 106  
         {
 107  0
             issue.setLink( elementValue );
 108  0
         }
 109  0
         else if ( qName.equals( "summary" ) )
 110  
         {
 111  0
             issue.setSummary( elementValue );
 112  0
         }
 113  0
         else if ( qName.equals( "type" ) )
 114  
         {
 115  0
             issue.setType( elementValue );
 116  0
         }
 117  0
         else if ( qName.equals( "status" ) )
 118  
         {
 119  0
             issue.setStatus( elementValue );
 120  0
         }
 121  0
         else if ( qName.equals( "resolution" ) )
 122  
         {
 123  0
             issue.setResolution( elementValue );
 124  0
         }
 125  0
         else if ( qName.equals( "assignee" ) )
 126  
         {
 127  0
             issue.setAssignee( elementValue );
 128  0
         }
 129  0
         else if ( qName.equals( "reporter" ) )
 130  
         {
 131  0
             issue.setReporter( elementValue );
 132  0
         }
 133  0
         else if ( qName.equals( "fixVersion" ) )
 134  
         {
 135  0
             issue.setFixVersion( elementValue );
 136  0
         }
 137  0
         else if ( qName.equals( "comment" ) )
 138  
         {
 139  0
             issue.addComment( elementValue );
 140  
         }
 141  0
     }
 142  
 
 143  
     public void characters( char[] buff, int offset, int len )
 144  
         throws SAXException
 145  
     {
 146  0
         String str = new String( buff, offset, len );
 147  
 
 148  0
         String string = str.trim();
 149  
 
 150  0
         if ( !string.equals( "" ) )
 151  
         {
 152  0
             elementValue = string;
 153  
         }
 154  0
     }
 155  
 
 156  
     public List getIssues()
 157  
     {
 158  0
         return this.issues;
 159  
     }
 160  
 
 161  
     public List getReleases( List issues )
 162  
     {
 163  0
         List releases = new ArrayList();
 164  
 
 165  0
         Release release = new Release();
 166  
 
 167  0
         String type = "";
 168  
 
 169  0
         for ( int i = 0; i < issues.size(); i++ )
 170  
         {
 171  0
             JiraAnnouncement issue = (JiraAnnouncement) issues.get( i );
 172  
 
 173  0
             Action action = new Action();
 174  
 
 175  0
             action.setIssue( issue.getKey() );
 176  
 
 177  0
             if ( issue.getType().equals( "Bug" ) )
 178  
             {
 179  0
                 type = "fix";
 180  0
             }
 181  0
             else if ( issue.getType().equals( "New Feature" ) )
 182  
             {
 183  0
                 type = "add";
 184  0
             }
 185  0
             else if ( issue.getType().equals( "Improvement" ) )
 186  
             {
 187  0
                 type = "update";
 188  
             }
 189  0
             action.setType( type );
 190  
 
 191  0
             action.setDev( issue.getAssignee() );
 192  
 
 193  
             //action.setDueTo( issue.getReporter() );
 194  
 
 195  0
             if ( issue.getComments() != null && !issue.getComments().isEmpty() )
 196  
             {
 197  0
                 int commentSize = issue.getComments().size();
 198  
 
 199  0
                 action.setAction( issue.getComments().get( commentSize - 1 ).toString() );
 200  0
             }
 201  
             else
 202  
             {
 203  0
                 action.setAction( "" );
 204  
             }
 205  0
             release.addAction( action );
 206  
 
 207  0
             release.setDescription( issue.getSummary() );
 208  
 
 209  0
             release.setVersion( issue.getFixVersion() );
 210  
 
 211  0
             releases.add( release );
 212  
         }
 213  0
         return releases;
 214  
     }
 215  
 }