Subversion Repositories XServices

Compare Revisions

Ignore whitespace Rev 166 → Rev 167

/SVN-ALFEventEmitter/trunk/src/net/brutex/emitter/ALFEmitter.java
21,10 → 21,14
import java.io.IOException;
import java.io.StringWriter;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
 
import javax.xml.bind.JAXBContext;
56,6 → 60,8
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.SVNAdminCommand;
import net.brutex.svn.SVNAdminExecutor;
import net.brutex.svn.SVNCommitInfo;
import net.brutex.svn.SVNLookExecutor;
 
88,7 → 94,9
import org.apache.log4j.Logger;
import org.jaxen.JaxenException;
 
import com.sun.xml.bind.v2.runtime.JAXBContextImpl;
 
 
/**
* The Class ALFEmitter.
*
104,6 → 112,7
// Keys to read from the configuration file.
//
private static final String OPTION_SVNLOOK = "svnlook";
private static final String OPTION_SVNADMIN = "svnadmin";
private static final String OPTION_LOCALE = "env.LANG";
private static final String OPTION_ENCODING = "env.encoding";
private static final String OPTION_ISSUEPATTERN = "issuepattern";
134,6 → 143,7
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_UPDATECOMMITMESSAGE = "isWithMessageUpdate";
private static final String OPTION_IS_WSTRACE = "trace";
private static final String OPTION_IS_XMLPROCESSINGENABLED = "isXmlProcessingEnabled";
 
166,6 → 176,8
 
private final List<String> internalissues = new ArrayList<String>();
//SBM IssueTypePrefix+IssueId, Title
private final Map<String, String> issues_titles = new HashMap<String, String>();
/**
* The main method.
187,6 → 199,9
ALFEmitter emitter = new ALFEmitter(cmd, startTime);
} catch (ConfigurationException e) {
System.exit(1);
} catch (MalformedURLException e) {
logger.error("Could not find/ load wsdl url.", e);
System.exit(1);
}
long endTime = System.currentTimeMillis();
logger.debug("Total execution took '"+(endTime-startTime)+"' milliseconds.");
262,7 → 277,7
return b.booleanValue();
}
private ALFEmitter(CommandLine cmd, long startTime) throws ConfigurationException {
private ALFEmitter(CommandLine cmd, long startTime) throws ConfigurationException, MalformedURLException {
this.startTime = startTime;
repos = cmd.getOptionValue(PARAM_REPOS);
txn = cmd.getOptionValue(PARAM_TXN);
277,7 → 292,7
config = new PropertiesConfiguration(config_file);
} catch (ConfigurationException e) {
logger.error("Could not find/ load '"+config_file+"' file.", e);
System.exit(1);
this.exit(1);
}
/*
300,6 → 315,7
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, "");
final boolean isWithCommitUpdate= readConfPropertyAsBoolean(OPTION_IS_UPDATECOMMITMESSAGE, false, true, "");
/*
* SVNLook phase
338,7 → 354,7
boolean isOK = verify(info.getIssues(), isTrace);
if(! isOK ) {
logger.error("Verification of issue failed. No matching issue was found.");
System.exit(1);
this.exit(1);
}
} else {
sbm_user = null; sbm_pass=null; endpoint=null; querytable=null; query=null;
345,6 → 361,31
}
 
/*
* Modify original commit message
* using svnadmin command
*/
if(isWithCommitUpdate) {
String svnadmin = readConfPropertyAsString(OPTION_SVNADMIN, null, true, null);
EmitterUtil.verifyFile(svnadmin, false, true);
/* If verification was turned on, we do already have the titles
* so only try to load the items when verification was off
*/
if(! isWithVerification) {
verify(info.getIssues(), isTrace);
}
/* Append associated items information and change log message */
StringBuffer newmessage = new StringBuffer();
newmessage.append(info.getLogmessage());
newmessage.append("\n\n Associated SBM items:\n");
for(String s : issues_titles.keySet()) {
newmessage.append(s+": ");
newmessage.append(issues_titles.get(s));
newmessage.append("\n");
}
postCommitUpdate(new File(svnadmin), repos, locale, encoding, rev, newmessage.toString());
}
/*
* XML processing phase
*/
if(isXmlProcessingEnabled) {
352,8 → 393,7
}
/*
* ALF Event Send phase
*/
400,25 → 440,24
} catch (FileNotFoundException e) {
logger.error(e.getMessage(), e);
System.exit(1);
this.exit(1);
} catch (ClientProtocolException e) {
logger.error(e.getMessage(), e);
System.exit(1);
this.exit(1);
} catch (IOException e) {
logger.error(e.getMessage(), e);
System.exit(1);
this.exit(1);
} catch (XMLStreamException e) {
logger.error(e.getMessage(), e);
System.exit(1);
this.exit(1);
} catch (JaxenException e) {
logger.error(e.getMessage(), e);
System.exit(1);
this.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);
this.exit(1);
}
}
490,7 → 529,7
.getDocument().getOMDocumentElement();
} catch (FileNotFoundException e1) {
logger.error(String.format("Could not load XML event template from file '%s'.", eventtemplate), e1);
System.exit(1);
this.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);
522,9 → 561,25
}
private boolean verify(List<String> issues, boolean isTrace) {
private boolean verify(List<String> issues, boolean isTrace) throws MalformedURLException {
for(String issueid : issues) {
TTItemList items = getTTItems(issueid, isTrace);
if(items == null) {
return false;
}
}
return true;
}
private TTItemList getTTItems(String issueid, boolean isTrace) throws MalformedURLException {
long startTime = System.currentTimeMillis();
/* -- */
Sbmappservices72 ss = new Sbmappservices72(ClassLoader.getSystemResource("sbmappservices72.wsdl") );
logger.debug("Total execution of sbmappservices72 wsdl read took '"+(System.currentTimeMillis()-startTime)+"' milliseconds.");
Sbmappservices72PortType port = ss.getSbmappservices72();
Client client = ClientProxy.getClient(port);
535,7 → 590,9
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
/* -- */
logger.debug("Total execution of sbmappservices72 initialisation took '"+(System.currentTimeMillis()-startTime)+"' milliseconds.");
ObjectFactory fac = new ObjectFactory();
Auth auth = fac.createAuth();
auth.setUserId(fac.createAuthUserId(sbm_user));
545,15 → 602,18
table.setDbName(fac.createTableIdentifierDbName(querytable));
MultipleResponseItemOptions options = fac.createMultipleResponseItemOptions();
options.setSections(SectionsOption.SECTIONS_NONE);
options.setSpecifiedSections(fac.createResponseItemOptionsSpecifiedSections("SECTION:FIXED"));
options.setSections(SectionsOption.SECTIONS_SPECIFIED);
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);
issueid = issueid.replaceAll("[^0-9]", "");
String queryWhereClause = "TS_ISSUEID = '"+issueid+"'";
if(query!=null && query.length()>0) queryWhereClause = queryWhereClause + " And " + query;
TTItemList items = null;
logger.debug(String.format("Using query against table '%s'. Query where clause: '%s'", querytable, queryWhereClause ));
try {
startTime = System.currentTimeMillis();
items = port.getItemsByQuery(auth, table, queryWhereClause, "", null, BigInteger.valueOf(1), options);
logger.debug("Total execution of sbmappservices72 GetItems took '"+(System.currentTimeMillis()-startTime)+"' milliseconds.");
//Marshaller m = JAXBContext.newInstance(TTItemList.class).createMarshaller();
//m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
561,23 → 621,35
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));
logger.debug(String.format("Verification query matched '%s' item(s) for issue '%s.'",items.getTotalCount(), issueid));
}
if(items.getTotalCount().intValue()<=0) {
return false;
return null;
} else {
/* store internal ids (tableid:itemid) */
internalissues.add(items.getItem().get(0).getId().getValue().getTableIdItemId().getValue());
/* Store a map entry with internal id and title */
issues_titles.put(items.getItem().get(0).getId().getValue().getDisplayName().getValue(),
items.getItem().get(0).getTitle().getValue());
}
} catch (AEWebservicesFaultFault e) {
} catch (AEWebservicesFaultFault e) {
logger.debug("Web service fault: " + e.getFaultInfo());
} catch (Exception e) {
} catch (Exception e) {
logger.debug("Unknown Exception", e);
}
}
return true;
return items;
}
}
private void postCommitUpdate(File svnadmin, String repos, String locale, String encoding, String revision, String newmessage) {
SVNAdminExecutor exec = new SVNAdminExecutor(svnadmin, repos);
exec.setRev(revision);
exec.setMessage(newmessage);
exec.setEncoding(encoding);
exec.setLocale(locale);
exec.executeSVNAdmin(SVNAdminCommand.SETLOG);
}
 
private void addElement(String pattern, String newCdata, boolean wrapCDATA) throws JaxenException {
OMComment comment = findComment(pattern);
618,6 → 690,12
logger.warn("Comment '"+pattern+"' was not found in the XML template.");
return null;
}
private void exit(int errorCode) {
long endTime = System.currentTimeMillis();
logger.debug("Total execution took '"+(endTime-startTime)+"' milliseconds.");
System.exit(errorCode);
}
@SuppressWarnings("static-access")
private static Options getOptions() {
656,7 → 734,7
// 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 footer = "Please send bug reports to bru@brutex.de.\n(c)2013 Brian Rosenberger";
String footer = "Please send bug reports to bru@brutex.de.\n(c)2014 Brian Rosenberger";
formatter.printHelp("java -jar SVN-ALFEventEmitter", header, getOptions(), footer, true);
}