-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto add headless true only using a feature
Pitest automatically adds -Djava.awt.headless=true to the jvm args to prevent keyboard focu being stolen on macs. The change introduces a new extention point ConfigurationUpdater to allow changes to be made to the supplied config. This interface uses the feature system, so implementations can be enabled and disabled at runtime. The previously hard coded adding of headless=true is moved into a feature. It is enabled by default, but can now be dissabled by passing features="-macos_focus" Consideration was given to only adding the param when running on OS X, but this was decided against and it would make the build inconsistent.
- Loading branch information
Henry Coles
committed
Jul 14, 2022
1 parent
206d89d
commit cf684f0
Showing
13 changed files
with
135 additions
and
11 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
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
32 changes: 32 additions & 0 deletions
32
pitest-entry/src/main/java/org/pitest/mutationtest/autoconfig/KeepMacOsFocus.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,32 @@ | ||
package org.pitest.mutationtest.autoconfig; | ||
|
||
import org.pitest.mutationtest.config.ConfigurationUpdater; | ||
import org.pitest.mutationtest.config.ReportOptions; | ||
import org.pitest.plugin.Feature; | ||
|
||
import static java.util.Collections.singletonList; | ||
|
||
/** | ||
* Pitest steals keyboard focus in OSX unless java is launched in | ||
* headless mode. | ||
*/ | ||
public class KeepMacOsFocus implements ConfigurationUpdater { | ||
|
||
@Override | ||
public void updateConfig(ReportOptions toModify) { | ||
toModify.addChildJVMArgs(singletonList("-Djava.awt.headless=true")); | ||
} | ||
|
||
@Override | ||
public Feature provides() { | ||
return Feature.named("MACOS_FOCUS") | ||
.withOnByDefault(true) | ||
.withDescription(description()); | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "Auto add java.awt.headless=true to keep keyboard focus on Mac OS"; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
pitest-entry/src/main/java/org/pitest/mutationtest/config/CompoundConfigurationUpdater.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,34 @@ | ||
package org.pitest.mutationtest.config; | ||
|
||
import org.pitest.plugin.Feature; | ||
import org.pitest.plugin.FeatureSelector; | ||
import org.pitest.plugin.FeatureSetting; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class CompoundConfigurationUpdater implements ConfigurationUpdater { | ||
private final FeatureSelector<ConfigurationUpdater> features; | ||
|
||
public CompoundConfigurationUpdater(List<FeatureSetting> features, | ||
Collection<ConfigurationUpdater> children) { | ||
this.features = new FeatureSelector<>(features, children); | ||
} | ||
|
||
@Override | ||
public void updateConfig(ReportOptions toModify) { | ||
for (ConfigurationUpdater each : features.getActiveFeatures() ) { | ||
each.updateConfig(toModify); | ||
} | ||
} | ||
|
||
@Override | ||
public Feature provides() { | ||
return Feature.named("n/a"); | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "n/a"; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
pitest-entry/src/main/java/org/pitest/mutationtest/config/ConfigurationUpdater.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,8 @@ | ||
package org.pitest.mutationtest.config; | ||
|
||
import org.pitest.plugin.ProvidesFeature; | ||
import org.pitest.plugin.ToolClasspathPlugin; | ||
|
||
public interface ConfigurationUpdater extends ToolClasspathPlugin, ProvidesFeature { | ||
void updateConfig(ReportOptions toModify); | ||
} |
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
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
1 change: 1 addition & 0 deletions
1
.../src/main/resources/META-INF/services/org.pitest.mutationtest.config.ConfigurationUpdater
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 @@ | ||
org.pitest.mutationtest.autoconfig.KeepMacOsFocus |
32 changes: 32 additions & 0 deletions
32
pitest-entry/src/test/java/org/pitest/mutationtest/autoconfig/KeepMacOsFocusTest.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,32 @@ | ||
package org.pitest.mutationtest.autoconfig; | ||
|
||
import org.junit.Test; | ||
import org.pitest.mutationtest.config.ReportOptions; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class KeepMacOsFocusTest { | ||
KeepMacOsFocus underTest = new KeepMacOsFocus(); | ||
|
||
@Test | ||
public void addsHeadlessTrueToJvmArgs() { | ||
ReportOptions data = new ReportOptions(); | ||
|
||
underTest.updateConfig(data); | ||
assertThat(data.getJvmArgs()).contains("-Djava.awt.headless=true"); | ||
} | ||
|
||
@Test | ||
public void featureIsNamedMacOsFocus() { | ||
KeepMacOsFocus underTest = new KeepMacOsFocus(); | ||
|
||
assertThat(underTest.provides().name()).isEqualTo("macos_focus"); | ||
} | ||
|
||
@Test | ||
public void featureIsOnByDefault() { | ||
KeepMacOsFocus underTest = new KeepMacOsFocus(); | ||
|
||
assertThat(underTest.provides().isOnByDefault()).isTrue(); | ||
} | ||
} |
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