Skip to content

Commit 66a536f

Browse files
[MINVOKER-336] Create empty .mvn directory in cloned projects
1 parent 1bcf216 commit 66a536f

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

src/it/clone-clean/verify.bsh renamed to src/it/clone-clean/setup.groovy

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,9 @@
1717
* under the License.
1818
*/
1919

20-
import java.io.*;
20+
File itRoot = new File(basedir, "target/it/clone-clean")
21+
itRoot.mkdirs()
22+
assert new File(itRoot, "foobar.log").createNewFile()
23+
24+
assert !new File(basedir, 'src/it/clone-clean/.mvn').exists()
2125

22-
try
23-
{
24-
File itRoot = new File( basedir, "target/it/clone-clean" );
25-
return !new File( itRoot, "foobar.log" ).exists();
26-
}
27-
catch( Throwable t )
28-
{
29-
t.printStackTrace();
30-
return false;
31-
}

src/it/clone-clean/setup.bsh renamed to src/it/clone-clean/verify.groovy

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,8 @@
1717
* under the License.
1818
*/
1919

20-
import java.io.*;
2120

22-
try
23-
{
24-
File itRoot = new File( basedir, "target/it/clone-clean" );
25-
itRoot.mkdirs();
26-
return new File(itRoot, "foobar.log").createNewFile();
27-
}
28-
catch( Throwable t )
29-
{
30-
t.printStackTrace();
31-
return false;
32-
}
21+
File itRoot = new File(basedir, "target/it/clone-clean")
22+
assert !new File(itRoot, "foobar.log").exists()
23+
// .mnv will be created
24+
assert new File(itRoot, ".mvn").isDirectory()

src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
820820

821821
if (cloneProjectsTo != null) {
822822
cloneProjects(collectedProjects);
823+
addMissingDotMvnDirectory(cloneProjectsTo, buildJobs);
823824
projectsDir = cloneProjectsTo;
824825
} else {
825826
getLog().warn("Filtering of parent/child POMs is not supported without cloning the projects");
@@ -856,6 +857,31 @@ public void execute() throws MojoExecutionException, MojoFailureException {
856857
processResults(new InvokerSession(buildJobs));
857858
}
858859

860+
/**
861+
* We need add missing {@code .mnvn} directories for executing projects
862+
*
863+
* @param projectsDir base of projects
864+
* @param buildJobs list of discovered jobs
865+
*/
866+
private void addMissingDotMvnDirectory(File projectsDir, List<BuildJob> buildJobs) throws MojoExecutionException {
867+
for (BuildJob buildJob : buildJobs) {
868+
Path projectPath = projectsDir.toPath().resolve(buildJob.getProject());
869+
870+
if (Files.isRegularFile(projectPath)) {
871+
projectPath = projectPath.getParent();
872+
}
873+
874+
Path mvnDotPath = projectPath.resolve(".mvn");
875+
if (!Files.exists(mvnDotPath)) {
876+
try {
877+
Files.createDirectories(mvnDotPath);
878+
} catch (IOException e) {
879+
throw new MojoExecutionException(e.getMessage(), e);
880+
}
881+
}
882+
}
883+
}
884+
859885
private void setupActualMavenVersion() throws MojoExecutionException {
860886
if (mavenHome != null) {
861887
try {

0 commit comments

Comments
 (0)