-
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.
Support @testprofile in native mode #12974
- Loading branch information
Showing
15 changed files
with
634 additions
and
133 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
29 changes: 0 additions & 29 deletions
29
core/runtime/src/main/java/io/quarkus/runtime/ConfigChangeRecorder.java
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigChangeRecorder.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,53 @@ | ||
package io.quarkus.runtime.configuration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.runtime.annotations.Recorder; | ||
import io.quarkus.runtime.configuration.ConfigurationRuntimeConfig.BuildTimeMismatchAtRuntime; | ||
|
||
@Recorder | ||
public class ConfigChangeRecorder { | ||
|
||
private static final Logger log = Logger.getLogger(ConfigChangeRecorder.class); | ||
|
||
public void handleConfigChange(ConfigurationRuntimeConfig configurationConfig, Map<String, String> buildTimeConfig) { | ||
Config configProvider = ConfigProvider.getConfig(); | ||
List<String> mismatches = null; | ||
for (Map.Entry<String, String> entry : buildTimeConfig.entrySet()) { | ||
Optional<String> val = configProvider.getOptionalValue(entry.getKey(), String.class); | ||
if (val.isPresent()) { | ||
if (!val.get().equals(entry.getValue())) { | ||
if (mismatches == null) { | ||
mismatches = new ArrayList<>(); | ||
} | ||
mismatches.add( | ||
" - " + entry.getKey() + " was '" + entry.getValue() + "' at build time and is now '" + val.get() | ||
+ "'"); | ||
} | ||
} | ||
} | ||
if (mismatches != null && !mismatches.isEmpty()) { | ||
final String msg = "Build time property cannot be changed at runtime:\n" | ||
+ mismatches.stream().collect(Collectors.joining("\n")); | ||
switch (configurationConfig.buildTimeMismatchAtRuntime) { | ||
case fail: | ||
throw new IllegalStateException(msg); | ||
case warn: | ||
log.warn(msg); | ||
break; | ||
default: | ||
throw new IllegalStateException("Unexpected " + BuildTimeMismatchAtRuntime.class.getName() + ": " | ||
+ configurationConfig.buildTimeMismatchAtRuntime); | ||
} | ||
|
||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigurationRuntimeConfig.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,29 @@ | ||
package io.quarkus.runtime.configuration; | ||
|
||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import io.quarkus.runtime.annotations.ConfigPhase; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
|
||
@ConfigRoot(name = "configuration", phase = ConfigPhase.RUN_TIME) | ||
public class ConfigurationRuntimeConfig { | ||
|
||
/** | ||
* What should happen if the application is started with a different build time configuration than it was compiled | ||
* against. This may be useful to prevent misconfiguration. | ||
* <p> | ||
* If this is set to {@code warn} the application will warn at start up. | ||
* <p> | ||
* If this is set to {@code fail} the application will fail at start up. | ||
* <p> | ||
* Native tests leveraging<code>@io.quarkus.test.junit.TestProfile</code> are always run with | ||
* {@code quarkus.configuration.build-time-mismatch-at-runtime = fail}. | ||
*/ | ||
@ConfigItem(defaultValue = "warn") | ||
public BuildTimeMismatchAtRuntime buildTimeMismatchAtRuntime; | ||
|
||
public enum BuildTimeMismatchAtRuntime { | ||
warn, | ||
fail | ||
} | ||
|
||
} |
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
Oops, something went wrong.