/SVN-ALFEventEmitter/trunk/ivy.xml |
---|
16,44 → 16,57 |
</info> |
<configurations> |
<conf name="default" visibility="public" description="runtime dependencies and master artifact can be used with this conf" extends="runtime,master"/> |
<conf name="master" visibility="public" description="contains only the artifact published by this module itself, with no transitive dependencies"/> |
<conf name="compile" visibility="public" description="this is the default scope, used if none is specified. Compile dependencies are available in all classpaths." extends="master"/> |
<conf name="provided" visibility="public" description="this is much like compile, but indicates you expect the JDK or a container to provide it. It is only available on the compilation classpath, and is not transitive."/> |
<conf name="runtime" visibility="public" description="this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath." extends="compile"/> |
<conf name="test" visibility="private" description="this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases." extends="runtime"/> |
<conf name="system" visibility="public" description="this scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository."/> |
<conf name="sources" visibility="public" description="this configuration contains the source artifact of this module, if any."/> |
<conf name="javadoc" visibility="public" description="this configuration contains the javadoc artifact of this module, if any."/> |
<conf name="default" visibility="public" |
description="runtime dependencies and master artifact can be used with this conf" |
extends="runtime,master"/> |
<conf name="master" visibility="public" |
description="contains only the artifact published by this module itself, with no transitive dependencies"/> |
<conf name="compile" visibility="public" |
description="this is the default scope, used if none is specified. Compile dependencies are available in all classpaths." |
extends="master"/> |
<conf name="provided" visibility="public" |
description="this is much like compile, but indicates you expect the JDK or a container to provide it. It is only available on the compilation classpath, and is not transitive."/> |
<conf name="runtime" visibility="public" |
description="this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath." |
extends="compile"/> |
<conf name="test" visibility="private" |
description="this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases." |
extends="runtime"/> |
<conf name="system" visibility="public" |
description="this scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository."/> |
<conf name="sources" visibility="public" |
description="this configuration contains the source artifact of this module, if any."/> |
<conf name="javadoc" visibility="public" |
description="this configuration contains the javadoc artifact of this module, if any."/> |
<conf name="optional" visibility="public" description="contains all optional dependencies"/> |
</configurations> |
<dependencies defaultconf="*->#(default),default(*)"> |
<dependency org="log4j" name="log4j" rev="1.2.17"/> |
<dependency org="commons-configuration" name="commons-configuration" rev="1.10"/> |
<dependency org="commons-cli" name="commons-cli" rev="1.2"/> |
<dependency org="org.apache.httpcomponents" name="httpclient" rev="4.3.1"/> |
<!--<dependencies defaultconf="*->#(default),default(*)">--> |
<dependencies defaultconf="default"> |
<dependency org="log4j" name="log4j" rev="1.2.17"/> |
<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-core" rev="3.0.2"/> |
<dependency org="org.apache.cxf" name="cxf-rt-frontend-jaxws" rev="3.0.2"/> |
<dependency org="org.apache.cxf" name="cxf-rt-transports-http" rev="3.0.2"/> |
<dependency org="org.jasypt" name="jasypt" rev="1.9.2"/> |
<!--<dependency org="org.apache.jcs" name="jcs" rev="1.3"/>--> |
<!-- |
Locally managed libraries |
--> |
<dependency org="commons-configuration" name="commons-configuration" rev="1.10"/> |
<dependency org="commons-cli" name="commons-cli" rev="1.4"/> |
<dependency org="org.apache.httpcomponents" name="httpclient" rev="4.5.12"/> |
<dependency org="org.apache.ws.commons.axiom" name="axiom-api" rev="1.2.22"/> |
<dependency org="org.apache.ws.commons.axiom" name="axiom-impl" rev="1.2.22"/> |
<!--<dependency org="com.sun.xml.bind" name="jaxb-impl" rev="2.2.7"/>--> |
<dependency org="org.apache.cxf" name="cxf-core" rev="3.4.0"/> |
<dependency org="org.apache.cxf" name="cxf-rt-frontend-jaxws" rev="3.4.0"/> |
<dependency org="org.apache.cxf" name="cxf-rt-transports-http" rev="3.4.0"/> |
<dependency org="org.jasypt" name="jasypt" rev="1.9.3"/> |
<!--<dependency org="org.apache.jcs" name="jcs" rev="1.3"/>--> |
<!-- |
Locally managed libraries |
--> |
<dependency org="lib" name="sbmappservices72" rev="1.1" conf="*->*"> |
<artifact name="sbmappservices72" type="jar" /> |
<artifact name="sbmappservices72" type="jar"/> |
</dependency> |
</dependencies> |
</ivy-module> |
/SVN-ALFEventEmitter/trunk/ivysettings.xml |
---|
2,18 → 2,19 |
<ivysettings> |
<settings defaultResolver="defaultchain" /> |
<resolvers> |
<ibiblio name="apache-maven" m2compatible="true" usepoms="true" root="http://repo.maven.apache.org/maven2/" /> |
<ibiblio name="java" m2compatible="true" usepoms="true" root="http://download.java.net/maven/2/" /> |
<ibiblio name="apache-maven" m2compatible="true" usepoms="true" root="https://repo1.maven.org/maven2/"/> |
<ibiblio name="sonatype" m2compatible="true" usepoms="true" |
root="https://oss.sonatype.org/content/repositories/releases/"/> |
<filesystem name="local-filesystem"> |
<!-- <ivy pattern="${ivy.settings.dir}/1/[organisation]/[module]/ivys/ivy-[revision].xml"/> --> |
<artifact pattern="${ivy.settings.dir}/lib/[artifact]-[revision].[ext]" /> |
<artifact pattern="${ivy.settings.dir}/lib/[artifact]-[revision].[ext]"/> |
</filesystem> |
<chain name="defaultchain"> |
<resolver ref="local-filesystem" /> |
<resolver ref="apache-maven" /> |
<resolver ref="java" /> |
<resolver ref="local-filesystem"/> |
<resolver ref="apache-maven"/> |
<resolver ref="sonatype"/> |
</chain> |
</resolvers> |
/SVN-ALFEventEmitter/trunk/src/net/brutex/emitter/ALFEmitter.java |
---|
15,53 → 15,19 |
*/ |
package net.brutex.emitter; |
import java.io.File; |
import java.io.FileInputStream; |
import java.io.FileNotFoundException; |
import java.io.IOException; |
import java.io.StringWriter; |
import java.math.BigInteger; |
import java.net.MalformedURLException; |
import java.text.SimpleDateFormat; |
import java.util.ArrayList; |
import java.util.HashMap; |
import java.util.List; |
import java.util.Map; |
import javax.xml.stream.XMLStreamException; |
import net.brutex.emitter.util.EmitterUtil; |
import net.brutex.emitter.util.PasswordEncrypter; |
import net.brutex.sbm.sbmappservices72.AEWebservicesFaultFault; |
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.sbm.sbmappservices72.api.*; |
import net.brutex.svn.SVNAdminCommand; |
import net.brutex.svn.SVNAdminExecutor; |
import net.brutex.svn.SVNCommitInfo; |
import net.brutex.svn.SVNLookExecutor; |
import org.apache.axiom.om.OMAbstractFactory; |
import org.apache.axiom.om.OMComment; |
import org.apache.axiom.om.OMElement; |
import org.apache.axiom.om.OMFactory; |
import org.apache.axiom.om.OMNamespace; |
import org.apache.axiom.om.OMNode; |
import org.apache.axiom.om.OMText; |
import org.apache.axiom.om.OMXMLBuilderFactory; |
import org.apache.axiom.om.*; |
import org.apache.axiom.om.xpath.AXIOMXPath; |
import org.apache.commons.cli.CommandLine; |
import org.apache.commons.cli.CommandLineParser; |
import org.apache.commons.cli.HelpFormatter; |
import org.apache.commons.cli.Option; |
import org.apache.commons.cli.OptionBuilder; |
import org.apache.commons.cli.Options; |
import org.apache.commons.cli.BasicParser; |
import org.apache.commons.cli.ParseException; |
import org.apache.commons.cli.*; |
import org.apache.commons.configuration.Configuration; |
import org.apache.commons.configuration.ConfigurationException; |
import org.apache.commons.configuration.PropertiesConfiguration; |
74,7 → 40,17 |
import org.apache.log4j.Logger; |
import org.jaxen.JaxenException; |
import javax.xml.stream.XMLStreamException; |
import java.io.*; |
import java.math.BigInteger; |
import java.net.MalformedURLException; |
import java.text.SimpleDateFormat; |
import java.util.ArrayList; |
import java.util.HashMap; |
import java.util.List; |
import java.util.Map; |
/** |
* The Class ALFEmitter. |
* |
82,10 → 58,10 |
* @since 0.1 |
*/ |
public class ALFEmitter { |
public static final String VERSION = "0.1"; |
public static final String VERSION = "0.2"; |
private static Logger logger = Logger.getRootLogger(); |
// |
// Keys to read from the configuration file. |
// |
685,37 → 661,46 |
logger.debug("Total execution took '"+(endTime-startTime)+"' milliseconds."); |
System.exit(errorCode); |
} |
@SuppressWarnings("static-access") |
private static Options getOptions() { |
Option repository = OptionBuilder.withArgName( "repository" ) |
.hasArg() |
.withLongOpt("repository") |
.withDescription( "Path or URL to the SVN repository." ) |
.create( PARAM_REPOS ); |
repository.setRequired(true); |
Option txn = OptionBuilder.withArgName( "transactionid" ) |
.hasArg() |
.withLongOpt("transaction") |
.withDescription( "The SVN transaction id to examine (TXN). You cannot combine txn with -rev. " |
+ "When a txn is given, the repository path must be a local path.") |
.create( PARAM_TXN ); |
Option rev = OptionBuilder.withArgName( "revision" ) |
Option repository = Option.builder(PARAM_REPOS) |
.argName("repository") |
.hasArg() |
.withDescription( "A revision to examine. You cannot combine revision with -txn." ) |
.create( PARAM_REV ); |
Option config = OptionBuilder.withArgName( "config_file" ) |
.longOpt("repository") |
.desc("Path or Url to the SVN repository") |
.required() |
.build(); |
Option txn = Option.builder(PARAM_TXN) |
.argName("transactionid") |
.hasArg() |
.withLongOpt("config") |
.withDescription( "The configuration file to use. Defaults to 'emitter.properties'.") |
.create( PARAM_CONFIG ); |
.longOpt("transaction") |
.desc("The SVN transaction id to examine (TXN). You cannot combine txn with -rev. " |
+ "When a txn is given, the repository path must be a local path.") |
.build(); |
Option rev = Option.builder(PARAM_REV) |
.argName("revision") |
.hasArg() |
.desc("A revision to examine. You cannot combine revision with -txn.") |
.build(); |
OptionGroup group = new OptionGroup() |
.addOption(txn) |
.addOption(rev); |
Option config = Option.builder(PARAM_CONFIG) |
.argName("config_file") |
.hasArg() |
.longOpt("config") |
.desc("The configuration file to use. Defaults to 'emitter.properties'.") |
.build(); |
Options options = new Options(); |
options.addOption(repository); |
options.addOption(txn); |
options.addOption(rev); |
options.addOption(config); |
options.addOptionGroup(group); |
return options; |
} |
722,8 → 707,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 footer = "Please send bug reports to bru@brutex.de.\n(c)2014 Brian Rosenberger"; |
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)2020 Brian Rosenberger"; |
formatter.setWidth(80); |
formatter.printHelp("java -jar SVN-ALFEventEmitter", header, getOptions(), footer, true); |
} |
/SVN-ALFEventEmitter/trunk/src/net/brutex/emitter/SimpleHttpEvent.java |
---|
15,10 → 15,6 |
*/ |
package net.brutex.emitter; |
import java.io.BufferedReader; |
import java.io.IOException; |
import java.io.InputStreamReader; |
import org.apache.http.HttpEntity; |
import org.apache.http.HttpResponse; |
import org.apache.http.client.ClientProtocolException; |
26,9 → 22,12 |
import org.apache.http.client.methods.HttpPost; |
import org.apache.http.impl.client.CloseableHttpClient; |
import org.apache.http.impl.client.HttpClients; |
import org.apache.http.util.EntityUtils; |
import org.apache.log4j.Logger; |
import java.io.BufferedReader; |
import java.io.IOException; |
import java.io.InputStreamReader; |
/** |
* Construct a HTTP POST and send it. |
* |
52,30 → 51,30 |
this.url = url; |
this.soapBody = soapBody; |
} |
/** |
* Send soap. |
* |
* @param url the url |
* @param soapBody the soap body |
* @param isDropResponse show interest in response or not |
* @throws ClientProtocolException the client protocol exception |
* @throws IOException Signals that an I/O exception has occurred. |
* @throws IOException Signals that an I/O exception has occurred. |
*/ |
public void sendSoap(boolean isDropResponse) throws ClientProtocolException, IOException { |
long start = System.currentTimeMillis(); |
HttpPost post = new HttpPost(url); |
post.addHeader("Accept" , "text/xml"); |
post.addHeader("SOAPAction",""); |
EntityBuilder entitybuilder = EntityBuilder.create(); |
entitybuilder.setContentEncoding("UTF-8"); |
entitybuilder.setText(soapBody); |
HttpEntity entity = entitybuilder.build(); |
post.setEntity(entity); |
CloseableHttpClient httpclient = HttpClients.createDefault(); |
HttpResponse r = httpclient.execute(post); |
logger.debug("Sending event to ALF event manager"); |
if(! isDropResponse) { |
post.addHeader("Accept", "text/xml"); |
post.addHeader("Content-Type", "text/xml; charset=utf-8"); |
post.addHeader("SOAPAction", ""); |
EntityBuilder entitybuilder = EntityBuilder.create(); |
entitybuilder.setContentEncoding("UTF-8"); |
entitybuilder.setText(soapBody); |
HttpEntity entity = entitybuilder.build(); |
post.setEntity(entity); |
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(); |
BufferedReader in = new BufferedReader(new InputStreamReader(e.getContent())); |
/SVN-ALFEventEmitter/trunk/src/net/brutex/svn/SVNCommitInfo.java |
---|
1,361 → 1,360 |
/* |
* Copyright 2013 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.svn; |
import java.util.ArrayList; |
import java.util.Date; |
import java.util.Iterator; |
import java.util.List; |
import java.util.regex.Matcher; |
import java.util.regex.Pattern; |
import org.apache.log4j.Logger; |
/** |
* The Class SVNCommitInfo represents changes commited to |
* a svn repository. The information is based on svnlook. |
* |
* 'A ' Object dem Projektarchiv hinzugefügt |
* 'D ' Objekt aus dem Projektarchiv gelöscht |
* 'U ' Dateiinhalt geändert |
* '_U' Eigenschaften eines Objektes geändert |
* 'UU' Dateiinhalt und Eigenschaften geändert |
* |
* @author Brian Rosenberger, bru(at)brutex.de |
* @since 0.1 |
* |
*/ |
public class SVNCommitInfo { |
/** The logger. */ |
private final Logger logger = Logger.getLogger(SVNCommitInfo.class); |
/** The author. */ |
private final String author; |
/** The commit message */ |
private String logmessage; |
/** The date. */ |
private final Date date; |
/** The Alist. */ |
private final List<String> Alist = new ArrayList<String>(0); |
/** The Dlist. */ |
private final List<String> Dlist = new ArrayList<String>(0); |
/** The Ulist. */ |
private final List<String> Ulist = new ArrayList<String>(5); |
/** The _ ulist. */ |
private final List<String> _Ulist = new ArrayList<String>(0); |
/** The U ulist. */ |
private final List<String> UUlist = new ArrayList<String>(0); |
/** The issues. */ |
private final List<String> issues = new ArrayList<String>(1); |
/** The txn. */ |
private String txn=""; |
/** The rev. */ |
private String rev=""; |
/** |
* Instantiates a new SVN commit info. |
* |
* @param author the commiter |
* @param date the commit date |
* @param logmessage the commit message |
*/ |
public SVNCommitInfo(String author, Date date, String logmessage) { |
this.author = author; |
this.date = date; |
this.logmessage = logmessage; |
} |
/** |
* Adds the file info. |
* |
* @param t the t |
* @param file the file |
*/ |
public void addFileInfo(ChangeType t, String file) { |
switch (t) { |
case ADDED: |
Alist.add(file); |
break; |
case DELETED: |
Dlist.add(file); |
break; |
case UPDATED: |
Ulist.add(file); |
break; |
case METAUPDATE: |
_Ulist.add(file); |
break; |
case BOTHUPDATE: |
UUlist.add(file); |
break; |
default: |
break; |
} |
} |
/** |
* Gets the author. |
* |
* @return the author |
*/ |
public String getAuthor() { |
return author; |
} |
/** |
* Gets the commit message. |
* |
* @return the commit message |
*/ |
public String getLogmessage() { |
return logmessage; |
} |
/** |
* Gets the commit date. |
* |
* @return the commit date |
*/ |
public Date getDate() { |
return date; |
} |
/** |
* Gets the svn transaction id. |
* |
* @return the txn |
*/ |
public String getTxn() { |
return txn; |
} |
/** |
* Sets the txn. |
* |
* @param txn the new txn |
*/ |
public void setTxn(String txn) { |
this.txn = txn; |
} |
/** |
* Gets the id. This is either the txn or revision. |
* |
* @return the id |
*/ |
public String getId() { |
if(txn!=null) return txn; |
return rev; |
} |
/** |
* Sets the rev. |
* |
* @param rev the new rev |
*/ |
public void setRev(String rev) { |
this.rev = rev; |
} |
/** |
* Gets the rev. |
* |
* @return the rev |
*/ |
public String getRev() { |
return rev; |
} |
/* |
* http://openbook.galileocomputing.de/javainsel9/javainsel_04_007.htm#mjd5b5d84cb3f1b5bcb7638ea9221a491f |
*/ |
/** |
* Parses the issues. |
* |
* @param patterns the patterns |
* @param isRemoveIssues |
*/ |
public void parseIssues(String[] patterns, boolean isRemoveIssues) { |
issues.clear(); //reset |
int count = 0; |
for(String p : patterns) { |
Pattern regex = Pattern.compile(p); |
Matcher matcher = regex.matcher(logmessage); |
logger.debug(String.format("Matching regex pattern '%s' against logmessage '%s'.", matcher.pattern().pattern(), logmessage)); |
while( matcher.find()) { |
issues.add( matcher.group() ); |
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."); |
} |
/** |
* Gets the change file list as string. |
* |
* @return the change file list as string |
*/ |
public String getChangeFileListAsString() { |
StringBuilder sb = new StringBuilder(); |
for (Iterator<String> iterator = Alist.iterator(); iterator.hasNext();) |
{ |
sb.append("A \t"); |
sb.append(iterator.next()); |
sb.append("\n"); |
} |
for (Iterator<String> iterator = Dlist.iterator(); iterator.hasNext();) |
{ |
sb.append("D \t"); |
sb.append(iterator.next()); |
sb.append("\n"); |
} |
for (Iterator<String> iterator = Ulist.iterator(); iterator.hasNext();) |
{ |
sb.append("U \t"); |
sb.append(iterator.next()); |
sb.append("\n"); |
} |
for (Iterator<String> iterator = _Ulist.iterator(); iterator.hasNext();) |
{ |
sb.append("_U\t"); |
sb.append(iterator.next()); |
sb.append("\n"); |
} |
for (Iterator<String> iterator = UUlist.iterator(); iterator.hasNext();) |
{ |
sb.append("UU\t"); |
sb.append(iterator.next()); |
sb.append("\n"); |
} |
sb.append("Summary: " + (Ulist.size()+UUlist.size()+_Ulist.size()) + " files updated, "); |
sb.append(Alist.size() + " files added, " + Dlist.size() + " files deleted."); |
return sb.toString(); |
} |
/** |
* Gets the added files. |
* |
* @return the added files |
*/ |
public List<String> getAddedFiles() { |
return Alist; |
} |
/** |
* Gets the deleted files. |
* |
* @return the deleted files |
*/ |
public List<String> getDeletedFiles() { |
return Dlist; |
} |
/** |
* Gets the changed files. |
* |
* @return the changed files |
*/ |
public List<String> getChangedFiles() { |
List<String> changed = new ArrayList<String>(); |
changed.addAll(Ulist); |
changed.addAll(UUlist); |
changed.addAll(_Ulist); |
return changed; |
} |
/** |
* Gets the issues. |
* |
* @return the issues |
*/ |
public List<String> getIssues() { |
return issues; |
} |
/** |
* The Enum ChangeType. |
* |
* @author Brian Rosenberger, bru(at)brutex.de |
*/ |
public enum ChangeType { |
/** The added. */ |
ADDED("A "), |
/** The deleted. */ |
DELETED("D "), |
/** The updated. */ |
UPDATED("U "), |
/** The metaupdate. */ |
METAUPDATE("_U"), |
/** The bothupdate. */ |
BOTHUPDATE("UU"); |
/** The indicator. */ |
private final String indicator; |
/** |
* Instantiates a new change type. |
* |
* @param svn the svn |
*/ |
private ChangeType(String svn) { |
this.indicator = svn; |
} |
/** |
* Gets the enum. |
* |
* @param s the s |
* @return the enum |
*/ |
public static ChangeType getEnum(String s) { |
for(ChangeType e : ChangeType.values()) { |
if(s.equals(e.getIndicator())) return e; |
} |
throw new IllegalArgumentException("ChangeType enum for value '"+s+"' does not exist."); |
} |
/** |
* Gets the indicator. |
* |
* @return the indicator |
*/ |
public String getIndicator() { |
return this.indicator; |
} |
} |
} |
/* |
* Copyright 2013 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.svn; |
import org.apache.log4j.Logger; |
import java.util.ArrayList; |
import java.util.Date; |
import java.util.Iterator; |
import java.util.List; |
import java.util.regex.Matcher; |
import java.util.regex.Pattern; |
/** |
* The Class SVNCommitInfo represents changes commited to |
* a svn repository. The information is based on svnlook. |
* <p> |
* 'A ' Object dem Projektarchiv hinzugefügt |
* 'D ' Objekt aus dem Projektarchiv gelöscht |
* 'U ' Dateiinhalt geändert |
* '_U' Eigenschaften eines Objektes geändert |
* 'UU' Dateiinhalt und Eigenschaften geändert |
* |
* @author Brian Rosenberger, bru(at)brutex.de |
* @since 0.1 |
*/ |
public class SVNCommitInfo { |
/** The logger. */ |
private final Logger logger = Logger.getLogger(SVNCommitInfo.class); |
/** The author. */ |
private final String author; |
/** The commit message */ |
private String logmessage; |
/** The date. */ |
private final Date date; |
/** The Alist. */ |
private final List<String> Alist = new ArrayList<String>(0); |
/** The Dlist. */ |
private final List<String> Dlist = new ArrayList<String>(0); |
/** The Ulist. */ |
private final List<String> Ulist = new ArrayList<String>(5); |
/** The _ ulist. */ |
private final List<String> _Ulist = new ArrayList<String>(0); |
/** The U ulist. */ |
private final List<String> UUlist = new ArrayList<String>(0); |
/** The issues. */ |
private final List<String> issues = new ArrayList<String>(1); |
/** The txn. */ |
private String txn=""; |
/** The rev. */ |
private String rev=""; |
/** |
* Instantiates a new SVN commit info. |
* |
* @param author the commiter |
* @param date the commit date |
* @param logmessage the commit message |
*/ |
public SVNCommitInfo(String author, Date date, String logmessage) { |
this.author = author; |
this.date = date; |
this.logmessage = logmessage; |
} |
/** |
* Adds the file info. |
* |
* @param t the t |
* @param file the file |
*/ |
public void addFileInfo(ChangeType t, String file) { |
switch (t) { |
case ADDED: |
Alist.add(file); |
break; |
case DELETED: |
Dlist.add(file); |
break; |
case UPDATED: |
Ulist.add(file); |
break; |
case METAUPDATE: |
_Ulist.add(file); |
break; |
case BOTHUPDATE: |
UUlist.add(file); |
break; |
default: |
break; |
} |
} |
/** |
* Gets the author. |
* |
* @return the author |
*/ |
public String getAuthor() { |
return author; |
} |
/** |
* Gets the commit message. |
* |
* @return the commit message |
*/ |
public String getLogmessage() { |
return logmessage; |
} |
/** |
* Gets the commit date. |
* |
* @return the commit date |
*/ |
public Date getDate() { |
return date; |
} |
/** |
* Gets the svn transaction id. |
* |
* @return the txn |
*/ |
public String getTxn() { |
return txn; |
} |
/** |
* Sets the txn. |
* |
* @param txn the new txn |
*/ |
public void setTxn(String txn) { |
this.txn = txn; |
} |
/** |
* Gets the id. This is either the txn or revision. |
* |
* @return the id |
*/ |
public String getId() { |
if(txn!=null) return txn; |
return rev; |
} |
/** |
* Sets the rev. |
* |
* @param rev the new rev |
*/ |
public void setRev(String rev) { |
this.rev = rev; |
} |
/** |
* Gets the rev. |
* |
* @return the rev |
*/ |
public String getRev() { |
return rev; |
} |
/* |
* http://openbook.galileocomputing.de/javainsel9/javainsel_04_007.htm#mjd5b5d84cb3f1b5bcb7638ea9221a491f |
*/ |
/** |
* Parses the issues. |
* |
* @param patterns the patterns |
* @param isRemoveIssues |
*/ |
public void parseIssues(String[] patterns, boolean isRemoveIssues) { |
issues.clear(); //reset |
int count = 0; |
for(String p : patterns) { |
Pattern regex = Pattern.compile(p); |
Matcher matcher = regex.matcher(logmessage); |
logger.debug(String.format("Matching regex pattern '%s' against logmessage '%s'.", matcher.pattern().pattern(), logmessage)); |
while( matcher.find()) { |
issues.add( matcher.group() ); |
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."); |
} |
/** |
* Gets the change file list as string. |
* |
* @return the change file list as string |
*/ |
public String getChangeFileListAsString() { |
StringBuilder sb = new StringBuilder(); |
for (Iterator<String> iterator = Alist.iterator(); iterator.hasNext();) |
{ |
sb.append("A \t"); |
sb.append(iterator.next()); |
sb.append("\n"); |
} |
for (Iterator<String> iterator = Dlist.iterator(); iterator.hasNext();) |
{ |
sb.append("D \t"); |
sb.append(iterator.next()); |
sb.append("\n"); |
} |
for (Iterator<String> iterator = Ulist.iterator(); iterator.hasNext();) |
{ |
sb.append("U \t"); |
sb.append(iterator.next()); |
sb.append("\n"); |
} |
for (Iterator<String> iterator = _Ulist.iterator(); iterator.hasNext();) |
{ |
sb.append("_U\t"); |
sb.append(iterator.next()); |
sb.append("\n"); |
} |
for (Iterator<String> iterator = UUlist.iterator(); iterator.hasNext();) |
{ |
sb.append("UU\t"); |
sb.append(iterator.next()); |
sb.append("\n"); |
} |
sb.append("Summary: " + (Ulist.size()+UUlist.size()+_Ulist.size()) + " files updated, "); |
sb.append(Alist.size() + " files added, " + Dlist.size() + " files deleted."); |
return sb.toString(); |
} |
/** |
* Gets the added files. |
* |
* @return the added files |
*/ |
public List<String> getAddedFiles() { |
return Alist; |
} |
/** |
* Gets the deleted files. |
* |
* @return the deleted files |
*/ |
public List<String> getDeletedFiles() { |
return Dlist; |
} |
/** |
* Gets the changed files. |
* |
* @return the changed files |
*/ |
public List<String> getChangedFiles() { |
List<String> changed = new ArrayList<String>(); |
changed.addAll(Ulist); |
changed.addAll(UUlist); |
changed.addAll(_Ulist); |
return changed; |
} |
/** |
* Gets the issues. |
* |
* @return the issues |
*/ |
public List<String> getIssues() { |
return issues; |
} |
/** |
* The Enum ChangeType. |
* |
* @author Brian Rosenberger, bru(at)brutex.de |
*/ |
public enum ChangeType { |
/** The added. */ |
ADDED("A "), |
/** The deleted. */ |
DELETED("D "), |
/** The updated. */ |
UPDATED("U "), |
/** The metaupdate. */ |
METAUPDATE("_U"), |
/** The bothupdate. */ |
BOTHUPDATE("UU"); |
/** The indicator. */ |
private final String indicator; |
/** |
* Instantiates a new change type. |
* |
* @param svn the svn |
*/ |
private ChangeType(String svn) { |
this.indicator = svn; |
} |
/** |
* Gets the enum. |
* |
* @param s the s |
* @return the enum |
*/ |
public static ChangeType getEnum(String s) { |
for(ChangeType e : ChangeType.values()) { |
if(s.equals(e.getIndicator())) return e; |
} |
throw new IllegalArgumentException("ChangeType enum for value '"+s+"' does not exist."); |
} |
/** |
* Gets the indicator. |
* |
* @return the indicator |
*/ |
public String getIndicator() { |
return this.indicator; |
} |
} |
} |