-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging branch ft-new-git-module, which is not finished but the existing
work can be merged and be used to solve some questions. Related to #60. * ft-new-git-module: Adding some documentation Refactoring method for counting commits that include a given file extension filtering commits that have altered java code. r #60 searching commits with gitective Adding Gitective [1] as a dependency and creating the class that will be responsible for the local Git repository analysis within Groundhog.
- Loading branch information
Showing
6 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/java/main/br/ufpe/cin/groundhog/extractor/GitCommitExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package br.ufpe.cin.groundhog.extractor; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.jgit.lib.PersonIdent; | ||
import org.eclipse.jgit.lib.Repository; | ||
import org.eclipse.jgit.revwalk.RevCommit; | ||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; | ||
import org.gitective.core.CommitFinder; | ||
import org.gitective.core.PathFilterUtils; | ||
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; | ||
|
||
import br.ufpe.cin.groundhog.Commit; | ||
import br.ufpe.cin.groundhog.User; | ||
|
||
/** | ||
* Extract Commit data from Git repositories | ||
* @author Rodrigo Alves | ||
* | ||
*/ | ||
public class GitCommitExtractor { | ||
|
||
public List<Commit> extractCommits(File project) { | ||
CommitListFilter list = new CommitListFilter(); | ||
|
||
String path = project.getAbsolutePath() + "/.git"; | ||
CommitFinder finder = new CommitFinder(path); | ||
|
||
finder.setFilter(list).find(); | ||
|
||
for (RevCommit rev : list.getCommits()){ | ||
System.out.println(rev.getName() + " " + rev.getAuthorIdent().getName() + " " + rev.getShortMessage()); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* A method that returns the number of commits that contain files with a given file extension | ||
* Example usage: | ||
* | ||
* File project = new File("/tmp/project"); | ||
* numberOfCommitsWithExtension(project, ".java") // Returns the number of commits in project that includes Java files | ||
* | ||
* @param project A {@link file} object for the directory where the Git repository is located | ||
* @param extension The extension to be searched within the commits | ||
* @return the number of commits that includes files with the given extension | ||
*/ | ||
public int numberOfCommitsWithExtension(File project, String extension) { | ||
CommitCountFilter commits = new CommitCountFilter(); | ||
String path = project.getAbsolutePath() + "/.git"; | ||
|
||
CommitFinder finder = new CommitFinder(path); | ||
finder.setFilter(PathFilterUtils.andSuffix("." + extension)); | ||
finder.setMatcher(commits); | ||
finder.find(); | ||
|
||
return (int) commits.getCount(); | ||
} | ||
|
||
/** | ||
* 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters