/SVN-ALFEventEmitter/trunk/src/net/brutex/svn/SVNLookCommand.java |
---|
0,0 → 1,42 |
/* |
* 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; |
/** |
* The Enum SVNLookCommand. Lists supported svnlook commands |
* |
* @author Brian Rosenberger, bru(at)brutex.de |
* @since 0.1 |
*/ |
public enum SVNLookCommand { |
CHANGED("changed"), |
LOG("log"), |
AUTHOR("author"); |
private final String value; |
private SVNLookCommand(String value) { |
this.value = value; |
} |
public String getValue() { |
return this.value; |
} |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/SVN-ALFEventEmitter/trunk/src/net/brutex/svn/SVNLookExecutor.java |
---|
0,0 → 1,177 |
/* |
* 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.io.BufferedReader; |
import java.io.File; |
import java.io.IOException; |
import java.io.InputStreamReader; |
import java.util.ArrayList; |
import java.util.Date; |
import java.util.List; |
import java.util.StringTokenizer; |
import net.brutex.svn.SVNCommitInfo.ChangeType; |
import org.apache.log4j.Logger; |
/** Executes the svnlook utility |
* |
* @author Brian Rosenberger bru(at)brutex.de |
* @since 0.1 |
*/ |
public class SVNLookExecutor { |
private Logger logger = Logger.getLogger(SVNLookExecutor.class); |
private final File svnlook; |
private final String repos; |
private String TXN = null; |
private String rev = null; |
/** |
* Instantiates a new sVN look executor. |
* |
* @param svnlook the svnlook |
* @param repos the repos |
*/ |
public SVNLookExecutor(File svnlook, String repos) { |
if(! svnlook.exists() ) throw new IllegalArgumentException( String.format("The svnlook executable at '%s' does not exist.", svnlook.toString())); |
if(! svnlook.isFile() ) throw new IllegalArgumentException( String.format("The svnlook utility at'%s' is not a file.", svnlook.toString())); |
logger.debug(String.format("Instantiating '%s' with svnlook at '%s'.", this.getClass().getCanonicalName(), svnlook.toString())); |
this.svnlook = svnlook; |
logger.debug(String.format("Working against svn repository at '%s'.", repos)); |
this.repos = repos; |
} |
/** |
* Execute svn look. |
* |
* @param command the command |
* @return the string |
*/ |
private String executeSVNLook(SVNLookCommand command) { |
StringBuilder sb = new StringBuilder(); |
StringBuilder sberr = new StringBuilder(); |
//This throws an IllegalArgumentException when neither TXN nor REV is valid |
String[] params; |
try { |
params = getTargetParam(); |
} catch (IllegalArgumentException e) { |
logger.error(e.getMessage()); |
throw e; |
} |
try { |
List<String> cmdline = new ArrayList<String>(5); |
cmdline.add(svnlook.toString()); |
cmdline.add(command.getValue()); |
cmdline.add(params[0]); |
cmdline.add(params[1]); |
cmdline.add(repos); |
ProcessBuilder pf = new ProcessBuilder(cmdline); |
logger.debug(String.format("Executing svnlook with commandline '%s'.", pf.command())); |
Process svnprocess = pf.start(); |
BufferedReader stdin = new BufferedReader(new InputStreamReader(svnprocess.getInputStream())); |
BufferedReader stderr = new BufferedReader(new InputStreamReader(svnprocess.getErrorStream())); |
String s; |
while( (s = stdin.readLine()) != null ) { |
sb.append(s + '\n'); |
} |
while( (s = stderr.readLine()) != null ) { |
sberr.append(s + '\n'); |
} |
stdin.close(); stderr.close(); |
} catch (IOException e) { |
logger.error( String.format( "Error calling the svnlook utility: '%s'", e.getMessage())); |
e.printStackTrace(); |
} |
String error = sberr.toString(); |
if( error.length()>0 ) { |
error = "Failed to call svnlook. The STDERR was '"+error+"'"; |
logger.error(error); |
throw new IllegalArgumentException(error); |
} |
String output = sb.toString().trim(); |
logger.debug(String.format("Svnlook output was '%s'", output)); |
return output; |
} |
/* |
* Returns either -t TXN oder -rev REVISION |
* |
* @returns |
*/ |
private String[] getTargetParam() { |
String[] result = new String[2]; |
if( (TXN==null || TXN.length()<=0) && (rev==null || rev.length()<=0) ) throw new IllegalArgumentException("Either TXN or revision must be provided."); |
if( TXN!=null && TXN.length()>0 && rev!=null && rev.length()>0 ) throw new IllegalArgumentException("Both, TXN and revision are given. Don't know what to use."); |
if( TXN!=null && TXN.length()>0) { |
result[0] = "-t"; |
result[1] = TXN; |
return result; |
} |
if( rev!=null && rev.length()>0) { |
result[0] = "-r"; |
result[1] = rev; |
return result; |
} |
throw new IllegalArgumentException("Either TXN or revision must be provided."); |
} |
public void setTXN(String TXN) { |
if(TXN==null || TXN.length()<=0) throw new IllegalArgumentException("TXN cannot be null or empty."); |
this.TXN = TXN; |
} |
public void setRev(String rev) { |
if(rev==null || rev.length()<=0) throw new IllegalArgumentException("Revision cannot be null or empty."); |
this.rev = rev; |
} |
public SVNCommitInfo getCommitInfo() { |
String author = executeSVNLook(SVNLookCommand.AUTHOR); |
String logmessage = executeSVNLook(SVNLookCommand.LOG); |
String files = executeSVNLook(SVNLookCommand.CHANGED); |
SVNCommitInfo result = new SVNCommitInfo(author, |
new Date(), |
logmessage); |
files += "\n"; |
StringTokenizer tokenizer = new StringTokenizer(files, "\n"); |
String s; |
while( tokenizer.hasMoreTokens()) { |
s=tokenizer.nextToken(); |
logger.debug(String.format("Tokenizing file list. Token '%s'.", s)); |
if(s.startsWith("A")) { result.addFileInfo(ChangeType.ADDED, s.substring(1).trim()); continue; } |
if(s.startsWith("D")) { result.addFileInfo(ChangeType.DELETED, s.substring(1).trim()); continue; } |
if(s.startsWith("UU")) { result.addFileInfo(ChangeType.BOTHUPDATE, s.substring(2).trim()); continue; } |
if(s.startsWith("_U")) { result.addFileInfo(ChangeType.METAUPDATE, s.substring(2).trim()); continue; } |
if(s.startsWith("U")) { result.addFileInfo(ChangeType.UPDATED, s.substring(1).trim()); continue; } |
} |
result.setTxn(TXN); |
result.setRev(rev); |
return result; |
} |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/SVN-ALFEventEmitter/trunk/src/net/brutex/svn/SVNCommitInfo.java |
---|
0,0 → 1,355 |
/* |
* 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 final 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 |
*/ |
public void parseIssues(String[] patterns) { |
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++; |
} |
} |
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; |
} |
} |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |