Subversion Repositories XServices

Rev

Rev 150 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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