Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ChangeLogSet |
|
| 1.5;1,5 |
1 | package org.apache.maven.scm.command.changelog; | |
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.text.SimpleDateFormat; | |
23 | import java.util.Date; | |
24 | import java.util.List; | |
25 | ||
26 | import org.apache.maven.scm.ChangeSet; | |
27 | import org.apache.maven.scm.ScmVersion; | |
28 | ||
29 | /** | |
30 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> | |
31 | * @version $Id: ChangeLogSet.java 1306864 2012-03-29 13:43:18Z olamy $ | |
32 | */ | |
33 | public class ChangeLogSet | |
34 | { | |
35 | public static final String DEFAULT_ENCODING = "ISO-8859-1"; | |
36 | ||
37 | private List<ChangeSet> entries; | |
38 | ||
39 | private Date startDate; | |
40 | ||
41 | private Date endDate; | |
42 | ||
43 | private ScmVersion startVersion; | |
44 | ||
45 | private ScmVersion endVersion; | |
46 | ||
47 | /** | |
48 | * Initializes a new instance of this class. | |
49 | * | |
50 | * @param startDate the start date/tag for this set. | |
51 | * @param endDate the end date/tag for this set, or <code>null</code> if this set goes to the present time. | |
52 | */ | |
53 | public ChangeLogSet( Date startDate, Date endDate ) | |
54 | 0 | { |
55 | 0 | this.startDate = startDate; |
56 | 0 | this.endDate = endDate; |
57 | 0 | } |
58 | ||
59 | /** | |
60 | * Initializes a new instance of this class. | |
61 | * | |
62 | * @param entries collection of {@link org.apache.maven.scm.ChangeSet} objects for this set. | |
63 | * @param startDate the start date/tag for this set. | |
64 | * @param endDate the end date/tag for this set, or <code>null</code> if this set goes to the present time. | |
65 | */ | |
66 | public ChangeLogSet( List<ChangeSet> entries, Date startDate, Date endDate ) | |
67 | { | |
68 | 0 | this( startDate, endDate ); |
69 | 0 | setChangeSets( entries ); |
70 | 0 | } |
71 | ||
72 | /** | |
73 | * Returns the start date. | |
74 | * | |
75 | * @return the start date. | |
76 | */ | |
77 | public Date getStartDate() | |
78 | { | |
79 | 0 | return startDate; |
80 | } | |
81 | ||
82 | /** | |
83 | * Returns the end date for this set. | |
84 | * | |
85 | * @return the end date for this set, or <code>null</code> if this set goes to the present time. | |
86 | */ | |
87 | public Date getEndDate() | |
88 | { | |
89 | 0 | return endDate; |
90 | } | |
91 | ||
92 | /** | |
93 | * Returns the start version (revision/branch/label) for this set. | |
94 | * | |
95 | * @return the start version (revision/branch/label) for this set, or <code>null</code>. | |
96 | */ | |
97 | public ScmVersion getStartVersion() | |
98 | { | |
99 | 0 | return startVersion; |
100 | } | |
101 | ||
102 | public void setStartVersion( ScmVersion startVersion ) | |
103 | { | |
104 | 0 | this.startVersion = startVersion; |
105 | 0 | } |
106 | ||
107 | /** | |
108 | * Returns the end version (revision/branch/label) for this set. | |
109 | * | |
110 | * @return the end version (revision/branch/label) for this set, or <code>null</code>. | |
111 | */ | |
112 | public ScmVersion getEndVersion() | |
113 | { | |
114 | 0 | return endVersion; |
115 | } | |
116 | ||
117 | public void setEndVersion( ScmVersion endVersion ) | |
118 | { | |
119 | 0 | this.endVersion = endVersion; |
120 | 0 | } |
121 | ||
122 | /** | |
123 | * Returns the collection of changeSet. | |
124 | * | |
125 | * @return the collection of {@link org.apache.maven.scm.ChangeSet} objects for this set. | |
126 | */ | |
127 | public List<ChangeSet> getChangeSets() | |
128 | { | |
129 | 0 | return entries; |
130 | } | |
131 | ||
132 | public void setChangeSets( List<ChangeSet> changeSets ) | |
133 | { | |
134 | 0 | this.entries = changeSets; |
135 | 0 | } |
136 | ||
137 | /** | |
138 | * Creates an XML representation of this change log set with a default encoding (ISO-8859-1). | |
139 | */ | |
140 | public String toXML() | |
141 | { | |
142 | 0 | return toXML( DEFAULT_ENCODING ); |
143 | } | |
144 | ||
145 | /** | |
146 | * Creates an XML representation of this change log set. | |
147 | */ | |
148 | public String toXML( String encoding ) | |
149 | { | |
150 | 0 | String encodingString = encoding; |
151 | ||
152 | 0 | if ( encodingString == null ) |
153 | { | |
154 | 0 | encodingString = DEFAULT_ENCODING; |
155 | } | |
156 | ||
157 | 0 | StringBuilder buffer = new StringBuilder(); |
158 | 0 | String pattern = "yyyyMMdd HH:mm:ss z"; |
159 | 0 | SimpleDateFormat formatter = new SimpleDateFormat( pattern ); |
160 | ||
161 | 0 | buffer.append( "<?xml version=\"1.0\" encoding=\"" + encodingString + "\"?>\n" ); |
162 | 0 | buffer.append( "<changeset datePattern=\"" ) |
163 | .append( pattern ) | |
164 | .append( "\"" ); | |
165 | ||
166 | 0 | if ( startDate != null ) |
167 | { | |
168 | 0 | buffer.append( " start=\"" ) |
169 | .append( formatter.format( getStartDate() ) ) | |
170 | .append( "\"" ); | |
171 | } | |
172 | 0 | if ( endDate != null ) |
173 | { | |
174 | 0 | buffer.append( " end=\"" ) |
175 | .append( formatter.format( getEndDate() ) ) | |
176 | .append( "\"" ); | |
177 | } | |
178 | ||
179 | 0 | if ( startVersion != null ) |
180 | { | |
181 | 0 | buffer.append( " startVersion=\"" ) |
182 | .append( getStartVersion() ) | |
183 | .append( "\"" ); | |
184 | } | |
185 | 0 | if ( endVersion != null ) |
186 | { | |
187 | 0 | buffer.append( " endVersion=\"" ) |
188 | .append( getEndVersion() ) | |
189 | .append( "\"" ); | |
190 | } | |
191 | ||
192 | 0 | buffer.append( ">\n" ); |
193 | ||
194 | // Write out the entries | |
195 | 0 | for ( ChangeSet changeSet : getChangeSets() ) |
196 | { | |
197 | 0 | buffer.append( changeSet.toXML() ); |
198 | } | |
199 | ||
200 | 0 | buffer.append( "</changeset>\n" ); |
201 | ||
202 | 0 | return buffer.toString(); |
203 | } | |
204 | } |