1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.changes;
20
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.apache.maven.plugin.logging.Log;
27 import org.apache.maven.plugins.changes.model.Body;
28 import org.apache.maven.plugins.changes.model.ChangesDocument;
29 import org.apache.maven.plugins.changes.model.Properties;
30 import org.apache.maven.plugins.changes.model.Release;
31 import org.apache.maven.plugins.changes.model.io.xpp3.ChangesXpp3Reader;
32
33
34
35
36
37
38 public class ChangesXML {
39
40
41 private List<Release> releaseList;
42
43
44 private String author;
45
46
47 private String title;
48
49
50 private String authorEmail;
51
52
53 private ChangesDocument changesDocument;
54
55
56
57
58
59
60
61
62 public ChangesXML(File xmlPath, Log log) throws ChangesXMLRuntimeException {
63
64 if (xmlPath == null || !xmlPath.exists()) {
65 log.error("changes xml file is null or not exists ");
66 return;
67 }
68
69 try {
70
71 ChangesXpp3Reader reader = new ChangesXpp3Reader();
72
73 try (FileInputStream fileInputStream = new FileInputStream(xmlPath)) {
74 changesDocument = reader.read(fileInputStream, false);
75 }
76
77 if (changesDocument == null) {
78 log.error("Cannot build Changes Report from file: " + xmlPath.getPath());
79 return;
80 }
81
82 Properties properties = changesDocument.getProperties();
83
84 if (properties != null) {
85 if (properties.getAuthor() != null) {
86 this.author = properties.getAuthor().getName();
87 this.authorEmail = properties.getAuthor().getName();
88 }
89 this.title = properties.getTitle();
90 }
91
92 Body body = changesDocument.getBody();
93
94 if (body != null) {
95 this.releaseList = body.getReleases();
96 }
97
98 } catch (Throwable e) {
99 log.error("An error occurred when parsing the changes.xml file: ", e);
100 throw new ChangesXMLRuntimeException("An error occurred when parsing the changes.xml file", e);
101 }
102 }
103
104
105
106
107
108
109 public void setAuthor(String author) {
110 this.author = author;
111 }
112
113
114
115
116
117
118 public String getAuthor() {
119 return author;
120 }
121
122
123
124
125
126
127 public void setReleaseList(List<Release> releaseList) {
128 this.releaseList = releaseList;
129 }
130
131
132
133
134
135
136 public List<Release> getReleaseList() {
137 return releaseList == null ? Collections.<Release>emptyList() : releaseList;
138 }
139
140
141
142
143
144
145 public void setTitle(String title) {
146 this.title = title;
147 }
148
149
150
151
152
153
154 public String getTitle() {
155 return title;
156 }
157
158
159
160
161
162
163 public ChangesDocument getChangesDocument() {
164 return changesDocument;
165 }
166
167
168
169
170
171
172 public String getAuthorEmail() {
173 return authorEmail;
174 }
175
176
177
178
179
180
181 public void setAuthorEmail(String authorEmail) {
182 this.authorEmail = authorEmail;
183 }
184 }