Skip to content

Commit 64d51ee

Browse files
author
TheSnoozer
committed
remove the MavenProject dependency from the GitDirLocator as it is not needed
1 parent 41da9b3 commit 64d51ee

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

src/main/java/pl/project13/maven/git/GitCommitIdMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ private void appendPropertiesToReactorProjects(LogInterface log, Properties prop
15101510
* @return the File representation of the .git directory
15111511
*/
15121512
private File lookupGitDirectory() throws GitCommitIdExecutionException {
1513-
return new GitDirLocator(project).lookupGitDirectory(dotGitDirectory);
1513+
return new GitDirLocator(project.getBasedir()).lookupGitDirectory(dotGitDirectory);
15141514
}
15151515

15161516
private void logProperties(LogInterface log, Properties propertiesToPublish) {

src/main/java/pl/project13/maven/git/GitDirLocator.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,25 @@
2323
import java.io.FileReader;
2424
import java.io.IOException;
2525
import java.nio.file.Path;
26-
import java.util.List;
2726
import javax.annotation.Nonnull;
2827
import javax.annotation.Nullable;
29-
import org.apache.maven.project.MavenProject;
3028
import org.eclipse.jgit.lib.Constants;
3129

3230
/**
3331
* This class encapsulates logic to locate a valid .git directory of the currently used project. If
3432
* it's not already specified, this logic will try to find it.
3533
*/
3634
public class GitDirLocator {
37-
final MavenProject mavenProject;
35+
final File projectBasedir;
3836

3937
/**
4038
* Constructor to encapsulates all references required to locate a valid .git directory
4139
*
42-
* @param mavenProject The currently used (maven) project.
40+
* @param projectBasedir The project basedir that will be used as last resort to search
41+
* the parent project hierarchy until a .git directory is found.
4342
*/
44-
public GitDirLocator(MavenProject mavenProject) {
45-
this.mavenProject = mavenProject;
43+
public GitDirLocator(File projectBasedir) {
44+
this.projectBasedir = projectBasedir;
4645
}
4746

4847
/**
@@ -82,17 +81,13 @@ public File lookupGitDirectory(@Nonnull File manuallyConfiguredDir) {
8281
}
8382

8483
/**
85-
* Search up all the maven parent project hierarchy until a .git directory is found.
84+
* Search up all the parent project hierarchy until a .git directory is found.
8685
*
8786
* @return File which represents the location of the .git directory or NULL if none found.
8887
*/
8988
@Nullable
9089
private File findProjectGitDirectory() {
91-
if (this.mavenProject == null) {
92-
return null;
93-
}
94-
95-
File basedir = mavenProject.getBasedir();
90+
File basedir = this.projectBasedir;
9691
while (basedir != null) {
9792
File gitdir = new File(basedir, Constants.DOT_GIT);
9893
if (gitdir.exists()) {

src/test/java/pl/project13/maven/git/GitDirLocatorTest.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,14 @@
2222

2323
import java.io.File;
2424
import java.nio.file.Files;
25-
import java.util.Collections;
26-
import java.util.List;
27-
import org.apache.maven.project.MavenProject;
2825
import org.junit.Rule;
2926
import org.junit.Test;
3027
import org.junit.rules.TemporaryFolder;
3128
import org.junit.runner.RunWith;
32-
import org.mockito.Mock;
3329
import org.mockito.junit.MockitoJUnitRunner;
3430

3531
@RunWith(MockitoJUnitRunner.class)
3632
public class GitDirLocatorTest {
37-
38-
@Mock MavenProject project;
39-
4033
@Rule
4134
public TemporaryFolder folder = new TemporaryFolder();
4235

@@ -46,7 +39,7 @@ public void shouldUseTheManuallySpecifiedDirectory() throws Exception {
4639
File dotGitDir = folder.newFolder("temp");
4740
try {
4841
// when
49-
GitDirLocator locator = new GitDirLocator(project);
42+
GitDirLocator locator = new GitDirLocator(dotGitDir);
5043
File foundDirectory = locator.lookupGitDirectory(dotGitDir);
5144

5245
// then
@@ -79,7 +72,7 @@ public void shouldResolveRelativeSubmodule() throws Exception {
7972

8073
try {
8174
// when
82-
GitDirLocator locator = new GitDirLocator(project);
75+
GitDirLocator locator = new GitDirLocator(dotGitDir);
8376
File foundDirectory = locator.lookupGitDirectory(dotGitDir);
8477

8578
// then

0 commit comments

Comments
 (0)