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

CLI: look for maven/gradle wrapper in parent dirs #20503

Merged
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
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();
}
}