1 package org.apache.maven.plugin.changes;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 import org.codehaus.plexus.util.IOUtil;
33
34
35
36
37
38
39 public class ChangesXML
40 {
41
42 private List releaseList;
43
44 private String author;
45
46 private String title;
47
48 private String authorEmail;
49
50 private ChangesDocument changesDocument;
51
52 public ChangesXML( File xmlPath, Log log )
53 {
54
55 if ( xmlPath == null || !xmlPath.exists() )
56 {
57 log.error( "changes xml file is null or not exists " );
58 return;
59 }
60
61 FileInputStream fileInputStream = null;
62
63 try
64 {
65
66 ChangesXpp3Reader reader = new ChangesXpp3Reader();
67
68 fileInputStream = new FileInputStream( xmlPath );
69 changesDocument = reader.read( fileInputStream, false );
70
71 if ( changesDocument == null )
72 {
73 log.error( "Cannot build Changes Report from file: " + xmlPath.getPath() );
74 return;
75 }
76
77 Properties properties = changesDocument.getProperties();
78
79 if ( properties != null )
80 {
81 if ( properties.getAuthor() != null )
82 {
83 this.author = properties.getAuthor().getName();
84 this.authorEmail = properties.getAuthor().getName();
85 }
86 this.title = properties.getTitle();
87 }
88
89
90 Body body = changesDocument.getBody();
91
92
93 if ( body != null )
94 {
95 this.releaseList = body.getReleases();
96 }
97
98 }
99 catch ( Throwable e )
100 {
101
102 log.error( "An error occurred when parsing the changes.xml file: ", e );
103 }
104 finally
105 {
106 IOUtil.close( fileInputStream );
107 }
108 }
109
110 public void setAuthor( String author )
111 {
112 this.author = author;
113 }
114
115 public String getAuthor()
116 {
117 return author;
118 }
119
120 public void setReleaseList( List releaseList )
121 {
122 this.releaseList = releaseList;
123 }
124
125 public List getReleaseList()
126 {
127 return releaseList == null ? Collections.EMPTY_LIST : releaseList;
128 }
129
130 public void setTitle( String title )
131 {
132 this.title = title;
133 }
134
135 public String getTitle()
136 {
137 return title;
138 }
139
140 public ChangesDocument getChangesDocument()
141 {
142 return changesDocument;
143 }
144
145 public String getAuthorEmail()
146 {
147 return authorEmail;
148 }
149
150 public void setAuthorEmail( String authorEmail )
151 {
152 this.authorEmail = authorEmail;
153 }
154
155 }