Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Nov 4, 2024
1 parent d8f1436 commit f11c573
Show file tree
Hide file tree
Showing 18 changed files with 808 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -589,13 +589,13 @@ private static boolean processQuarkusDir(ResolvedDependencyBuilder artifactBuild
return false;
}
artifactBuilder.setRuntimeExtensionArtifact();
final String extensionCoords = artifactBuilder.toGACTVString();
modelBuilder.handleExtensionProperties(extProps, extensionCoords);
modelBuilder.handleExtensionProperties(extProps, artifactBuilder.getKey());

final String providesCapabilities = extProps.getProperty(BootstrapConstants.PROP_PROVIDES_CAPABILITIES);
if (providesCapabilities != null) {
modelBuilder
.addExtensionCapabilities(CapabilityContract.of(extensionCoords, providesCapabilities, null));
.addExtensionCapabilities(
CapabilityContract.of(artifactBuilder.toGACTVString(), providesCapabilities, null));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,13 @@ private static boolean processQuarkusDir(ResolvedDependencyBuilder artifactBuild
return false;
}
artifactBuilder.setRuntimeExtensionArtifact();
final String extensionCoords = artifactBuilder.toGACTVString();
modelBuilder.handleExtensionProperties(extProps, extensionCoords);
modelBuilder.handleExtensionProperties(extProps, artifactBuilder.getKey());

final String providesCapabilities = extProps.getProperty(BootstrapConstants.PROP_PROVIDES_CAPABILITIES);
if (providesCapabilities != null) {
modelBuilder
.addExtensionCapabilities(CapabilityContract.of(extensionCoords, providesCapabilities, null));
.addExtensionCapabilities(
CapabilityContract.of(artifactBuilder.toGACTVString(), providesCapabilities, null));
}
return true;
}
Expand Down
46 changes: 41 additions & 5 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
import io.quarkus.bootstrap.app.QuarkusBootstrap;
import io.quarkus.bootstrap.devmode.DependenciesFilter;
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.model.JvmArgs;
import io.quarkus.bootstrap.model.JvmArgsBuilder;
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
Expand Down Expand Up @@ -386,6 +388,9 @@ public class DevMojo extends AbstractMojo {
@Parameter(defaultValue = "org.codehaus.mojo:flatten-maven-plugin")
Set<String> skipPlugins;

@Parameter
ExtensionDevModeJvmArgFilter extensionJvmArgs;

/**
* console attributes, used to restore the console state
*/
Expand Down Expand Up @@ -1270,15 +1275,13 @@ private QuarkusDevModeLauncher newLauncher(String actualDebugPort, String bootst
builder.jvmArgs("-Dio.quarkus.force-color-support=true");
}

final JvmArgsBuilder jvmArgsBuilder = JvmArgs.builder();
if (openJavaLang) {
builder.jvmArgs("--add-opens");
builder.jvmArgs("java.base/java.lang=ALL-UNNAMED");
jvmArgsBuilder.add("add-opens", "java.base/java.lang=ALL-UNNAMED");
}

if (modules != null && !modules.isEmpty()) {
String mods = String.join(",", this.modules);
builder.jvmArgs("--add-modules");
builder.jvmArgs(mods);
jvmArgsBuilder.addAll("add-modules", this.modules);
}

builder.projectDir(project.getFile().getParentFile());
Expand Down Expand Up @@ -1392,6 +1395,11 @@ private QuarkusDevModeLauncher newLauncher(String actualDebugPort, String bootst
.resolveModel(mvnCtx.getCurrentProject().getAppArtifact());
}

addExtensionJvmArgs(appModel, jvmArgsBuilder);
for (var arg : jvmArgsBuilder.build()) {
builder.jvmArgs(arg.toCliArguments());
}

// serialize the app model to avoid re-resolving it in the dev process
BootstrapUtils.serializeAppModel(appModel, appModelLocation);
builder.jvmArgs("-D" + BootstrapConstants.SERIALIZED_APP_MODEL + "=" + appModelLocation);
Expand Down Expand Up @@ -1448,6 +1456,34 @@ private QuarkusDevModeLauncher newLauncher(String actualDebugPort, String bootst
return builder.build();
}

private void addExtensionJvmArgs(ApplicationModel appModel, JvmArgsBuilder jvmArgsBuilder) {
if (extensionJvmArgs == null || !extensionJvmArgs.isDisableAll()) {
if (appModel.getExtensionDevModeConfig() != null) {
for (var extDevMode : appModel.getExtensionDevModeConfig()) {
if (extensionJvmArgs.isDisabled(extDevMode.getExtensionKey())) {
debug("Skipped JVM arguments from %s", extDevMode.getExtensionKey());
continue;
}
debug("Adding JVM arguments from %s", extDevMode.getExtensionKey());
if (extDevMode.getJvmArgs() != null) {
jvmArgsBuilder.add(extDevMode.getJvmArgs());
if (getLog().isDebugEnabled()) {
for (var arg : extDevMode.getJvmArgs().asCollection()) {
getLog().debug(" " + arg.getName() + ": " + arg.getValues());
}
}
}
}
}
}
}

private void debug(String msg, Object... args) {
if (getLog().isDebugEnabled()) {
getLog().debug(String.format(msg, args));
}
}

private void setJvmArgs(Builder builder) throws Exception {
String jvmArgs = this.jvmArgs;
if (!systemProperties.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.quarkus.maven;

import java.util.ArrayList;
import java.util.List;

import io.quarkus.maven.dependency.ArtifactCoordsPattern;
import io.quarkus.maven.dependency.ArtifactKey;

public class ExtensionDevModeJvmArgFilter {

private boolean disableAll;

private List<String> disableFor = List.of();
private List<ArtifactCoordsPattern> disableForPatterns;

public boolean isDisableAll() {
return disableAll;
}

public void setDisableAll(boolean disableAll) {
this.disableAll = disableAll;
resetPatterns();
}

public List<String> getDisableFor() {
return disableFor;
}

public void setDisableFor(List<String> disableFor) {
this.disableFor = disableFor;
resetPatterns();
}

private void resetPatterns() {
disableForPatterns = null;
}

List<ArtifactCoordsPattern> getDisableForPatterns() {
if (disableFor.isEmpty()) {
return List.of();
}
if (disableForPatterns == null) {
var result = new ArrayList<ArtifactCoordsPattern>(disableFor.size());
for (var s : disableFor) {
result.add(ArtifactCoordsPattern.of(s));
}
disableForPatterns = result;
}
return disableForPatterns;
}

boolean isDisabled(ArtifactKey extensionKey) {
for (var pattern : getDisableForPatterns()) {
if (pattern.matches(extensionKey.getGroupId(), extensionKey.getArtifactId(), extensionKey.getClassifier(), "jar",
null)) {
return true;
}
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ public interface BootstrapConstants {
String PLATFORM_PROPERTY_PREFIX = "platform.";

String QUARKUS_BOOTSTRAP_WORKSPACE_DISCOVERY = "quarkus.bootstrap.workspace-discovery";

String EXTENSION_DEV_MODE_JVM_ARGS_PREFIX = "dev-mode.jvm-args.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,6 @@ private static void collectModules(WorkspaceModule module, Map<WorkspaceModuleId
collectModules(((ResolvedDependency) d).getWorkspaceModule(), collected);
}
}

Collection<ExtensionDevModeConfig> getExtensionDevModeConfig();
}
Loading

0 comments on commit f11c573

Please sign in to comment.