Skip to content

Check out what I did! #3

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

Merged
3 commits merged into from
Feb 21, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/main/java/pl/project13/maven/git/GitCommitIdMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public class GitCommitIdMojo extends AbstractMojo {
* The root directory of the repository we want to check
*
* @parameter
* @required
*/
private File dotGitDirectory;

Expand All @@ -101,6 +100,8 @@ public class GitCommitIdMojo extends AbstractMojo {
public final String logPrefix = "[GitCommitIdMojo] ";

public void execute() throws MojoExecutionException {
dotGitDirectory = lookupGitDirectory();

getLog().info(logPrefix + "Running on '" + dotGitDirectory.getAbsolutePath() + "' repository...");

try {
Expand All @@ -117,7 +118,30 @@ public void execute() throws MojoExecutionException {
getLog().info(logPrefix + "Finished running.");
}

private void initProperties() throws MojoExecutionException {
private File lookupGitDirectory()
{
if (dotGitDirectory != null && dotGitDirectory.exists())
{
return dotGitDirectory;
}

if(project == null)
{
dotGitDirectory = new File(".git");
if(dotGitDirectory.exists() && !dotGitDirectory.isFile()) { return dotGitDirectory; }
}

dotGitDirectory = new File(project.getBasedir().getAbsolutePath() + "/.git");

if(dotGitDirectory.exists() && !dotGitDirectory.isFile()) { return dotGitDirectory; }

dotGitDirectory = new File(project.getParent().getBasedir().getAbsolutePath() + "/.git");

if(dotGitDirectory.exists() && !dotGitDirectory.isFile()) { return dotGitDirectory; }
return dotGitDirectory;
}

private void initProperties() throws MojoExecutionException {
getLog().info(logPrefix + "initializing properties...");
if (project != null) {
getLog().info(logPrefix + "Using maven project properties...");
Expand Down Expand Up @@ -202,10 +226,6 @@ private Repository getGitRepository() throws MojoExecutionException {
Repository repository = null;

FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder();
if (dotGitDirectory == null) {
dotGitDirectory = project.getBasedir();
}

try {
repository = repositoryBuilder
.setGitDir(dotGitDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class GitCommitIdMojoTest extends PlexusTestCase {

public void setUp() throws Exception {
mojo = new GitCommitIdMojo();
mojo.setDotGitDirectory(new File("/home/ktoso/coding/maven-plugins/git-commit-id-plugin/.git/"));
mojo.setDotGitDirectory(new File(".git/"));
mojo.setPrefix("git");
mojo.setDateFormat("dd.MM.yyyy '@' HH:mm:ss z");
mojo.setVerbose(true);
Expand Down