Skip to content

Commit 1c167ae

Browse files
authored
Merge pull request quarkusio#49112 from gsmet/fix-run-mode
Make sure RUN mode is correctly taken into account
2 parents a1924df + 927daaa commit 1c167ae

File tree

43 files changed

+123
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+123
-90
lines changed

core/deployment/src/main/java/io/quarkus/deployment/IsNormal.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
/**
99
* boolean supplier that returns true if the application is running in normal
1010
* mode. Intended for use with {@link BuildStep#onlyIf()}
11+
*
12+
* @deprecated This class was marked as deprecated to raise awareness that the semantic you want is probably provided by
13+
* {@link IsProduction}. If you actually need this specific supplier, please open an issue so that we undeprecate
14+
* it.
1115
*/
16+
@Deprecated(since = "3.25")
1217
public class IsNormal implements BooleanSupplier {
1318

1419
private final LaunchMode launchMode;
@@ -19,6 +24,6 @@ public IsNormal(LaunchMode launchMode) {
1924

2025
@Override
2126
public boolean getAsBoolean() {
22-
return launchMode == LaunchMode.NORMAL || launchMode == LaunchMode.RUN;
27+
return launchMode == LaunchMode.NORMAL;
2328
}
2429
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.quarkus.deployment;
2+
3+
import java.util.function.BooleanSupplier;
4+
5+
import io.quarkus.deployment.annotations.BuildStep;
6+
import io.quarkus.runtime.LaunchMode;
7+
8+
/**
9+
* boolean supplier that returns true if the application is running in production
10+
* mode i.e. either NORMAL or RUN. Intended for use with {@link BuildStep#onlyIf()}
11+
*/
12+
public class IsProduction implements BooleanSupplier {
13+
14+
private final LaunchMode launchMode;
15+
16+
public IsProduction(LaunchMode launchMode) {
17+
this.launchMode = launchMode;
18+
}
19+
20+
@Override
21+
public boolean getAsBoolean() {
22+
return launchMode == LaunchMode.NORMAL || launchMode == LaunchMode.RUN;
23+
}
24+
}

core/deployment/src/main/java/io/quarkus/deployment/QuarkusAugmentor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public BuildResult run() throws Exception {
160160
BuildResult buildResult = execBuilder.execute();
161161
String message = "Quarkus augmentation completed in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start)
162162
+ "ms";
163-
if (launchMode == LaunchMode.NORMAL) {
163+
if (launchMode.isProduction()) {
164164
log.info(message);
165165
if (Boolean.parseBoolean(System.getProperty("quarkus.debug.dump-build-metrics"))) {
166166
buildResult.getMetrics().dumpTo(targetDir.resolve("build-metrics.json"));
@@ -170,7 +170,7 @@ public BuildResult run() throws Exception {
170170
log.debug(message);
171171

172172
// Dump the metrics in the dev mode but not remote-dev (as it could cause issues with container permissions)
173-
if ((launchMode == LaunchMode.DEVELOPMENT) && !LaunchMode.isRemoteDev()) {
173+
if (launchMode.isDev() && !launchMode.isRemoteDev()) {
174174
buildResult.getMetrics().dumpTo(targetDir.resolve("build-metrics.json"));
175175
}
176176
}

core/deployment/src/main/java/io/quarkus/deployment/SnapStartProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
public class SnapStartProcessor {
2727

28-
@BuildStep(onlyIf = IsNormal.class, onlyIfNot = NativeBuild.class)
28+
@BuildStep(onlyIf = IsProduction.class, onlyIfNot = NativeBuild.class)
2929
@Record(ExecutionTime.STATIC_INIT)
3030
public void processSnapStart(BuildProducer<PreloadClassesEnabledBuildItem> preload,
3131
BuildProducer<SnapStartEnabledBuildItem> snapStartEnabled,
@@ -46,7 +46,7 @@ public void processSnapStart(BuildProducer<PreloadClassesEnabledBuildItem> prelo
4646
recorder.register(config.fullWarmup());
4747
}
4848

49-
@BuildStep(onlyIf = IsNormal.class, onlyIfNot = NativeBuild.class)
49+
@BuildStep(onlyIf = IsProduction.class, onlyIfNot = NativeBuild.class)
5050
public void generateClassListFromApplication(
5151
SnapStartConfig config,
5252
Optional<SnapStartDefaultValueBuildItem> defaultVal,

core/deployment/src/main/java/io/quarkus/deployment/dev/io/NioThreadPoolDevModeProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.quarkus.deployment.dev.io;
22

3-
import io.quarkus.deployment.IsNormal;
3+
import io.quarkus.deployment.IsProduction;
44
import io.quarkus.deployment.annotations.BuildStep;
55
import io.quarkus.deployment.annotations.ExecutionTime;
66
import io.quarkus.deployment.annotations.Produce;
@@ -12,7 +12,7 @@
1212
public class NioThreadPoolDevModeProcessor {
1313

1414
@Produce(TestSetupBuildItem.class)
15-
@BuildStep(onlyIfNot = IsNormal.class)
15+
@BuildStep(onlyIfNot = IsProduction.class)
1616
@Record(ExecutionTime.STATIC_INIT)
1717
void setupTCCL(NioThreadPoolRecorder recorder, ShutdownContextBuildItem shutdownContextBuildItem) {
1818
recorder.updateTccl(shutdownContextBuildItem);

core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestTracingProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
2929
import io.quarkus.deployment.IsDevelopment;
30-
import io.quarkus.deployment.IsNormal;
30+
import io.quarkus.deployment.IsProduction;
3131
import io.quarkus.deployment.IsTest;
3232
import io.quarkus.deployment.annotations.BuildProducer;
3333
import io.quarkus.deployment.annotations.BuildStep;
@@ -56,7 +56,7 @@
5656
*/
5757
public class TestTracingProcessor {
5858

59-
@BuildStep(onlyIfNot = IsNormal.class)
59+
@BuildStep(onlyIfNot = IsProduction.class)
6060
LogCleanupFilterBuildItem handle() {
6161
return new LogCleanupFilterBuildItem("org.junit.platform.launcher.core.EngineDiscoveryOrchestrator", "0 containers");
6262
}

core/deployment/src/main/java/io/quarkus/deployment/logging/LoggingResourceProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
import io.quarkus.bootstrap.workspace.WorkspaceModule;
6161
import io.quarkus.deployment.ApplicationArchive;
6262
import io.quarkus.deployment.GeneratedClassGizmo2Adaptor;
63-
import io.quarkus.deployment.IsNormal;
63+
import io.quarkus.deployment.IsProduction;
6464
import io.quarkus.deployment.annotations.BuildProducer;
6565
import io.quarkus.deployment.annotations.BuildStep;
6666
import io.quarkus.deployment.annotations.Consume;
@@ -391,7 +391,7 @@ private DiscoveredLogComponents discoverLogComponents(IndexView index) {
391391
return result;
392392
}
393393

394-
@BuildStep(onlyIfNot = IsNormal.class)
394+
@BuildStep(onlyIfNot = IsProduction.class)
395395
@Produce(TestSetupBuildItem.class)
396396
@Produce(LogConsoleFormatBuildItem.class)
397397
@Consume(ConsoleInstalledBuildItem.class)

core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/FileSystemResourcesBuildStep.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.nio.file.Path;
88
import java.util.List;
99

10-
import io.quarkus.deployment.IsNormal;
10+
import io.quarkus.deployment.IsProduction;
1111
import io.quarkus.deployment.annotations.BuildProducer;
1212
import io.quarkus.deployment.annotations.BuildStep;
1313
import io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem;
@@ -19,7 +19,7 @@
1919

2020
public class FileSystemResourcesBuildStep {
2121

22-
@BuildStep(onlyIfNot = IsNormal.class)
22+
@BuildStep(onlyIfNot = IsProduction.class)
2323
public void notNormalMode(OutputTargetBuildItem outputTargetBuildItem,
2424
LaunchModeBuildItem launchMode,
2525
List<GeneratedFileSystemResourceBuildItem> generatedFileSystemResources,
@@ -30,7 +30,7 @@ public void notNormalMode(OutputTargetBuildItem outputTargetBuildItem,
3030
producer.produce(new GeneratedFileSystemResourceHandledBuildItem());
3131
}
3232

33-
@BuildStep(onlyIf = IsNormal.class)
33+
@BuildStep(onlyIf = IsProduction.class)
3434
public void normalMode(OutputTargetBuildItem outputTargetBuildItem,
3535
List<GeneratedFileSystemResourceBuildItem> generatedFileSystemResources,
3636
// this is added to ensure that the build step will be run

core/deployment/src/main/java/io/quarkus/deployment/steps/ConfigGenerationBuildStep.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
4646
import io.quarkus.deployment.GeneratedClassGizmoAdaptor;
47-
import io.quarkus.deployment.IsNormal;
47+
import io.quarkus.deployment.IsProduction;
4848
import io.quarkus.deployment.annotations.BuildProducer;
4949
import io.quarkus.deployment.annotations.BuildStep;
5050
import io.quarkus.deployment.annotations.ExecutionTime;
@@ -185,7 +185,7 @@ void buildTimeRunTimeConfig(
185185
runTimeConfigBuilder.produce(new RunTimeConfigBuilderBuildItem(builderClassName));
186186
}
187187

188-
@BuildStep(onlyIfNot = { IsNormal.class }) // for dev or test
188+
@BuildStep(onlyIfNot = { IsProduction.class }) // for dev or test
189189
void runtimeOverrideConfig(
190190
BuildProducer<StaticInitConfigBuilderBuildItem> staticInitConfigBuilder,
191191
BuildProducer<RunTimeConfigBuilderBuildItem> runTimeConfigBuilder) {
@@ -425,7 +425,7 @@ public void checkForBuildTimeConfigChange(
425425
recorder.handleConfigChange(values);
426426
}
427427

428-
@BuildStep(onlyIfNot = { IsNormal.class })
428+
@BuildStep(onlyIfNot = { IsProduction.class })
429429
public void setupConfigOverride(
430430
BuildProducer<GeneratedClassBuildItem> generatedClassBuildItemBuildProducer) {
431431

@@ -548,7 +548,7 @@ void warnDifferentProfileUsedBetweenBuildAndRunTime(ConfigRecorder configRecorde
548548
configRecorder.handleNativeProfileChange(config.getProfiles());
549549
}
550550

551-
@BuildStep(onlyIf = IsNormal.class)
551+
@BuildStep(onlyIf = IsProduction.class)
552552
void persistReadConfigOptions(
553553
BuildProducer<ArtifactResultBuildItem> dummy,
554554
QuarkusBuildCloseablesBuildItem closeables,

core/runtime/src/main/java/io/quarkus/runtime/LaunchMode.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,6 @@ public enum LaunchMode {
2424
public static final String PROD_PROFILE = "prod";
2525
public static final String TEST_PROFILE = "test";
2626

27-
public boolean isDevOrTest() {
28-
return this != NORMAL;
29-
}
30-
31-
public static boolean isDev() {
32-
return current() == DEVELOPMENT;
33-
}
34-
35-
/**
36-
* Returns true if the current launch is the server side of remote dev.
37-
*/
38-
public static boolean isRemoteDev() {
39-
return (current() == DEVELOPMENT) && "true".equals(System.getenv("QUARKUS_LAUNCH_DEVMODE"));
40-
}
41-
4227
private final String defaultProfile;
4328
private final String profileKey;
4429
private final boolean devServicesSupported;
@@ -60,6 +45,28 @@ public String getProfileKey() {
6045
return profileKey;
6146
}
6247

48+
public boolean isDev() {
49+
return this == DEVELOPMENT;
50+
}
51+
52+
/**
53+
* Returns true if the current launch is the server side of remote dev.
54+
*/
55+
public boolean isRemoteDev() {
56+
return (this == DEVELOPMENT) && "true".equals(System.getenv("QUARKUS_LAUNCH_DEVMODE"));
57+
}
58+
59+
public boolean isDevOrTest() {
60+
return this == DEVELOPMENT || this == TEST;
61+
}
62+
63+
/**
64+
* Returns true if the current launch is a production mode, such as NORMAL or RUN.
65+
*/
66+
public boolean isProduction() {
67+
return LaunchMode.PROD_PROFILE.equals(getDefaultProfile());
68+
}
69+
6370
public boolean isDevServicesSupported() {
6471
return devServicesSupported;
6572
}

0 commit comments

Comments
 (0)