From 8ae3e04244955fb4d65bc6c9ff33aae164f24378 Mon Sep 17 00:00:00 2001 From: Guillaume Le Floch Date: Wed, 12 Jan 2022 21:55:53 +0100 Subject: [PATCH 1/2] Test that jandex plugin is ran on quarkusBuild task --- .../quarkus/gradle/JandexMultiModuleTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 integration-tests/gradle/src/test/java/io/quarkus/gradle/JandexMultiModuleTest.java diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/JandexMultiModuleTest.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/JandexMultiModuleTest.java new file mode 100644 index 0000000000000..f27fe605878b6 --- /dev/null +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/JandexMultiModuleTest.java @@ -0,0 +1,21 @@ +package io.quarkus.gradle; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; + +import org.junit.jupiter.api.Test; + +public class JandexMultiModuleTest extends QuarkusGradleWrapperTestBase { + + @Test + public void testBasicMultiModuleBuild() throws Exception { + + final File projectDir = getProjectDir("jandex-basic-multi-module-project"); + + BuildResult build = runGradleWrapper(projectDir, "clean", ":application:quarkusBuild"); + assertThat(build.getTasks().get(":common:jandex")).isEqualTo(BuildResult.SUCCESS_OUTCOME); + assertThat(build.getTasks().get(":application:quarkusBuild")).isEqualTo(BuildResult.SUCCESS_OUTCOME); + } + +} From c9111018792faa9a919f7bad83e899186e2dec6e Mon Sep 17 00:00:00 2001 From: Guillaume Le Floch Date: Wed, 12 Jan 2022 22:21:35 +0100 Subject: [PATCH 2/2] Index classes using jandex plugin before starting devmode if configured --- .../main/java/io/quarkus/maven/DevMojo.java | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java index 9039b20dad2b4..11bb422a0353e 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java @@ -116,9 +116,9 @@ public class DevMojo extends AbstractMojo { /** * running any one of these phases means the compile phase will have been run, if these have - * not been run we manually run compile + * not been run we manually run compile. */ - private static final Set POST_COMPILE_PHASES = Set.of( + private static final List POST_COMPILE_PHASES = List.of( "compile", "process-classes", "generate-test-sources", @@ -141,7 +141,7 @@ public class DevMojo extends AbstractMojo { * running any one of these phases means the test-compile phase will have been run, if these have * not been run we manually run test-compile */ - private static final Set POST_TEST_COMPILE_PHASES = Set.of( + private static final List POST_TEST_COMPILE_PHASES = List.of( "test-compile", "process-test-classes", "test", @@ -153,6 +153,7 @@ public class DevMojo extends AbstractMojo { "verify", "install", "deploy"); + private static final String QUARKUS_GENERATE_CODE_GOAL = "generate-code"; private static final String QUARKUS_GENERATE_CODE_TESTS_GOAL = "generate-code-tests"; @@ -164,6 +165,9 @@ public class DevMojo extends AbstractMojo { private static final String ORG_JETBRAINS_KOTLIN = "org.jetbrains.kotlin"; private static final String KOTLIN_MAVEN_PLUGIN = "kotlin-maven-plugin"; + private static final String ORG_JBOSS_JANDEX = "org.jboss.jandex"; + private static final String JANDEX_MAVEN_PLUGIN = "jandex-maven-plugin"; + /** * The directory for compiled classes. */ @@ -363,7 +367,7 @@ public void execute() throws MojoFailureException, MojoExecutionException { initToolchain(); - //we always want to compile if needed, so if it is run from the parent it will compile dependent projects + // we always want to compile if needed, so if it is run from the parent it will compile dependent projects handleAutoCompile(); if (enforceBuildGoal) { @@ -492,6 +496,10 @@ private void handleAutoCompile() throws MojoExecutionException { boolean testCompileNeeded = true; boolean prepareNeeded = true; boolean prepareTestsNeeded = true; + + String jandexGoalPhase = getGoalPhaseOrNull(ORG_JBOSS_JANDEX, JANDEX_MAVEN_PLUGIN, "jandex", "process-classes"); + boolean indexClassNeeded = jandexGoalPhase != null; + for (String goal : session.getGoals()) { if (goal.endsWith("quarkus:generate-code")) { prepareNeeded = false; @@ -502,11 +510,15 @@ private void handleAutoCompile() throws MojoExecutionException { if (POST_COMPILE_PHASES.contains(goal)) { compileNeeded = false; - break; } + + if (jandexGoalPhase != null + && POST_COMPILE_PHASES.indexOf(goal) >= POST_COMPILE_PHASES.indexOf(jandexGoalPhase)) { + indexClassNeeded = false; + } + if (POST_TEST_COMPILE_PHASES.contains(goal)) { testCompileNeeded = false; - break; } if (goal.endsWith("quarkus:dev")) { break; @@ -517,6 +529,9 @@ private void handleAutoCompile() throws MojoExecutionException { if (compileNeeded) { triggerCompile(false, prepareNeeded); } + if (indexClassNeeded) { + initClassIndexes(); + } if (testCompileNeeded) { try { triggerCompile(true, prepareTestsNeeded); @@ -537,6 +552,10 @@ private void triggerPrepare(boolean test) throws MojoExecutionException { Collections.singletonMap("mode", LaunchMode.DEVELOPMENT.name())); } + private void initClassIndexes() throws MojoExecutionException { + executeIfConfigured(ORG_JBOSS_JANDEX, JANDEX_MAVEN_PLUGIN, "jandex", Collections.emptyMap()); + } + private PluginDescriptor getPluginDescriptor() { return (PluginDescriptor) getPluginContext().get("pluginDescriptor"); } @@ -591,6 +610,21 @@ private void executeIfConfigured(String pluginGroupId, String pluginArtifactId, pluginManager)); } + private String getGoalPhaseOrNull(String groupId, String artifactId, String goal, String defaultPhase) { + Plugin plugin = getConfiguredPluginOrNull(groupId, artifactId); + + if (plugin == null) { + return null; + } + for (PluginExecution pluginExecution : plugin.getExecutions()) { + if (pluginExecution.getGoals().contains(goal)) { + var configuredPhase = pluginExecution.getPhase(); + return configuredPhase != null ? configuredPhase : defaultPhase; + } + } + return null; + } + public boolean isGoalConfigured(Plugin plugin, String goal) { if (plugin == null) { return false;