Skip to content

Commit

Permalink
Merge pull request #20503 from TomasHofman/cli-look-for-wrapper-in-pa…
Browse files Browse the repository at this point in the history
…rent-dirs

CLI: look for maven/gradle wrapper in parent dirs
  • Loading branch information
ebullient authored Oct 5, 2021
2 parents ece3e3f + 79eb372 commit a4e2280
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ default BuildCommandArgs prependExecutable(ArrayDeque<String> args) {
File wrapper = getWrapper();
if (wrapper != null) {
args.addFirst(wrapper.getAbsolutePath());
cmd.targetDirectory = wrapper.getParentFile();
} else {
File command = getExecutable();
args.addFirst(command.getAbsolutePath());
cmd.targetDirectory = getProjectRoot().toFile();
}
cmd.targetDirectory = getProjectRoot().toFile();
cmd.arguments = args.toArray(new String[0]);
return cmd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ public static File findWrapper(Path projectRoot, String[] windows, String other)
return wrapper;
}

return null;
// look for a wrapper in a parent directory
Path normalizedPath = projectRoot.normalize();
if (!normalizedPath.equals(projectRoot.getRoot())) {
return findWrapper(normalizedPath.getParent(), windows, other);
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.quarkus.cli.build;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class ExecuteUtilTest {

private final static String MVNW = "mvnw.junittest";
private final static String[] WINDOWS_WRAPPER = new String[] { MVNW };

@TempDir
Path tempDir;

@Test
public void findWrapperRecursionTest() throws IOException {
File wrapper = ExecuteUtil.findWrapper(tempDir, WINDOWS_WRAPPER, MVNW);
assertThat(wrapper).isNull();

wrapper = ExecuteUtil.findWrapper(tempDir.resolve("subproject/nestedSubproject"), WINDOWS_WRAPPER, MVNW);
assertThat(wrapper).isNull();

// create a file representing the maven wrapper
Path wrapperLocation = tempDir.resolve(MVNW);
assertThat(wrapperLocation.toFile().createNewFile()).isTrue();

wrapper = ExecuteUtil.findWrapper(tempDir, WINDOWS_WRAPPER, MVNW);
assertThat(wrapper).isNotNull();
assertThat(wrapper).isEqualTo(wrapperLocation.toFile());

wrapper = ExecuteUtil.findWrapper(tempDir.resolve("subproject/nestedSubproject"), WINDOWS_WRAPPER, MVNW);
assertThat(wrapper).isNotNull();
assertThat(wrapper).isEqualTo(wrapperLocation.toFile());

wrapper = ExecuteUtil.findWrapper(tempDir.resolve(".."), WINDOWS_WRAPPER, MVNW);
assertThat(wrapper).isNull();
}
}

0 comments on commit a4e2280

Please sign in to comment.