Skip to content

Commit 8dfa083

Browse files
committed
Skip JVM tests by default when using nativeTest
1 parent 7c2efd6 commit 8dfa083

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/NativeImagePlugin.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
import java.util.Map;
137137
import java.util.Objects;
138138
import java.util.Set;
139+
import java.util.concurrent.atomic.AtomicBoolean;
139140
import java.util.function.Consumer;
140141
import java.util.function.Predicate;
141142
import java.util.function.Supplier;
@@ -682,7 +683,7 @@ public void registerTestBinary(Project project,
682683
test.systemProperty(JUNIT_PLATFORM_LISTENERS_UID_TRACKING_ENABLED, true);
683684

684685
// Set system property to skip execution of JVM tests before native tests
685-
if (shouldSkipJVMTests(testOptions.getSkipJVMTests().get())) {
686+
if (shouldSkipJVMTests(project, testOptions.getSkipJVMTests())) {
686687
if (graalExtension.getAgent().getEnabled().get()) {
687688
throw new IllegalStateException("Native Image Agent and skipJVMTests cannot be used at the same time.");
688689
}
@@ -724,13 +725,44 @@ public void registerTestBinary(Project project,
724725
});
725726
}
726727

727-
private boolean shouldSkipJVMTests(boolean valueFromBuildFile) {
728+
private boolean isNativeTestTask(Project project) {
729+
List<String> userCalledTasks = project.getGradle().getStartParameter().getTaskNames();
730+
for (var task : userCalledTasks) {
731+
if (task.contains("native") && task.contains("Test")) {
732+
return true;
733+
}
734+
}
735+
736+
return false;
737+
}
738+
private boolean shouldSkipJVMTests(Project project, Property<Boolean> valueFromBuildFile) {
728739
String valueFromCommandLine = System.getProperty("skipJVMTests");
729-
if (valueFromCommandLine == null) {
730-
return valueFromBuildFile;
740+
if (valueFromCommandLine != null) {
741+
// value explicitly set through system property (command line)
742+
boolean val = Boolean.parseBoolean(valueFromCommandLine);
743+
logger.log("Skipping JVM tests execution explicitly set to " + val + " using system property");
744+
745+
return val;
746+
}
747+
748+
if (valueFromBuildFile.isPresent()) {
749+
// value explicitly set through build file
750+
boolean val = valueFromBuildFile.get();
751+
logger.log("Skipping JVM tests execution explicitly set to " + val + " using build file");
752+
753+
return val;
754+
}
755+
756+
List<String> userCalledTasks = project.getGradle().getStartParameter().getTaskNames();
757+
for (String task : userCalledTasks) {
758+
if (task.contains("native") && task.contains("Test")) {
759+
logger.log("Task " + task + " sets skipping JVM tests execution to true");
760+
761+
return true;
762+
}
731763
}
732764

733-
return Boolean.parseBoolean(valueFromCommandLine);
765+
return false;
734766
}
735767

736768
/**

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/dsl/NativeImageCompileOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public interface NativeImageCompileOptions {
234234
*
235235
* @return true if JVM tests should be skipped
236236
*/
237+
@Optional
237238
@Input
238239
Property<Boolean> getSkipJVMTests();
239240

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/BaseNativeImageOptions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ public BaseNativeImageOptions(String name,
276276
getSharedLibrary().convention(false);
277277
getImageName().convention(defaultImageName);
278278
getUseFatJar().convention(false);
279-
getSkipJVMTests().convention(false);
280279
getPgoInstrument().convention(false);
281280
DirectoryProperty pgoProfileDir = objectFactory.directoryProperty();
282281
pgoProfileDir.convention(layout.getProjectDirectory().dir("src/pgo-profiles/" + name));

0 commit comments

Comments
 (0)