Skip to content

Commit

Permalink
Merge pull request #33855 from aloubyansky/DevMojo-goal-name
Browse files Browse the repository at this point in the history
Get the DevMojo goal name from the MojoExecution instead of a hardcoded constant
  • Loading branch information
aloubyansky committed Jun 7, 2023
2 parents dee218a + 2738989 commit 69682b3
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,14 @@ public void execute() throws MojoFailureException, MojoExecutionException {
if (enforceBuildGoal) {
final PluginDescriptor pluginDescr = getPluginDescriptor();
final Plugin pluginDef = getConfiguredPluginOrNull(pluginDescr.getGroupId(), pluginDescr.getArtifactId());
if (pluginDef == null || !isGoalConfigured(pluginDef, "build")) {
getLog().warn("The quarkus-maven-plugin build goal was not configured for this project," +
" skipping quarkus:dev as this is assumed to be a support library. If you want to run quarkus:dev" +
" on this project make sure the quarkus-maven-plugin is configured with the build goal" +
" or disable the enforceBuildGoal flag (via plugin configuration or via" +
" -Dquarkus.enforceBuildGoal=false).");
if (!isGoalConfigured(pluginDef, "build")) {
var currentGoal = getCurrentGoal();
getLog().warn(
"The quarkus-maven-plugin build goal was not configured for this project, skipping " +
currentGoal + " as this is assumed to be a support library. If you want to run " + currentGoal +
" on this project make sure the quarkus-maven-plugin is configured with the build goal" +
" or disable the enforceBuildGoal flag (via plugin configuration or via" +
" -Dquarkus.enforceBuildGoal=false).");
return;
}
}
Expand Down Expand Up @@ -518,10 +520,11 @@ private void handleAutoCompile() throws MojoExecutionException {
if (goals.isEmpty() && !StringUtils.isEmpty(project.getDefaultGoal())) {
goals = List.of(StringUtils.split(project.getDefaultGoal()));
}
final String currentGoal = getCurrentGoal();

int latestHandledPhaseIndex = -1;
for (String goal : goals) {
if (goal.endsWith("quarkus:dev")) {
if (goal.endsWith(currentGoal)) {
break;
}
if (goal.indexOf(':') >= 0 || IGNORED_PHASES.contains(goal)) {
Expand All @@ -541,7 +544,7 @@ private void handleAutoCompile() throws MojoExecutionException {
// configured plugin executions by lifecycle phases
final Map<String, List<Map.Entry<Plugin, PluginExecution>>> phaseExecutions = new HashMap<>();
// goals with prefixes on the command line
final Map<String, Plugin> prefixedGoals = new HashMap<>();
final Map<String, Plugin> pluginPrefixes = new HashMap<>();
for (Plugin p : project.getBuildPlugins()) {
if (p.getExecutions().isEmpty()) {
continue;
Expand Down Expand Up @@ -576,22 +579,20 @@ private void handleAutoCompile() throws MojoExecutionException {
}
if (!e.getGoals().isEmpty()) {
var goalPrefix = getMojoDescriptor(p, e.getGoals().get(0)).getPluginDescriptor().getGoalPrefix();
for (String goal : e.getGoals()) {
prefixedGoals.put(goalPrefix + ":" + goal, p);
}
pluginPrefixes.put(goalPrefix, p);
}
}
}

// Map<pluginId, List<goals>>
final Map<String, List<String>> executedPluginGoals = new HashMap<>();
for (String goal : goals) {
if (goal.endsWith("quarkus:dev")) {
if (goal.endsWith(currentGoal)) {
break;
}
var colon = goal.indexOf(':');
if (colon >= 0) {
var plugin = prefixedGoals.get(goal);
var plugin = pluginPrefixes.get(goal.substring(0, colon));
if (plugin == null) {
getLog().warn("Failed to locate plugin for " + goal);
} else {
Expand Down Expand Up @@ -630,6 +631,11 @@ private void handleAutoCompile() throws MojoExecutionException {
}
}

private String getCurrentGoal() {
return mojoExecution.getMojoDescriptor().getPluginDescriptor().getGoalPrefix() + ":"
+ mojoExecution.getGoal();
}

private PluginDescriptor getPluginDescriptor() {
return mojoExecution.getMojoDescriptor().getPluginDescriptor();
}
Expand Down

0 comments on commit 69682b3

Please sign in to comment.