Skip to content

Commit

Permalink
Index classes using jandex plugin before starting devmode if configured
Browse files Browse the repository at this point in the history
  • Loading branch information
glefloch committed Jan 22, 2022
1 parent 8ae3e04 commit c911101
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> POST_COMPILE_PHASES = Set.of(
private static final List<String> POST_COMPILE_PHASES = List.of(
"compile",
"process-classes",
"generate-test-sources",
Expand All @@ -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<String> POST_TEST_COMPILE_PHASES = Set.of(
private static final List<String> POST_TEST_COMPILE_PHASES = List.of(
"test-compile",
"process-test-classes",
"test",
Expand All @@ -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";

Expand All @@ -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.
*/
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -517,6 +529,9 @@ private void handleAutoCompile() throws MojoExecutionException {
if (compileNeeded) {
triggerCompile(false, prepareNeeded);
}
if (indexClassNeeded) {
initClassIndexes();
}
if (testCompileNeeded) {
try {
triggerCompile(true, prepareTestsNeeded);
Expand All @@ -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");
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c911101

Please sign in to comment.