Subversion Repositories XServices

Compare Revisions

No changes between revisions

Ignore whitespace Rev 150 → Rev 149

/SVN-ALFEventEmitter/trunk/WebContent/META-INF/MANIFEST.MF
File deleted
Property changes:
Deleted: svn:mime-type
-text/plain
\ No newline at end of property
/SVN-ALFEventEmitter/trunk/lib/sbmappservices72-1.0.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/SVN-ALFEventEmitter/trunk/ivysettings.xml
File deleted
Property changes:
Deleted: svn:mime-type
-text/plain
\ No newline at end of property
/SVN-ALFEventEmitter/trunk/.classpath
1,13 → 1,7
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=SVN-ALFEventEmitter&amp;ivyXmlPath=ivy.xml&amp;confs=default&amp;ivySettingsPath=ivysettings.xml&amp;loadSettingsOnDemand=false&amp;ivyUserDir=&amp;propertyFiles="/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=SVNConnector&amp;ivyXmlPath=ivy.xml&amp;confs=*"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/SVN-ALFEventEmitter/trunk/.project
6,32 → 6,13
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.apache.ivyde.eclipse.ivynature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
/SVN-ALFEventEmitter/trunk/ivy.xml
40,16 → 40,5
<dependency org="org.apache.ws.commons.axiom" name="axiom-api" rev="1.2.14"/>
<dependency org="org.apache.ws.commons.axiom" name="axiom-impl" rev="1.2.14"/>
<dependency org="com.sun.xml.bind" name="jaxb-impl" rev="2.2.7"/>
<dependency org="org.apache.cxf" name="cxf-rt-core" rev="2.7.0"/>
<dependency org="org.apache.cxf" name="cxf-rt-frontend-jaxws" rev="2.7.0"/>
<!--
Locally managed libraries
-->
<dependency org="lib" name="sbmappservices72" rev="1.0" conf="*->*">
<artifact name="sbmappservices72" type="jar" />
</dependency>
</dependencies>
</ivy-module>
/SVN-ALFEventEmitter/trunk/src/sbmadminservices72.wsdl
File deleted
\ No newline at end of file
Property changes:
Deleted: svn:mime-type
-text/plain
\ No newline at end of property
/SVN-ALFEventEmitter/trunk/src/sbmappservices72.wsdl
File deleted
\ No newline at end of file
Property changes:
Deleted: svn:mime-type
-text/plain
\ No newline at end of property
/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 String logmessage;
private final String logmessage;
/** The date. */
private final Date date;
198,9 → 198,8
* Parses the issues.
*
* @param patterns the patterns
* @param isRemoveIssues
*/
public void parseIssues(String[] patterns, boolean isRemoveIssues) {
public void parseIssues(String[] patterns) {
issues.clear(); //reset
int count = 0;
for(String p : patterns) {
212,11 → 211,6
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/util/EmitterUtil.java
File deleted
Property changes:
Deleted: svn:mime-type
-text/plain
\ No newline at end of property
/SVN-ALFEventEmitter/trunk/src/net/brutex/emitter/EventManagerContext.java
File deleted
Property changes:
Deleted: svn:mime-type
-text/plain
\ No newline at end of property
/SVN-ALFEventEmitter/trunk/src/net/brutex/emitter/SimpleHttpEvent.java
74,7 → 74,6
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,42 → 20,13
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;
 
79,11 → 50,6
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;
97,75 → 63,13
*/
public class ALFEmitter {
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 version = "0.1";
static Logger logger = Logger.getRootLogger();
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.
*
174,7 → 78,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) {
182,92 → 86,27
printHelp();
System.exit(1);
}
try {
ALFEmitter emitter = new ALFEmitter(cmd, startTime);
} catch (ConfigurationException e) {
System.exit(1);
}
ALFEmitter emitter = new ALFEmitter(cmd, startTime);
long endTime = System.currentTimeMillis();
logger.debug("Total execution took '"+(endTime-startTime)+"' milliseconds.");
System.exit(0);
}
/**
* 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;
 
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 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;
private ALFEmitter(CommandLine cmd, long startTime) throws ConfigurationException {
private ALFEmitter(CommandLine cmd, long startTime) {
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));
282,165 → 121,99
/*
* Load Properties from Configuration file
*/
//it might be interesting to look into SVNKit
//for a pure Java implementation in future
final String svnlook = readConfPropertyAsString(OPTION_SVNLOOK, null, true, null);
EmitterUtil.verifyFile(svnlook, false, true);
// 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()));
// 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, "");
/*
* 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);
logger.debug("SVNCommitInfo author: "+ info.getAuthor());
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
logger.debug("SVNCommitInfo date: "+ datestring);
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);
}
 
final String svnlook = config.getString("svnlook");
logger.debug("Using svnlook at '" + svnlook +"'.");
/**
* Event XML Erzeugen
*/
try {
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);
final String[] issuepatterns = config.getStringArray("issuepattern");
StringBuilder sb = new StringBuilder(); for(String s : issuepatterns) sb.append(s);
logger.debug(String.format("Using issue id patterns: '%s'.", sb.toString()));
} else {
logger.debug("Xml processing is deactivated.");
}
final String eventtemplate = config.getString("eventtemplate");
logger.debug("Using alf event template at '" + eventtemplate +"'.");
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);
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);
} 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"));
}
/*
*
*/
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);
logger.debug("SVNCommitInfo author: "+ info.getAuthor());
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
logger.debug("SVNCommitInfo date: "+ datestring);
logger.debug("SVNCommitInfo log message: "+ info.getLogmessage());
logger.debug("SVNCommitInfo file list: "+ info.getChangeFileListAsString());
/**
* 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);
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);
473,106 → 246,69
sec.addChild(token);
n.addChild(sec);
}
}
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);
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() ));
}
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);
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);
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() ));
}
 
StringWriter out = new StringWriter();
template.getParent().serialize(out);
out.flush();
}
private boolean verify(List<String> issues, boolean isTrace) {
Sbmappservices72 ss = new Sbmappservices72(ClassLoader.getSystemResource("sbmappservices72.wsdl") );
Sbmappservices72PortType port = ss.getSbmappservices72();
String resultxml = out.getBuffer().toString();
logger.debug("ALFEvent result:\n"+resultxml);
Client client = ClientProxy.getClient(port);
if(isTrace) {
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
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.");
}
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));
TableIdentifier table = fac.createTableIdentifier();
table.setDbName(fac.createTableIdentifierDbName(querytable));
} 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);
}
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) {
612,6 → 348,43
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() {
649,16 → 422,10
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/.settings/org.eclipse.wst.jsdt.ui.superType.container
File deleted
\ No newline at end of file
/SVN-ALFEventEmitter/trunk/.settings/.jsdtscope
File deleted
/SVN-ALFEventEmitter/trunk/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml
File deleted
Property changes:
Deleted: svn:mime-type
-text/plain
\ No newline at end of property
/SVN-ALFEventEmitter/trunk/.settings/org.eclipse.wst.common.project.facet.core.xml
File deleted
Property changes:
Deleted: svn:mime-type
-text/plain
\ No newline at end of property
/SVN-ALFEventEmitter/trunk/.settings/org.eclipse.wst.jsdt.ui.superType.name
File deleted
\ No newline at end of file
/SVN-ALFEventEmitter/trunk/.settings/org.eclipse.jst.ws.cxf.core.prefs
File deleted
Property changes:
Deleted: svn:mime-type
-text/plain
\ No newline at end of property
/SVN-ALFEventEmitter/trunk/.settings/org.eclipse.wst.common.component
File deleted