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

Get the DevMojo goal name from the MojoExecution instead of a hardcoded constant #33855

Merged
merged 1 commit into from
Jun 7, 2023
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
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