Skip to content

Commit

Permalink
Finishing writing Javadocs for the br.ufpe.cin.groundhog.scmclient pa…
Browse files Browse the repository at this point in the history
…ckage. Related to #20.
  • Loading branch information
Rodrigo Alves Vieira committed May 4, 2013
1 parent 35729c5 commit c393f93
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import br.ufpe.cin.groundhog.GroundhogException;

/**
* Thrown when a checkout operation is attempted for a date that corresponds
* to phase when the project has zero commits.
* @author fjsj
*
*/
public class EmptyProjectAtDateException extends GroundhogException {
private static final long serialVersionUID = 1L;

public EmptyProjectAtDateException(String msg) {
super(msg);
}

}
40 changes: 31 additions & 9 deletions src/java/main/br/ufpe/cin/groundhog/scmclient/GitClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@

public class GitClient {

/**
* Performs a clone operation for the given project URL and places the fetched code
* into the destination directory.
* @param url the project's URL
* @param destination
* @throws InvalidRemoteException
* @throws TransportException
* @throws GitAPIException
*/
public void clone(String url, File destination)
throws InvalidRemoteException, TransportException, GitAPIException {
Repository rep = Git.cloneRepository().
Expand All @@ -37,8 +46,20 @@ public void clone(String url, File destination)
rep.close();
}

/**
* Performs a checkout to the given Git repository
* @param repositoryFolder the repository where the checkout will be performed
* @param date
* @throws IOException
* @throws RefAlreadyExistsException
* @throws RefNotFoundException
* @throws InvalidRefNameException
* @throws CheckoutConflictException
* @throws GitAPIException
* @throws EmptyProjectAtDateException
*/
public void checkout(File repositoryFolder, Date date)
throws IOException,RefAlreadyExistsException, RefNotFoundException,
throws IOException, RefAlreadyExistsException, RefNotFoundException,
InvalidRefNameException, CheckoutConflictException, GitAPIException,
EmptyProjectAtDateException {
Git git = Git.open(repositoryFolder);
Expand Down Expand Up @@ -69,13 +90,14 @@ public int compare(RevCommit c1, RevCommit c2) {
return c1.getCommitterIdent().getWhen().compareTo(c2.getCommitterIdent().getWhen());
}
});

// Workaround ahead, since JGit in Windows automatically
// adds ^M (Carriage Returns) to some files after, leaving the working tree dirty.
// JGit stash won't work and reset also not. So we need to commit!
// This commit doesn't affects metrics, since we do a checkout after it.
// To reproduce this bug, try to checkout https://github.com/playframework/ to 2012-05-01 12:00
// TODO: report this bug to JGit team.

/* Workaround ahead, since JGit in Windows automatically adds ^M (Carriage Returns) to some files after,
* leaving the working tree dirty.
* Neither JGit stash nor reset will work. So we need to commit!
* This commit doesn't affects metrics, since we do a checkout after it.
* To reproduce this bug, try to checkout https://github.com/playframework/ to 2012-05-01 12:00
* TODO: report this bug to JGit team.
*/
Set<String> mods = git.status().call().getModified();
if (!mods.isEmpty()) {
AddCommand addCmd = git.add();
Expand All @@ -85,7 +107,7 @@ public int compare(RevCommit c1, RevCommit c2) {
addCmd.call();
git.commit().setMessage("Groundhog commit").call();
}
// workaround end.
/* workaround end.*/

git.checkout().setName("groundhog-analyze").setStartPoint(closest).setCreateBranch(true).call();
rep.close();
Expand Down
14 changes: 14 additions & 0 deletions src/java/main/br/ufpe/cin/groundhog/scmclient/SVNClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public SVNClient() {
this.svn = SVNClientManager.newInstance();
}

/**
* Performs a checkout for a project with the given URL on the given destination directory
* @param url the project URL
* @param destination the destination directory
* @throws SVNException
*/
public void checkout(String url, File destination) throws SVNException {
SVNUpdateClient client = svn.getUpdateClient();
client.doCheckout(SVNURL.parseURIDecoded(url),
Expand All @@ -26,6 +32,14 @@ public void checkout(String url, File destination) throws SVNException {
false);
}

/**
* Performs a checkout for a project with the given URL on the given destination directory with a
* specified SVN revision
* @param url the project URL
* @param destination the destination directory
* @param revision the SVN revision
* @throws SVNException
*/
public void checkout(String url, File destination, SVNRevision revision) throws SVNException {
SVNUpdateClient client = svn.getUpdateClient();
client.doCheckout(SVNURL.parseURIDecoded(url),
Expand Down

0 comments on commit c393f93

Please sign in to comment.