001 package org.apache.maven.scm.command.changelog;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.text.SimpleDateFormat;
023 import java.util.Date;
024 import java.util.List;
025
026 import org.apache.maven.scm.ChangeSet;
027 import org.apache.maven.scm.ScmVersion;
028
029 /**
030 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
031 *
032 */
033 public class ChangeLogSet
034 {
035 public static final String DEFAULT_ENCODING = "ISO-8859-1";
036
037 private List<ChangeSet> entries;
038
039 private Date startDate;
040
041 private Date endDate;
042
043 private ScmVersion startVersion;
044
045 private ScmVersion endVersion;
046
047 /**
048 * Initializes a new instance of this class.
049 *
050 * @param startDate the start date/tag for this set.
051 * @param endDate the end date/tag for this set, or <code>null</code> if this set goes to the present time.
052 */
053 public ChangeLogSet( Date startDate, Date endDate )
054 {
055 this.startDate = startDate;
056 this.endDate = endDate;
057 }
058
059 /**
060 * Initializes a new instance of this class.
061 *
062 * @param entries collection of {@link org.apache.maven.scm.ChangeSet} objects for this set.
063 * @param startDate the start date/tag for this set.
064 * @param endDate the end date/tag for this set, or <code>null</code> if this set goes to the present time.
065 */
066 public ChangeLogSet( List<ChangeSet> entries, Date startDate, Date endDate )
067 {
068 this( startDate, endDate );
069 setChangeSets( entries );
070 }
071
072 /**
073 * Returns the start date.
074 *
075 * @return the start date.
076 */
077 public Date getStartDate()
078 {
079 return startDate;
080 }
081
082 /**
083 * Returns the end date for this set.
084 *
085 * @return the end date for this set, or <code>null</code> if this set goes to the present time.
086 */
087 public Date getEndDate()
088 {
089 return endDate;
090 }
091
092 /**
093 * Returns the start version (revision/branch/label) for this set.
094 *
095 * @return the start version (revision/branch/label) for this set, or <code>null</code>.
096 */
097 public ScmVersion getStartVersion()
098 {
099 return startVersion;
100 }
101
102 public void setStartVersion( ScmVersion startVersion )
103 {
104 this.startVersion = startVersion;
105 }
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 return endVersion;
115 }
116
117 public void setEndVersion( ScmVersion endVersion )
118 {
119 this.endVersion = endVersion;
120 }
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 return entries;
130 }
131
132 public void setChangeSets( List<ChangeSet> changeSets )
133 {
134 this.entries = changeSets;
135 }
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 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 String encodingString = encoding;
151
152 if ( encodingString == null )
153 {
154 encodingString = DEFAULT_ENCODING;
155 }
156
157 StringBuilder buffer = new StringBuilder();
158 String pattern = "yyyyMMdd HH:mm:ss z";
159 SimpleDateFormat formatter = new SimpleDateFormat( pattern );
160
161 buffer.append( "<?xml version=\"1.0\" encoding=\"" + encodingString + "\"?>\n" );
162 buffer.append( "<changeset datePattern=\"" )
163 .append( pattern )
164 .append( "\"" );
165
166 if ( startDate != null )
167 {
168 buffer.append( " start=\"" )
169 .append( formatter.format( getStartDate() ) )
170 .append( "\"" );
171 }
172 if ( endDate != null )
173 {
174 buffer.append( " end=\"" )
175 .append( formatter.format( getEndDate() ) )
176 .append( "\"" );
177 }
178
179 if ( startVersion != null )
180 {
181 buffer.append( " startVersion=\"" )
182 .append( getStartVersion() )
183 .append( "\"" );
184 }
185 if ( endVersion != null )
186 {
187 buffer.append( " endVersion=\"" )
188 .append( getEndVersion() )
189 .append( "\"" );
190 }
191
192 buffer.append( ">\n" );
193
194 // Write out the entries
195 for ( ChangeSet changeSet : getChangeSets() )
196 {
197 buffer.append( changeSet.toXML() );
198 }
199
200 buffer.append( "</changeset>\n" );
201
202 return buffer.toString();
203 }
204 }