View Javadoc

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   * XML Parser for changes.xml files.
35   *
36   * @version $Id: ChangesXML.html 816592 2012-05-08 12:40:21Z hboutemy $
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      {
53  
54          if ( xmlPath == null || !xmlPath.exists() )
55          {
56              log.error( "changes xml file is null or not exists " );
57              return;
58          }
59  
60          try
61          {
62  
63              ChangesXpp3Reader reader = new ChangesXpp3Reader();
64  
65              changesDocument = reader.read( new FileInputStream( xmlPath ), false );
66  
67              if ( changesDocument == null )
68              {
69                  log.error( "cannot build changes from file " + xmlPath.getPath() );
70                  return;
71              }
72  
73              Properties properties = changesDocument.getProperties();
74  
75              if ( properties != null )
76              {
77                  if ( properties.getAuthor() != null )
78                  {
79                      this.author = properties.getAuthor().getName();
80                      this.authorEmail = properties.getAuthor().getName();
81                  }
82                  this.title = properties.getTitle();
83              }
84  
85  
86              Body body = changesDocument.getBody();
87  
88  
89              if ( body != null )
90              {
91                  this.releaseList = changesDocument.getBody().getReleases();
92              }
93  
94          }
95          catch ( Throwable e )
96          {
97              // FIXME throw an Exception ?
98              log.error( "An error occured when parsing the changes.xml file:", e );
99          }
100     }
101 
102     public void setAuthor( String author )
103     {
104         this.author = author;
105     }
106 
107     public String getAuthor()
108     {
109         return author;
110     }
111 
112     public void setReleaseList( List releaseList )
113     {
114         this.releaseList = releaseList;
115     }
116 
117     public List getReleaseList()
118     {
119         return releaseList == null ? Collections.EMPTY_LIST : releaseList;
120     }
121 
122     public void setTitle( String title )
123     {
124         this.title = title;
125     }
126 
127     public String getTitle()
128     {
129         return title;
130     }
131 
132     public ChangesDocument getChangesDocument()
133     {
134         return changesDocument;
135     }
136 
137     public String getAuthorEmail()
138     {
139         return authorEmail;
140     }
141 
142     public void setAuthorEmail( String authorEmail )
143     {
144         this.authorEmail = authorEmail;
145     }
146 
147 }