Subversion Repositories XServices

Rev

Rev 149 | Rev 152 | 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.emitter;
16
package net.brutex.emitter;
17
 
17
 
18
import java.io.File;
18
import java.io.File;
19
import java.io.FileInputStream;
19
import java.io.FileInputStream;
20
import java.io.FileNotFoundException;
20
import java.io.FileNotFoundException;
21
import java.io.IOException;
21
import java.io.IOException;
22
import java.io.StringWriter;
22
import java.io.StringWriter;
-
 
23
import java.math.BigInteger;
23
import java.text.SimpleDateFormat;
24
import java.text.SimpleDateFormat;
-
 
25
import java.util.ArrayList;
24
import java.util.Iterator;
26
import java.util.Iterator;
25
import java.util.List;
27
import java.util.List;
26
import java.util.UUID;
28
import java.util.UUID;
-
 
29
 
-
 
30
import javax.xml.bind.JAXBContext;
-
 
31
import javax.xml.bind.JAXBElement;
-
 
32
import javax.xml.bind.Marshaller;
27
 
33
import javax.xml.namespace.QName;
-
 
34
import javax.xml.stream.XMLStreamException;
-
 
35
 
-
 
36
 
-
 
37
 
-
 
38
 
-
 
39
 
-
 
40
 
-
 
41
 
-
 
42
 
-
 
43
 
-
 
44
 
-
 
45
 
-
 
46
 
-
 
47
import javax.xml.ws.BindingProvider;
-
 
48
 
-
 
49
import net.brutex.emitter.util.EmitterUtil;
-
 
50
import net.brutex.sbm.sbmappservices72.AEWebservicesFaultFault;
-
 
51
import net.brutex.sbm.sbmappservices72.Sbmappservices72;
-
 
52
import net.brutex.sbm.sbmappservices72.Sbmappservices72PortType;
-
 
53
import net.brutex.sbm.sbmappservices72.api.Auth;
-
 
54
import net.brutex.sbm.sbmappservices72.api.MultipleResponseItemOptions;
-
 
55
import net.brutex.sbm.sbmappservices72.api.ObjectFactory;
-
 
56
import net.brutex.sbm.sbmappservices72.api.SectionsOption;
28
import javax.xml.stream.XMLStreamException;
57
import net.brutex.sbm.sbmappservices72.api.TTItemList;
29
 
58
import net.brutex.sbm.sbmappservices72.api.TableIdentifier;
30
import net.brutex.svn.SVNCommitInfo;
59
import net.brutex.svn.SVNCommitInfo;
31
import net.brutex.svn.SVNLookExecutor;
60
import net.brutex.svn.SVNLookExecutor;
32
 
61
 
33
import org.apache.axiom.om.OMAbstractFactory;
62
import org.apache.axiom.om.OMAbstractFactory;
34
import org.apache.axiom.om.OMComment;
63
import org.apache.axiom.om.OMComment;
35
import org.apache.axiom.om.OMElement;
64
import org.apache.axiom.om.OMElement;
36
import org.apache.axiom.om.OMFactory;
65
import org.apache.axiom.om.OMFactory;
37
import org.apache.axiom.om.OMNamespace;
66
import org.apache.axiom.om.OMNamespace;
38
import org.apache.axiom.om.OMNode;
67
import org.apache.axiom.om.OMNode;
39
import org.apache.axiom.om.OMText;
68
import org.apache.axiom.om.OMText;
40
import org.apache.axiom.om.OMXMLBuilderFactory;
69
import org.apache.axiom.om.OMXMLBuilderFactory;
41
import org.apache.axiom.om.xpath.AXIOMXPath;
70
import org.apache.axiom.om.xpath.AXIOMXPath;
42
import org.apache.commons.cli.CommandLine;
71
import org.apache.commons.cli.CommandLine;
43
import org.apache.commons.cli.CommandLineParser;
72
import org.apache.commons.cli.CommandLineParser;
44
import org.apache.commons.cli.HelpFormatter;
73
import org.apache.commons.cli.HelpFormatter;
45
import org.apache.commons.cli.Option;
74
import org.apache.commons.cli.Option;
46
import org.apache.commons.cli.OptionBuilder;
75
import org.apache.commons.cli.OptionBuilder;
47
import org.apache.commons.cli.Options;
76
import org.apache.commons.cli.Options;
48
import org.apache.commons.cli.BasicParser;
77
import org.apache.commons.cli.BasicParser;
49
import org.apache.commons.cli.ParseException;
78
import org.apache.commons.cli.ParseException;
50
import org.apache.commons.configuration.Configuration;
79
import org.apache.commons.configuration.Configuration;
51
import org.apache.commons.configuration.ConfigurationException;
80
import org.apache.commons.configuration.ConfigurationException;
52
import org.apache.commons.configuration.PropertiesConfiguration;
81
import org.apache.commons.configuration.PropertiesConfiguration;
-
 
82
import org.apache.cxf.endpoint.Client;
-
 
83
import org.apache.cxf.frontend.ClientProxy;
-
 
84
import org.apache.cxf.interceptor.LoggingInInterceptor;
-
 
85
import org.apache.cxf.interceptor.LoggingOutInterceptor;
-
 
86
import org.apache.cxf.message.Message;
53
import org.apache.http.client.ClientProtocolException;
87
import org.apache.http.client.ClientProtocolException;
54
import org.apache.log4j.Logger;
88
import org.apache.log4j.Logger;
55
import org.jaxen.JaxenException;
89
import org.jaxen.JaxenException;
56
 
90
 
57
 
91
 
58
/**
92
/**
59
 * The Class ALFEmitter.
93
 * The Class ALFEmitter.
60
 *
94
 *
61
 * @author Brian Rosenberger, bru(at)brutex.de
95
 * @author Brian Rosenberger, bru(at)brutex.de
62
 * @since 0.1
96
 * @since 0.1
63
 */
97
 */
64
public class ALFEmitter {
98
public class ALFEmitter {
65
	
99
	
66
	private static final String version = "0.1";
100
	public static final String VERSION = "0.1";
-
 
101
	private static Logger logger = Logger.getRootLogger();
-
 
102
	
-
 
103
	//
-
 
104
	// Keys to read from the configuration file.
-
 
105
	//
-
 
106
	private static final String OPTION_SVNLOOK = "svnlook";
-
 
107
	private static final String OPTION_ISSUEPATTERN = "issuepattern";
-
 
108
	
-
 
109
	private static final String OPTION_EVENTTEMPLATE = "eventtemplate";
-
 
110
	private static final String OPTION_EVENTNAMESPACE = "eventnamespace";
-
 
111
	private static final String OPTION_EVENTMANAGER_URL = "eventmanager";
-
 
112
	private static final String OPTION_EVENTMANAGER_USER = "eventmanager.user";
-
 
113
	private static final String OPTION_EVENTMANAGER_PASSWORD = "eventmanager.password";
-
 
114
	
-
 
115
	private static final String OPTION_SBM_ENDPOINT = "sbmappservices72";
-
 
116
	private static final String OPTION_SBM_USER = "sbmuser";
-
 
117
	private static final String OPTION_SBM_PASSWORD = "sbmpassword";
-
 
118
	private static final String OPTION_SBM_TABLE = "querytable";
-
 
119
	private static final String OPTION_SBM_QUERY = "query";
-
 
120
 
-
 
121
	
-
 
122
	private static final String OPTION_MARKER_LOGMESSAGE = "marker.logmessage";
-
 
123
	private static final String OPTION_MARKER_AUTHOR = "marker.author";
-
 
124
	private static final String OPTION_MARKER_REVISION = "marker.revision";
-
 
125
	private static final String OPTION_MARKER_ADDEDFILES = "marker.addedfiles";
-
 
126
	private static final String OPTION_MARKER_DELETEDFILES = "marker.deletedfiles";
-
 
127
	private static final String OPTION_MARKER_CHANGEDFILES = "marker.changedfiles";
-
 
128
	private static final String OPTION_MARKER_ISSUES = "marker.issues";
-
 
129
	private static final String OPTION_MARKER_INTERNALISSUES = "marker.internalissues";
-
 
130
	private static final String OPTION_REMOVE_ISSUES_FROM_COMMIT = "removeissuesfromcommit";
-
 
131
	
-
 
132
	private static final String OPTION_IS_SOAPENABLED = "isSoapEnabled";
-
 
133
	private static final String OPTION_IS_DROPENABLED = "isDropResponse";
-
 
134
	private static final String OPTION_IS_FORCEFAILENABLED = "forcefail";
-
 
135
	private static final String OPTION_IS_VERIFICATIONENABLED = "isWithVerification";
-
 
136
	private static final String OPTION_IS_WSTRACE = "trace";
-
 
137
	private static final String OPTION_IS_XMLPROCESSINGENABLED = "isXmlProcessingEnabled";
-
 
138
 
-
 
139
	//
-
 
140
	// Command line parameters
67
	static Logger logger = Logger.getRootLogger();
141
	//
68
	private static final String PARAM_REPOS = "repos";
142
	private static final String PARAM_REPOS = "repos";
69
	private static final String PARAM_TXN = "txn";
143
	private static final String PARAM_TXN = "txn";
70
	private static final String PARAM_REV = "rev";
144
	private static final String PARAM_REV = "rev";
71
	private static final String PARAM_CONFIG = "conf";
145
	private static final String PARAM_CONFIG = "conf";
-
 
146
	
-
 
147
	//
-
 
148
	// Member variables
-
 
149
	//
-
 
150
	private final String repos;
-
 
151
	private final String txn;
-
 
152
	private final String rev;
-
 
153
	private SVNCommitInfo info;
-
 
154
	private OMElement template = null;
-
 
155
	private Configuration config;
-
 
156
	private String nss = null;
-
 
157
	private final long startTime;
-
 
158
	
-
 
159
	//Member for SBM endpoint configuration
-
 
160
	private final String endpoint;
-
 
161
	private final String sbm_user;
-
 
162
	private final String sbm_pass;
-
 
163
	private final String querytable;
-
 
164
	private final String query;
-
 
165
 
-
 
166
	
-
 
167
	private final List<String> internalissues = new ArrayList<String>();
72
 
168
	
73
	/**
169
	/**
74
	 * The main method.
170
	 * The main method.
75
	 *
171
	 *
76
	 * @param args the arguments
172
	 * @param args the arguments
77
	 */
173
	 */
78
	public static void main(String[] args) {
174
	public static void main(String[] args) {
79
		long startTime = System.currentTimeMillis();
175
		long startTime = System.currentTimeMillis();
80
		CommandLineParser parser = new BasicParser();
176
		CommandLineParser parser = new BasicParser();
81
		CommandLine cmd = null;;
177
		CommandLine cmd = null;
82
		try {
178
		try {
83
			cmd = parser.parse( getOptions(), args);
179
			cmd = parser.parse( getOptions(), args);
84
		} catch (ParseException e1) {
180
		} catch (ParseException e1) {
85
			logger.error(e1.getMessage());
181
			logger.error(e1.getMessage());
86
			printHelp();
182
			printHelp();
87
			System.exit(1);
183
			System.exit(1);
88
		}
184
		}
-
 
185
		try {
89
		ALFEmitter emitter = new ALFEmitter(cmd, startTime);
186
			ALFEmitter emitter = new ALFEmitter(cmd, startTime);
-
 
187
		} catch (ConfigurationException e) {
-
 
188
			System.exit(1);
-
 
189
		}
90
		long endTime = System.currentTimeMillis();
190
		long endTime = System.currentTimeMillis();
91
		logger.debug("Total execution took '"+(endTime-startTime)+"' milliseconds.");
191
		logger.debug("Total execution took '"+(endTime-startTime)+"' milliseconds.");
92
		System.exit(0);
192
		System.exit(0);
93
	}
193
	}
-
 
194
	
-
 
195
	/**
-
 
196
	 * Read a configuration parameter from the config file
-
 
197
	 * Creates log messages according to parameters.
-
 
198
	 * 
-
 
199
	 * @param key				property name
-
 
200
	 * @param defaultValue		default value or null
-
 
201
	 * @param isRequired		wether or not this is a required option
-
 
202
	 * @param logmessage		optional log message (or null)
-
 
203
	 * @return					property value
-
 
204
	 * @throws ConfigurationException
-
 
205
	 */
-
 
206
	private Object readConfProperty(String key, Object defaultValue, boolean isRequired, PropertyType type, String logmessage) throws ConfigurationException {
-
 
207
		Object value = null;
-
 
208
		switch (type) {
-
 
209
		case BOOLEAN:
-
 
210
			value = config.getBoolean(key, (Boolean) defaultValue);
-
 
211
			break;
94
	
212
		case STRINGARRAY:
95
	private final String repos;
213
			value = config.getStringArray(key);
-
 
214
			defaultValue = null;
-
 
215
			break;
-
 
216
 
-
 
217
		default:
-
 
218
			value = config.getString(key, (String) defaultValue);
-
 
219
			break;
-
 
220
		}
-
 
221
		 
96
	private final String txn;
222
		if(isRequired && value == null) {
97
	private final String rev;
223
			//required property	
98
	private SVNCommitInfo info;
224
			if(defaultValue == null) {
-
 
225
				//No value, no default
-
 
226
				String s = String.format("Could not load a value for the key '%s' from the configuration file. This is a required property without a default.", key);
99
	private OMElement template;
227
				logger.error(s);
-
 
228
				throw new ConfigurationException(s);
100
	private Configuration config;
229
			}
-
 
230
			if(defaultValue!=null) {
-
 
231
				//No value, but default
-
 
232
				logger.debug(String.format("Using property value '%s' for key '%s'. This is the default value. The property is required.", value, key));
-
 
233
			}
-
 
234
		} 
-
 
235
		if( (! isRequired) && value == null) {
-
 
236
			//not required
-
 
237
			if(value == null && defaultValue == null) {
-
 
238
				//No value, no default
-
 
239
				String s = String.format("Could not load a value for the key '%s' from the configuration file. This property has no default, but it is optional anyway.", key);
-
 
240
				logger.warn(s);
-
 
241
			}
-
 
242
			if(value == null && defaultValue!=null) {
-
 
243
				//No value, but default
-
 
244
				logger.debug(String.format("Using property value '%s' for key '%s'. This is the default value. The property is optional.", value, key));
-
 
245
			}
-
 
246
		}
-
 
247
		if(value!=null) logger.debug(String.format("Using property value '%s' for key '%s'.", value, key));
-
 
248
		if(logmessage!=null) logger.info(logmessage);
-
 
249
		return value;
-
 
250
	}
-
 
251
	
-
 
252
	
-
 
253
	private String readConfPropertyAsString(String key, String defaultValue, boolean isRequired, String logmessage) throws ConfigurationException {
-
 
254
		return (String) readConfProperty(key, defaultValue, isRequired, PropertyType.STRING, logmessage);
-
 
255
	}
-
 
256
	private String[] readConfPropertyAsStringArray(String key, boolean isRequired, String logmessage) throws ConfigurationException {
-
 
257
		return (String[]) readConfProperty(key, null, isRequired, PropertyType.STRINGARRAY, logmessage);
-
 
258
	}
-
 
259
	private boolean readConfPropertyAsBoolean(String key, boolean defaultValue, boolean isRequired, String logmessage) throws ConfigurationException {
101
	private final String nss;
260
		Boolean b =  (Boolean) readConfProperty(key, defaultValue, isRequired, PropertyType.BOOLEAN, logmessage);
-
 
261
		return b.booleanValue();
102
	private final long startTime;
262
	}
103
		
263
		
104
	private ALFEmitter(CommandLine cmd, long startTime) {
264
	private ALFEmitter(CommandLine cmd, long startTime) throws ConfigurationException {
105
		this.startTime = startTime;
265
		this.startTime = startTime;
106
		repos = cmd.getOptionValue(PARAM_REPOS);
266
		repos = cmd.getOptionValue(PARAM_REPOS);
107
		txn = cmd.getOptionValue(PARAM_TXN);
267
		txn = cmd.getOptionValue(PARAM_TXN);
108
		rev = cmd.getOptionValue(PARAM_REV);
268
		rev = cmd.getOptionValue(PARAM_REV);
109
		String config_file = cmd.getOptionValue(PARAM_CONFIG, "emitter.properties");
269
		String config_file = cmd.getOptionValue(PARAM_CONFIG, "emitter.properties");
-
 
270
		EmitterUtil.verifyFile(config_file, false, false);
110
 
271
 
111
		logger.debug(String.format("Using REPOS='%s' and TXN='%s'.", repos, txn));
272
		logger.debug(String.format("Using REPOS='%s' and TXN='%s'.", repos, txn));
112
	
273
	
113
		config = null;
274
		config = null;
114
		try {
275
		try {
115
			config = new PropertiesConfiguration(config_file);
276
			config = new PropertiesConfiguration(config_file);
116
		} catch (ConfigurationException e) {
277
		} catch (ConfigurationException e) {
117
			logger.error("Could not find/ load '"+config_file+"' file.", e);
278
			logger.error("Could not find/ load '"+config_file+"' file.", e);
118
			System.exit(1);
279
			System.exit(1);
119
		}
280
		}
120
		
281
		
121
		/*
282
		/*
122
		 * Load Properties from Configuration file
283
		 * Load Properties from Configuration file
123
		 */
284
		 */
124
		
-
 
125
		//it might be interesting to look into SVNKit
285
		//it might be interesting to look into SVNKit
126
		//for a pure Java implementation in future
286
		//for a pure Java implementation in future
127
		final String svnlook = config.getString("svnlook"); 
287
			final String svnlook			=	readConfPropertyAsString(OPTION_SVNLOOK, null, true, null);
128
		logger.debug("Using svnlook at '" + svnlook +"'.");
288
			EmitterUtil.verifyFile(svnlook, false, true);
129
		
289
			
-
 
290
			// Issue Id RegEx to parse commit message
130
		final String[] issuepatterns = config.getStringArray("issuepattern");
291
			final String[] issuepatterns = readConfPropertyAsStringArray(OPTION_ISSUEPATTERN, false, null);
131
		StringBuilder sb = new StringBuilder(); for(String s : issuepatterns) sb.append(s);
292
			StringBuilder sb = new StringBuilder(); for(String s : issuepatterns) sb.append(s);
132
		logger.debug(String.format("Using issue id patterns: '%s'.", sb.toString()));
293
			logger.debug(String.format("Using issue id patterns: '%s'.", sb.toString()));
133
		
294
			
-
 
295
			// Flags to indicate what should be done
134
		final String eventtemplate = config.getString("eventtemplate");
296
			final boolean isSoapEnabled 	= readConfPropertyAsBoolean(OPTION_IS_SOAPENABLED, true, true, null);
-
 
297
			final boolean isXmlProcessingEnabled 	= readConfPropertyAsBoolean(OPTION_IS_XMLPROCESSINGENABLED, true, true, null);
-
 
298
			final boolean isWithVerification= readConfPropertyAsBoolean(OPTION_IS_VERIFICATIONENABLED, false, true, null);
135
		logger.debug("Using alf event template at '" + eventtemplate +"'.");
299
			final boolean isRemoveIssues	= readConfPropertyAsBoolean(OPTION_REMOVE_ISSUES_FROM_COMMIT, false, true, "");
136
		
300
			
-
 
301
			/*
-
 
302
			 * SVNLook phase
-
 
303
			 * Use svnlook to obtain information from SVN
-
 
304
			 */
137
		nss = config.getString("eventnamespace", "http://www.eclipse.org/alf/schema/EventBase/1");
305
			SVNLookExecutor exec = new SVNLookExecutor(new File(svnlook), repos);
-
 
306
			if(cmd.hasOption(PARAM_TXN)) exec.setTXN(txn);
-
 
307
			if(cmd.hasOption(PARAM_REV)) exec.setRev(rev);
-
 
308
			info = exec.getCommitInfo();			
138
		logger.debug("Using alf event namespace '" + nss +"'.");
309
			info.parseIssues(issuepatterns, isRemoveIssues);
139
		
310
			
-
 
311
			logger.debug("SVNCommitInfo author: "+ info.getAuthor());
140
		final String marker_logmessage = config.getString("marker.logmessage", "@@logmessage@@");
312
			SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
-
 
313
			String datestring = f.format(info.getDate());
141
		logger.debug("Using comment marker '<!-- " + marker_logmessage +" -->' in event template for logmessage.");
314
			datestring= datestring.substring(0, 26) + ":" + datestring.substring(26); //hack into ISO 8601 format
142
		
-
 
-
 
315
			logger.debug("SVNCommitInfo date: "+ datestring);
143
		final String marker_author = config.getString("marker.author", "@@author@@");
316
			logger.debug("SVNCommitInfo log message: "+ info.getLogmessage());
144
		logger.debug("Using comment marker '<!-- " + marker_author +" -->' with event template for author.");
317
			logger.debug("SVNCommitInfo file list: "+ info.getChangeFileListAsString());
145
		
318
			
-
 
319
			/*
-
 
320
			 * Verification phase
-
 
321
			 */
-
 
322
			boolean isTrace = false;
-
 
323
			if(isWithVerification) {
-
 
324
				sbm_user 					= 	readConfPropertyAsString(OPTION_SBM_USER, null, true, null);
146
		final String marker_addedfiles = config.getString("marker.addedfiles", "@@addedfiles@@");
325
				sbm_pass 					= 	readConfPropertyAsString(OPTION_SBM_PASSWORD, null, false, null);
147
		logger.debug("Using comment marker '<!-- " + marker_addedfiles +" -->' with event template for files added during commit.");
326
				endpoint					= 	readConfPropertyAsString(OPTION_SBM_ENDPOINT, "http://localhost/gsoap/gsoap_ssl.dll?sbmappservices72", true, null);
-
 
327
				querytable					= 	readConfPropertyAsString(OPTION_SBM_TABLE, null, true, null);
-
 
328
				query						= 	readConfPropertyAsString(OPTION_SBM_QUERY, null, false, null);
-
 
329
				isTrace						=	readConfPropertyAsBoolean(OPTION_IS_WSTRACE, false, true, null);
148
		
330
			
149
		final String marker_deletedfiles = config.getString("marker.deletedfiles", "@@deletedfiles@@");
331
				logger.debug(String.format("Starting verification for '%s' issues in the list.", info.getIssues().size()));
-
 
332
				boolean isOK = verify(info.getIssues(), isTrace);
-
 
333
				if(! isOK ) {
150
		logger.debug("Using comment marker '<!-- " + marker_deletedfiles +" -->' with event template for files deleted during commit.");
334
					logger.error("Verification of issue failed. No matching issue was found.");
-
 
335
					System.exit(1);
-
 
336
				}
-
 
337
			} else {
-
 
338
				sbm_user = null; sbm_pass=null; endpoint=null; querytable=null; query=null;
-
 
339
			}
151
		
340
 
-
 
341
			/*
152
		final String marker_changedfiles = config.getString("marker.changedfiles", "@@changedfiles@@");
342
			 * XML processing phase
-
 
343
			 */			
153
		logger.debug("Using comment marker '<!-- " + marker_changedfiles +" -->' with event template for files changed during commit.");
344
			if(isXmlProcessingEnabled) {
154
		
345
				
155
		final String marker_fileselementname = config.getString("marker.fileselementname", "file");
-
 
156
		logger.debug("Using element name '" +marker_fileselementname +"' to wrap files list.");
-
 
157
		
346
				
158
		final String marker_issues = config.getString("marker.issues", "@@issues@@");
-
 
159
		logger.debug("Using comment marker '<!-- " + marker_issues +" -->' with event template for issue list.");
-
 
-
 
347
			}
160
		
348
			
161
		final String marker_issueselementname = config.getString("marker.issueselementname", "issue");
-
 
162
		logger.debug("Using element name '" +marker_issueselementname +"' to wrap issue list.");
-
 
163
		
349
			
164
		final String eventmanager = config.getString("eventmanager");
-
 
165
		logger.debug("Using eventmanager at '" +eventmanager +"'.");
-
 
166
		
350
			
-
 
351
			/*
167
		final String eventmanager_user = config.getString("eventmanager.user");
352
			 * ALF Event Send phase
-
 
353
			 */
168
		final String eventmanager_pass = config.getString("eventmanager.password");
354
			String eventmanager = null;
-
 
355
			if(isSoapEnabled) {
169
		logger.debug("Using username '" +eventmanager_user +"' and a password.");
356
				eventmanager 		= 	readConfPropertyAsString(OPTION_EVENTMANAGER_URL, null, true, null);
-
 
357
			}
170
		
358
 
171
		final boolean isSoapEnabled = config.getBoolean("isSoapEnabled", true);
-
 
172
		logger.debug("Sending soap message is enabled='" +isSoapEnabled +"'.");
-
 
-
 
359
			
-
 
360
			
-
 
361
		
-
 
362
		/**
-
 
363
		 * Event XML Erzeugen
-
 
364
		 */
-
 
365
		try {
-
 
366
			String resultxml=null;
-
 
367
			if(isXmlProcessingEnabled) {
-
 
368
				
-
 
369
				processXml();
-
 
370
				addALFSecurity();
-
 
371
				addEventHeader();
-
 
372
				
-
 
373
				// Serialize xml message to String
-
 
374
				StringWriter out = new StringWriter();
-
 
375
				template.getParent().serialize(out);
-
 
376
				out.flush();
173
		
377
				
174
		final boolean isDropResponse = config.getBoolean("isDropResponse", true);
378
				resultxml =  out.getBuffer().toString();
-
 
379
				logger.debug("ALFEvent result:\n"+resultxml);
-
 
380
		
-
 
381
			} else {
-
 
382
				logger.debug("Xml processing is deactivated.");
-
 
383
			}
-
 
384
		
-
 
385
			if(isSoapEnabled && isXmlProcessingEnabled) {
-
 
386
				final boolean isDropResponse 	= readConfPropertyAsBoolean(OPTION_IS_DROPENABLED, true, true, null);
175
		logger.debug("Receiving the soap response is enabled='" +isDropResponse +"'.");
387
				SimpleHttpEvent sender = new SimpleHttpEvent(eventmanager, resultxml);
176
		
388
				sender.sendSoap(isDropResponse);
-
 
389
				logger.debug(String.format("Sending/ receiving the soap message took '%s' milliseconds.", sender.getDuration()));
-
 
390
			} else {
-
 
391
				logger.warn("Sending soap message and/ or xml processing is deactivated.");
-
 
392
			}
177
		
393
			
-
 
394
			
178
		try {
395
		} catch (FileNotFoundException e) {
-
 
396
			logger.error(e.getMessage(), e);
-
 
397
			System.exit(1);
-
 
398
		} catch (ClientProtocolException e) {
179
			template = OMXMLBuilderFactory.createOMBuilder(new FileInputStream(new File(eventtemplate)))
399
			logger.error(e.getMessage(), e);
180
					.getDocument().getOMDocumentElement();
400
			System.exit(1);
-
 
401
		} catch (IOException e) {
-
 
402
			logger.error(e.getMessage(), e);
-
 
403
			System.exit(1);
-
 
404
		} catch (XMLStreamException e) {
-
 
405
			logger.error(e.getMessage(), e);
-
 
406
			System.exit(1);
-
 
407
		} catch (JaxenException e) {
-
 
408
			logger.error(e.getMessage(), e);
-
 
409
			System.exit(1);
-
 
410
		} finally {
-
 
411
			logger.debug("Total execution took '"+(System.currentTimeMillis()-startTime)+"' milliseconds.");
-
 
412
			String forcefail = config.getString(OPTION_IS_FORCEFAILENABLED, "");
-
 
413
			if(forcefail.length()>0) {
-
 
414
				logger.warn("Force fail is active. All commits will be blocked.");
181
		} catch (FileNotFoundException e1) {
415
				System.exit(1);
182
			logger.error(String.format("Could not load XML event template from file '%s'.", eventtemplate), e1);
-
 
183
			System.exit(1);
416
			}
184
		}
-
 
185
		
-
 
186
		/*
417
			
187
		 * 
418
		}
188
		 */
-
 
189
		SVNLookExecutor exec = new SVNLookExecutor(new File(svnlook), repos);
-
 
190
		if(cmd.hasOption(PARAM_TXN)) exec.setTXN(txn);
419
		
191
		if(cmd.hasOption(PARAM_REV)) exec.setRev(rev);
-
 
192
		info = exec.getCommitInfo();
420
	}
193
		
-
 
194
		info.parseIssues(issuepatterns);
421
		private void addEventHeader() throws JaxenException {
195
		
-
 
196
		logger.debug("SVNCommitInfo author: "+ info.getAuthor());
-
 
197
		SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
422
			AXIOMXPath path = new AXIOMXPath("//bru1:Base/bru1:EventId");
198
		String datestring = f.format(info.getDate());
-
 
199
		datestring= datestring.substring(0, 26) + ":" + datestring.substring(26); //hack into ISO 8601 format
-
 
200
		logger.debug("SVNCommitInfo date: "+ datestring);
-
 
201
		logger.debug("SVNCommitInfo log message: "+ info.getLogmessage());
423
			path.addNamespace("bru1",  nss);
202
		logger.debug("SVNCommitInfo file list: "+ info.getChangeFileListAsString());
424
			OMElement n = (OMElement) path.selectSingleNode(template);
203
		
425
			if(n==null) {
204
		
-
 
205
		/**
-
 
206
		 * Event XML Erzeugen
-
 
207
		 */
-
 
208
		try {
-
 
209
			addElement( marker_logmessage, info.getLogmessage(), true);
-
 
210
			addElement(marker_author, info.getAuthor(), false);
-
 
211
			addElement("@@timestamp@@", datestring, false);
-
 
-
 
426
				logger.error("<Base> element in message is incomplete. <EventId> is missing.");
-
 
427
			} else {
-
 
428
				n.addChild( n.getOMFactory().createOMText("1"));
-
 
429
			}
-
 
430
			
-
 
431
			path = new AXIOMXPath("//bru1:Base/bru1:ObjectId");
-
 
432
			path.addNamespace("bru1",  nss);
-
 
433
			n = (OMElement) path.selectSingleNode(template);
-
 
434
			if(n==null) {
-
 
435
				logger.error("<Base> element in message is incomplete. <ObjectId> is missing.");
-
 
436
			} else {
-
 
437
				n.addChild( n.getOMFactory().createOMText(info.getTxn() ));
-
 
438
			}
212
			addElements(marker_changedfiles, info.getChangedFiles(), marker_fileselementname);
439
		}
213
			addElements(marker_deletedfiles, info.getDeletedFiles(), marker_fileselementname);
440
	
214
			addElements(marker_addedfiles, info.getAddedFiles(), marker_fileselementname);
441
		private void addALFSecurity() throws ConfigurationException, JaxenException {
215
			addElements(marker_issues, info.getIssues(), marker_issueselementname);
442
			final String eventmanager_user 	= 	readConfPropertyAsString(OPTION_EVENTMANAGER_USER, null, false, null);
216
			
443
			final String eventmanager_pass 	= 	readConfPropertyAsString(OPTION_EVENTMANAGER_PASSWORD, null, false, null);
217
			AXIOMXPath path = new AXIOMXPath("//bru1:User");
444
			AXIOMXPath path = new AXIOMXPath("//bru1:User");
218
			OMNamespace ns = template.findNamespace(nss, null);
445
			OMNamespace ns = template.findNamespace(nss, null);
219
			path.addNamespace("bru1", nss);
446
			path.addNamespace("bru1", nss);
220
			OMElement n = (OMElement) path.selectSingleNode(template);
447
			OMElement n = (OMElement) path.selectSingleNode(template);
221
			if(n== null) { 
448
			if(n== null) { 
222
				logger.warn( String.format("<User> element was not found in namespace '%s'. Cannot add ALFSecurity elements. This is required since SBM 10.1.x.", nss));
449
				logger.warn( String.format("<User> element was not found in namespace '%s'. Cannot add ALFSecurity elements. This is required since SBM 10.1.x.", nss));
223
			} else {
450
			} else {
224
				/*
451
				/*
225
				 *  <ns:User>
452
				 *  <ns:User>
226
            		<!--Optional:-->
453
            		<!--Optional:-->
227
               		<ns:ALFSecurity>
454
               		<ns:ALFSecurity>
228
                  		<ns:UsernameToken>
455
                  		<ns:UsernameToken>
229
                     		<ns:Username>admin</ns:Username>
456
                     		<ns:Username>admin</ns:Username>
230
                     		<ns:Password></ns:Password>
457
                     		<ns:Password></ns:Password>
231
                  		</ns:UsernameToken>
458
                  		</ns:UsernameToken>
232
               		</ns:ALFSecurity>
459
               		</ns:ALFSecurity>
233
					</ns:User> 
460
					</ns:User> 
234
				 */
461
				 */
235
				n.removeChildren();
462
				n.removeChildren();
236
				OMFactory fac = n.getOMFactory();
463
				OMFactory fac = n.getOMFactory();
237
				fac.createOMComment(n, "Generated by SVN-ALFEmitter");
464
				fac.createOMComment(n, "Generated by SVN-ALFEmitter");
238
				OMElement sec = fac.createOMElement("ALFSecurity", ns);
465
				OMElement sec = fac.createOMElement("ALFSecurity", ns);
239
				OMElement token = fac.createOMElement("UsernameToken", ns);
466
				OMElement token = fac.createOMElement("UsernameToken", ns);
240
				OMElement user = fac.createOMElement("Username", ns);
467
				OMElement user = fac.createOMElement("Username", ns);
241
				user.addChild( fac.createOMText(eventmanager_user));
468
				user.addChild( fac.createOMText(eventmanager_user));
242
				OMElement pass = fac.createOMElement("Password", ns);
469
				OMElement pass = fac.createOMElement("Password", ns);
243
				pass.addChild(fac.createOMText(eventmanager_pass, OMNode.CDATA_SECTION_NODE));
470
				pass.addChild(fac.createOMText(eventmanager_pass, OMNode.CDATA_SECTION_NODE));
244
				token.addChild( user );
471
				token.addChild( user );
245
				token.addChild( pass);
472
				token.addChild( pass);
246
				sec.addChild(token);
473
				sec.addChild(token);
247
				n.addChild(sec);				
474
				n.addChild(sec);				
248
			}
475
			}
-
 
476
		}
249
			
477
	
250
			path = new AXIOMXPath("//bru1:Base/bru1:EventId");
478
		private void processXml() throws ConfigurationException, JaxenException {
251
			path.addNamespace("bru1",  nss);
479
			// read additional configuration
-
 
480
			final String eventtemplate 		= 	readConfPropertyAsString(OPTION_EVENTTEMPLATE, null, true, null);
252
			n = (OMElement) path.selectSingleNode(template);
481
			EmitterUtil.verifyFile(eventtemplate, false, false);
253
			if(n==null) {
482
			try {
254
				logger.error("<Base> element in message is incomplete. <EventId> is missing.");
483
				template = OMXMLBuilderFactory.createOMBuilder(new FileInputStream(new File(eventtemplate)))
-
 
484
						.getDocument().getOMDocumentElement();
255
			} else {
485
			} catch (FileNotFoundException e1) {
256
				n.addChild( n.getOMFactory().createOMText(UUID.randomUUID().toString() ));
486
				logger.error(String.format("Could not load XML event template from file '%s'.", eventtemplate), e1);
-
 
487
				System.exit(1);
257
			}
488
			}
-
 
489
			nss 	= 	readConfPropertyAsString(OPTION_EVENTNAMESPACE, "http://www.eclipse.org/alf/schema/EventBase/1", true, null);
-
 
490
			final String marker_logmessage 	= 	readConfPropertyAsString(OPTION_MARKER_LOGMESSAGE, "@@logmessage@@", true, null);
-
 
491
			final String marker_author 		= 	readConfPropertyAsString(OPTION_MARKER_AUTHOR, "@@author@@", true, null);
-
 
492
			final String marker_revision	= 	readConfPropertyAsString(OPTION_MARKER_REVISION, "@@revision@@", true, null);
-
 
493
			final String marker_addedfiles 	= 	readConfPropertyAsString(OPTION_MARKER_ADDEDFILES, "@@addedfiles@@", true, null);
-
 
494
			final String marker_deletedfiles = 	readConfPropertyAsString(OPTION_MARKER_DELETEDFILES, "@@deletedfiles@@", true, null);
-
 
495
			final String marker_changedfiles = 	readConfPropertyAsString(OPTION_MARKER_CHANGEDFILES, "@@changedfiles@@", true, null);
-
 
496
			final String marker_fileselementname = readConfPropertyAsString("marker.fileselementname", "file", true, null);
-
 
497
			final String marker_issues 		= 	readConfPropertyAsString(OPTION_MARKER_ISSUES, "@@issues@@", true, null);
-
 
498
			final String marker_issueselementname = readConfPropertyAsString("marker.issueselementname", "issue", true, null);
-
 
499
			final String marker_internalissues    = readConfPropertyAsString(OPTION_MARKER_INTERNALISSUES, "@@internalissues@@", true, null);
-
 
500
	
-
 
501
			SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
-
 
502
			String datestring = f.format(info.getDate());
-
 
503
			datestring= datestring.substring(0, 26) + ":" + datestring.substring(26); //hack into ISO 8601 format
258
			
504
			
259
			path = new AXIOMXPath("//bru1:Base/bru1:ObjectId");
505
			// add content from SVNCommitInfo object where
260
			path.addNamespace("bru1",  nss);
506
			// XML commit markers are
261
			n = (OMElement) path.selectSingleNode(template);
507
			addElement( marker_logmessage, info.getLogmessage(), true);
262
			if(n==null) {
508
			addElement(marker_author, info.getAuthor(), false);
263
				logger.error("<Base> element in message is incomplete. <ObjectId> is missing.");
509
			addElement(marker_revision, info.getRev(), false);
264
			} else {
510
			addElement("@@timestamp@@", datestring, false);
265
				n.addChild( n.getOMFactory().createOMText(info.getTxn() ));
-
 
266
			}
-
 
-
 
511
			addElements(marker_changedfiles, info.getChangedFiles(), marker_fileselementname);
267
 
512
			addElements(marker_deletedfiles, info.getDeletedFiles(), marker_fileselementname);
268
			StringWriter out = new StringWriter();
513
			addElements(marker_addedfiles, info.getAddedFiles(), marker_fileselementname);
269
			template.getParent().serialize(out);
514
			addElements(marker_issues, info.getIssues(), marker_issueselementname);
-
 
515
			addElements(marker_internalissues, internalissues, marker_issueselementname);
-
 
516
			
270
			out.flush();
517
		}
-
 
518
	
-
 
519
		private boolean verify(List<String> issues, boolean isTrace) {
271
			
520
		
272
			String resultxml =  out.getBuffer().toString();
-
 
273
			logger.debug("ALFEvent result:\n"+resultxml);
521
			Sbmappservices72 ss = new Sbmappservices72(ClassLoader.getSystemResource("sbmappservices72.wsdl") );
274
			
522
			Sbmappservices72PortType port = ss.getSbmappservices72();
275
			if(isSoapEnabled) {
523
			
276
				SimpleHttpEvent sender = new SimpleHttpEvent(eventmanager, resultxml);
-
 
277
				sender.sendSoap(isDropResponse);
524
			Client client = ClientProxy.getClient(port);
278
				logger.debug(String.format("Sending/ receiving the soap message took '%s' milliseconds.", sender.getDuration()));
525
			if(isTrace) {
-
 
526
		        client.getInInterceptors().add(new LoggingInInterceptor());
-
 
527
		        client.getOutInterceptors().add(new LoggingOutInterceptor());
-
 
528
			}
-
 
529
			BindingProvider bindingProvider = (BindingProvider) port;
-
 
530
	        bindingProvider.getRequestContext().put(
-
 
531
	        BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
-
 
532
			
279
			} else {
-
 
280
				logger.warn("Sending soap message is deactivated.");
-
 
281
			}
-
 
282
			
-
 
283
			
-
 
284
		} catch (FileNotFoundException e) {
-
 
285
			logger.error(e.getMessage(), e);
-
 
286
			System.exit(1);
-
 
287
		} catch (ClientProtocolException e) {
-
 
288
			logger.error(e.getMessage(), e);
-
 
289
			System.exit(1);
-
 
290
		} catch (IOException e) {
-
 
291
			logger.error(e.getMessage(), e);
-
 
292
			System.exit(1);
-
 
293
		} catch (XMLStreamException e) {
-
 
294
			logger.error(e.getMessage(), e);
-
 
295
			System.exit(1);
-
 
296
		} catch (JaxenException e) {
533
			ObjectFactory fac = new ObjectFactory();
297
			logger.error(e.getMessage(), e);
-
 
298
			System.exit(1);
534
			Auth auth = fac.createAuth();
299
		} finally {
-
 
300
			logger.debug("Total execution took '"+(System.currentTimeMillis()-startTime)+"' milliseconds.");
-
 
-
 
535
			auth.setUserId(fac.createAuthUserId(sbm_user));
-
 
536
			auth.setPassword(fac.createAuthPassword(sbm_pass));
-
 
537
			
-
 
538
			TableIdentifier table = fac.createTableIdentifier();
-
 
539
			table.setDbName(fac.createTableIdentifierDbName(querytable));
-
 
540
			
-
 
541
			MultipleResponseItemOptions options = fac.createMultipleResponseItemOptions();
-
 
542
			options.setSections(SectionsOption.SECTIONS_NONE);
-
 
543
			
-
 
544
			for(String issue : issues) {
-
 
545
				issue = issue.replaceAll("[^0-9]", "");
-
 
546
				String queryWhereClause = "TS_ISSUEID = '"+issue+"'";
-
 
547
				if(query!=null && query.length()>0) queryWhereClause = queryWhereClause + " And " + query;
-
 
548
				logger.debug(String.format("Using query against table '%s'. Query where clause: '%s'", querytable, queryWhereClause ));
-
 
549
				try {
-
 
550
					TTItemList items = port.getItemsByQuery(auth, table, queryWhereClause, "", null, BigInteger.valueOf(1), options);
-
 
551
					
-
 
552
					//Marshaller m = JAXBContext.newInstance(TTItemList.class).createMarshaller();
-
 
553
					//m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
-
 
554
					//m.marshal( new JAXBElement<TTItemList>(new QName("uri","local"), TTItemList.class, items), System.err);
-
 
555
					
-
 
556
					logger.debug(String.format("Got Response from getItemsByQuery"));
-
 
557
					if(items!=null) {
-
 
558
						logger.debug(String.format("Verification query matched '%s' item(s) for issue '%s.'",items.getTotalCount(), issue));
-
 
559
					}
-
 
560
					if(items.getTotalCount().intValue()<=0) {
-
 
561
						return false;
-
 
562
					} else {
-
 
563
						internalissues.add(items.getItem().get(0).getId().getValue().getTableIdItemId().getValue());
-
 
564
					}
301
			String forcefail = config.getString("forcefail", "");
565
					
-
 
566
				} catch (AEWebservicesFaultFault e) {
302
			if(forcefail.length()>0) {
567
					logger.debug("Web service fault: " + e.getFaultInfo());
303
				logger.warn("Force fail is active. All commits will be blocked.");
-
 
304
				System.exit(1);
568
				} catch (Exception e) {
305
			}
569
					logger.debug("Unknown Exception", e);
306
			
570
				}
307
		}
571
			}
308
		
572
			return true;
309
	}
573
		
310
	
574
	}
311
	
575
 
312
		private void addElement(String pattern, String newCdata, boolean wrapCDATA) throws JaxenException {
576
		private void addElement(String pattern, String newCdata, boolean wrapCDATA) throws JaxenException {
313
			OMComment comment = findComment(pattern);
577
			OMComment comment = findComment(pattern);
314
			if(comment!=null) {
578
			if(comment!=null) {
315
				OMFactory fac = OMAbstractFactory.getOMFactory();
579
				OMFactory fac = OMAbstractFactory.getOMFactory();
316
				int type = OMNode.TEXT_NODE;
580
				int type = OMNode.TEXT_NODE;
317
				if(wrapCDATA) {
581
				if(wrapCDATA) {
318
					type = OMNode.CDATA_SECTION_NODE;
582
					type = OMNode.CDATA_SECTION_NODE;
319
				}
583
				}
320
				OMText text = fac.createOMText(newCdata, type);
584
				OMText text = fac.createOMText(newCdata, type);
321
				comment.insertSiblingAfter(text);
585
				comment.insertSiblingAfter(text);
322
			}			
586
			}			
323
		}
587
		}
324
		
588
		
325
		private void addElements(String pattern, List<String> files, String elementName) throws JaxenException {
589
		private void addElements(String pattern, List<String> files, String elementName) throws JaxenException {
326
			if(files.size()<=0) return;
590
			if(files.size()<=0) return;
327
			OMComment comment = findComment(pattern);
591
			OMComment comment = findComment(pattern);
328
			if(comment!=null) {
592
			if(comment!=null) {
329
				OMFactory fac = OMAbstractFactory.getOMFactory();
593
				OMFactory fac = OMAbstractFactory.getOMFactory();
330
				OMNamespace ns = template.findNamespace(nss, null);
594
				OMNamespace ns = template.findNamespace(nss, null);
331
				if(ns == null) logger.error(String.format("The namespace '%s' is not defined in the template.", nss));
595
				if(ns == null) logger.error(String.format("The namespace '%s' is not defined in the template.", nss));
332
				for(String s : files) {
596
				for(String s : files) {
333
					OMElement e = fac.createOMElement(elementName, ns);
597
					OMElement e = fac.createOMElement(elementName, ns);
334
					OMText text = fac.createOMText(s, OMNode.TEXT_NODE);
598
					OMText text = fac.createOMText(s, OMNode.TEXT_NODE);
335
					e.addChild(text);
599
					e.addChild(text);
336
					comment.insertSiblingAfter(e);
600
					comment.insertSiblingAfter(e);
337
				}				
601
				}				
338
			}
602
			}
339
		}
603
		}
340
		
604
		
341
	
605
	
342
		private OMComment findComment(String pattern) throws JaxenException {
606
		private OMComment findComment(String pattern) throws JaxenException {
343
			AXIOMXPath path = new AXIOMXPath("//comment()[. = '"+pattern+"'][1]");
607
			AXIOMXPath path = new AXIOMXPath("//comment()[. = '"+pattern+"'][1]");
344
			//OMNamespace ns = template.findNamespace(nss, null);
608
			//OMNamespace ns = template.findNamespace(nss, null);
345
			path.addNamespace("bru1", nss);
609
			path.addNamespace("bru1", nss);
346
			OMComment n = (OMComment) path.selectSingleNode(template);
610
			OMComment n = (OMComment) path.selectSingleNode(template);
347
			if(n!=null) return n;
611
			if(n!=null) return n;
348
			logger.warn("Comment '"+pattern+"' was not found in the XML template.");
612
			logger.warn("Comment '"+pattern+"' was not found in the XML template.");
349
			return null;
613
			return null;
350
		}
614
		}
351
		/*
-
 
352
		private static OMComment findComment(OMElement element, String pattern) {
-
 
353
			logger.trace( String.format("Searching for comment pattern '%s' in element with name '%s'.", pattern, element.getLocalName()));
-
 
354
			Iterator iter = element.getChildren();
-
 
355
 
-
 
356
			while(iter.hasNext()) {
-
 
357
				Object o = iter.next(); 
-
 
358
				if(o instanceof OMNode) {
-
 
359
					OMNode node =  ((OMNode)o);
-
 
360
					
-
 
361
					switch (node.getType() ) {
-
 
362
					case OMNode.COMMENT_NODE:
-
 
363
						OMComment comment = ((OMComment)node);
-
 
364
						String value = comment.getValue().trim();
-
 
365
						if(value.equals(pattern)) {
-
 
366
							logger.debug("Found comment '" + pattern + "' in event template.");
-
 
367
							return comment;
-
 
368
						}
-
 
369
						break;
-
 
370
						
-
 
371
 
-
 
372
					case OMNode.ELEMENT_NODE:
-
 
373
						//traverse
-
 
374
						OMComment result = findComment( (OMElement)node, pattern);
-
 
375
						if(result!=null) return result;
-
 
376
						break;
-
 
377
						
-
 
378
					default:
-
 
379
						break;
-
 
380
					}
-
 
381
				}
-
 
382
			}
-
 
383
			//logger.info("Comment '" + pattern + "' was not found in event template.");
-
 
384
			return null;
-
 
385
		}
-
 
386
		*/
-
 
387
		
-
 
388
	
615
	
389
	@SuppressWarnings("static-access")
616
	@SuppressWarnings("static-access")
390
	private static Options getOptions() {
617
	private static Options getOptions() {
391
		Option repository = OptionBuilder.withArgName( "repository" )
618
		Option repository = OptionBuilder.withArgName( "repository" )
392
											.hasArg()
619
											.hasArg()
393
											.withLongOpt("repository")
620
											.withLongOpt("repository")
394
											.withDescription(  "Path or URL to the SVN repository." )
621
											.withDescription(  "Path or URL to the SVN repository." )
395
											.create( PARAM_REPOS );
622
											.create( PARAM_REPOS );
396
		repository.setRequired(true);
623
		repository.setRequired(true);
397
		
624
		
398
		Option txn = OptionBuilder.withArgName( "transactionid" )
625
		Option txn = OptionBuilder.withArgName( "transactionid" )
399
											.hasArg()
626
											.hasArg()
400
											.withLongOpt("transaction")
627
											.withLongOpt("transaction")
401
											.withDescription(  "The SVN transaction id to examine (TXN). You cannot combine txn with -rev. "
628
											.withDescription(  "The SVN transaction id to examine (TXN). You cannot combine txn with -rev. "
402
													+ "When a txn is given, the repository path must be a local path.")
629
													+ "When a txn is given, the repository path must be a local path.")
403
											.create( PARAM_TXN );
630
											.create( PARAM_TXN );
404
		Option rev = OptionBuilder.withArgName( "revision" )
631
		Option rev = OptionBuilder.withArgName( "revision" )
405
				.hasArg()
632
				.hasArg()
406
				.withDescription(  "A revision to examine. You cannot combine revision with -txn." )
633
				.withDescription(  "A revision to examine. You cannot combine revision with -txn." )
407
				.create( PARAM_REV );
634
				.create( PARAM_REV );
408
		Option config = OptionBuilder.withArgName( "config_file" )
635
		Option config = OptionBuilder.withArgName( "config_file" )
409
				.hasArg()
636
				.hasArg()
410
				.withLongOpt("config")
637
				.withLongOpt("config")
411
				.withDescription(  "The configuration file to use. Defaults to 'emitter.properties'.")
638
				.withDescription(  "The configuration file to use. Defaults to 'emitter.properties'.")
412
				.create( PARAM_CONFIG );
639
				.create( PARAM_CONFIG );
413
		
640
		
414
		Options options = new Options();
641
		Options options = new Options();
415
		options.addOption(repository);
642
		options.addOption(repository);
416
		options.addOption(txn);
643
		options.addOption(txn);
417
		options.addOption(rev);
644
		options.addOption(rev);
418
		options.addOption(config);
645
		options.addOption(config);
419
		return options;
646
		return options;
420
	}
647
	}
421
	
648
	
422
	private static void printHelp() {
649
	private static void printHelp() {
423
		// automatically generate the help statement
650
		// automatically generate the help statement
424
		HelpFormatter formatter = new HelpFormatter();
651
		HelpFormatter formatter = new HelpFormatter();
425
		String header = "\nSVN-ALFEventEmitter " + version +", a SVN hook implemented in Java to emit Eclipse ALFEvents on commit.\n\n";
652
		String header = "\nSVN-ALFEventEmitter " + VERSION +", a SVN hook implemented in Java to emit Eclipse ALFEvents on commit.\n\n";
426
		String footer = "Please send bug reports to bru@brutex.de.\n(c)2013 Brian Rosenberger";
653
		String footer = "Please send bug reports to bru@brutex.de.\n(c)2013 Brian Rosenberger";
427
		formatter.printHelp("java -jar SVN-ALFEventEmitter", header, getOptions(), footer, true);
654
		formatter.printHelp("java -jar SVN-ALFEventEmitter", header, getOptions(), footer, true);
428
	}
655
	}
-
 
656
	
-
 
657
	
-
 
658
	
-
 
659
	private enum PropertyType {
-
 
660
		STRING(), STRINGARRAY(), BOOLEAN();
-
 
661
	}
429
	
662
	
430
	
663
	
431
}
664
}