Skip to content

Commit 8647580

Browse files
committed
allow plugable mutation groupers
1 parent 08dad91 commit 8647580

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

pitest-entry/src/main/java/org/pitest/mutationtest/build/DefaultMutationGrouperFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.Properties;
44

55
import org.pitest.classpath.CodeSource;
6+
import org.pitest.plugin.Feature;
67

78
public class DefaultMutationGrouperFactory implements MutationGrouperFactory {
89

@@ -17,4 +18,11 @@ public MutationGrouper makeFactory(final Properties props,
1718
return new DefaultGrouper(unitSize);
1819
}
1920

21+
@Override
22+
public Feature provides() {
23+
return Feature.named("defaultgrouper")
24+
.asInternalFeature()
25+
.withOnByDefault(true)
26+
.withDescription(description());
27+
}
2028
}

pitest-entry/src/main/java/org/pitest/mutationtest/build/MutationGrouperFactory.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
import java.util.Properties;
44

55
import org.pitest.classpath.CodeSource;
6+
import org.pitest.plugin.ProvidesFeature;
67
import org.pitest.plugin.ToolClasspathPlugin;
78

8-
public interface MutationGrouperFactory extends ToolClasspathPlugin {
9+
/**
10+
* Groups mutations within units. Additional precautions must be taken to ensure
11+
* JVMS do not become poisoned if mutations from different classes are grouped within
12+
* the same unit. Do not implement unless you understand this and know what you are doing.
13+
*/
14+
public interface MutationGrouperFactory extends ToolClasspathPlugin, ProvidesFeature {
915

1016
MutationGrouper makeFactory(Properties props, CodeSource codeSource,
1117
int numberOfThreads, int unitSize);

pitest-entry/src/main/java/org/pitest/mutationtest/config/PluginServices.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Collection<? extends TestPluginFactory> findTestFrameworkPlugins() {
9595
return load(TestPluginFactory.class);
9696
}
9797

98-
Collection<? extends MutationGrouperFactory> findGroupers() {
98+
Collection<MutationGrouperFactory> findGroupers() {
9999
return load(MutationGrouperFactory.class);
100100
}
101101

pitest-entry/src/main/java/org/pitest/mutationtest/config/SettingsFactory.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,24 @@ public JavaExecutableLocator getJavaExecutable() {
117117
}
118118

119119
public MutationGrouperFactory getMutationGrouper() {
120-
// Grouping behaviour is important. We cannot have more than 1 class mutated within
121-
// a JVM or else the last mutation will poison the next. This restriction can only
122-
// be removed if the hotswap functionality is reworked.
123-
// Grouping behaviour is therefore hard coded for now.
124-
return new DefaultMutationGrouperFactory();
120+
// Grouping behaviour is important. Without additional work to ensure a JVM is
121+
// not poisoned, grouping mutations from different classes together will result
122+
// in incorrect results. Implement with care.
123+
final FeatureParser parser = new FeatureParser();
124+
Collection<MutationGrouperFactory> available = this.plugins.findGroupers();
125+
FeatureSelector<MutationGrouperFactory> features = new FeatureSelector<>(parser.parseFeatures(this.options.getFeatures()), available);
126+
List<MutationGrouperFactory> enabled = features.getActiveFeatures();
127+
128+
if (enabled.isEmpty()) {
129+
return new DefaultMutationGrouperFactory();
130+
}
131+
132+
if (enabled.size() > 1) {
133+
throw new RuntimeException("Only one grouper may be enabled");
134+
}
135+
136+
return enabled.get(0);
137+
125138
}
126139

127140
public CodeSource createCodeSource(ProjectClassPaths classPath) {

0 commit comments

Comments
 (0)