-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow quarkus:run to launch DevServices
Closes: #40270
- Loading branch information
Showing
6 changed files
with
114 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...loyment/src/main/java/io/quarkus/deployment/cmd/StartDevServicesAndRunCommandHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.quarkus.deployment.cmd; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Consumer; | ||
|
||
import io.quarkus.builder.BuildResult; | ||
import io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem; | ||
|
||
public class StartDevServicesAndRunCommandHandler implements BiConsumer<Object, BuildResult> { | ||
|
||
@Override | ||
public void accept(Object o, BuildResult buildResult) { | ||
var runCommandActionResult = buildResult.consume(RunCommandActionResultBuildItem.class); | ||
var devServicesLauncherConfigResult = buildResult.consume(DevServicesLauncherConfigResultBuildItem.class); | ||
|
||
// FYI: AugmentAction.performCustomBuild runs in its own classloader | ||
// so we can only pass back instances of those classes in the system classloader | ||
|
||
Consumer<Map<String, List>> consumer = (Consumer<Map<String, List>>) o; | ||
|
||
// build up the commands | ||
Map<String, List> cmds = new HashMap<>(); | ||
for (RunCommandActionBuildItem item : runCommandActionResult.getCommands()) { | ||
List<String> itemList = new ArrayList<>(); | ||
addLaunchCommand(itemList, item, devServicesLauncherConfigResult.getConfig()); | ||
cmds.put(item.getCommandName(), itemList); | ||
} | ||
|
||
consumer.accept(cmds); | ||
} | ||
|
||
private void addLaunchCommand(List list, RunCommandActionBuildItem item, Map<String, String> devServicesProperties) { | ||
List<String> effectiveArgs; | ||
List<String> originalArgs = item.getArgs(); | ||
if (devServicesProperties.isEmpty()) { | ||
effectiveArgs = originalArgs; | ||
} else { | ||
// here we want to "inject" our dev services configuration into the predetermined launch command | ||
|
||
effectiveArgs = new ArrayList<>(originalArgs.size() + devServicesProperties.size()); | ||
int jarArgIndex = -1; | ||
for (int i = 0; i < originalArgs.size(); i++) { | ||
if (originalArgs.get(i).trim().equals("-jar")) { | ||
jarArgIndex = i; | ||
break; | ||
} | ||
} | ||
if (jarArgIndex == -1) { | ||
effectiveArgs = originalArgs; | ||
} else { | ||
effectiveArgs.addAll(originalArgs.subList(0, jarArgIndex)); | ||
for (var devServiceConfigEntry : devServicesProperties.entrySet()) { | ||
effectiveArgs.add("-D" + devServiceConfigEntry.getKey() + "=" + devServiceConfigEntry.getValue()); | ||
} | ||
effectiveArgs.addAll(originalArgs.subList(jarArgIndex, originalArgs.size())); | ||
} | ||
} | ||
|
||
list.add(effectiveArgs); | ||
list.add(item.getWorkingDirectory()); | ||
list.add(item.getStartedExpression()); | ||
list.add(item.isNeedsLogfile()); | ||
list.add(item.getLogFile()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters