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 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
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 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 = changesDocument.getBody().getReleases(); |
92 | |
} |
93 | |
|
94 | |
} |
95 | 0 | catch ( Throwable e ) |
96 | |
{ |
97 | |
|
98 | 0 | log.error( "An error occured 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 | |
} |