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

Provide actionable message when @QuarkusIntegrationTest is run before the Quarkus build #18081

Merged
merged 1 commit into from
Jun 22, 2021
Merged
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 @@ -232,8 +232,22 @@ static Properties readQuarkusArtifactProperties(ExtensionContext context) {
Path buildOutputDirectory = determineBuildOutputDirectory(context);
Path artifactProperties = buildOutputDirectory.resolve("quarkus-artifact.properties");
if (!Files.exists(artifactProperties)) {
throw new IllegalStateException(
"Unable to locate the artifact metadata file created that must be created by Quarkus in order to run integration tests.");
TestLauncher testLauncher = determineTestLauncher();
String errorMessage = "Unable to locate the artifact metadata file created that must be created by Quarkus in order to run integration tests. ";
if (testLauncher == TestLauncher.MAVEN) {
errorMessage += "Make sure this test is run after 'mvn package'. ";
if (context.getTestClass().isPresent()) {
String testClassName = context.getTestClass().get().getName();
if (testClassName.endsWith("Test")) {
errorMessage += "The easiest way to ensure this is by having the 'maven-failsafe-plugin' run the test instead of the 'maven-surefire-plugin'.";
}
}
} else if (testLauncher == TestLauncher.GRADLE) {
errorMessage += "Make sure this test is run after the 'quarkusBuild' Gradle task.";
} else {
errorMessage += "Make sure this test is run after the Quarkus artifact is built from your build tool.";
}
throw new IllegalStateException(errorMessage);
}
try {
Properties properties = new Properties();
Expand All @@ -246,6 +260,33 @@ static Properties readQuarkusArtifactProperties(ExtensionContext context) {
}
}

private static TestLauncher determineTestLauncher() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
geoand marked this conversation as resolved.
Show resolved Hide resolved
int i = stackTrace.length - 1;
TestLauncher testLauncher = TestLauncher.UNKNOWN;
while (true) {
StackTraceElement element = stackTrace[i--];
String className = element.getClassName();
if (className.startsWith("org.apache.maven")) {
testLauncher = TestLauncher.MAVEN;
break;
}
if (className.startsWith("org.gradle")) {
testLauncher = TestLauncher.GRADLE;
}
if (i == 0) {
break;
}
}
return testLauncher;
}

private enum TestLauncher {
MAVEN,
GRADLE,
UNKNOWN
}

static Path determineBuildOutputDirectory(ExtensionContext context) {
String buildOutputDirStr = System.getProperty("build.output.directory");
Path result = null;
Expand Down