Coverage Report - org.apache.maven.plugin.changes.ChangesXML
 
Classes in this File Line Coverage Branch Coverage Complexity
ChangesXML
54%
19/35
50%
7/14
2
 
 1  
 package org.apache.maven.plugin.changes;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.File;
 23  
 import java.io.FileInputStream;
 24  
 import java.util.Collections;
 25  
 import java.util.List;
 26  
 
 27  
 import org.apache.maven.plugin.logging.Log;
 28  
 import org.apache.maven.plugins.changes.model.Body;
 29  
 import org.apache.maven.plugins.changes.model.ChangesDocument;
 30  
 import org.apache.maven.plugins.changes.model.Properties;
 31  
 import org.apache.maven.plugins.changes.model.io.xpp3.ChangesXpp3Reader;
 32  
 
 33  
 /**
 34  
  * A facade for a changes.xml file.
 35  
  *
 36  
  * @version $Id: ChangesXML.java 1056199 2011-01-07 06:33:11Z dennisl $
 37  
  */
 38  
 public class ChangesXML
 39  
 {
 40  
 
 41  
     private List releaseList;
 42  
 
 43  
     private String author;
 44  
 
 45  
     private String title;
 46  
 
 47  
     private String authorEmail;
 48  
 
 49  
     private ChangesDocument changesDocument;
 50  
 
 51  
     public ChangesXML( File xmlPath, Log log )
 52  2
     {
 53  
 
 54  2
         if ( xmlPath == null || !xmlPath.exists() )
 55  
         {
 56  0
             log.error( "changes xml file is null or not exists " );
 57  0
             return;
 58  
         }
 59  
 
 60  
         try
 61  
         {
 62  
 
 63  2
             ChangesXpp3Reader reader = new ChangesXpp3Reader();
 64  
 
 65  2
             changesDocument = reader.read( new FileInputStream( xmlPath ), false );
 66  
 
 67  2
             if ( changesDocument == null )
 68  
             {
 69  0
                 log.error( "Cannot build Changes Report from file: " + xmlPath.getPath() );
 70  0
                 return;
 71  
             }
 72  
 
 73  2
             Properties properties = changesDocument.getProperties();
 74  
 
 75  2
             if ( properties != null )
 76  
             {
 77  2
                 if ( properties.getAuthor() != null )
 78  
                 {
 79  2
                     this.author = properties.getAuthor().getName();
 80  2
                     this.authorEmail = properties.getAuthor().getName();
 81  
                 }
 82  2
                 this.title = properties.getTitle();
 83  
             }
 84  
 
 85  
 
 86  2
             Body body = changesDocument.getBody();
 87  
 
 88  
 
 89  2
             if ( body != null )
 90  
             {
 91  2
                 this.releaseList = body.getReleases();
 92  
             }
 93  
 
 94  
         }
 95  0
         catch ( Throwable e )
 96  
         {
 97  
             // FIXME throw an Exception ?
 98  0
             log.error( "An error occurred when parsing the changes.xml file: ", e );
 99  2
         }
 100  2
     }
 101  
 
 102  
     public void setAuthor( String author )
 103  
     {
 104  0
         this.author = author;
 105  0
     }
 106  
 
 107  
     public String getAuthor()
 108  
     {
 109  0
         return author;
 110  
     }
 111  
 
 112  
     public void setReleaseList( List releaseList )
 113  
     {
 114  0
         this.releaseList = releaseList;
 115  0
     }
 116  
 
 117  
     public List getReleaseList()
 118  
     {
 119  2
         return releaseList == null ? Collections.EMPTY_LIST : releaseList;
 120  
     }
 121  
 
 122  
     public void setTitle( String title )
 123  
     {
 124  0
         this.title = title;
 125  0
     }
 126  
 
 127  
     public String getTitle()
 128  
     {
 129  1
         return title;
 130  
     }
 131  
 
 132  
     public ChangesDocument getChangesDocument()
 133  
     {
 134  1
         return changesDocument;
 135  
     }
 136  
 
 137  
     public String getAuthorEmail()
 138  
     {
 139  0
         return authorEmail;
 140  
     }
 141  
 
 142  
     public void setAuthorEmail( String authorEmail )
 143  
     {
 144  0
         this.authorEmail = authorEmail;
 145  0
     }
 146  
 
 147  
 }