Permalink
Browse files

Merge branch 'master' of github.com:r1j0/Bugspot into cleanup

  • Loading branch information...
2 parents 9ef7eb3 + d3a7efc commit b1c5464b0cdba4cca058b5724337fde5dd5f8972 @0x20h committed Feb 26, 2012
View
2 .project
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>BugSpot</name>
+ <name>Bugspot</name>
<comment></comment>
<projects>
</projects>
View
5 pom.xml
@@ -20,6 +20,11 @@
<artifactId>svnkit-javahl</artifactId>
<version>1.3.5</version>
</dependency>
+ <dependency>
+ <groupId>com.madgag</groupId>
+ <artifactId>org.eclipse.jgit</artifactId>
+ <version>1.2.0.0.2-UNOFFICIAL-ROBERTO-RELEASE</version>
+ </dependency>
</dependencies>
<build>
<plugins>
View
106 src/com/github/r1j0/bugspot/Bugspot.java
@@ -0,0 +1,106 @@
+package com.github.r1j0.bugspot;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+
+import com.github.r1j0.bugspot.repository.LogEntries;
+import com.github.r1j0.bugspot.repository.Repository;
+import com.github.r1j0.bugspot.repository.RepositoryFactory;
+
+public class Bugspot {
+
+ private static final String NAME = Bugspot.class.getSimpleName();
+
+
+ public static void main(String[] args) {
+ args = new String[] { "-h" };
+// args = new String[] { "-url", "http://svn.apache.org/repos/asf/hadoop/common/trunk/hadoop-common-project", "-u", "anonymous", "-p", "anonymous" };
+ /**
+ * <code>
+ * args = new String[] { "-url", "http://svn.apache.org/repos/asf/hadoop/common/trunk/hadoop-common-project", "-u", "anonymous", "-p", "anonymous" };
+ * </code>
+ */
+ CommandLineParser parser = new PosixParser();
+ Options commandLineOptions = OptionsBuilder.build();
+ CommandLine line = null;
+
+ try {
+ line = parser.parse(commandLineOptions, args);
+ } catch (ParseException e) {
+ System.out.println(e.getMessage() + "\n");
+ printHelp(commandLineOptions);
+ System.exit(1);
+ }
+
+ checkConditions(line, commandLineOptions);
+ final Map<String, String> options = parseCommandLineOptions(line);
+
+ Repository repository = RepositoryFactory.getInstance(options.get("type"), options.get("url"), options.get("username"), options.get("password"));
+ List<LogEntries> logEntries = repository.checkout(1200180, 1241260);
+
+ Computate computate = new Computate(logEntries);
+ computate.compute();
+ Map<String, Double> hotspots = computate.getHotspots();
+
+ for (Entry<String, Double> entrySet : hotspots.entrySet()) {
+ System.out.println("PATH: " + entrySet.getKey() + " VALUE: " + entrySet.getValue());
+ }
+ }
+
+
+ private static Map<String, String> parseCommandLineOptions(final CommandLine line) {
+ final Map<String, String> options = new HashMap<String, String>();
+
+ options.put("url", line.getOptionValue("url"));
+ options.put("username", "anonymous");
+ options.put("password", "anonymous");
+ options.put("type", "svn");
+
+ if (line.hasOption("u")) {
+ options.put("username", line.getOptionValue("u"));
+ }
+
+ if (line.hasOption("p")) {
+ options.put("password", line.getOptionValue("p"));
+ }
+
+ if (line.hasOption("t")) {
+ options.put("type", line.getOptionValue("t"));
+ }
+
+ return options;
+ }
+
+
+ private static void checkConditions(CommandLine line, Options options) {
+ if (line.hasOption("h")) {
+ printHelp(options);
+ System.exit(0);
+ }
+
+ if (line.hasOption("version")) {
+ System.out.println("Version is and will be infinite.");
+ System.exit(0);
+ }
+
+ if (!line.hasOption("url")) {
+ System.out.println("No repository url has been given.");
+ System.exit(0);
+ }
+ }
+
+
+ private static void printHelp(Options options) {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp(NAME, options);
+ }
+}
View
83 src/com/github/r1j0/bugspot/Computate.java
@@ -0,0 +1,83 @@
+package com.github.r1j0.bugspot;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.github.r1j0.bugspot.repository.LogEntries;
+
+public class Computate {
+
+ private final Pattern fixesPattern = Pattern.compile("fix(es|ed)?|close(s|d)?", Pattern.CASE_INSENSITIVE);
+ private final Pattern ignorePattern = Pattern.compile(".*\\.txt|.*\\.xml", Pattern.CASE_INSENSITIVE);
+ private final List<LogEntries> logEntries;
+ private Map<String, Double> hotspots = new HashMap<String, Double>();
+
+
+ public Computate(List<LogEntries> logEntries) {
+ this.logEntries = logEntries;
+ }
+
+
+ public void compute() {
+ List<LogEntries> fixes = extractFixes();
+ LogEntries lastEntry = fixes.get(fixes.size() - 1);
+
+ for (LogEntries logEntries : fixes) {
+ Map<String, String> logPath = logEntries.getLogPath();
+
+ for (Entry<String, String> entrySet : logPath.entrySet()) {
+ String fullPath = entrySet.getValue();
+
+ Matcher ignoreMatcher = ignorePattern.matcher(fullPath);
+
+ if (ignoreMatcher.matches()) {
+ continue;
+ }
+
+ Double bugSportValue = calculateBugSpot(lastEntry, logEntries, fullPath);
+ hotspots.put(fullPath, bugSportValue);
+ }
+ }
+ }
+
+
+ public Map<String, Double> getHotspots() {
+ return hotspots;
+ }
+
+
+ private List<LogEntries> extractFixes() {
+ final List<LogEntries> fixes = new ArrayList<LogEntries>();
+
+ for (LogEntries logEntry : logEntries) {
+ Matcher fixesMatcher = fixesPattern.matcher(logEntry.getMessage());
+
+ if (fixesMatcher.find()) {
+ fixes.add(logEntry);
+ }
+ }
+
+ return fixes;
+ }
+
+
+ private Double calculateBugSpot(LogEntries lastEntry, LogEntries logEntries, String fullPath) {
+ float t = 1 - (((System.currentTimeMillis() - logEntries.getDate().getTime()) / (System.currentTimeMillis() - lastEntry.getDate().getTime())) / 1000);
+
+ Double oldBugSpotValue = hotspots.get(fullPath);
+ Double newBugSpotValue;
+
+ if (oldBugSpotValue != null) {
+ newBugSpotValue = oldBugSpotValue + (1 / (1 + Math.exp((-12 * t) + 12)));
+ } else {
+ newBugSpotValue = 1 / (1 + Math.exp((-12 * t) + 12));
+ }
+
+ return newBugSpotValue;
+ }
+}
View
69 src/com/github/r1j0/bugspot/OptionsBuilder.java
@@ -0,0 +1,69 @@
+package com.github.r1j0.bugspot;
+
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+
+public class OptionsBuilder {
+
+ public static Options build() {
+ Options options = new Options();
+
+ addHelpOption(options);
+ addVersionOption(options);
+ addUrlOption(options);
+ addUsernameOption(options);
+ addPasswordOption(options);
+ addRepositoryTypeOption(options);
+ return options;
+ }
+
+
+ private static void addUrlOption(Options options) {
+ OptionBuilder.withArgName("url");
+ OptionBuilder.withDescription("repository url");
+ OptionBuilder.hasArg();
+ OptionBuilder.withArgName("URL");
+ options.addOption(OptionBuilder.create("url"));
+ }
+
+
+ private static void addUsernameOption(Options options) {
+ OptionBuilder.withArgName("u");
+ OptionBuilder.withLongOpt("username");
+ OptionBuilder.withDescription("repository username");
+ OptionBuilder.hasArg();
+ OptionBuilder.withArgName("USERNAME");
+ options.addOption(OptionBuilder.create("u"));
+ }
+
+
+ private static void addPasswordOption(Options options) {
+ OptionBuilder.withArgName("p");
+ OptionBuilder.withLongOpt("password");
+ OptionBuilder.withDescription("repository password");
+ OptionBuilder.hasArg();
+ OptionBuilder.withArgName("PASSWORD");
+ options.addOption(OptionBuilder.create("p"));
+ }
+
+
+ private static void addRepositoryTypeOption(Options options) {
+ OptionBuilder.withArgName("t");
+ OptionBuilder.withLongOpt("type");
+ OptionBuilder.withDescription("repository type, e.g. svn or git");
+ OptionBuilder.hasArg();
+ OptionBuilder.withArgName("TYPE");
+ options.addOption(OptionBuilder.create("t"));
+ }
+
+
+ private static void addVersionOption(Options options) {
+ options.addOption(new Option("version", "print the version information and exit"));
+ }
+
+
+ private static void addHelpOption(Options options) {
+ options.addOption(new Option("h", "help", false, "print this message"));
+ }
+}
View
27 src/com/github/r1j0/bugspot/repository/GitRepository.java
@@ -0,0 +1,27 @@
+package com.github.r1j0.bugspot.repository;
+
+import java.util.List;
+
+public class GitRepository implements Repository {
+
+ private final String url;
+ private final String username;
+ private final String password;
+
+
+ public GitRepository(String url, String username, String password) {
+ this.url = url;
+ this.username = username;
+ this.password = password;
+ }
+
+
+ public List<LogEntries> checkout(long startRevision) {
+ throw new IllegalArgumentException("Not implemented yet.");
+ }
+
+
+ public List<LogEntries> checkout(long startRevision, long endRevision) {
+ throw new IllegalArgumentException("Not implemented yet.");
+ }
+}
View
22 src/com/github/r1j0/bugspot/repository/LogEntries.java
@@ -0,0 +1,22 @@
+package com.github.r1j0.bugspot.repository;
+
+import java.util.Date;
+import java.util.Map;
+
+public interface LogEntries {
+
+ long getRevision();
+
+
+ String getAuthor();
+
+
+ Date getDate();
+
+
+ String getMessage();
+
+
+ Map<String, String> getLogPath();
+
+}
View
48 src/com/github/r1j0/bugspot/repository/LogEntriesImpl.java
@@ -0,0 +1,48 @@
+package com.github.r1j0.bugspot.repository;
+
+import java.util.Date;
+import java.util.Map;
+
+public class LogEntriesImpl implements LogEntries {
+
+ private final long revision;
+ private final String author;
+ private final String message;
+ private final Map<String, String> logPath;
+ private final Date date;
+
+
+ public LogEntriesImpl(long revision, String author, Date date, String message, Map<String, String> logPath) {
+ this.revision = revision;
+ this.author = author;
+ this.date = date;
+ this.message = message;
+ this.logPath = logPath;
+ }
+
+
+ public long getRevision() {
+ return revision;
+ }
+
+
+ public String getAuthor() {
+ return author;
+ }
+
+
+ public Date getDate() {
+ return date;
+ }
+
+
+ public String getMessage() {
+ return message;
+ }
+
+
+ public Map<String, String> getLogPath() {
+ return logPath;
+ }
+
+}
View
18 src/com/github/r1j0/bugspot/repository/Repository.java
@@ -0,0 +1,18 @@
+package com.github.r1j0.bugspot.repository;
+
+import java.util.List;
+
+public interface Repository {
+
+ public static final char TYPE_ADDED = 'A';
+ public static final char TYPE_DELETED = 'D';
+ public static final char TYPE_MODIFIED = 'M';
+ public static final char TYPE_REPLACED = 'R';
+
+
+ List<LogEntries> checkout(long startRevision);
+
+
+ List<LogEntries> checkout(long startRevision, long endRevision);
+
+}
View
17 src/com/github/r1j0/bugspot/repository/RepositoryFactory.java
@@ -0,0 +1,17 @@
+package com.github.r1j0.bugspot.repository;
+
+public class RepositoryFactory {
+
+ public static Repository getInstance(final String type, final String url, final String username, final String password) {
+ final String typeLowerCase = type.toLowerCase();
+
+ if (typeLowerCase.equals("svn")) {
+ return new SvnRepository(url, username, password);
+ } else if (typeLowerCase.equals("git")) {
+ return new GitRepository(url, username, password);
+ }
+
+ throw new IllegalArgumentException("No repository connector for repository type " + type + " available.");
+ }
+
+}
View
96 src/com/github/r1j0/bugspot/repository/SvnRepository.java
@@ -0,0 +1,96 @@
+package com.github.r1j0.bugspot.repository;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.SVNLogEntry;
+import org.tmatesoft.svn.core.SVNLogEntryPath;
+import org.tmatesoft.svn.core.SVNURL;
+import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
+import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
+import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
+import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
+import org.tmatesoft.svn.core.io.SVNRepository;
+import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
+import org.tmatesoft.svn.core.wc.SVNWCUtil;
+
+public class SvnRepository implements Repository {
+
+ private static final int HEAD_REVISION = -1;
+
+ private final String url;
+ private final String username;
+ private final String password;
+
+
+ public SvnRepository(String url, String username, String password) {
+ this.url = url;
+ this.username = username;
+ this.password = password;
+
+ setup();
+ }
+
+
+ public List<LogEntries> checkout(long startRevision) {
+ return checkout(startRevision, HEAD_REVISION);
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public List<LogEntries> checkout(long startRevision, long endRevision) {
+ SVNRepository repository = null;
+
+ try {
+ repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
+ } catch (SVNException svne) {
+ System.err.println("Error for repository with location: " + url + ". Message: " + svne.getMessage());
+ System.exit(1);
+ }
+
+ ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password);
+ repository.setAuthenticationManager(authManager);
+
+ Collection<SVNLogEntry> svnLogEntries = null;
+
+ try {
+ svnLogEntries = repository.log(new String[] { "" }, null, startRevision, endRevision, true, true);
+ } catch (SVNException svne) {
+ System.out.println("Error retrieving log information for repository: " + url + ". Message: " + svne.getMessage());
+ System.exit(1);
+ }
+
+ List<LogEntries> logEntries = new ArrayList<LogEntries>();
+
+ for (Iterator<SVNLogEntry> entries = svnLogEntries.iterator(); entries.hasNext();) {
+ SVNLogEntry logEntry = entries.next();
+ Map<String, String> logPath = new HashMap<String, String>();
+
+ if (logEntry.getChangedPaths().size() > 0) {
+ Set<SVNLogEntryPath> changedPathsSet = logEntry.getChangedPaths().keySet();
+
+ for (Iterator<SVNLogEntryPath> changedPaths = changedPathsSet.iterator(); changedPaths.hasNext();) {
+ SVNLogEntryPath entryPath = (SVNLogEntryPath) logEntry.getChangedPaths().get(changedPaths.next());
+ logPath.put(Character.toString(entryPath.getType()), entryPath.getPath());
+ }
+ }
+
+ logEntries.add(new LogEntriesImpl(logEntry.getRevision(), logEntry.getAuthor(), logEntry.getDate(), logEntry.getMessage(), logPath));
+ }
+
+ return logEntries;
+ }
+
+
+ private void setup() {
+ DAVRepositoryFactory.setup();
+ SVNRepositoryFactoryImpl.setup();
+ FSRepositoryFactory.setup();
+ }
+}
View
90 src/local/r1j0/bugspot/BugSpot.java
@@ -1,90 +0,0 @@
-package local.r1j0.bugspot;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import local.r1j0.bugspot.repository.LogEntries;
-import local.r1j0.bugspot.repository.Repository;
-import local.r1j0.bugspot.repository.SvnRepository;
-
-public class BugSpot {
-
- public static void main(String[] args) {
-
- String url = "http://svn.apache.org/repos/asf/hadoop/common/trunk/hadoop-common-project";
- String username = "anonymous";
- String password = "anonymous";
-
- Repository svnRepository = new SvnRepository(url, username, password);
-// List<LogEntries> logEntries = svnRepository.checkout(500180, 1241260);
- List<LogEntries> logEntries = svnRepository.checkout(1200180, 1241260);
-
- Computate computate = new Computate(logEntries);
- computate.compute();
- Map<String, Double> hotspots = computate.getHotspots();
-
- for (Entry<String,Double> entrySet : hotspots.entrySet()) {
- System.out.println("PATH: " + entrySet.getKey() + " VALUE: " + entrySet.getValue());
- }
-
-// Pattern p = Pattern.compile("fix(es|ed)?|close(s|d)?", Pattern.CASE_INSENSITIVE);
-//
-// for (LogEntries logEntry : logEntries) {
-// System.out.println("------------");
-// System.out.println("AUTHOR: " + logEntry.getAuthor());
-// System.out.println("REVISION: " + logEntry.getRevision());
-// System.out.println("MESSAGE: " + logEntry.getMessage());
-//
-// Matcher matcher = p.matcher(logEntry.getMessage());
-//
-// if (matcher.find()) {
-// System.out.println("YEPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPppp");
-// }
-// }
-
- /**
- * <code>
- Options options = new Options();
- options.addOption(new Option("h", "help", false, "print this message"));
- options.addOption(new Option("version",
- "print the version information and exit"));
- OptionBuilder.withArgName("u");
- OptionBuilder.withDescription("repository username");
- OptionBuilder.hasArg();
- OptionBuilder.withArgName("USERNAME");
- options.addOption(OptionBuilder.create("u"));
-
- // create the parser
- CommandLineParser parser = new PosixParser();
-
- args = new String[] { "-h", "--version" };
-
- // parse the command line arguments
- CommandLine line = null;
-
- try {
- line = parser.parse(options, args);
- } catch (ParseException e) {
- System.out.println(e.getMessage() + "\n");
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp("BugSpot", options);
- System.exit(1);
- }
-
- if (line.hasOption("h")) {
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp("BugSpot", options);
- }
-
- if (line.hasOption("version")) {
- System.out.println("Version is crap.");
- }
-
- if (line.hasOption("u")) {
- System.out.println("username: " + line.getOptionValue("u"));
- }
- </code>
- */
- }
-}
View
76 src/local/r1j0/bugspot/Computate.java
@@ -1,76 +0,0 @@
-package local.r1j0.bugspot;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import local.r1j0.bugspot.repository.LogEntries;
-
-public class Computate {
-
- private final Pattern pattern = Pattern.compile("fix(es|ed)?|close(s|d)?", Pattern.CASE_INSENSITIVE);
- private final List<LogEntries> logEntries;
- private Map<String, Double> hotspots = new HashMap<String, Double>();
-
-
- public Computate(List<LogEntries> logEntries) {
- this.logEntries = logEntries;
- }
-
-
- public void compute() {
- List<LogEntries> fixes = extractFixes();
- LogEntries lastEntry = fixes.get(fixes.size() - 1);
-
- for (LogEntries logEntries : fixes) {
- Map<String, String> logPath = logEntries.getLogPath();
-
- for (Entry<String, String> entrySet : logPath.entrySet()) {
- String fullPath = entrySet.getValue();
-
- Double bugSportValue = calculateBugSpot(lastEntry, logEntries, fullPath);
- hotspots.put(fullPath, bugSportValue);
- }
- }
- }
-
-
- public Map<String, Double> getHotspots() {
- return hotspots;
- }
-
-
- private List<LogEntries> extractFixes() {
- final List<LogEntries> fixes = new ArrayList<LogEntries>();
-
- for (LogEntries logEntry : logEntries) {
- Matcher matcher = pattern.matcher(logEntry.getMessage());
-
- if (matcher.find()) {
- fixes.add(logEntry);
- }
- }
-
- return fixes;
- }
-
-
- private Double calculateBugSpot(LogEntries lastEntry, LogEntries logEntries, String fullPath) {
- float t = 1 - ((System.currentTimeMillis() - logEntries.getDate().getTime()) / (System.currentTimeMillis() - lastEntry.getDate().getTime()));
-
- Double oldBugSpotValue = hotspots.get(fullPath);
- Double newBugSpotValue;
-
- if (oldBugSpotValue != null) {
- newBugSpotValue = oldBugSpotValue + (1 / (1 + Math.exp((-12 * t) + 12)));
- } else {
- newBugSpotValue = 1 / (1 + Math.exp((-12 * t) + 12));
- }
-
- return newBugSpotValue;
- }
-}
View
22 src/local/r1j0/bugspot/repository/LogEntries.java
@@ -1,22 +0,0 @@
-package local.r1j0.bugspot.repository;
-
-import java.util.Date;
-import java.util.Map;
-
-public interface LogEntries {
-
- long getRevision();
-
-
- String getAuthor();
-
-
- Date getDate();
-
-
- String getMessage();
-
-
- Map<String, String> getLogPath();
-
-}
View
48 src/local/r1j0/bugspot/repository/LogEntriesImpl.java
@@ -1,48 +0,0 @@
-package local.r1j0.bugspot.repository;
-
-import java.util.Date;
-import java.util.Map;
-
-public class LogEntriesImpl implements LogEntries {
-
- private final long revision;
- private final String author;
- private final String message;
- private final Map<String, String> logPath;
- private final Date date;
-
-
- public LogEntriesImpl(long revision, String author, Date date, String message, Map<String, String> logPath) {
- this.revision = revision;
- this.author = author;
- this.date = date;
- this.message = message;
- this.logPath = logPath;
- }
-
-
- public long getRevision() {
- return revision;
- }
-
-
- public String getAuthor() {
- return author;
- }
-
-
- public Date getDate() {
- return date;
- }
-
-
- public String getMessage() {
- return message;
- }
-
-
- public Map<String, String> getLogPath() {
- return logPath;
- }
-
-}
View
18 src/local/r1j0/bugspot/repository/Repository.java
@@ -1,18 +0,0 @@
-package local.r1j0.bugspot.repository;
-
-import java.util.List;
-
-public interface Repository {
-
- public static final char TYPE_ADDED = 'A';
- public static final char TYPE_DELETED = 'D';
- public static final char TYPE_MODIFIED = 'M';
- public static final char TYPE_REPLACED = 'R';
-
-
- List<LogEntries> checkout(long startRevision);
-
-
- List<LogEntries> checkout(long startRevision, long endRevision);
-
-}
View
96 src/local/r1j0/bugspot/repository/SvnRepository.java
@@ -1,96 +0,0 @@
-package local.r1j0.bugspot.repository;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.tmatesoft.svn.core.SVNException;
-import org.tmatesoft.svn.core.SVNLogEntry;
-import org.tmatesoft.svn.core.SVNLogEntryPath;
-import org.tmatesoft.svn.core.SVNURL;
-import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
-import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
-import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
-import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
-import org.tmatesoft.svn.core.io.SVNRepository;
-import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
-import org.tmatesoft.svn.core.wc.SVNWCUtil;
-
-public class SvnRepository implements Repository {
-
- private static final int HEAD_REVISION = -1;
-
- private final String url;
- private final String username;
- private final String password;
-
-
- public SvnRepository(String url, String username, String password) {
- this.url = url;
- this.username = username;
- this.password = password;
-
- setup();
- }
-
-
- public List<LogEntries> checkout(long startRevision) {
- return checkout(startRevision, HEAD_REVISION);
- }
-
-
- @SuppressWarnings("unchecked")
- public List<LogEntries> checkout(long startRevision, long endRevision) {
- SVNRepository repository = null;
-
- try {
- repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
- } catch (SVNException svne) {
- System.err.println("Error for repository with location: " + url + ". Message: " + svne.getMessage());
- System.exit(1);
- }
-
- ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password);
- repository.setAuthenticationManager(authManager);
-
- Collection<SVNLogEntry> svnLogEntries = null;
-
- try {
- svnLogEntries = repository.log(new String[] { "" }, null, startRevision, endRevision, true, true);
- } catch (SVNException svne) {
- System.out.println("Error retrieving log information for repository: " + url + ". Message: " + svne.getMessage());
- System.exit(1);
- }
-
- List<LogEntries> logEntries = new ArrayList<LogEntries>();
-
- for (Iterator<SVNLogEntry> entries = svnLogEntries.iterator(); entries.hasNext();) {
- SVNLogEntry logEntry = entries.next();
- Map<String, String> logPath = new HashMap<String, String>();
-
- if (logEntry.getChangedPaths().size() > 0) {
- Set<SVNLogEntryPath> changedPathsSet = logEntry.getChangedPaths().keySet();
-
- for (Iterator<SVNLogEntryPath> changedPaths = changedPathsSet.iterator(); changedPaths.hasNext();) {
- SVNLogEntryPath entryPath = (SVNLogEntryPath) logEntry.getChangedPaths().get(changedPaths.next());
- logPath.put(Character.toString(entryPath.getType()), entryPath.getPath());
- }
- }
-
- logEntries.add(new LogEntriesImpl(logEntry.getRevision(), logEntry.getAuthor(), logEntry.getDate(), logEntry.getMessage(), logPath));
- }
-
- return logEntries;
- }
-
-
- private void setup() {
- DAVRepositoryFactory.setup();
- SVNRepositoryFactoryImpl.setup();
- FSRepositoryFactory.setup();
- }
-}

0 comments on commit b1c5464

Please sign in to comment.