/SVN-ALFEventEmitter/branches/Maint 0.1 JRE6/src/net/brutex/svn/SVNAdminCommand.java |
---|
0,0 → 1,40 |
/* |
* 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.svn; |
/** |
* The Enum SVNAdminCommand. Lists supported svnladmin commands |
* |
* @author Brian Rosenberger, bru(at)brutex.de |
* @since 0.1 |
*/ |
public enum SVNAdminCommand { |
SETLOG("setlog"); |
private final String value; |
private SVNAdminCommand(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/branches/Maint 0.1 JRE6/src/net/brutex/svn/SVNAdminExecutor.java |
---|
0,0 → 1,181 |
/* |
* 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.svn; |
import java.io.BufferedReader; |
import java.io.BufferedWriter; |
import java.io.File; |
import java.io.FileOutputStream; |
import java.io.IOException; |
import java.io.InputStreamReader; |
import java.io.OutputStreamWriter; |
import java.util.ArrayList; |
import java.util.List; |
import java.util.Map; |
import org.apache.log4j.Logger; |
/* Executes the svnadmin utility |
* |
* @author Brian Rosenberger bru(at)brutex.de |
* @since 0.1 |
*/ |
public class SVNAdminExecutor { |
private Logger logger = Logger.getLogger(SVNAdminExecutor.class); |
private final File svnadmin; |
private final String repos; |
private String rev = null; |
private String message = null; |
private String locale = "de_DE.UTF-8"; |
private String encoding = "UTF-8"; |
private boolean useBypassHooks = true; |
/** |
* Instantiates a new SVN admin executor. |
* |
* @param svnadmin the svnadmin |
* @param repos the repos |
*/ |
public SVNAdminExecutor(File svnadmin, String repos) { |
if(! svnadmin.exists() ) throw new IllegalArgumentException( String.format("The svnadmin executable at '%s' does not exist.", svnadmin.toString())); |
if(! svnadmin.isFile() ) throw new IllegalArgumentException( String.format("The svnadmin utility at'%s' is not a file.", svnadmin.toString())); |
logger.debug(String.format("Instantiating '%s' with svnadmin at '%s'.", this.getClass().getCanonicalName(), svnadmin.toString())); |
this.svnadmin = svnadmin; |
logger.debug(String.format("Working against svn repository at '%s'.", repos)); |
this.repos = repos; |
} |
/** |
* Execute svn admin. |
* |
* @param command the command |
* @return the string |
*/ |
public String executeSVNAdmin(SVNAdminCommand command) { |
StringBuilder sb = new StringBuilder(); |
StringBuilder sberr = new StringBuilder(); |
if(rev==null) { |
logger.error("The revision can not be 'null' for the svnadmin command."); |
return null; |
} |
if(message==null) { |
logger.error("The new log message can not be 'null' for the svnadmin command."); |
return null; |
} |
File logfile = null; |
try { |
logfile = File.createTempFile("~msg"+rev+"_", ".tmp"); |
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(logfile), encoding)); |
out.write(message); |
out.flush(); |
out.close(); |
} catch (IOException e) { |
logger.error("Failed to write new log message to temporary file '"+logfile.getAbsolutePath()+"'.", e); |
return null; |
} |
try { |
List<String> cmdline = new ArrayList<String>(5); |
cmdline.add(svnadmin.toString()); |
cmdline.add(command.getValue()); |
cmdline.add(repos); |
if(useBypassHooks) { |
cmdline.add("--bypass-hooks"); |
} |
cmdline.add("-r"); |
cmdline.add(rev); |
cmdline.add(logfile.getAbsolutePath()); |
ProcessBuilder pf = new ProcessBuilder(cmdline); |
logger.debug(String.format("Executing svnadmin with commandline '%s'.", pf.command())); |
Map<String, String> env = pf.environment(); |
env.put("LANG", locale); |
Process svnprocess = pf.start(); |
BufferedReader stdin = new BufferedReader(new InputStreamReader(svnprocess.getInputStream(), encoding)); |
BufferedReader stderr = new BufferedReader(new InputStreamReader(svnprocess.getErrorStream(), encoding)); |
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 svnadmin utility: '%s'", e.getMessage())); |
e.printStackTrace(); |
} finally { |
logfile.deleteOnExit(); |
} |
String error = sberr.toString(); |
if( error.length()>0 ) { |
error = "Failed to call svnadmin. The STDERR was '"+error+"'"; |
logger.error(error); |
throw new IllegalArgumentException(error); |
} |
String output = sb.toString().trim(); |
logger.debug(String.format("Svnadmin output was '%s'", output)); |
return output; |
} |
public void setRev(String rev) { |
if(rev==null || rev.length()<=0) throw new IllegalArgumentException("Revision cannot be null or empty."); |
this.rev = rev; |
} |
public void setEncoding(String encoding) { |
this.encoding = encoding; |
} |
/** |
* Set the locale that will be pushed into |
* 'LANG' environment variable. |
* |
* @param locale i.e. de_DE.UTF-8 |
*/ |
public void setLocale(String locale) { |
this.locale = locale; |
} |
/** |
* Set the new log message. |
* |
* @param message new message |
*/ |
public void setMessage(String message) { |
this.message = message; |
} |
/** |
* Set this to true to bypass the pre-revprop-change and post-revprop-change |
* hooks. |
* |
* @param useBypassHooks defaults to true |
*/ |
public void setUseBypassHooks(boolean useBypassHooks) { |
this.useBypassHooks = useBypassHooks; |
} |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/SVN-ALFEventEmitter/branches/Maint 0.1 JRE6/src/net/brutex/svn/SVNLookExecutor.java |
---|
0,0 → 1,194 |
/* |
* 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.Map; |
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; |
private String locale = "de_DE.UTF-8"; |
private String encoding = "UTF-8"; |
/** |
* 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())); |
Map<String, String> env = pf.environment(); |
env.put("LANG", locale); |
Process svnprocess = pf.start(); |
BufferedReader stdin = new BufferedReader(new InputStreamReader(svnprocess.getInputStream(), encoding)); |
BufferedReader stderr = new BufferedReader(new InputStreamReader(svnprocess.getErrorStream(), encoding)); |
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; |
} |
public void setEncoding(String encoding) { |
this.encoding = encoding; |
} |
/** |
* Set the locale that will be pushed into |
* 'LANG' environment variable. |
* |
* @param locale i.e. de_DE.UTF-8 |
*/ |
public void setLocale(String locale) { |
this.locale = locale; |
} |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/SVN-ALFEventEmitter/branches/Maint 0.1 JRE6/src/net/brutex/svn/SVNCommitInfo.java |
---|
0,0 → 1,361 |
/* |
* 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; |
} |
} |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/SVN-ALFEventEmitter/branches/Maint 0.1 JRE6/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 |