Skip to content
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

[MINVOKER-336] Create empty .mvn directory in cloned projects #232

Merged
merged 1 commit into from
May 3, 2024
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
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