Subversion Repositories XServices

Compare Revisions

No changes between revisions

Regard whitespace Rev 149 → Rev 151

/SVN-ALFEventEmitter/trunk/src/net/brutex/svn/SVNLookExecutor.java
28,7 → 28,7
 
import org.apache.log4j.Logger;
 
/** Executes the svnlook utility
/* Executes the svnlook utility
*
* @author Brian Rosenberger bru(at)brutex.de
* @since 0.1
/SVN-ALFEventEmitter/trunk/src/net/brutex/svn/SVNCommitInfo.java
47,7 → 47,7
private final String author;
/** The commit message */
private final String logmessage;
private String logmessage;
/** The date. */
private final Date date;
198,8 → 198,9
* Parses the issues.
*
* @param patterns the patterns
* @param isRemoveIssues
*/
public void parseIssues(String[] patterns) {
public void parseIssues(String[] patterns, boolean isRemoveIssues) {
issues.clear(); //reset
int count = 0;
for(String p : patterns) {
211,7 → 212,12
logger.debug("Found issue '" + matcher.group() + "' in the logmessage.");
count++;
}
if(isRemoveIssues) {
logmessage = matcher.replaceAll("");
logger.debug("Removing all matched issues from commit message");
}
}
logger.debug("Found '" + count + "' issues in the logmessage.");
}
/SVN-ALFEventEmitter/trunk/src/net/brutex/emitter/EventManagerContext.java
0,0 → 1,91
/*
* Copyright 2014 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.emitter;
 
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
 
import org.apache.log4j.Logger;
 
/**
* The EventManagerContext class represents the eventmanager endpoint and authentication credentials.
*
* @author Brian Rosenberger, bru(at)brutex.de
* @since 0.1
*/
public class EventManagerContext {
private Logger logger = Logger.getLogger(EventManagerContext.class);
private final URL url;
private final String user;
private final byte[] pass;
private static final String CHARSET_UTF8 = "UTF-8";
/**
* Create a new Eventmanager context.
*
* @param url URL for the SBM ALF Eventmanager
* @param username ALFSecurity user name
* @param password ALFSecurity password
* @throws MalformedURLException
*/
public EventManagerContext(String url, String username, String password) throws MalformedURLException {
//Verify URL
try {
this.url = new URL(url);
} catch (MalformedURLException e) {
logger.error(String.format("Could not parse '%s' as a valid URL. %s", url, e.getMessage()));
throw e;
}
//Verify username
this.user = username;
if(this.user==null) {
final String s = "Username for ALF Eventmanager cannot be null.";
logger.error(s);
throw new IllegalArgumentException(s);
}
//Verify password
try {
this.pass = password.getBytes(CHARSET_UTF8);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new IllegalArgumentException(e.getMessage());
}
if(this.pass==null) {
final String s = "Password for ALF Eventmanager cannot be null.";
logger.error(s);
throw new IllegalArgumentException(s);
}
}
 
public URL getUrl() {
return url;
}
public String getUser() {
return user;
}
public byte[] getPass() {
return pass;
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/SVN-ALFEventEmitter/trunk/src/net/brutex/emitter/SimpleHttpEvent.java
74,6 → 74,7
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpResponse r = httpclient.execute(post);
logger.debug("Sending event to ALF event manager");
if(! isDropResponse) {
HttpEntity e = r.getEntity();
StringBuilder sb = new StringBuilder();
/SVN-ALFEventEmitter/trunk/src/net/brutex/emitter/ALFEmitter.java
20,13 → 20,42
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringWriter;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
 
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
 
 
 
 
 
 
 
 
 
 
 
 
import javax.xml.ws.BindingProvider;
 
import net.brutex.emitter.util.EmitterUtil;
import net.brutex.sbm.sbmappservices72.AEWebservicesFaultFault;
import net.brutex.sbm.sbmappservices72.Sbmappservices72;
import net.brutex.sbm.sbmappservices72.Sbmappservices72PortType;
import net.brutex.sbm.sbmappservices72.api.Auth;
import net.brutex.sbm.sbmappservices72.api.MultipleResponseItemOptions;
import net.brutex.sbm.sbmappservices72.api.ObjectFactory;
import net.brutex.sbm.sbmappservices72.api.SectionsOption;
import net.brutex.sbm.sbmappservices72.api.TTItemList;
import net.brutex.sbm.sbmappservices72.api.TableIdentifier;
import net.brutex.svn.SVNCommitInfo;
import net.brutex.svn.SVNLookExecutor;
 
50,6 → 79,11
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.message.Message;
import org.apache.http.client.ClientProtocolException;
import org.apache.log4j.Logger;
import org.jaxen.JaxenException;
63,13 → 97,75
*/
public class ALFEmitter {
private static final String version = "0.1";
static Logger logger = Logger.getRootLogger();
public static final String VERSION = "0.1";
private static Logger logger = Logger.getRootLogger();
//
// Keys to read from the configuration file.
//
private static final String OPTION_SVNLOOK = "svnlook";
private static final String OPTION_ISSUEPATTERN = "issuepattern";
private static final String OPTION_EVENTTEMPLATE = "eventtemplate";
private static final String OPTION_EVENTNAMESPACE = "eventnamespace";
private static final String OPTION_EVENTMANAGER_URL = "eventmanager";
private static final String OPTION_EVENTMANAGER_USER = "eventmanager.user";
private static final String OPTION_EVENTMANAGER_PASSWORD = "eventmanager.password";
private static final String OPTION_SBM_ENDPOINT = "sbmappservices72";
private static final String OPTION_SBM_USER = "sbmuser";
private static final String OPTION_SBM_PASSWORD = "sbmpassword";
private static final String OPTION_SBM_TABLE = "querytable";
private static final String OPTION_SBM_QUERY = "query";
 
private static final String OPTION_MARKER_LOGMESSAGE = "marker.logmessage";
private static final String OPTION_MARKER_AUTHOR = "marker.author";
private static final String OPTION_MARKER_REVISION = "marker.revision";
private static final String OPTION_MARKER_ADDEDFILES = "marker.addedfiles";
private static final String OPTION_MARKER_DELETEDFILES = "marker.deletedfiles";
private static final String OPTION_MARKER_CHANGEDFILES = "marker.changedfiles";
private static final String OPTION_MARKER_ISSUES = "marker.issues";
private static final String OPTION_MARKER_INTERNALISSUES = "marker.internalissues";
private static final String OPTION_REMOVE_ISSUES_FROM_COMMIT = "removeissuesfromcommit";
private static final String OPTION_IS_SOAPENABLED = "isSoapEnabled";
private static final String OPTION_IS_DROPENABLED = "isDropResponse";
private static final String OPTION_IS_FORCEFAILENABLED = "forcefail";
private static final String OPTION_IS_VERIFICATIONENABLED = "isWithVerification";
private static final String OPTION_IS_WSTRACE = "trace";
private static final String OPTION_IS_XMLPROCESSINGENABLED = "isXmlProcessingEnabled";
 
//
// Command line parameters
//
private static final String PARAM_REPOS = "repos";
private static final String PARAM_TXN = "txn";
private static final String PARAM_REV = "rev";
private static final String PARAM_CONFIG = "conf";
 
//
// Member variables
//
private final String repos;
private final String txn;
private final String rev;
private SVNCommitInfo info;
private OMElement template = null;
private Configuration config;
private String nss = null;
private final long startTime;
//Member for SBM endpoint configuration
private final String endpoint;
private final String sbm_user;
private final String sbm_pass;
private final String querytable;
private final String query;
 
private final List<String> internalissues = new ArrayList<String>();
/**
* The main method.
*
78,7 → 174,7
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
CommandLineParser parser = new BasicParser();
CommandLine cmd = null;;
CommandLine cmd = null;
try {
cmd = parser.parse( getOptions(), args);
} catch (ParseException e1) {
86,27 → 182,92
printHelp();
System.exit(1);
}
try {
ALFEmitter emitter = new ALFEmitter(cmd, startTime);
} catch (ConfigurationException e) {
System.exit(1);
}
long endTime = System.currentTimeMillis();
logger.debug("Total execution took '"+(endTime-startTime)+"' milliseconds.");
System.exit(0);
}
private final String repos;
private final String txn;
private final String rev;
private SVNCommitInfo info;
private OMElement template;
private Configuration config;
private final String nss;
private final long startTime;
/**
* Read a configuration parameter from the config file
* Creates log messages according to parameters.
*
* @param key property name
* @param defaultValue default value or null
* @param isRequired wether or not this is a required option
* @param logmessage optional log message (or null)
* @return property value
* @throws ConfigurationException
*/
private Object readConfProperty(String key, Object defaultValue, boolean isRequired, PropertyType type, String logmessage) throws ConfigurationException {
Object value = null;
switch (type) {
case BOOLEAN:
value = config.getBoolean(key, (Boolean) defaultValue);
break;
case STRINGARRAY:
value = config.getStringArray(key);
defaultValue = null;
break;
private ALFEmitter(CommandLine cmd, long startTime) {
default:
value = config.getString(key, (String) defaultValue);
break;
}
if(isRequired && value == null) {
//required property
if(defaultValue == null) {
//No value, no default
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);
logger.error(s);
throw new ConfigurationException(s);
}
if(defaultValue!=null) {
//No value, but default
logger.debug(String.format("Using property value '%s' for key '%s'. This is the default value. The property is required.", value, key));
}
}
if( (! isRequired) && value == null) {
//not required
if(value == null && defaultValue == null) {
//No value, no default
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);
logger.warn(s);
}
if(value == null && defaultValue!=null) {
//No value, but default
logger.debug(String.format("Using property value '%s' for key '%s'. This is the default value. The property is optional.", value, key));
}
}
if(value!=null) logger.debug(String.format("Using property value '%s' for key '%s'.", value, key));
if(logmessage!=null) logger.info(logmessage);
return value;
}
private String readConfPropertyAsString(String key, String defaultValue, boolean isRequired, String logmessage) throws ConfigurationException {
return (String) readConfProperty(key, defaultValue, isRequired, PropertyType.STRING, logmessage);
}
private String[] readConfPropertyAsStringArray(String key, boolean isRequired, String logmessage) throws ConfigurationException {
return (String[]) readConfProperty(key, null, isRequired, PropertyType.STRINGARRAY, logmessage);
}
private boolean readConfPropertyAsBoolean(String key, boolean defaultValue, boolean isRequired, String logmessage) throws ConfigurationException {
Boolean b = (Boolean) readConfProperty(key, defaultValue, isRequired, PropertyType.BOOLEAN, logmessage);
return b.booleanValue();
}
private ALFEmitter(CommandLine cmd, long startTime) throws ConfigurationException {
this.startTime = startTime;
repos = cmd.getOptionValue(PARAM_REPOS);
txn = cmd.getOptionValue(PARAM_TXN);
rev = cmd.getOptionValue(PARAM_REV);
String config_file = cmd.getOptionValue(PARAM_CONFIG, "emitter.properties");
EmitterUtil.verifyFile(config_file, false, false);
 
logger.debug(String.format("Using REPOS='%s' and TXN='%s'.", repos, txn));
121,78 → 282,32
/*
* Load Properties from Configuration file
*/
//it might be interesting to look into SVNKit
//for a pure Java implementation in future
final String svnlook = config.getString("svnlook");
logger.debug("Using svnlook at '" + svnlook +"'.");
final String svnlook = readConfPropertyAsString(OPTION_SVNLOOK, null, true, null);
EmitterUtil.verifyFile(svnlook, false, true);
final String[] issuepatterns = config.getStringArray("issuepattern");
// Issue Id RegEx to parse commit message
final String[] issuepatterns = readConfPropertyAsStringArray(OPTION_ISSUEPATTERN, false, null);
StringBuilder sb = new StringBuilder(); for(String s : issuepatterns) sb.append(s);
logger.debug(String.format("Using issue id patterns: '%s'.", sb.toString()));
final String eventtemplate = config.getString("eventtemplate");
logger.debug("Using alf event template at '" + eventtemplate +"'.");
// Flags to indicate what should be done
final boolean isSoapEnabled = readConfPropertyAsBoolean(OPTION_IS_SOAPENABLED, true, true, null);
final boolean isXmlProcessingEnabled = readConfPropertyAsBoolean(OPTION_IS_XMLPROCESSINGENABLED, true, true, null);
final boolean isWithVerification= readConfPropertyAsBoolean(OPTION_IS_VERIFICATIONENABLED, false, true, null);
final boolean isRemoveIssues = readConfPropertyAsBoolean(OPTION_REMOVE_ISSUES_FROM_COMMIT, false, true, "");
nss = config.getString("eventnamespace", "http://www.eclipse.org/alf/schema/EventBase/1");
logger.debug("Using alf event namespace '" + nss +"'.");
final String marker_logmessage = config.getString("marker.logmessage", "@@logmessage@@");
logger.debug("Using comment marker '<!-- " + marker_logmessage +" -->' in event template for logmessage.");
final String marker_author = config.getString("marker.author", "@@author@@");
logger.debug("Using comment marker '<!-- " + marker_author +" -->' with event template for author.");
final String marker_addedfiles = config.getString("marker.addedfiles", "@@addedfiles@@");
logger.debug("Using comment marker '<!-- " + marker_addedfiles +" -->' with event template for files added during commit.");
final String marker_deletedfiles = config.getString("marker.deletedfiles", "@@deletedfiles@@");
logger.debug("Using comment marker '<!-- " + marker_deletedfiles +" -->' with event template for files deleted during commit.");
final String marker_changedfiles = config.getString("marker.changedfiles", "@@changedfiles@@");
logger.debug("Using comment marker '<!-- " + marker_changedfiles +" -->' with event template for files changed during commit.");
final String marker_fileselementname = config.getString("marker.fileselementname", "file");
logger.debug("Using element name '" +marker_fileselementname +"' to wrap files list.");
final String marker_issues = config.getString("marker.issues", "@@issues@@");
logger.debug("Using comment marker '<!-- " + marker_issues +" -->' with event template for issue list.");
final String marker_issueselementname = config.getString("marker.issueselementname", "issue");
logger.debug("Using element name '" +marker_issueselementname +"' to wrap issue list.");
final String eventmanager = config.getString("eventmanager");
logger.debug("Using eventmanager at '" +eventmanager +"'.");
final String eventmanager_user = config.getString("eventmanager.user");
final String eventmanager_pass = config.getString("eventmanager.password");
logger.debug("Using username '" +eventmanager_user +"' and a password.");
final boolean isSoapEnabled = config.getBoolean("isSoapEnabled", true);
logger.debug("Sending soap message is enabled='" +isSoapEnabled +"'.");
final boolean isDropResponse = config.getBoolean("isDropResponse", true);
logger.debug("Receiving the soap response is enabled='" +isDropResponse +"'.");
try {
template = OMXMLBuilderFactory.createOMBuilder(new FileInputStream(new File(eventtemplate)))
.getDocument().getOMDocumentElement();
} catch (FileNotFoundException e1) {
logger.error(String.format("Could not load XML event template from file '%s'.", eventtemplate), e1);
System.exit(1);
}
/*
*
* SVNLook phase
* Use svnlook to obtain information from SVN
*/
SVNLookExecutor exec = new SVNLookExecutor(new File(svnlook), repos);
if(cmd.hasOption(PARAM_TXN)) exec.setTXN(txn);
if(cmd.hasOption(PARAM_REV)) exec.setRev(rev);
info = exec.getCommitInfo();
info.parseIssues(issuepatterns, isRemoveIssues);
info.parseIssues(issuepatterns);
logger.debug("SVNCommitInfo author: "+ info.getAuthor());
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
String datestring = f.format(info.getDate());
201,19 → 316,131
logger.debug("SVNCommitInfo log message: "+ info.getLogmessage());
logger.debug("SVNCommitInfo file list: "+ info.getChangeFileListAsString());
/*
* Verification phase
*/
boolean isTrace = false;
if(isWithVerification) {
sbm_user = readConfPropertyAsString(OPTION_SBM_USER, null, true, null);
sbm_pass = readConfPropertyAsString(OPTION_SBM_PASSWORD, null, false, null);
endpoint = readConfPropertyAsString(OPTION_SBM_ENDPOINT, "http://localhost/gsoap/gsoap_ssl.dll?sbmappservices72", true, null);
querytable = readConfPropertyAsString(OPTION_SBM_TABLE, null, true, null);
query = readConfPropertyAsString(OPTION_SBM_QUERY, null, false, null);
isTrace = readConfPropertyAsBoolean(OPTION_IS_WSTRACE, false, true, null);
logger.debug(String.format("Starting verification for '%s' issues in the list.", info.getIssues().size()));
boolean isOK = verify(info.getIssues(), isTrace);
if(! isOK ) {
logger.error("Verification of issue failed. No matching issue was found.");
System.exit(1);
}
} else {
sbm_user = null; sbm_pass=null; endpoint=null; querytable=null; query=null;
}
 
/*
* XML processing phase
*/
if(isXmlProcessingEnabled) {
}
/*
* ALF Event Send phase
*/
String eventmanager = null;
if(isSoapEnabled) {
eventmanager = readConfPropertyAsString(OPTION_EVENTMANAGER_URL, null, true, null);
}
 
/**
* Event XML Erzeugen
*/
try {
addElement( marker_logmessage, info.getLogmessage(), true);
addElement(marker_author, info.getAuthor(), false);
addElement("@@timestamp@@", datestring, false);
addElements(marker_changedfiles, info.getChangedFiles(), marker_fileselementname);
addElements(marker_deletedfiles, info.getDeletedFiles(), marker_fileselementname);
addElements(marker_addedfiles, info.getAddedFiles(), marker_fileselementname);
addElements(marker_issues, info.getIssues(), marker_issueselementname);
String resultxml=null;
if(isXmlProcessingEnabled) {
processXml();
addALFSecurity();
addEventHeader();
// Serialize xml message to String
StringWriter out = new StringWriter();
template.getParent().serialize(out);
out.flush();
resultxml = out.getBuffer().toString();
logger.debug("ALFEvent result:\n"+resultxml);
} else {
logger.debug("Xml processing is deactivated.");
}
if(isSoapEnabled && isXmlProcessingEnabled) {
final boolean isDropResponse = readConfPropertyAsBoolean(OPTION_IS_DROPENABLED, true, true, null);
SimpleHttpEvent sender = new SimpleHttpEvent(eventmanager, resultxml);
sender.sendSoap(isDropResponse);
logger.debug(String.format("Sending/ receiving the soap message took '%s' milliseconds.", sender.getDuration()));
} else {
logger.warn("Sending soap message and/ or xml processing is deactivated.");
}
} catch (FileNotFoundException e) {
logger.error(e.getMessage(), e);
System.exit(1);
} catch (ClientProtocolException e) {
logger.error(e.getMessage(), e);
System.exit(1);
} catch (IOException e) {
logger.error(e.getMessage(), e);
System.exit(1);
} catch (XMLStreamException e) {
logger.error(e.getMessage(), e);
System.exit(1);
} catch (JaxenException e) {
logger.error(e.getMessage(), e);
System.exit(1);
} finally {
logger.debug("Total execution took '"+(System.currentTimeMillis()-startTime)+"' milliseconds.");
String forcefail = config.getString(OPTION_IS_FORCEFAILENABLED, "");
if(forcefail.length()>0) {
logger.warn("Force fail is active. All commits will be blocked.");
System.exit(1);
}
}
}
private void addEventHeader() throws JaxenException {
AXIOMXPath path = new AXIOMXPath("//bru1:Base/bru1:EventId");
path.addNamespace("bru1", nss);
OMElement n = (OMElement) path.selectSingleNode(template);
if(n==null) {
logger.error("<Base> element in message is incomplete. <EventId> is missing.");
} else {
n.addChild( n.getOMFactory().createOMText("1"));
}
path = new AXIOMXPath("//bru1:Base/bru1:ObjectId");
path.addNamespace("bru1", nss);
n = (OMElement) path.selectSingleNode(template);
if(n==null) {
logger.error("<Base> element in message is incomplete. <ObjectId> is missing.");
} else {
n.addChild( n.getOMFactory().createOMText(info.getTxn() ));
}
}
private void addALFSecurity() throws ConfigurationException, JaxenException {
final String eventmanager_user = readConfPropertyAsString(OPTION_EVENTMANAGER_USER, null, false, null);
final String eventmanager_pass = readConfPropertyAsString(OPTION_EVENTMANAGER_PASSWORD, null, false, null);
AXIOMXPath path = new AXIOMXPath("//bru1:User");
OMNamespace ns = template.findNamespace(nss, null);
path.addNamespace("bru1", nss);
246,69 → 473,106
sec.addChild(token);
n.addChild(sec);
}
}
path = new AXIOMXPath("//bru1:Base/bru1:EventId");
path.addNamespace("bru1", nss);
n = (OMElement) path.selectSingleNode(template);
if(n==null) {
logger.error("<Base> element in message is incomplete. <EventId> is missing.");
} else {
n.addChild( n.getOMFactory().createOMText(UUID.randomUUID().toString() ));
private void processXml() throws ConfigurationException, JaxenException {
// read additional configuration
final String eventtemplate = readConfPropertyAsString(OPTION_EVENTTEMPLATE, null, true, null);
EmitterUtil.verifyFile(eventtemplate, false, false);
try {
template = OMXMLBuilderFactory.createOMBuilder(new FileInputStream(new File(eventtemplate)))
.getDocument().getOMDocumentElement();
} catch (FileNotFoundException e1) {
logger.error(String.format("Could not load XML event template from file '%s'.", eventtemplate), e1);
System.exit(1);
}
nss = readConfPropertyAsString(OPTION_EVENTNAMESPACE, "http://www.eclipse.org/alf/schema/EventBase/1", true, null);
final String marker_logmessage = readConfPropertyAsString(OPTION_MARKER_LOGMESSAGE, "@@logmessage@@", true, null);
final String marker_author = readConfPropertyAsString(OPTION_MARKER_AUTHOR, "@@author@@", true, null);
final String marker_revision = readConfPropertyAsString(OPTION_MARKER_REVISION, "@@revision@@", true, null);
final String marker_addedfiles = readConfPropertyAsString(OPTION_MARKER_ADDEDFILES, "@@addedfiles@@", true, null);
final String marker_deletedfiles = readConfPropertyAsString(OPTION_MARKER_DELETEDFILES, "@@deletedfiles@@", true, null);
final String marker_changedfiles = readConfPropertyAsString(OPTION_MARKER_CHANGEDFILES, "@@changedfiles@@", true, null);
final String marker_fileselementname = readConfPropertyAsString("marker.fileselementname", "file", true, null);
final String marker_issues = readConfPropertyAsString(OPTION_MARKER_ISSUES, "@@issues@@", true, null);
final String marker_issueselementname = readConfPropertyAsString("marker.issueselementname", "issue", true, null);
final String marker_internalissues = readConfPropertyAsString(OPTION_MARKER_INTERNALISSUES, "@@internalissues@@", true, null);
path = new AXIOMXPath("//bru1:Base/bru1:ObjectId");
path.addNamespace("bru1", nss);
n = (OMElement) path.selectSingleNode(template);
if(n==null) {
logger.error("<Base> element in message is incomplete. <ObjectId> is missing.");
} else {
n.addChild( n.getOMFactory().createOMText(info.getTxn() ));
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
String datestring = f.format(info.getDate());
datestring= datestring.substring(0, 26) + ":" + datestring.substring(26); //hack into ISO 8601 format
// add content from SVNCommitInfo object where
// XML commit markers are
addElement( marker_logmessage, info.getLogmessage(), true);
addElement(marker_author, info.getAuthor(), false);
addElement(marker_revision, info.getRev(), false);
addElement("@@timestamp@@", datestring, false);
addElements(marker_changedfiles, info.getChangedFiles(), marker_fileselementname);
addElements(marker_deletedfiles, info.getDeletedFiles(), marker_fileselementname);
addElements(marker_addedfiles, info.getAddedFiles(), marker_fileselementname);
addElements(marker_issues, info.getIssues(), marker_issueselementname);
addElements(marker_internalissues, internalissues, marker_issueselementname);
}
 
StringWriter out = new StringWriter();
template.getParent().serialize(out);
out.flush();
private boolean verify(List<String> issues, boolean isTrace) {
String resultxml = out.getBuffer().toString();
logger.debug("ALFEvent result:\n"+resultxml);
Sbmappservices72 ss = new Sbmappservices72(ClassLoader.getSystemResource("sbmappservices72.wsdl") );
Sbmappservices72PortType port = ss.getSbmappservices72();
if(isSoapEnabled) {
SimpleHttpEvent sender = new SimpleHttpEvent(eventmanager, resultxml);
sender.sendSoap(isDropResponse);
logger.debug(String.format("Sending/ receiving the soap message took '%s' milliseconds.", sender.getDuration()));
} else {
logger.warn("Sending soap message is deactivated.");
Client client = ClientProxy.getClient(port);
if(isTrace) {
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
}
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
ObjectFactory fac = new ObjectFactory();
Auth auth = fac.createAuth();
auth.setUserId(fac.createAuthUserId(sbm_user));
auth.setPassword(fac.createAuthPassword(sbm_pass));
} catch (FileNotFoundException e) {
logger.error(e.getMessage(), e);
System.exit(1);
} catch (ClientProtocolException e) {
logger.error(e.getMessage(), e);
System.exit(1);
} catch (IOException e) {
logger.error(e.getMessage(), e);
System.exit(1);
} catch (XMLStreamException e) {
logger.error(e.getMessage(), e);
System.exit(1);
} catch (JaxenException e) {
logger.error(e.getMessage(), e);
System.exit(1);
} finally {
logger.debug("Total execution took '"+(System.currentTimeMillis()-startTime)+"' milliseconds.");
String forcefail = config.getString("forcefail", "");
if(forcefail.length()>0) {
logger.warn("Force fail is active. All commits will be blocked.");
System.exit(1);
TableIdentifier table = fac.createTableIdentifier();
table.setDbName(fac.createTableIdentifierDbName(querytable));
MultipleResponseItemOptions options = fac.createMultipleResponseItemOptions();
options.setSections(SectionsOption.SECTIONS_NONE);
for(String issue : issues) {
issue = issue.replaceAll("[^0-9]", "");
String queryWhereClause = "TS_ISSUEID = '"+issue+"'";
if(query!=null && query.length()>0) queryWhereClause = queryWhereClause + " And " + query;
logger.debug(String.format("Using query against table '%s'. Query where clause: '%s'", querytable, queryWhereClause ));
try {
TTItemList items = port.getItemsByQuery(auth, table, queryWhereClause, "", null, BigInteger.valueOf(1), options);
//Marshaller m = JAXBContext.newInstance(TTItemList.class).createMarshaller();
//m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
//m.marshal( new JAXBElement<TTItemList>(new QName("uri","local"), TTItemList.class, items), System.err);
logger.debug(String.format("Got Response from getItemsByQuery"));
if(items!=null) {
logger.debug(String.format("Verification query matched '%s' item(s) for issue '%s.'",items.getTotalCount(), issue));
}
if(items.getTotalCount().intValue()<=0) {
return false;
} else {
internalissues.add(items.getItem().get(0).getId().getValue().getTableIdItemId().getValue());
}
} catch (AEWebservicesFaultFault e) {
logger.debug("Web service fault: " + e.getFaultInfo());
} catch (Exception e) {
logger.debug("Unknown Exception", e);
}
}
return true;
}
private void addElement(String pattern, String newCdata, boolean wrapCDATA) throws JaxenException {
OMComment comment = findComment(pattern);
if(comment!=null) {
348,44 → 612,7
logger.warn("Comment '"+pattern+"' was not found in the XML template.");
return null;
}
/*
private static OMComment findComment(OMElement element, String pattern) {
logger.trace( String.format("Searching for comment pattern '%s' in element with name '%s'.", pattern, element.getLocalName()));
Iterator iter = element.getChildren();
 
while(iter.hasNext()) {
Object o = iter.next();
if(o instanceof OMNode) {
OMNode node = ((OMNode)o);
switch (node.getType() ) {
case OMNode.COMMENT_NODE:
OMComment comment = ((OMComment)node);
String value = comment.getValue().trim();
if(value.equals(pattern)) {
logger.debug("Found comment '" + pattern + "' in event template.");
return comment;
}
break;
 
case OMNode.ELEMENT_NODE:
//traverse
OMComment result = findComment( (OMElement)node, pattern);
if(result!=null) return result;
break;
default:
break;
}
}
}
//logger.info("Comment '" + pattern + "' was not found in event template.");
return null;
}
*/
@SuppressWarnings("static-access")
private static Options getOptions() {
Option repository = OptionBuilder.withArgName( "repository" )
422,10 → 649,16
private static void printHelp() {
// automatically generate the help statement
HelpFormatter formatter = new HelpFormatter();
String header = "\nSVN-ALFEventEmitter " + version +", a SVN hook implemented in Java to emit Eclipse ALFEvents on commit.\n\n";
String header = "\nSVN-ALFEventEmitter " + VERSION +", a SVN hook implemented in Java to emit Eclipse ALFEvents on commit.\n\n";
String footer = "Please send bug reports to bru@brutex.de.\n(c)2013 Brian Rosenberger";
formatter.printHelp("java -jar SVN-ALFEventEmitter", header, getOptions(), footer, true);
}
private enum PropertyType {
STRING(), STRINGARRAY(), BOOLEAN();
}
}
/SVN-ALFEventEmitter/trunk/src/net/brutex/emitter/util/EmitterUtil.java
0,0 → 1,60
/*
* Copyright 2014 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.emitter.util;
 
import java.io.File;
 
import org.apache.log4j.Logger;
 
/**
* The Class EmitterUtil.
*
* @author Brian Rosenberger, bru(at)brutex.de
*/
public final class EmitterUtil {
 
private static Logger logger = Logger.getLogger(EmitterUtil.class);
 
/**
* Check if the file exists and is readable.
*
* @param file The file to check
* @param isWritable also check if file is writable
* @param isExecutable also check if file is executable
* @return
*/
public static boolean verifyFile(String file, boolean isWritable, boolean isExecutable) {
logger.debug(String.format("Verifying file '%s'.", file));
File f = new File(file);
String fn = f.getAbsolutePath();
if(f.exists() && f.isFile()) {
if(isWritable && !f.canWrite()) {
logger.error(String.format("Cannot write to file '%s'.", fn));
return false;
}
if(isExecutable && !f.canExecute()) {
logger.error(String.format("Cannot execute file '%s'.", fn));
return false;
}
return true;
}
logger.error(String.format("Cannot read file '%s'.", fn));
return false;
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property