Skip to content

Commit

Permalink
Adding Gitective [1] as a dependency and creating the class that will be
Browse files Browse the repository at this point in the history
responsible for the local Git repository analysis within Groundhog.

Starting with non-parameterized commit extraction and extraction of commits from a given user.

Nothing finished just yet. Code in main package only present for current
debugging and testing purposes, once the commit message extraction is
done it will be moved to the groundhog-case-study [2] project.

[1]: https://github.com/kevinsawicki/gitective
[2]: github.com/gustavopinto/groundhog-case-study

Related to #55 and #60
  • Loading branch information
Rodrigo Alves committed Sep 5, 2013
1 parent 6177b1d commit ea3e82d
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependency>
<dependency>
<groupId>org.gitective</groupId>
<artifactId>gitective-core</artifactId>
<version>0.9.9</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -270,4 +275,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
1 change: 1 addition & 0 deletions src/java/main/br/ufpe/cin/groundhog/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public Project(String name, String description) {
public Project(User user, String name) {
this.user = user;
this.name = name;
this.scmURL = "https://github.com/" + user.getLogin() + "/" + name + ".git";
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/java/main/br/ufpe/cin/groundhog/crawler/CrawlGitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* @author fjsj, gustavopinto
*/
public class CrawlGitHub extends ForgeCrawler {

private final static Logger logger = LoggerFactory.getLogger(CrawlGitHub.class);

private final GitClient gitClient;
Expand All @@ -35,7 +34,6 @@ public File downloadProject(Project project) throws DownloadException {
File projectDestinationFolder = new File(destinationFolder, projectName);

logger.info(String.format("Downloading %s project..", project.getName()));


try {
this.gitClient.clone(projectUrl, projectDestinationFolder);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package br.ufpe.cin.groundhog.extractor;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import br.ufpe.cin.groundhog.Commit;
import br.ufpe.cin.groundhog.User;

import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.gitective.core.CommitFinder;
import org.gitective.core.filter.commit.AndCommitFilter;
import org.gitective.core.filter.commit.AuthorFilter;
import org.gitective.core.filter.commit.CommitCountFilter;
import org.gitective.core.filter.commit.CommitListFilter;

/**
* Extract Commit data from Git repositories
* @author Rodrigo Alves
*
*/
public class GitCommitExtractor {
private CommitCountFilter commits;

public GitCommitExtractor() {
this.commits = new CommitCountFilter();
}

/**
*
* @param project
* @return
* @throws IOException
*/
public List<Commit> extractCommits(File project) throws IOException {
List<Commit> commits = new ArrayList<>();
String path = project.getAbsolutePath();

CommitFinder finder = new CommitFinder(path);
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(path)).readEnvironment()
.findGitDir()
.build();

CommitListFilter list = new CommitListFilter();

for (RevCommit rev : list.getCommits()){
System.out.println(rev.getName());
System.out.println(rev.getAuthorIdent().getName());
System.out.println(rev.getShortMessage());
}

return commits;
}

/**
* Extracts only the commits from a given {@link User}
* TODO: implement this method
* @return a {@link List} of {@link Commit} objects
* @throws IOException
*/
public List<Commit> extractCommitFromUser(User user, File project) throws IOException {
List<Commit> commits = new ArrayList<>();

String path = project.getAbsolutePath();

CommitFinder finder = new CommitFinder(path);
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(path)).readEnvironment()
.findGitDir()
.build();

CommitListFilter list = new CommitListFilter();
AndCommitFilter filters = new AndCommitFilter();
PersonIdent author = new PersonIdent(user.getName(), user.getEmail());

filters.add(new AuthorFilter(author));
return commits;
}
}
20 changes: 20 additions & 0 deletions src/java/main/br/ufpe/cin/groundhog/main/TestMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

import br.ufpe.cin.groundhog.Project;
import br.ufpe.cin.groundhog.SCM;
import br.ufpe.cin.groundhog.User;
import br.ufpe.cin.groundhog.codehistory.CodeHistoryModule;
import br.ufpe.cin.groundhog.codehistory.GitCodeHistory;
import br.ufpe.cin.groundhog.codehistory.SFCodeHistory;
import br.ufpe.cin.groundhog.crawler.CrawlGitHub;
import br.ufpe.cin.groundhog.crawler.CrawlGoogleCode;
import br.ufpe.cin.groundhog.crawler.CrawlSourceForge;
import br.ufpe.cin.groundhog.crawler.ForgeCrawler;
import br.ufpe.cin.groundhog.extractor.GitCommitExtractor;
import br.ufpe.cin.groundhog.http.HttpModule;
import br.ufpe.cin.groundhog.http.Requests;
import br.ufpe.cin.groundhog.parser.java.JavaParser;
Expand Down Expand Up @@ -184,6 +186,24 @@ public static void googleCodeExample(String term) throws Exception {
public static void main(String[] args) throws Exception {
// gitHubExample("restfulie-java");

GitClient gitClient = new GitClient();
File folder = new File("/Users/rodrigovieira/Desktop");

CrawlGitHub crawler = new CrawlGitHub(gitClient, folder);
User u = new User("gustavopinto");

Project pr = new Project(u, "groundhog-case-study");

System.out.println("url e: " + pr.getScmURL());

crawler.downloadProject(pr);

File project = new File("/Users/rodrigovieira/Desktop/groundhog-case-study");

GitCommitExtractor extractor = new GitCommitExtractor();
extractor.extractCommits(project);

System.out.println("Pronto!");
// sourceForgeExample();
// googleCodeExample("facebook-java-api"); // Google Code SVN
// googleCodeExample("guava-libraries"); // Google Code Git
Expand Down

0 comments on commit ea3e82d

Please sign in to comment.