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 {
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
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 }