Skip to content

Commit 1ed554b

Browse files
committed
Let QuarkusTest pass its launch mode to QuarkusDev
1 parent da86c81 commit 1ed554b

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,16 @@ private boolean classesExist() {
411411
return false;
412412
}
413413

414+
/**
415+
* Returns launch mode for the target application model.
416+
*
417+
* @return launch mode for the target application model
418+
*/
419+
@Internal
420+
protected LaunchMode getLaunchMode() {
421+
return LaunchMode.DEVELOPMENT;
422+
}
423+
414424
private DevModeCommandLine newLauncher(final AnalyticsService analyticsService) throws Exception {
415425
final Project project = getProject();
416426
final JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class);
@@ -466,7 +476,7 @@ private DevModeCommandLine newLauncher(final AnalyticsService analyticsService)
466476

467477
builder.sourceEncoding(getSourceEncoding());
468478

469-
final ApplicationModel appModel = extension().getApplicationModel(LaunchMode.DEVELOPMENT);
479+
final ApplicationModel appModel = extension().getApplicationModel(getLaunchMode());
470480
builder.extensionDevModeConfig(appModel.getExtensionDevModeConfig())
471481
.extensionDevModeJvmOptionFilter(extensionJvmOptions);
472482

@@ -538,7 +548,8 @@ private DevModeCommandLine newLauncher(final AnalyticsService analyticsService)
538548
serializedModel.toFile().deleteOnExit();
539549
builder.jvmArgs("-D" + BootstrapConstants.SERIALIZED_APP_MODEL + "=" + serializedModel.toAbsolutePath());
540550

541-
final ApplicationModel testAppModel = extension().getApplicationModel(LaunchMode.TEST);
551+
final ApplicationModel testAppModel = getLaunchMode().equals(LaunchMode.TEST) ? appModel
552+
: extension().getApplicationModel(LaunchMode.TEST);
542553
final Path serializedTestModel = ToolingUtils.serializeAppModel(testAppModel, this, true);
543554
serializedTestModel.toFile().deleteOnExit();
544555
builder.jvmArgs("-D" + BootstrapConstants.SERIALIZED_TEST_APP_MODEL + "=" + serializedTestModel.toAbsolutePath());
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package io.quarkus.gradle.tasks;
22

3-
import java.util.function.Consumer;
4-
53
import javax.inject.Inject;
64

75
import org.gradle.api.artifacts.Configuration;
6+
import org.gradle.api.tasks.Internal;
87

98
import io.quarkus.deployment.dev.DevModeCommandLineBuilder;
10-
import io.quarkus.deployment.dev.DevModeContext;
119
import io.quarkus.deployment.dev.IsolatedTestModeMain;
1210
import io.quarkus.gradle.extension.QuarkusPluginExtension;
11+
import io.quarkus.runtime.LaunchMode;
1312

1413
public abstract class QuarkusTest extends QuarkusDev {
1514

@@ -21,12 +20,15 @@ public QuarkusTest(Configuration quarkusDevConfiguration, QuarkusPluginExtension
2120
extension);
2221
}
2322

23+
@Override
2424
protected void modifyDevModeContext(DevModeCommandLineBuilder builder) {
25-
builder.entryPointCustomizer(new Consumer<DevModeContext>() {
26-
@Override
27-
public void accept(DevModeContext devModeContext) {
28-
devModeContext.setAlternateEntryPoint(IsolatedTestModeMain.class.getName());
29-
}
30-
});
25+
builder.entryPointCustomizer(
26+
devModeContext -> devModeContext.setAlternateEntryPoint(IsolatedTestModeMain.class.getName()));
27+
}
28+
29+
@Override
30+
@Internal
31+
protected LaunchMode getLaunchMode() {
32+
return LaunchMode.TEST;
3133
}
3234
}

devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/tooling/GradleApplicationModelBuilder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ public static ResolvedDependencyBuilder getProjectArtifact(Project project, bool
193193

194194
initProjectModule(project, mainModule, sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME), ArtifactSources.MAIN);
195195
if (workspaceDiscovery) {
196+
appArtifact.setReloadable();
196197
final TaskCollection<Test> testTasks = project.getTasks().withType(Test.class);
197198
if (!testTasks.isEmpty()) {
198199
final Map<File, SourceSet> sourceSetsByClassesDir = new HashMap<>();
@@ -319,7 +320,7 @@ private static void processDeploymentDependency(Project project, ResolvedDepende
319320
clearReloadableFlag = true;
320321
}
321322
dep.setDeploymentCp();
322-
if (clearReloadableFlag) {
323+
if (clearReloadableFlag && dep != modelBuilder.getApplicationArtifact()) {
323324
dep.clearFlag(DependencyFlags.RELOADABLE);
324325
}
325326
}
@@ -480,14 +481,14 @@ private void collectDependencies(org.gradle.api.artifacts.ResolvedDependency res
480481
flags = clearFlag(flags, COLLECT_RELOADABLE_MODULES);
481482
}
482483
modelBuilder.addDependency(depBuilder);
483-
if (projectModule == null && depBuilder.getWorkspaceModule() != null) {
484-
projectModule = depBuilder.getWorkspaceModule().mutable();
485-
}
486484

487485
if (artifactFiles != null) {
488486
artifactFiles.add(a.getFile());
489487
}
490488
}
489+
if (projectModule == null && depBuilder.getWorkspaceModule() != null) {
490+
projectModule = depBuilder.getWorkspaceModule().mutable();
491+
}
491492
if (isFlagOn(flags, COLLECT_DIRECT_DEPS)) {
492493
depBuilder.setDirect(true);
493494
flags = clearFlag(flags, COLLECT_DIRECT_DEPS);

0 commit comments

Comments
 (0)