Subversion Repositories XServices

Rev

Rev 150 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
149 brianR 1
/*
2
 *   Copyright 2013 Brian Rosenberger (Brutex Network)
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
15
 */
16
package net.brutex.svn;
17
 
18
import java.util.ArrayList;
19
import java.util.Date;
20
import java.util.Iterator;
21
import java.util.List;
22
import java.util.regex.Matcher;
23
import java.util.regex.Pattern;
24
 
25
import org.apache.log4j.Logger;
26
 
27
/**
28
 * The Class SVNCommitInfo represents changes commited to
29
 * a svn repository. The information is based on svnlook.
30
 *
31
 * 'A ' Object dem Projektarchiv hinzugefügt
32
 * 'D ' Objekt aus dem Projektarchiv gelöscht
33
 * 'U ' Dateiinhalt geändert
34
 * '_U' Eigenschaften eines Objektes geändert
35
 * 'UU' Dateiinhalt und Eigenschaften geändert
36
 *
37
 * @author Brian Rosenberger, bru(at)brutex.de
38
 * @since 0.1
39
 *
40
 */
41
public class SVNCommitInfo {
42
 
43
	/** The logger. */
44
	private final Logger logger = Logger.getLogger(SVNCommitInfo.class);
45
 
46
	/** The author. */
47
	private final String author;
48
 
49
	/** The commit message */
50
	private final String logmessage;
51
 
52
	/** The date. */
53
	private final Date date;
54
 
55
	/** The Alist. */
56
	private final List<String> Alist = new ArrayList<String>(0);
57
 
58
	/** The Dlist. */
59
	private final List<String> Dlist = new ArrayList<String>(0);
60
 
61
	/** The Ulist. */
62
	private final List<String> Ulist = new ArrayList<String>(5);
63
 
64
	/** The _ ulist. */
65
	private final List<String> _Ulist = new ArrayList<String>(0);
66
 
67
	/** The U ulist. */
68
	private final List<String> UUlist = new ArrayList<String>(0);
69
 
70
	/** The issues. */
71
	private final List<String> issues = new ArrayList<String>(1);
72
 
73
	/** The txn. */
74
	private String txn="";
75
 
76
	/** The rev. */
77
	private String rev="";
78
 
79
 
80
	/**
81
	 * Instantiates a new SVN commit info.
82
	 *
83
	 * @param author the commiter
84
	 * @param date the commit date
85
	 * @param logmessage the commit message
86
	 */
87
	public SVNCommitInfo(String author, Date date, String logmessage) {
88
		this.author = author;
89
		this.date = date;
90
		this.logmessage = logmessage;
91
	}
92
 
93
	/**
94
	 * Adds the file info.
95
	 *
96
	 * @param t the t
97
	 * @param file the file
98
	 */
99
	public void addFileInfo(ChangeType t, String file) {
100
		switch (t) {
101
		case ADDED:
102
			Alist.add(file);
103
			break;
104
		case DELETED:
105
			Dlist.add(file);
106
			break;
107
		case UPDATED:
108
			Ulist.add(file);
109
			break;
110
		case METAUPDATE:
111
			_Ulist.add(file);
112
			break;
113
		case BOTHUPDATE:
114
			UUlist.add(file);
115
			break;
116
 
117
		default:
118
			break;
119
		}
120
	}
121
 
122
	/**
123
	 * Gets the author.
124
	 *
125
	 * @return the author
126
	 */
127
	public String getAuthor() {
128
		return author;
129
	}
130
 
131
	/**
132
	 * Gets the commit message.
133
	 *
134
	 * @return the commit message
135
	 */
136
	public String getLogmessage() {
137
		return logmessage;
138
	}
139
 
140
	/**
141
	 * Gets the commit date.
142
	 *
143
	 * @return the commit date
144
	 */
145
	public Date getDate() {
146
		return date;
147
	}
148
 
149
	/**
150
	 * Gets the svn transaction id.
151
	 *
152
	 * @return the txn
153
	 */
154
	public String getTxn() {
155
		return txn;
156
	}
157
 
158
	/**
159
	 * Sets the txn.
160
	 *
161
	 * @param txn the new txn
162
	 */
163
	public void setTxn(String txn) {
164
		this.txn = txn;
165
	}
166
 
167
	/**
168
	 * Gets the id. This is either the txn or revision.
169
	 *
170
	 * @return the id
171
	 */
172
	public String getId() {
173
		if(txn!=null) return txn;
174
		return rev;
175
	}
176
 
177
	/**
178
	 * Sets the rev.
179
	 *
180
	 * @param rev the new rev
181
	 */
182
	public void setRev(String rev) {
183
		this.rev = rev;
184
	}
185
 
186
	/**
187
	 * Gets the rev.
188
	 *
189
	 * @return the rev
190
	 */
191
	public String getRev() {
192
		return rev;
193
	}
194
	/*
195
	 * http://openbook.galileocomputing.de/javainsel9/javainsel_04_007.htm#mjd5b5d84cb3f1b5bcb7638ea9221a491f
196
	 */
197
	/**
198
	 * Parses the issues.
199
	 *
200
	 * @param patterns the patterns
201
	 */
202
	public void parseIssues(String[] patterns) {
203
		issues.clear(); //reset
204
		int count = 0;
205
		for(String p : patterns) {
206
			Pattern regex = Pattern.compile(p);
207
			Matcher matcher = regex.matcher(logmessage);
208
			logger.debug(String.format("Matching regex pattern '%s' against logmessage '%s'.", matcher.pattern().pattern(), logmessage));
209
			while( matcher.find()) {
210
				issues.add( matcher.group() );
211
				logger.debug("Found  issue '" + matcher.group() + "' in the logmessage.");
212
				count++;
213
			}
214
		}
215
		logger.debug("Found '" + count + "' issues in the logmessage.");
216
	}
217
 
218
	/**
219
	 * Gets the change file list as string.
220
	 *
221
	 * @return the change file list as string
222
	 */
223
	public String getChangeFileListAsString() {
224
		StringBuilder sb = new StringBuilder();
225
		for (Iterator<String> iterator = Alist.iterator(); iterator.hasNext();)
226
		{
227
			sb.append("A \t");
228
			sb.append(iterator.next());
229
			sb.append("\n");
230
		}
231
		for (Iterator<String> iterator = Dlist.iterator(); iterator.hasNext();)
232
		{
233
			sb.append("D \t");
234
			sb.append(iterator.next());
235
			sb.append("\n");
236
		}
237
		for (Iterator<String> iterator = Ulist.iterator(); iterator.hasNext();)
238
		{
239
			sb.append("U \t");
240
			sb.append(iterator.next());
241
			sb.append("\n");
242
		}
243
		for (Iterator<String> iterator = _Ulist.iterator(); iterator.hasNext();)
244
		{
245
			sb.append("_U\t");
246
			sb.append(iterator.next());
247
			sb.append("\n");
248
		}
249
		for (Iterator<String> iterator = UUlist.iterator(); iterator.hasNext();)
250
		{
251
			sb.append("UU\t");
252
			sb.append(iterator.next());
253
			sb.append("\n");
254
		}
255
 
256
		sb.append("Summary: " + (Ulist.size()+UUlist.size()+_Ulist.size()) + " files updated, ");
257
		sb.append(Alist.size() + " files added, " + Dlist.size() + " files deleted.");
258
		return sb.toString();
259
	}
260
 
261
	/**
262
	 * Gets the added files.
263
	 *
264
	 * @return the added files
265
	 */
266
	public List<String> getAddedFiles() {
267
		return Alist;
268
	}
269
 
270
	/**
271
	 * Gets the deleted files.
272
	 *
273
	 * @return the deleted files
274
	 */
275
	public List<String> getDeletedFiles() {
276
		return Dlist;
277
	}
278
 
279
	/**
280
	 * Gets the changed files.
281
	 *
282
	 * @return the changed files
283
	 */
284
	public List<String> getChangedFiles() {
285
		List<String> changed = new ArrayList<String>();
286
		changed.addAll(Ulist);
287
		changed.addAll(UUlist);
288
		changed.addAll(_Ulist);
289
		return changed;
290
	}
291
 
292
	/**
293
	 * Gets the issues.
294
	 *
295
	 * @return the issues
296
	 */
297
	public List<String> getIssues() {
298
		return issues;
299
	}
300
 
301
 
302
	/**
303
	 * The Enum ChangeType.
304
	 *
305
	 * @author Brian Rosenberger, bru(at)brutex.de
306
	 */
307
	public enum ChangeType {
308
 
309
		/** The added. */
310
		ADDED("A "),
311
 /** The deleted. */
312
 DELETED("D "),
313
 /** The updated. */
314
 UPDATED("U "),
315
 /** The metaupdate. */
316
 METAUPDATE("_U"),
317
 /** The bothupdate. */
318
 BOTHUPDATE("UU");
319
 
320
		/** The indicator. */
321
		private final String indicator;
322
 
323
		/**
324
		 * Instantiates a new change type.
325
		 *
326
		 * @param svn the svn
327
		 */
328
		private ChangeType(String svn) {
329
			this.indicator = svn;
330
		}
331
 
332
		/**
333
		 * Gets the enum.
334
		 *
335
		 * @param s the s
336
		 * @return the enum
337
		 */
338
		public static ChangeType getEnum(String s) {
339
			for(ChangeType e : ChangeType.values()) {
340
				if(s.equals(e.getIndicator())) return e;
341
			}
342
			throw new IllegalArgumentException("ChangeType enum for value '"+s+"' does not exist.");
343
		}
344
 
345
		/**
346
		 * Gets the indicator.
347
		 *
348
		 * @return the indicator
349
		 */
350
		public String getIndicator() {
351
			return this.indicator;
352
		}
353
	}
354
 
355
}