Subversion Repositories XServices

Rev

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

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