{
return this;
}
+ /**
+ * Whether to run in dry run mode.
+ *
+ * Defaults to {@code false}
+ *
+ * @param isDryRun {@code true} or {@code false}
+ * @return this operation instance
+ */
+ public PitestOperation dryRun(boolean isDryRun) {
+ if (isDryRun) {
+ options_.put("--dryRun", TRUE);
+ } else {
+ options_.put("--dryRun", FALSE);
+ }
+ return this;
+ }
+
/**
* List of globs to match against class names. Matching classes will be excluded from mutation.
*
@@ -415,9 +445,10 @@ public class PitestOperation extends AbstractProcessOperation {
if (project_ != null) {
args.add(javaTool());
args.add("-cp");
- args.add(String.format("%s:%s:%s:%s", new File(project_.libTestDirectory(), "*"),
- new File(project_.libCompileDirectory(), "*"), project_.buildMainDirectory(),
- project_.buildTestDirectory()));
+ args.add(buildClassPath(joinClasspathJar(project_.testClasspathJars()),
+ joinClasspathJar(project_.compileClasspathJars()),
+ joinClasspathJar(project_.providedClasspathJars()),
+ project_.buildMainDirectory().getAbsolutePath(), project_.buildTestDirectory().getAbsolutePath()));
args.add("org.pitest.mutationtest.commandline.MutationCoverageReport");
if (!options_.containsKey(SOURCE_DIRS)) {
@@ -432,6 +463,10 @@ public class PitestOperation extends AbstractProcessOperation {
});
}
+ if (LOGGER.isLoggable(Level.FINE)) {
+ LOGGER.fine(String.join(" ", args));
+ }
+
return args;
}
@@ -665,6 +700,14 @@ public class PitestOperation extends AbstractProcessOperation {
return s != null && !s.isBlank();
}
+ private String joinClasspathJar(List jars) {
+ if (!jars.isEmpty()) {
+ return String.join(File.pathSeparator, jars.stream().map(File::getAbsolutePath).toList());
+ } else {
+ return "";
+ }
+ }
+
/**
* Argument string to use when PIT launches child processes. This is most commonly used to increase the amount of
* memory available to the process, but may be used to pass any valid JVM argument.
diff --git a/src/test/java/rife/bld/extension/PitestOperationTest.java b/src/test/java/rife/bld/extension/PitestOperationTest.java
index 82f446c..bb5ed8c 100644
--- a/src/test/java/rife/bld/extension/PitestOperationTest.java
+++ b/src/test/java/rife/bld/extension/PitestOperationTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2023-2024 the original author or authors.
+ * Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,10 @@
package rife.bld.extension;
+import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import rife.bld.BaseProject;
import rife.bld.Project;
import rife.bld.WebProject;
@@ -37,9 +40,9 @@ import static rife.bld.extension.PitestOperation.TRUE;
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class PitestOperationTest {
private static final String AS_LIST = "as list";
- private final static String BAR = "bar";
- private final static String FOO = "foo";
- private final static String FOOBAR = FOO + ',' + BAR;
+ private static final String BAR = "bar";
+ private static final String FOO = "foo";
+ private static final String FOOBAR = FOO + ',' + BAR;
@Test
void argLine() {
@@ -63,6 +66,7 @@ class PitestOperationTest {
}
@Test
+ @EnabledOnOs(OS.LINUX)
void checkAllParameters() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "pitest-args.txt"));
@@ -76,6 +80,7 @@ class PitestOperationTest {
.classPathFile(FOO)
.coverageThreshold(0)
.detectInlinedCode(false)
+ .dryRun(false)
.excludedClasses("class")
.excludedClasses(List.of(FOO, BAR))
.excludedGroups("group")
@@ -121,15 +126,17 @@ class PitestOperationTest {
.verbosity("default")
.executeConstructProcessCommandList();
- for (var p : args) {
- var found = false;
- for (var a : params) {
- if (a.startsWith(p)) {
- found = true;
- break;
+ try (var softly = new AutoCloseableSoftAssertions()) {
+ for (var p : args) {
+ var found = false;
+ for (var a : params) {
+ if (a.startsWith(p)) {
+ found = true;
+ break;
+ }
}
+ softly.assertThat(found).as(p + " not found.").isTrue();
}
- assertThat(found).as(p + " not found.").isTrue();
}
}
diff --git a/src/test/resources/pitest-args.txt b/src/test/resources/pitest-args.txt
index 348f16e..df24bfb 100644
--- a/src/test/resources/pitest-args.txt
+++ b/src/test/resources/pitest-args.txt
@@ -4,6 +4,7 @@
--classPathFile
--coverageThreshold
--detectInlinedCode
+--dryRun
--excludedClasses
--excludedGroups
--excludedMethods