Subversion Repositories XServices

Rev

Rev 149 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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