-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3332 from aloubyansky/gradle-project-test
Support running Quarkus tests from Gradle
- Loading branch information
Showing
4 changed files
with
96 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import org.gradle.api.plugins.BasePlugin; | ||
import org.gradle.api.plugins.JavaPlugin; | ||
import org.gradle.api.tasks.TaskContainer; | ||
import org.gradle.api.tasks.testing.Test; | ||
import org.gradle.util.GradleVersion; | ||
|
||
import io.quarkus.gradle.tasks.QuarkusAddExtension; | ||
|
@@ -15,6 +16,7 @@ | |
import io.quarkus.gradle.tasks.QuarkusGenerateConfig; | ||
import io.quarkus.gradle.tasks.QuarkusListExtensions; | ||
import io.quarkus.gradle.tasks.QuarkusNative; | ||
import io.quarkus.gradle.tasks.QuarkusTestConfig; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Ståle Pedersen</a> | ||
|
@@ -51,6 +53,10 @@ private void registerTasks(Project project) { | |
}); | ||
|
||
tasks.create("buildNative", QuarkusNative.class).dependsOn(quarkusBuild); | ||
|
||
// Quarkus test configuration task which should be executed before any Quarkus test | ||
final QuarkusTestConfig quarkusTestConfig = tasks.create("quarkusTestConfig", QuarkusTestConfig.class); | ||
tasks.withType(Test.class).forEach(t -> t.dependsOn(quarkusTestConfig)); | ||
} | ||
|
||
private void verifyGradleVersion() { | ||
|
44 changes: 44 additions & 0 deletions
44
devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusTestConfig.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,44 @@ | ||
package io.quarkus.gradle.tasks; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.api.tasks.testing.Test; | ||
|
||
import io.quarkus.bootstrap.BootstrapClassLoaderFactory; | ||
import io.quarkus.bootstrap.model.AppDependency; | ||
import io.quarkus.gradle.QuarkusPluginExtension; | ||
|
||
public class QuarkusTestConfig extends QuarkusTask { | ||
|
||
public QuarkusTestConfig() { | ||
super("Sets the necessary system properties for the Quarkus tests to run."); | ||
} | ||
|
||
@TaskAction | ||
public void setupTest() { | ||
final QuarkusPluginExtension quarkusExt = extension(); | ||
try { | ||
final List<AppDependency> deploymentDeps = quarkusExt.resolveAppModel().resolveModel(quarkusExt.getAppArtifact()) | ||
.getDeploymentDependencies(); | ||
final StringBuilder buf = new StringBuilder(); | ||
for (AppDependency dep : deploymentDeps) { | ||
buf.append(dep.getArtifact().getPath().toUri().toURL().toExternalForm()); | ||
buf.append(' '); | ||
} | ||
final String deploymentCp = buf.toString(); | ||
final String nativeRunner = getProject().getBuildDir().toPath().resolve(quarkusExt.finalName() + "-runner") | ||
.toAbsolutePath() | ||
.toString(); | ||
|
||
for (Test test : getProject().getTasks().withType(Test.class)) { | ||
final Map<String, Object> props = test.getSystemProperties(); | ||
props.put(BootstrapClassLoaderFactory.PROP_DEPLOYMENT_CP, deploymentCp); | ||
props.put("native.image.path", nativeRunner); | ||
} | ||
} catch (Exception e) { | ||
throw new IllegalStateException("Failed to resolve deployment classpath", e); | ||
} | ||
} | ||
} |
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
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