-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
feb0daa
commit 1d7e972
Showing
4 changed files
with
59 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
*/ | ||
package com.mycila.maven.plugin.license.git; | ||
|
||
import java.io.Closeable; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
|
@@ -44,7 +45,7 @@ | |
* | ||
* @author <a href="mailto:[email protected]">Peter Palaga</a> | ||
*/ | ||
public class GitLookup { | ||
public class GitLookup implements Closeable { | ||
public static final TimeZone DEFAULT_ZONE = TimeZone.getTimeZone("GMT"); | ||
|
||
public enum DateSource { | ||
|
@@ -71,10 +72,13 @@ public enum DateSource { | |
* @throws IOException | ||
*/ | ||
public GitLookup(File anyFile, DateSource dateSource, TimeZone timeZone, int checkCommitsCount) throws IOException { | ||
super(); | ||
this.repository = new FileRepositoryBuilder().findGitDir(anyFile).build(); | ||
/* A workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=457961 */ | ||
// Also contains contents of .git/shallow and can detect shallow repo | ||
// the line below reads and caches the entries in the FileObjectDatabase of the repository to | ||
// avoid concurrent modifications during RevWalk | ||
// Closing the repository will close the FileObjectDatabase. | ||
// Here the newReader() is a WindowCursor which delegates the getShallowCommits() to the FileObjectDatabase. | ||
this.shallow = !this.repository.getObjectDatabase().newReader().getShallowCommits().isEmpty(); | ||
|
||
this.pathResolver = new GitPathResolver(repository.getWorkTree().getAbsolutePath()); | ||
|
@@ -148,12 +152,12 @@ int getYearOfCreation(File file) throws IOException, GitAPIException { | |
commitYear = getYearFromCommit(commit); | ||
} | ||
walk.dispose(); | ||
|
||
// If we couldn't find a creation year from Git assume newly created file | ||
if (commitYear == 0) { | ||
return getCurrentYear(); | ||
} | ||
return getCurrentYear(); | ||
} | ||
|
||
return commitYear; | ||
} | ||
|
||
|
@@ -182,7 +186,7 @@ String getAuthorEmailOfCreation(File file) throws IOException { | |
walk.dispose(); | ||
return authorEmail; | ||
} | ||
|
||
boolean isShallowRepository() { | ||
return this.shallow; | ||
} | ||
|
@@ -245,4 +249,9 @@ private String getAuthorEmailFromCommit(RevCommit commit) { | |
PersonIdent id = commit.getAuthorIdent(); | ||
return id.getEmailAddress(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
repository.close(); | ||
} | ||
} |
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