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

Take quarkus.package.output-directory into account when launching native tests #28165

Merged
merged 1 commit into from
Sep 26, 2022
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 @@ -34,6 +34,7 @@ public class DefaultNativeImageLauncher implements NativeImageLauncher {
private String testProfile;
private List<String> argLine;
private String nativeImagePath;
private String configuredOutputDirectory;
private Class<?> testClass;

private Process quarkusProcess;
Expand All @@ -48,6 +49,7 @@ public void init(NativeImageInitContext initContext) {
this.waitTimeSeconds = initContext.waitTime().getSeconds();
this.testProfile = initContext.testProfile();
this.nativeImagePath = initContext.nativeImagePath();
this.configuredOutputDirectory = initContext.getConfiguredOutputDirectory();
this.argLine = initContext.argLine();
this.testClass = initContext.testClass();
}
Expand Down Expand Up @@ -173,7 +175,7 @@ private void waitForStartedSupplier(Supplier<Boolean> startedSupplier, Process q
}
}

private static String guessPath(Class<?> testClass) {
private String guessPath(Class<?> testClass) {
//ok, lets make a guess
//this is a horrible hack, but it is intended to make this work in IDE's

Expand Down Expand Up @@ -203,41 +205,47 @@ private static String guessPath(Class<?> testClass) {
"Unable to automatically find native image, please set the native.image.path to the native executable you wish to test");
}

private static String guessPath(final URL url) {
private String guessPath(final URL url) {
if (url == null) {
return null;
}
String file = null;
if (url.getProtocol().equals("file") && url.getPath().endsWith("test-classes/")) {
//we have the maven test classes dir
File testClasses = new File(url.getPath());
for (File file : testClasses.getParentFile().listFiles()) {
if (isNativeExecutable(file)) {
logGuessedPath(file.getAbsolutePath());
return file.getAbsolutePath();
}
}
file = guessPathFromDir(testClasses.getParentFile());
} else if (url.getProtocol().equals("file") && url.getPath().endsWith("test/")) {
//we have the gradle test classes dir, build/classes/java/test
File testClasses = new File(url.getPath());
for (File file : testClasses.getParentFile().getParentFile().getParentFile().listFiles()) {
if (isNativeExecutable(file)) {
logGuessedPath(file.getAbsolutePath());
return file.getAbsolutePath();
}
}
file = guessPathFromDir(testClasses.getParentFile().getParentFile().getParentFile());
} else if (url.getProtocol().equals("file") && url.getPath().contains("/target/surefire/")) {
//this will make mvn failsafe:integration-test work
String path = url.getPath();
int index = path.lastIndexOf("/target/");
File targetDir = new File(path.substring(0, index) + "/target/");
for (File file : targetDir.listFiles()) {
if (isNativeExecutable(file)) {
logGuessedPath(file.getAbsolutePath());
return file.getAbsolutePath();
}
}
file = guessPathFromDir(targetDir);

}
return file;
}

private String guessPathFromDir(File dir) {
if (dir == null) {
return null;
}
if (configuredOutputDirectory != null) {
dir = dir.toPath().resolve(configuredOutputDirectory).toFile();
}
File[] files = dir.listFiles();
if (files == null) {
return null;
}
for (File file : files) {
if (isNativeExecutable(file)) {
logGuessedPath(file.getAbsolutePath());
return file.getAbsolutePath();
}
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ interface NativeImageInitContext extends InitContext {

String nativeImagePath();

String getConfiguredOutputDirectory();

Class<?> testClass();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public void close() {
}
},
System.getProperty("native.image.path"),
config.getOptionalValue("quarkus.package.output-directory", String.class).orElse(null),
requiredTestClass));
return launcher;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public NativeImageLauncher create(CreateContext context) {
ConfigUtil.argLineValue(config),
context.devServicesLaunchResult(),
System.getProperty("native.image.path"),
config.getOptionalValue("quarkus.package.output-directory", String.class).orElse(null),
context.testClass()));
return launcher;
} else {
Expand All @@ -57,12 +58,14 @@ public static class DefaultNativeImageInitContext extends DefaultInitContextBase

private final String nativeImagePath;
private final Class<?> testClass;
private final String configuredOutputDirectory;

public DefaultNativeImageInitContext(int httpPort, int httpsPort, Duration waitTime, String testProfile,
List<String> argLine, ArtifactLauncher.InitContext.DevServicesLaunchResult devServicesLaunchResult,
String nativeImagePath, Class<?> testClass) {
String nativeImagePath, String configuredOutputDirectory, Class<?> testClass) {
super(httpPort, httpsPort, waitTime, testProfile, argLine, devServicesLaunchResult);
this.nativeImagePath = nativeImagePath;
this.configuredOutputDirectory = configuredOutputDirectory;
this.testClass = testClass;
}

Expand All @@ -71,6 +74,11 @@ public String nativeImagePath() {
return nativeImagePath;
}

@Override
public String getConfiguredOutputDirectory() {
return configuredOutputDirectory;
}

@Override
public Class<?> testClass() {
return testClass;
Expand Down