Subversion Repositories XServices

Rev

Rev 149 | Rev 152 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 150
Line 18... Line 18...
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;
Line -... Line 29...
-
 
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;
Line -... Line 34...
-
 
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;
Line 30... Line 59...
30
import net.brutex.svn.SVNCommitInfo;
59
import net.brutex.svn.SVNCommitInfo;
31
import net.brutex.svn.SVNLookExecutor;
60
import net.brutex.svn.SVNLookExecutor;
Line 48... Line 77...
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;
Line 61... Line 95...
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 {
Line 65... Line 99...
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";
-
 
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;
Line -... Line 164...
-
 
164
	private final String query;
-
 
165
 
-
 
166
	
71
	private static final String PARAM_CONFIG = "conf";
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();
-
 
183
			System.exit(1);
87
			System.exit(1);
184
		}
-
 
185
		try {
-
 
186
			ALFEmitter emitter = new ALFEmitter(cmd, startTime);
-
 
187
		} catch (ConfigurationException e) {
88
		}
188
			System.exit(1);
89
		ALFEmitter emitter = new ALFEmitter(cmd, startTime);
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.");
Line -... Line 192...
-
 
192
		System.exit(0);
-
 
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:
92
		System.exit(0);
210
			value = config.getBoolean(key, (Boolean) defaultValue);
93
	}
211
			break;
-
 
212
		case STRINGARRAY:
-
 
213
			value = config.getStringArray(key);
-
 
214
			defaultValue = null;
-
 
215
			break;
-
 
216
 
-
 
217
		default:
-
 
218
			value = config.getString(key, (String) defaultValue);
-
 
219
			break;
94
	
220
		}
95
	private final String repos;
221
		 
96
	private final String txn;
222
		if(isRequired && value == null) {
-
 
223
			//required property	
-
 
224
			if(defaultValue == null) {
97
	private final String rev;
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);
98
	private SVNCommitInfo info;
227
				logger.error(s);
-
 
228
				throw new ConfigurationException(s);
-
 
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);
99
	private OMElement template;
258
	}
-
 
259
	private boolean readConfPropertyAsBoolean(String key, boolean defaultValue, boolean isRequired, String logmessage) throws ConfigurationException {
Line 100... Line 260...
100
	private Configuration config;
260
		Boolean b =  (Boolean) readConfProperty(key, defaultValue, isRequired, PropertyType.BOOLEAN, logmessage);
101
	private final String nss;
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;
-
 
266
		repos = cmd.getOptionValue(PARAM_REPOS);
Line 106... Line 267...
106
		repos = cmd.getOptionValue(PARAM_REPOS);
267
		txn = cmd.getOptionValue(PARAM_TXN);
Line 107... Line 268...
107
		txn = cmd.getOptionValue(PARAM_TXN);
268
		rev = cmd.getOptionValue(PARAM_REV);
108
		rev = cmd.getOptionValue(PARAM_REV);
269
		String config_file = cmd.getOptionValue(PARAM_CONFIG, "emitter.properties");
Line 119... Line 280...
119
		}
280
		}
Line 120... Line 281...
120
		
281
		
121
		/*
282
		/*
122
		 * Load Properties from Configuration file
283
		 * Load Properties from Configuration file
123
		 */
-
 
124
		
284
		 */
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);
-
 
289
			
129
		
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()));
-
 
294
			
133
		
295
			// Flags to indicate what should be done
-
 
296
			final boolean isSoapEnabled 	= readConfPropertyAsBoolean(OPTION_IS_SOAPENABLED, true, true, null);
-
 
297
			final boolean isXmlProcessingEnabled 	= readConfPropertyAsBoolean(OPTION_IS_XMLPROCESSINGENABLED, true, true, null);
134
		final String eventtemplate = config.getString("eventtemplate");
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, "");
-
 
300
			
-
 
301
			/*
-
 
302
			 * SVNLook phase
-
 
303
			 * Use svnlook to obtain information from SVN
136
		
304
			 */
-
 
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);
137
		nss = config.getString("eventnamespace", "http://www.eclipse.org/alf/schema/EventBase/1");
308
			info = exec.getCommitInfo();			
138
		logger.debug("Using alf event namespace '" + nss +"'.");
309
			info.parseIssues(issuepatterns, isRemoveIssues);
-
 
310
			
139
		
311
			logger.debug("SVNCommitInfo author: "+ info.getAuthor());
-
 
312
			SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
140
		final String marker_logmessage = config.getString("marker.logmessage", "@@logmessage@@");
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());
-
 
318
			
-
 
319
			/*
-
 
320
			 * Verification phase
-
 
321
			 */
-
 
322
			boolean isTrace = false;
-
 
323
			if(isWithVerification) {
145
		
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);
-
 
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);
147
		logger.debug("Using comment marker '<!-- " + marker_addedfiles +" -->' with event template for files added during commit.");
329
				isTrace						=	readConfPropertyAsBoolean(OPTION_IS_WSTRACE, false, true, null);
148
		
330
			
-
 
331
				logger.debug(String.format("Starting verification for '%s' issues in the list.", info.getIssues().size()));
-
 
332
				boolean isOK = verify(info.getIssues(), isTrace);
149
		final String marker_deletedfiles = config.getString("marker.deletedfiles", "@@deletedfiles@@");
333
				if(! isOK ) {
-
 
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;
150
		logger.debug("Using comment marker '<!-- " + marker_deletedfiles +" -->' with event template for files deleted during commit.");
339
			}
-
 
340
 
151
		
341
			/*
-
 
342
			 * XML processing phase
152
		final String marker_changedfiles = config.getString("marker.changedfiles", "@@changedfiles@@");
343
			 */			
153
		logger.debug("Using comment marker '<!-- " + marker_changedfiles +" -->' with event template for files changed during commit.");
344
			if(isXmlProcessingEnabled) {
154
		
-
 
155
		final String marker_fileselementname = config.getString("marker.fileselementname", "file");
-
 
156
		logger.debug("Using element name '" +marker_fileselementname +"' to wrap files list.");
345
				
157
		
-
 
158
		final String marker_issues = config.getString("marker.issues", "@@issues@@");
-
 
-
 
346
				
159
		logger.debug("Using comment marker '<!-- " + marker_issues +" -->' with event template for issue list.");
347
			}
160
		
-
 
161
		final String marker_issueselementname = config.getString("marker.issueselementname", "issue");
-
 
162
		logger.debug("Using element name '" +marker_issueselementname +"' to wrap issue list.");
348
			
163
		
-
 
164
		final String eventmanager = config.getString("eventmanager");
-
 
165
		logger.debug("Using eventmanager at '" +eventmanager +"'.");
349
			
-
 
350
			
166
		
351
			/*
-
 
352
			 * ALF Event Send phase
167
		final String eventmanager_user = config.getString("eventmanager.user");
353
			 */
-
 
354
			String eventmanager = null;
168
		final String eventmanager_pass = config.getString("eventmanager.password");
355
			if(isSoapEnabled) {
-
 
356
				eventmanager 		= 	readConfPropertyAsString(OPTION_EVENTMANAGER_URL, null, true, null);
169
		logger.debug("Using username '" +eventmanager_user +"' and a password.");
357
			}
170
		
-
 
171
		final boolean isSoapEnabled = config.getBoolean("isSoapEnabled", true);
-
 
-
 
358
 
-
 
359
			
Line -... Line 360...
-
 
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);
172
		logger.debug("Sending soap message is enabled='" +isSoapEnabled +"'.");
376
				out.flush();
173
		
377
				
Line -... Line 378...
-
 
378
				resultxml =  out.getBuffer().toString();
-
 
379
				logger.debug("ALFEvent result:\n"+resultxml);
-
 
380
		
Line -... Line 381...
-
 
381
			} else {
-
 
382
				logger.debug("Xml processing is deactivated.");
-
 
383
			}
-
 
384
		
-
 
385
			if(isSoapEnabled && isXmlProcessingEnabled) {
174
		final boolean isDropResponse = config.getBoolean("isDropResponse", true);
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);
-
 
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.");
176
		
392
			}
-
 
393
			
177
		
394
			
-
 
395
		} catch (FileNotFoundException e) {
-
 
396
			logger.error(e.getMessage(), e);
-
 
397
			System.exit(1);
178
		try {
398
		} catch (ClientProtocolException e) {
179
			template = OMXMLBuilderFactory.createOMBuilder(new FileInputStream(new File(eventtemplate)))
399
			logger.error(e.getMessage(), e);
-
 
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) {
180
					.getDocument().getOMDocumentElement();
414
				logger.warn("Force fail is active. All commits will be blocked.");
Line 181... Line -...
181
		} catch (FileNotFoundException e1) {
-
 
182
			logger.error(String.format("Could not load XML event template from file '%s'.", eventtemplate), e1);
415
				System.exit(1);
183
			System.exit(1);
-
 
184
		}
-
 
185
		
416
			}
186
		/*
417
			
187
		 * 
-
 
188
		 */
-
 
189
		SVNLookExecutor exec = new SVNLookExecutor(new File(svnlook), repos);
418
		}
190
		if(cmd.hasOption(PARAM_TXN)) exec.setTXN(txn);
-
 
191
		if(cmd.hasOption(PARAM_REV)) exec.setRev(rev);
419
		
192
		info = exec.getCommitInfo();
-
 
193
		
420
	}
194
		info.parseIssues(issuepatterns);
-
 
195
		
-
 
196
		logger.debug("SVNCommitInfo author: "+ info.getAuthor());
421
		private void addEventHeader() throws JaxenException {
197
		SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
-
 
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);
422
			AXIOMXPath path = new AXIOMXPath("//bru1:Base/bru1:EventId");
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
		
-
 
204
		
-
 
205
		/**
-
 
206
		 * Event XML Erzeugen
-
 
207
		 */
-
 
208
		try {
-
 
209
			addElement( marker_logmessage, info.getLogmessage(), true);
-
 
210
			addElement(marker_author, info.getAuthor(), false);
-
 
Line -... Line 425...
-
 
425
			if(n==null) {
-
 
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() ));
211
			addElement("@@timestamp@@", datestring, false);
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);
Line 244... Line 471...
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
Line 258... Line 504...
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);
Line -... Line 515...
-
 
515
			addElements(marker_internalissues, internalissues, marker_issueselementname);
-
 
516
			
270
			out.flush();
517
		}
-
 
518
	
-
 
519
		private boolean verify(List<String> issues, boolean isTrace) {
271
			
520
		
Line 272... Line -...
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
			}
Line -... Line 529...
-
 
529
			BindingProvider bindingProvider = (BindingProvider) port;
-
 
530
	        bindingProvider.getRequestContext().put(
-
 
531
	        BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
-
 
532
			
Line 279... Line -...
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.");
-
 
Line -... Line 535...
-
 
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) {
Line 302... Line 567...
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
		
Line 346... Line 610...
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
		
-
 
Line 388... Line 615...
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" )
Line 420... Line 647...
420
	}
647
	}
Line 421... Line 648...
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);
Line -... Line 655...
-
 
655
	}
-
 
656
	
-
 
657
	
-
 
658
	
-
 
659
	private enum PropertyType {
-
 
660
		STRING(), STRINGARRAY(), BOOLEAN();
428
	}
661
	}