Subversion Repositories XServices

Rev

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

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