-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Javadoc2 #72
Javadoc2 #72
Changes from all commits
644d577
edac36f
952f33b
504a98f
4872375
9f7d41c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
package org.repodriller; | ||
|
||
/** | ||
* Catch-all type for internal exceptions thrown by RepoDriller. | ||
* | ||
* @author Mauricio Aniche | ||
*/ | ||
public class RepoDrillerException extends RuntimeException{ | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public RepoDrillerException(String msg) { | ||
super(msg); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package org.repodriller; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.repodriller.domain.Commit; | ||
import org.repodriller.persistence.PersistenceMechanism; | ||
import org.repodriller.persistence.csv.CSVFileFormatException; | ||
import org.repodriller.scm.CommitVisitor; | ||
import org.repodriller.scm.SCMRepository; | ||
|
||
/** | ||
* A RepoVisitor offers Repo-level visiting to a group of CommitVisitors. | ||
* The metaphor is of a "tour bus" for CommitVisitors. | ||
* The RepoVisitor drives each CommitVisitor to the Commits for each SCMRepository. | ||
* | ||
* Intended use: | ||
* - {@link RepoVisitor#addVisitor} all of the CommitVisitor/PersistenceMechanism pairs you want. | ||
* - {@link RepoVisitor#beginRepoTour} to start a new repo | ||
* - {@link RepoVisitor#visit} for each Commit you're visiting in the current repo | ||
* - {#link CommitVisitorIterator#endRepoTour} after you're done with this repo | ||
* | ||
* @author Mauricio Aniche | ||
* | ||
*/ | ||
public class RepoVisitor { | ||
|
||
private Map<CommitVisitor, PersistenceMechanism> visitors; | ||
private static final Logger log = Logger.getLogger(RepoVisitor.class); | ||
private SCMRepository currentRepo; // One at a time. | ||
|
||
public RepoVisitor() { | ||
visitors = new HashMap<CommitVisitor, PersistenceMechanism>(); | ||
currentRepo = null; | ||
} | ||
|
||
/*** | ||
* Methods for managing CommitVisitors. | ||
***/ | ||
|
||
/** | ||
* Add this <CommitVisitor, PersistenceMechanism> pair to my collection. | ||
* | ||
* @param visitor | ||
* @param writer | ||
*/ | ||
public void addVisitor(CommitVisitor visitor, PersistenceMechanism writer) { | ||
visitors.put(visitor, writer); | ||
} | ||
|
||
/** | ||
* Remove this CommitVisitors from my collection, if present. | ||
* | ||
* @param visitor | ||
*/ | ||
public void removeVisitor(CommitVisitor visitor) { | ||
visitors.remove(visitor); | ||
} | ||
|
||
/** | ||
* Empty my collection of CommitVisitors. | ||
*/ | ||
public void clearVisitors() { | ||
visitors.clear(); | ||
} | ||
|
||
/** | ||
* Print a description of all of the CommitVisitors I maintain. | ||
*/ | ||
void printVisitors() { | ||
for(CommitVisitor visitor : visitors.keySet()) { | ||
log.info("- " + visitor.name() + " (" + visitor.getClass().getName() + ")"); | ||
} | ||
} | ||
|
||
/** | ||
* @return True if no CommitVisitors, else false. | ||
*/ | ||
public boolean isEmpty() { | ||
return visitors.isEmpty(); | ||
} | ||
|
||
/*** | ||
* Methods for visiting an SCMRepository. | ||
***/ | ||
|
||
/** | ||
* Prepare for the next repo we visit. | ||
* Calls {@link CommitVisitor#initialize} on each CommitVisitor in my collection. | ||
* | ||
* @param repo The repo we are visiting next | ||
*/ | ||
void beginRepoVisit(SCMRepository repo) { | ||
if (currentRepo != null) | ||
throw new RepoDrillerException("Error, one repo at a time. We are already visiting a repo."); | ||
currentRepo = repo; | ||
|
||
for(Map.Entry<CommitVisitor, PersistenceMechanism> entry : visitors.entrySet()) { | ||
CommitVisitor visitor = entry.getKey(); | ||
PersistenceMechanism writer = entry.getValue(); | ||
|
||
try { | ||
log.info("-> Initializing visitor " + visitor.name()); | ||
visitor.initialize(currentRepo, writer); | ||
} catch (Exception e) { | ||
log.error("error in " + currentRepo.getPath() + | ||
"when initializing " + visitor.name() + ", error=" + e.getMessage(), e); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Visit this commit in the current repo. | ||
* Calls {@link CommitVisitor#process} on each CommitVisitor in my collection. | ||
* | ||
* @param commit | ||
*/ | ||
void visitCommit(Commit commit) { | ||
for(Map.Entry<CommitVisitor, PersistenceMechanism> entry : visitors.entrySet()) { | ||
CommitVisitor visitor = entry.getKey(); | ||
PersistenceMechanism writer = entry.getValue(); | ||
|
||
try { | ||
log.info("-> Processing " + commit.getHash() + " with " + visitor.name()); | ||
visitor.process(currentRepo, commit, writer); | ||
} catch (CSVFileFormatException e) { | ||
log.fatal(e); | ||
System.exit(-1); | ||
} catch (Exception e) { | ||
log.error("error processing #" + commit.getHash() + " in " + currentRepo.getPath() + | ||
", processor=" + visitor.name() + ", error=" + e.getMessage(), e); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Conclude the visit to the current repo. | ||
* Calls {@link CommitVisitor#finalize} on each CommitVisitor in my collection. | ||
*/ | ||
void endRepoVisit() { | ||
for(Map.Entry<CommitVisitor, PersistenceMechanism> entry : visitors.entrySet()) { | ||
CommitVisitor visitor = entry.getKey(); | ||
PersistenceMechanism writer = entry.getValue(); | ||
|
||
try { | ||
log.info("-> Finalizing visitor " + visitor.name()); | ||
visitor.finalize(currentRepo, writer); | ||
} catch (Exception e) { | ||
log.error("error in " + currentRepo.getPath() + | ||
"when finalizing " + visitor.name() + ", error=" + e.getMessage(), e); | ||
} | ||
} | ||
|
||
currentRepo = null; | ||
} | ||
|
||
/** | ||
* Close all of the PersistenceMechanism's associated with visitors. | ||
*/ | ||
void closeAllPersistence() { | ||
/* TODO: This API doesn't make sense to me. Why are the persistence mechanisms closed by this class? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where would you close them? Would you leave for the client to close them? The problem is that, then, the user can't write a beautiful fluent instantiation of the repo:
The user would have to store In addition, I'd not expect the program to do anything else after repodriller is done. So, I guess I implemented it as a 'courtesy' to the user. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that the inline PersistenceMechanism instantiation is lovely, and that if code is written in the functional style then RepositoryMining must close up the PersistenceMechanism's it's been given. On the other hand, there's a mismatch between where the PM is created (client level) and where it is closed (framework level), which is surprising. How about we overload There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's open an issue to discuss about that (#77), so that I can move on with this PR |
||
* I think it should be removed. */ | ||
for(PersistenceMechanism persist : visitors.values()) { | ||
persist.close(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why this exception is here... This deserves an issue: #74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should define what the behavior is if a CommitVisitor throws an exception.
Options:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the behavior is already correct there. If an exception happens, repodriller logs it, and moves forward. It could maybe notify the study or the visitors about the error.
But this particular CSVFileFormat, not sure what it does there. I think it halts the problem as soon as it notices that the output is not being saved. It makes sense to completely stop the execution. But we should make it more general, so that this behaviour is the same through all the persistence mechanisms! This should be in #74