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

DevMojo add only properties from the quarkus namespace #28000

Merged
merged 1 commit into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -878,13 +878,16 @@ private Converter<?> getConverter(SmallRyeConfig config, Field field, ConverterT
* We collect all properties from eligible ConfigSources, because Config#getPropertyNames exclude the active
* profiled properties, meaning that the property is written in the default config source without the profile
* prefix. This may cause issues if we run with a different profile and fallback to defaults.
*
* <br>
* We also filter the properties coming from the System with the registered roots, because we don't want to
* record properties set by the compiling JVM (or other properties that are only related to the build).
* <br>
* Properties coming from the Environment are ignored.
*/
private Set<String> getAllProperties(final Set<String> registeredRoots) {
Set<String> properties = new HashSet<>();
for (ConfigSource configSource : config.getConfigSources()) {
// This is a BuildTimeSysPropConfigSource
if (configSource instanceof SysPropConfigSource) {
for (String propertyName : configSource.getProperties().keySet()) {
NameIterator ni = new NameIterator(propertyName);
Expand All @@ -893,6 +896,7 @@ private Set<String> getAllProperties(final Set<String> registeredRoots) {
}
}
} else {
// The BuildTimeEnvConfigSource returns an empty Set
properties.addAll(configSource.getPropertyNames());
}
}
Expand All @@ -906,10 +910,10 @@ private Set<String> getAllProperties(final Set<String> registeredRoots) {
* Use this Config instance to record the runtime default values. We cannot use the main Config
* instance because it may record values coming from the EnvSource in build time. Environment variable values
* may be completely different between build and runtime, so it doesn't make sense to record these.
*
* <br>
* We do exclude the properties coming from the EnvSource, but a call to getValue may still provide a result
* coming from the EnvSource, so we need to exclude it from the sources when recording values for runtime.
*
* <br>
* We also do not want to completely exclude the EnvSource, because it may provide values for the build. This
* is only specific when recording the defaults.
*
Expand Down
29 changes: 28 additions & 1 deletion devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.maven;

import static io.smallrye.common.expression.Expression.Flag.LENIENT_SYNTAX;
import static io.smallrye.common.expression.Expression.Flag.NO_TRIM;
import static java.util.function.Predicate.not;
import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId;
import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration;
Expand Down Expand Up @@ -105,6 +107,7 @@
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.paths.PathList;
import io.quarkus.runtime.LaunchMode;
import io.smallrye.common.expression.Expression;

/**
* The dev mojo, that runs a quarkus app in a forked process. A background compilation process is launched and any changes are
Expand Down Expand Up @@ -983,7 +986,31 @@ private QuarkusDevModeLauncher newLauncher() throws Exception {
}

builder.projectDir(project.getFile().getParentFile());
builder.buildSystemProperties((Map) project.getProperties());

Properties projectProperties = project.getProperties();
Map<String, String> effectiveProperties = new HashMap<>();
for (String name : projectProperties.stringPropertyNames()) {
if (name.startsWith("quarkus.")) {
effectiveProperties.put(name, projectProperties.getProperty(name));
}
}

// Add other properties that may be required for expansion
for (String value : effectiveProperties.values()) {
for (String reference : Expression.compile(value, LENIENT_SYNTAX, NO_TRIM).getReferencedStrings()) {
String referenceValue = session.getUserProperties().getProperty(reference);
if (referenceValue != null) {
effectiveProperties.put(reference, referenceValue);
continue;
}

referenceValue = projectProperties.getProperty(reference);
if (referenceValue != null) {
effectiveProperties.put(reference, referenceValue);
}
}
}
builder.buildSystemProperties(effectiveProperties);

builder.applicationName(project.getArtifactId());
builder.applicationVersion(project.getVersion());
Expand Down