Skip to content

Commit

Permalink
[MINVOKER-336] Create empty .mvn directory in cloned projects
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed May 3, 2024
1 parent 1bcf216 commit 66a536f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
16 changes: 5 additions & 11 deletions src/it/clone-clean/verify.bsh → src/it/clone-clean/setup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@
* under the License.
*/

import java.io.*;
File itRoot = new File(basedir, "target/it/clone-clean")
itRoot.mkdirs()
assert new File(itRoot, "foobar.log").createNewFile()

assert !new File(basedir, 'src/it/clone-clean/.mvn').exists()

try
{
File itRoot = new File( basedir, "target/it/clone-clean" );
return !new File( itRoot, "foobar.log" ).exists();
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}
16 changes: 4 additions & 12 deletions src/it/clone-clean/setup.bsh → src/it/clone-clean/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,8 @@
* under the License.
*/

import java.io.*;

try
{
File itRoot = new File( basedir, "target/it/clone-clean" );
itRoot.mkdirs();
return new File(itRoot, "foobar.log").createNewFile();
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}
File itRoot = new File(basedir, "target/it/clone-clean")
assert !new File(itRoot, "foobar.log").exists()
// .mnv will be created
assert new File(itRoot, ".mvn").isDirectory()
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {

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

/**
* We need add missing {@code .mnvn} directories for executing projects
*
* @param projectsDir base of projects
* @param buildJobs list of discovered jobs
*/
private void addMissingDotMvnDirectory(File projectsDir, List<BuildJob> buildJobs) throws MojoExecutionException {
for (BuildJob buildJob : buildJobs) {
Path projectPath = projectsDir.toPath().resolve(buildJob.getProject());

if (Files.isRegularFile(projectPath)) {
projectPath = projectPath.getParent();
}

Path mvnDotPath = projectPath.resolve(".mvn");
if (!Files.exists(mvnDotPath)) {
try {
Files.createDirectories(mvnDotPath);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
}
}

private void setupActualMavenVersion() throws MojoExecutionException {
if (mavenHome != null) {
try {
Expand Down

0 comments on commit 66a536f

Please sign in to comment.