├── .gitattributes ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── src ├── main │ ├── groovy │ │ └── pl │ │ │ └── mjedynak │ │ │ └── idea │ │ │ └── plugins │ │ │ └── pit │ │ │ ├── maven │ │ │ ├── MavenPomReader.groovy │ │ │ └── MavenProjectDeterminer.groovy │ │ │ ├── gradle │ │ │ └── GradleProjectDeterminer.groovy │ │ │ ├── console │ │ │ └── DirectoryReader.groovy │ │ │ ├── ClassPathPopulator.groovy │ │ │ ├── configuration │ │ │ └── PitRunConfigurationStorer.groovy │ │ │ ├── JavaParametersCreator.groovy │ │ │ └── cli │ │ │ └── factory │ │ │ └── DefaultArgumentsContainerPopulator.groovy │ ├── java │ │ └── pl │ │ │ └── mjedynak │ │ │ └── idea │ │ │ └── plugins │ │ │ └── pit │ │ │ ├── cli │ │ │ ├── PitCommandLineArgumentsContainer.java │ │ │ ├── model │ │ │ │ └── PitCommandLineArgument.java │ │ │ ├── PitCommandLineArgumentsContainerImpl.java │ │ │ └── factory │ │ │ │ └── DefaultArgumentsContainerFactory.java │ │ │ ├── actions │ │ │ ├── RunAllPitAction.java │ │ │ ├── PitActionUtils.java │ │ │ ├── PitAction.java │ │ │ ├── DirectoryOrFilePitAction.java │ │ │ ├── RunSomeTestsPitAction.java │ │ │ └── PitTestSomeClassesAction.java │ │ │ ├── configuration │ │ │ ├── PitRunConfigurationFactory.java │ │ │ ├── PitConfigurationType.java │ │ │ └── PitRunConfiguration.java │ │ │ └── gui │ │ │ ├── populator │ │ │ ├── ProgramParametersListPopulator.java │ │ │ └── PitConfigurationFormPopulator.java │ │ │ ├── PitConfigurationForm.form │ │ │ └── PitConfigurationForm.java │ └── resources │ │ └── pit.svg └── test │ └── groovy │ └── pl │ └── mjedynak │ └── idea │ └── plugins │ └── pit │ ├── maven │ ├── MavenPomReaderTest.groovy │ └── MavenProjectDeterminerTest.groovy │ ├── cli │ ├── model │ │ └── PitCommandLineArgumentTest.groovy │ ├── factory │ │ ├── DefaultArgumentsContainerFactoryTest.groovy │ │ └── DefaultArgumentsContainerPopulatorTest.groovy │ └── PitCommandLineArgumentsContainerImplTest.groovy │ ├── ClassPathPopulatorTest.groovy │ ├── gradle │ └── GradleProjectDeterminerTest.groovy │ └── console │ └── DirectoryReaderTest.groovy ├── .github └── workflows │ └── build-gradle-project.yml ├── META-INF ├── pluginIcon.svg └── plugin.xml ├── LICENSE ├── gradlew.bat └── gradlew /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.ipr 3 | *.iws 4 | .idea 5 | .idea/* 6 | .gradle/* 7 | build/* 8 | out/* -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjedynak/pit-idea-plugin/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PIT Idea Plugin ![build](https://github.com/mjedynak/pit-idea-plugin/actions/workflows/build-gradle-project.yml/badge.svg?branch=master) 2 | 3 | 4 | IntelliJ IDEA plugin for PIT mutation testing (http://pitest.org). 5 | 6 | -------------------------------------------------------------------------------- /src/main/groovy/pl/mjedynak/idea/plugins/pit/maven/MavenPomReader.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.maven 2 | 3 | class MavenPomReader { 4 | 5 | String getGroupId(InputStream pomFile) { 6 | Node project = new XmlParser().parse(pomFile) 7 | project.groupId.text() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/cli/PitCommandLineArgumentsContainer.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.cli; 2 | 3 | import pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument; 4 | 5 | public interface PitCommandLineArgumentsContainer { 6 | 7 | void put(PitCommandLineArgument argument, String value); 8 | 9 | String get(PitCommandLineArgument argument); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/groovy/pl/mjedynak/idea/plugins/pit/maven/MavenProjectDeterminer.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.maven 2 | 3 | import com.intellij.openapi.project.Project 4 | import groovy.transform.CompileStatic 5 | import org.jetbrains.annotations.NotNull 6 | 7 | @CompileStatic 8 | class MavenProjectDeterminer { 9 | public static final String POM_FILE = 'pom.xml' 10 | 11 | boolean isMavenProject(@NotNull Project project) { 12 | project.baseDir?.findChild(POM_FILE) != null 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/groovy/pl/mjedynak/idea/plugins/pit/gradle/GradleProjectDeterminer.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.gradle 2 | 3 | import com.intellij.openapi.project.Project 4 | import groovy.transform.CompileStatic 5 | import org.jetbrains.annotations.NotNull 6 | 7 | @CompileStatic 8 | class GradleProjectDeterminer { 9 | 10 | static final String BUILD_GRADLE_FILE = 'build.gradle' 11 | 12 | boolean isGradleProject(@NotNull Project project) { 13 | project.baseDir?.findChild(BUILD_GRADLE_FILE) != null 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/cli/model/PitCommandLineArgument.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.cli.model; 2 | 3 | public enum PitCommandLineArgument { 4 | REPORT_DIR("--reportDir"), 5 | SOURCE_DIRS("--sourceDirs"), 6 | TARGET_CLASSES("--targetClasses"), 7 | TARGET_TESTS("--targetTests"); 8 | 9 | private String name; 10 | 11 | PitCommandLineArgument(String name) { 12 | this.name = name; 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.github/workflows/build-gradle-project.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | gradle: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | - uses: actions/setup-java@v4 15 | with: 16 | distribution: temurin 17 | java-version: 17 18 | 19 | - name: Setup Gradle 20 | uses: gradle/actions/setup-gradle@v3 21 | with: 22 | gradle-version: 8.6 23 | 24 | - name: Execute Gradle build 25 | run: gradle build 26 | -------------------------------------------------------------------------------- /src/main/groovy/pl/mjedynak/idea/plugins/pit/console/DirectoryReader.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.console 2 | 3 | import com.google.common.base.Optional 4 | import groovy.transform.CompileStatic 5 | 6 | @CompileStatic 7 | class DirectoryReader { 8 | 9 | Optional getLatestDirectoryFrom(File parentDir) { 10 | Optional result = Optional.absent() 11 | if (parentDir.isDirectory()) { 12 | List files = parentDir.listFiles().findAll { File f -> f.isDirectory() }.sort { File f -> f.lastModified() } 13 | if (!files.empty) { 14 | result = Optional.of(files[-1]) 15 | } 16 | } 17 | result 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/cli/PitCommandLineArgumentsContainerImpl.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.cli; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | import pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument; 6 | 7 | public class PitCommandLineArgumentsContainerImpl implements PitCommandLineArgumentsContainer { 8 | 9 | private Map map = new ConcurrentHashMap(); 10 | 11 | @Override 12 | public void put(PitCommandLineArgument argument, String value) { 13 | map.put(argument, value); 14 | } 15 | 16 | @Override 17 | public String get(PitCommandLineArgument argument) { 18 | return map.get(argument); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/groovy/pl/mjedynak/idea/plugins/pit/maven/MavenPomReaderTest.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.maven 2 | 3 | import spock.lang.Specification 4 | 5 | class MavenPomReaderTest extends Specification { 6 | 7 | MavenPomReader mavenPomReader = new MavenPomReader() 8 | 9 | def "should read group id from maven pom file"() { 10 | String groupId = 'group' 11 | String pomFileText = """ 12 | $groupId 13 | artifact 14 | 1.0.0 15 | """ 16 | InputStream pomFile = new ByteArrayInputStream(pomFileText.bytes) 17 | when: 18 | String result = mavenPomReader.getGroupId(pomFile) 19 | then: 20 | result == groupId 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/actions/RunAllPitAction.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.actions; 2 | 3 | import com.intellij.openapi.actionSystem.AnActionEvent; 4 | import com.intellij.openapi.actionSystem.DataKeys; 5 | import com.intellij.openapi.project.Project; 6 | import pl.mjedynak.idea.plugins.pit.configuration.PitRunConfiguration; 7 | import pl.mjedynak.idea.plugins.pit.configuration.PitRunConfigurationFactory; 8 | 9 | public class RunAllPitAction extends PitAction { 10 | 11 | protected PitRunConfiguration getConfigurationForActionEvent(final AnActionEvent e) { 12 | final Project project = e.getData(DataKeys.PROJECT); 13 | 14 | final PitRunConfigurationFactory pitRunConfigurationFactory = new PitRunConfigurationFactory(); 15 | return pitRunConfigurationFactory.createConfiguration(project); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/groovy/pl/mjedynak/idea/plugins/pit/cli/model/PitCommandLineArgumentTest.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.cli.model 2 | 3 | import spock.lang.Specification 4 | 5 | class PitCommandLineArgumentTest extends Specification { 6 | 7 | PitCommandLineArgument pitCommandLineArgument 8 | 9 | def "report dir argument is mapped"() { 10 | when: 11 | pitCommandLineArgument = PitCommandLineArgument.REPORT_DIR 12 | 13 | then: 14 | pitCommandLineArgument.name == '--reportDir' 15 | } 16 | 17 | def "source dirs argument is mapped"() { 18 | when: 19 | pitCommandLineArgument = PitCommandLineArgument.SOURCE_DIRS 20 | 21 | then: 22 | pitCommandLineArgument.name == '--sourceDirs' 23 | } 24 | 25 | def "target classes argument is mapped"() { 26 | when: 27 | pitCommandLineArgument = PitCommandLineArgument.TARGET_CLASSES 28 | 29 | then: 30 | pitCommandLineArgument.name == '--targetClasses' 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/resources/pit.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /META-INF/pluginIcon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Michal Jedynak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/cli/factory/DefaultArgumentsContainerFactory.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.cli.factory; 2 | 3 | import com.intellij.openapi.project.Project; 4 | import pl.mjedynak.idea.plugins.pit.cli.PitCommandLineArgumentsContainer; 5 | import pl.mjedynak.idea.plugins.pit.cli.PitCommandLineArgumentsContainerImpl; 6 | 7 | public class DefaultArgumentsContainerFactory { 8 | 9 | private DefaultArgumentsContainerPopulator defaultArgumentsContainerPopulator; 10 | 11 | public DefaultArgumentsContainerFactory(DefaultArgumentsContainerPopulator defaultArgumentsContainerPopulator) { 12 | this.defaultArgumentsContainerPopulator = defaultArgumentsContainerPopulator; 13 | } 14 | 15 | public PitCommandLineArgumentsContainer createDefaultPitCommandLineArgumentsContainer(Project project) { 16 | PitCommandLineArgumentsContainer container = new PitCommandLineArgumentsContainerImpl(); 17 | defaultArgumentsContainerPopulator.addReportDir(project, container); 18 | defaultArgumentsContainerPopulator.addSourceDir(container); 19 | defaultArgumentsContainerPopulator.addTargetClasses(project, container); 20 | return container; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/groovy/pl/mjedynak/idea/plugins/pit/cli/factory/DefaultArgumentsContainerFactoryTest.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.cli.factory 2 | 3 | import com.intellij.openapi.project.Project 4 | import pl.mjedynak.idea.plugins.pit.cli.PitCommandLineArgumentsContainer 5 | import spock.lang.Specification 6 | 7 | class DefaultArgumentsContainerFactoryTest extends Specification { 8 | 9 | DefaultArgumentsContainerPopulator defaultArgumentsContainerPopulator = Mock() 10 | Project project = Mock() 11 | 12 | DefaultArgumentsContainerFactory defaultArgumentsContainerFactory = new DefaultArgumentsContainerFactory(defaultArgumentsContainerPopulator) 13 | 14 | def "should delegate creation to populator"() { 15 | when: 16 | PitCommandLineArgumentsContainer container = defaultArgumentsContainerFactory.createDefaultPitCommandLineArgumentsContainer(project) 17 | 18 | then: 19 | container != null 20 | 1 * defaultArgumentsContainerPopulator.addReportDir(project, _ as PitCommandLineArgumentsContainer) 21 | 1 * defaultArgumentsContainerPopulator.addSourceDir(_ as PitCommandLineArgumentsContainer) 22 | 1 * defaultArgumentsContainerPopulator.addTargetClasses(project, _ as PitCommandLineArgumentsContainer) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/configuration/PitRunConfigurationFactory.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.configuration; 2 | 3 | import com.intellij.openapi.project.Project; 4 | import com.intellij.openapi.roots.ProjectRootManager; 5 | import com.intellij.psi.PsiManager; 6 | import pl.mjedynak.idea.plugins.pit.cli.factory.DefaultArgumentsContainerFactory; 7 | import pl.mjedynak.idea.plugins.pit.cli.factory.DefaultArgumentsContainerPopulator; 8 | 9 | public class PitRunConfigurationFactory { 10 | 11 | public PitRunConfiguration createConfiguration(Project project) { 12 | DefaultArgumentsContainerPopulator defaultArgumentsContainerPopulator = new DefaultArgumentsContainerPopulator( 13 | ProjectRootManager.getInstance(project), PsiManager.getInstance(project)); 14 | DefaultArgumentsContainerFactory defaultArgumentsContainerFactory = 15 | new DefaultArgumentsContainerFactory(defaultArgumentsContainerPopulator); 16 | return new PitRunConfiguration( 17 | "PIT Run Configuration", 18 | project, 19 | PitConfigurationType.getInstance().getConfigurationFactories()[0], 20 | defaultArgumentsContainerFactory); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/groovy/pl/mjedynak/idea/plugins/pit/maven/MavenProjectDeterminerTest.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.maven 2 | 3 | import spock.lang.Specification 4 | import com.intellij.openapi.project.Project 5 | import com.intellij.openapi.vfs.VirtualFile 6 | 7 | class MavenProjectDeterminerTest extends Specification { 8 | 9 | MavenProjectDeterminer projectDeterminer = new MavenProjectDeterminer() 10 | Project project = Mock() 11 | VirtualFile baseDir = Mock() 12 | 13 | def "should determine that project is mavenized if it has pom.xml"() { 14 | project.baseDir >> baseDir 15 | VirtualFile pomFile = Mock() 16 | baseDir.findChild(MavenProjectDeterminer.POM_FILE) >> pomFile 17 | 18 | when: 19 | def result = projectDeterminer.isMavenProject(project) 20 | 21 | then: 22 | result == true 23 | } 24 | 25 | def "should determine that project is not mavenized if pom.xml not found"() { 26 | project.baseDir >> baseDir 27 | 28 | when: 29 | def result = projectDeterminer.isMavenProject(project) 30 | 31 | then: 32 | result == false 33 | } 34 | 35 | def "should determine that project is not mavenized if base dir not found"() { 36 | when: 37 | def result = projectDeterminer.isMavenProject(project) 38 | 39 | then: 40 | result == false 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/groovy/pl/mjedynak/idea/plugins/pit/ClassPathPopulatorTest.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit 2 | 3 | import spock.lang.Specification 4 | 5 | import static pl.mjedynak.idea.plugins.pit.ClassPathPopulator.PITEST_VERSION 6 | import static pl.mjedynak.idea.plugins.pit.ClassPathPopulator.PITEST_JUNIT5_PLUGIN_VERSION 7 | 8 | class ClassPathPopulatorTest extends Specification { 9 | 10 | def "should have the same PIT version as specified in build.gradle"() { 11 | when: 12 | File gradleBuildFile = new File('build.gradle') 13 | String lineWithVersion = gradleBuildFile.filterLine { String line -> line.startsWith('ext.pitVersion') } 14 | String version = lineWithVersion[lineWithVersion.indexOf("'") + 1 .. lineWithVersion.lastIndexOf("'") - 1] 15 | 16 | then: 17 | version == PITEST_VERSION 18 | } 19 | 20 | def "should have the same PIT Junit5 Plugin version as specified in build.gradle"() { 21 | when: 22 | File gradleBuildFile = new File('build.gradle') 23 | String lineWithVersion = gradleBuildFile.filterLine { String line -> line.startsWith('ext.pitJunit5PluginVersion') } 24 | String version = lineWithVersion[lineWithVersion.indexOf("'") + 1 .. lineWithVersion.lastIndexOf("'") - 1] 25 | 26 | then: 27 | version == PITEST_JUNIT5_PLUGIN_VERSION 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/groovy/pl/mjedynak/idea/plugins/pit/gradle/GradleProjectDeterminerTest.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.gradle 2 | 3 | import com.intellij.openapi.project.Project 4 | import com.intellij.openapi.vfs.VirtualFile 5 | import spock.lang.Specification 6 | 7 | class GradleProjectDeterminerTest extends Specification { 8 | 9 | Project project = Mock() 10 | VirtualFile baseDir = Mock() 11 | GradleProjectDeterminer projectDeterminer = new GradleProjectDeterminer() 12 | 13 | def "should determine that project is gradle one if it has build.gradle"() { 14 | project.baseDir >> baseDir 15 | VirtualFile buildGradleFile = Mock() 16 | baseDir.findChild(GradleProjectDeterminer.BUILD_GRADLE_FILE) >> buildGradleFile 17 | 18 | when: 19 | def result = projectDeterminer.isGradleProject(project) 20 | 21 | then: 22 | result == true 23 | } 24 | 25 | def "should determine that project is not gradle one if build.gradle not found"() { 26 | project.baseDir >> baseDir 27 | 28 | when: 29 | def result = projectDeterminer.isGradleProject(project) 30 | 31 | then: 32 | result == false 33 | } 34 | 35 | def "should determine that project is not gradle one if base dir not found"() { 36 | when: 37 | def result = projectDeterminer.isGradleProject(project) 38 | 39 | then: 40 | result == false 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/groovy/pl/mjedynak/idea/plugins/pit/cli/PitCommandLineArgumentsContainerImplTest.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.cli 2 | 3 | import pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument 4 | import spock.lang.Specification 5 | 6 | class PitCommandLineArgumentsContainerImplTest extends Specification { 7 | 8 | PitCommandLineArgumentsContainer pitCommandLineArgumentsContainer = new PitCommandLineArgumentsContainerImpl() 9 | 10 | def "should hold value of command line argument"() { 11 | PitCommandLineArgument argument = PitCommandLineArgument.REPORT_DIR 12 | String reportDir = 'report' 13 | 14 | when: 15 | pitCommandLineArgumentsContainer.put(argument, reportDir) 16 | 17 | then: 18 | pitCommandLineArgumentsContainer.get(argument) == reportDir 19 | } 20 | 21 | def "should hold multiple values of command line arguments"() { 22 | PitCommandLineArgument argument = PitCommandLineArgument.REPORT_DIR 23 | String reportDir = 'report' 24 | PitCommandLineArgument secondArgument = PitCommandLineArgument.SOURCE_DIRS 25 | String sourceDirs = 'src/main/java' 26 | 27 | when: 28 | pitCommandLineArgumentsContainer.put(argument, reportDir) 29 | pitCommandLineArgumentsContainer.put(secondArgument, sourceDirs) 30 | 31 | then: 32 | pitCommandLineArgumentsContainer.get(argument) == reportDir 33 | pitCommandLineArgumentsContainer.get(secondArgument) == sourceDirs 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/groovy/pl/mjedynak/idea/plugins/pit/ClassPathPopulator.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit 2 | 3 | import com.intellij.openapi.application.PathManager 4 | import com.intellij.util.PathsList 5 | import groovy.transform.CompileStatic 6 | 7 | @CompileStatic 8 | class ClassPathPopulator { 9 | 10 | static final String PITEST_VERSION = '1.20.0' 11 | static final String PITEST_JUNIT5_PLUGIN_VERSION = '1.2.3' 12 | static final String SEPARATOR = System.getProperty('file.separator') 13 | static final String PLUGIN_NAME = 'pit-idea-plugin' 14 | static final String LIB_DIR = 'lib' 15 | 16 | void populateClassPathWithPitJar(PathsList classPath) { 17 | String pluginsPath = PathManager.pluginsPath 18 | String path = pluginsPath + SEPARATOR + PLUGIN_NAME + SEPARATOR + LIB_DIR + SEPARATOR 19 | classPath.with { 20 | addFirst(path + "pitest-${PITEST_VERSION}.jar") 21 | addFirst(path + "pitest-command-line-${PITEST_VERSION}.jar") 22 | addFirst(path + "pitest-entry-${PITEST_VERSION}.jar") 23 | addFirst(path + 'commons-lang3-3.12.0.jar') 24 | addFirst(path + 'commons-text-1.10.0.jar') 25 | addFirst(path + "pitest-junit5-plugin-${PITEST_JUNIT5_PLUGIN_VERSION}.jar") 26 | if (noPlatformLauncherDependency(classPath)) { 27 | addFirst(path + 'junit-platform-launcher-1.9.2.jar') 28 | } 29 | } 30 | } 31 | 32 | private static boolean noPlatformLauncherDependency(PathsList classPath) { 33 | return !classPath.pathList.find { it.contains("junit-platform-launcher") } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/groovy/pl/mjedynak/idea/plugins/pit/console/DirectoryReaderTest.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.console 2 | 3 | import com.google.common.base.Optional 4 | import spock.lang.Ignore 5 | import spock.lang.Specification 6 | 7 | import static com.google.common.io.Files.createTempDir 8 | import static java.util.concurrent.TimeUnit.MILLISECONDS 9 | 10 | class DirectoryReaderTest extends Specification { 11 | 12 | DirectoryReader directoryReader = new DirectoryReader() 13 | 14 | @Ignore 15 | def "should read latest directory from given parent directory"() { 16 | File tempDir = createTempDir() 17 | tempDir.deleteOnExit() 18 | File olderDir = new File(tempDir, "older") 19 | olderDir.mkdir() 20 | olderDir.deleteOnExit() 21 | MILLISECONDS.sleep(1) 22 | File newerDir = new File(tempDir, "newer") 23 | newerDir.mkdir() 24 | newerDir.deleteOnExit() 25 | 26 | when: 27 | Optional result = directoryReader.getLatestDirectoryFrom(tempDir) 28 | 29 | then: 30 | result.get() == newerDir 31 | } 32 | 33 | def "should return empty option when no directories in parent directory"() { 34 | File tempDir = createTempDir() 35 | tempDir.deleteOnExit() 36 | 37 | when: 38 | Optional result = directoryReader.getLatestDirectoryFrom(tempDir) 39 | 40 | then: 41 | result.isPresent() == false 42 | } 43 | 44 | def "should return empty option when given incorrect argument"() { 45 | when: 46 | Optional result = directoryReader.getLatestDirectoryFrom(new File('notExistingDirectory')) 47 | 48 | then: 49 | result.isPresent() == false 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/actions/PitActionUtils.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.actions; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.psi.PsiDirectory; 5 | import com.intellij.psi.PsiFile; 6 | import com.intellij.psi.PsiJavaFile; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | public class PitActionUtils { 12 | 13 | private PitActionUtils() {} 14 | 15 | @NotNull 16 | static List getClassNamesForFile(final PsiFile psiFile) { 17 | final List classNames = new ArrayList(); 18 | if (!(psiFile instanceof PsiJavaFile)) { 19 | return classNames; 20 | } 21 | 22 | final PsiJavaFile psiJavaFile = (PsiJavaFile) psiFile; 23 | final PsiClass[] classes = psiJavaFile.getClasses(); 24 | for (final PsiClass pc : classes) { 25 | classNames.add(pc.getQualifiedName()); 26 | } 27 | return classNames; 28 | } 29 | 30 | @NotNull 31 | static List getClassNamesInDirectory(final PsiDirectory psiDirectory) { 32 | final List classNames = new ArrayList(); 33 | if (psiDirectory == null) { 34 | return classNames; 35 | } 36 | 37 | final PsiDirectory[] directories = psiDirectory.getSubdirectories(); 38 | for (final PsiDirectory d : directories) { 39 | classNames.addAll(getClassNamesInDirectory(d)); 40 | } 41 | 42 | final PsiFile[] files = psiDirectory.getFiles(); 43 | for (final PsiFile f : files) { 44 | classNames.addAll(getClassNamesForFile(f)); 45 | } 46 | return classNames; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/groovy/pl/mjedynak/idea/plugins/pit/configuration/PitRunConfigurationStorer.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.configuration 2 | 3 | import groovy.transform.CompileStatic 4 | import org.jdom.Element 5 | import pl.mjedynak.idea.plugins.pit.gui.PitConfigurationForm 6 | 7 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.REPORT_DIR 8 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.SOURCE_DIRS 9 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.TARGET_CLASSES 10 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.TARGET_TESTS 11 | 12 | @CompileStatic 13 | class PitRunConfigurationStorer { 14 | 15 | static final String OTHER_PARAMS = 'otherParams' 16 | 17 | void readExternal(PitConfigurationForm pitConfigurationForm, Element element) { 18 | pitConfigurationForm.setReportDir(element.getAttribute(REPORT_DIR.toString())?.value) 19 | pitConfigurationForm.setSourceDir(element.getAttribute(SOURCE_DIRS.toString())?.value) 20 | pitConfigurationForm.setTargetClasses(element.getAttribute(TARGET_CLASSES.toString())?.value) 21 | pitConfigurationForm.setTargetTests(element.getAttribute(TARGET_TESTS.toString())?.value) 22 | pitConfigurationForm.setOtherParams(element.getAttribute(OTHER_PARAMS)?.value) 23 | } 24 | 25 | void writeExternal(PitConfigurationForm pitConfigurationForm, Element element) { 26 | element.setAttribute(REPORT_DIR.toString(), pitConfigurationForm.reportDir) 27 | element.setAttribute(SOURCE_DIRS.toString(), pitConfigurationForm.sourceDir) 28 | element.setAttribute(TARGET_CLASSES.toString(), pitConfigurationForm.targetClasses) 29 | element.setAttribute(TARGET_TESTS.toString(), pitConfigurationForm.targetTests) 30 | element.setAttribute(OTHER_PARAMS, pitConfigurationForm.otherParams) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/groovy/pl/mjedynak/idea/plugins/pit/JavaParametersCreator.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit 2 | 3 | import com.intellij.execution.configurations.JavaParameters 4 | import com.intellij.execution.configurations.RunConfigurationModule 5 | import com.intellij.execution.util.JavaParametersUtil 6 | import com.intellij.openapi.module.Module 7 | import com.intellij.openapi.module.ModuleManager 8 | import groovy.transform.CompileStatic 9 | import pl.mjedynak.idea.plugins.pit.gui.PitConfigurationForm 10 | import pl.mjedynak.idea.plugins.pit.gui.populator.ProgramParametersListPopulator 11 | 12 | @CompileStatic 13 | class JavaParametersCreator { 14 | 15 | private static final String PIT_MAIN_CLASS = 'org.pitest.mutationtest.commandline.MutationCoverageReport' 16 | 17 | ProgramParametersListPopulator programParametersListPopulator = new ProgramParametersListPopulator() 18 | ClassPathPopulator classPathPopulator = new ClassPathPopulator() 19 | 20 | JavaParameters createJavaParameters(RunConfigurationModule runConfigurationModule, PitConfigurationForm pitConfigurationForm) { 21 | JavaParameters javaParameters = new JavaParameters() 22 | javaParameters.setUseClasspathJar(true) 23 | ModuleManager moduleManager = ModuleManager.getInstance(runConfigurationModule.project) 24 | configureModules(moduleManager, javaParameters) 25 | programParametersListPopulator.populateProgramParametersList(javaParameters.programParametersList, pitConfigurationForm) 26 | javaParameters.setWorkingDirectory(runConfigurationModule.project.getBasePath()) 27 | javaParameters.setMainClass(PIT_MAIN_CLASS) 28 | classPathPopulator.populateClassPathWithPitJar(javaParameters.classPath) 29 | javaParameters 30 | } 31 | 32 | private static void configureModules(ModuleManager moduleManager, JavaParameters javaParameters) { 33 | Module[] modules = moduleManager.modules 34 | modules.each { Module module -> 35 | JavaParametersUtil.configureModule(module, javaParameters, JavaParameters.JDK_AND_CLASSES_AND_TESTS, null) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/actions/PitAction.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.actions; 2 | 3 | import com.intellij.execution.ProgramRunnerUtil; 4 | import com.intellij.execution.executors.DefaultRunExecutor; 5 | import com.intellij.execution.runners.ExecutionEnvironmentBuilder; 6 | import com.intellij.openapi.actionSystem.AnAction; 7 | import com.intellij.openapi.actionSystem.AnActionEvent; 8 | import com.intellij.openapi.actionSystem.DataKeys; 9 | import com.intellij.openapi.module.Module; 10 | import com.intellij.openapi.project.Project; 11 | import org.jetbrains.annotations.NotNull; 12 | import org.jetbrains.annotations.Nullable; 13 | import pl.mjedynak.idea.plugins.pit.configuration.PitRunConfiguration; 14 | 15 | public abstract class PitAction extends AnAction { 16 | 17 | @Override 18 | public void update(@NotNull final AnActionEvent e) { 19 | final Project project = e.getData(DataKeys.PROJECT); 20 | final Module module = e.getData(DataKeys.MODULE); 21 | final boolean available = (project != null) && (module != null); 22 | e.getPresentation().setEnabledAndVisible(available); 23 | } 24 | 25 | @Override 26 | public final void actionPerformed(final AnActionEvent e) { 27 | final Project project = e.getData(DataKeys.PROJECT); 28 | final Module module = e.getData(DataKeys.MODULE); 29 | if (project == null || module == null) { 30 | return; 31 | } 32 | 33 | final PitRunConfiguration pitRunConfiguration = getConfigurationForActionEvent(e); 34 | 35 | if (pitRunConfiguration == null) { 36 | return; 37 | } 38 | 39 | final ExecutionEnvironmentBuilder builder = 40 | ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), pitRunConfiguration); 41 | 42 | ProgramRunnerUtil.executeConfiguration( 43 | builder.contentToReuse(null).dataContext(null).activeTarget().build(), true, true); 44 | } 45 | 46 | @Nullable 47 | abstract PitRunConfiguration getConfigurationForActionEvent(final AnActionEvent e); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/gui/populator/ProgramParametersListPopulator.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.gui.populator; 2 | 3 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.REPORT_DIR; 4 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.SOURCE_DIRS; 5 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.TARGET_CLASSES; 6 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.TARGET_TESTS; 7 | 8 | import com.intellij.execution.configurations.ParametersList; 9 | import pl.mjedynak.idea.plugins.pit.gui.PitConfigurationForm; 10 | 11 | public class ProgramParametersListPopulator { 12 | 13 | public void populateProgramParametersList( 14 | ParametersList programParametersList, PitConfigurationForm pitConfigurationForm) { 15 | addReportDir(programParametersList, pitConfigurationForm); 16 | addSourceDir(programParametersList, pitConfigurationForm); 17 | addTargetClasses(programParametersList, pitConfigurationForm); 18 | addTargetTests(programParametersList, pitConfigurationForm); 19 | addOtherParams(programParametersList, pitConfigurationForm); 20 | } 21 | 22 | private void addReportDir(ParametersList programParametersList, PitConfigurationForm pitConfigurationForm) { 23 | programParametersList.add(REPORT_DIR.getName()); 24 | programParametersList.add(pitConfigurationForm.getReportDir()); 25 | } 26 | 27 | private void addSourceDir(ParametersList programParametersList, PitConfigurationForm pitConfigurationForm) { 28 | programParametersList.add(SOURCE_DIRS.getName()); 29 | programParametersList.add(pitConfigurationForm.getSourceDir()); 30 | } 31 | 32 | private void addTargetClasses(ParametersList programParametersList, PitConfigurationForm pitConfigurationForm) { 33 | programParametersList.add(TARGET_CLASSES.getName()); 34 | programParametersList.add(pitConfigurationForm.getTargetClasses()); 35 | } 36 | 37 | private void addTargetTests(ParametersList programParametersList, PitConfigurationForm pitConfigurationForm) { 38 | /* Only add this parameter if it is set - otherwise default is the target classes */ 39 | if (!pitConfigurationForm.getTargetTests().isEmpty()) { 40 | programParametersList.add(TARGET_TESTS.getName()); 41 | programParametersList.add(pitConfigurationForm.getTargetTests()); 42 | } 43 | } 44 | 45 | private void addOtherParams(ParametersList programParametersList, PitConfigurationForm pitConfigurationForm) { 46 | String otherParams = pitConfigurationForm.getOtherParams(); 47 | String[] namesAndValues = otherParams.split(" "); 48 | for (String param : namesAndValues) { 49 | programParametersList.add(param); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/gui/populator/PitConfigurationFormPopulator.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.gui.populator; 2 | 3 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.REPORT_DIR; 4 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.SOURCE_DIRS; 5 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.TARGET_CLASSES; 6 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.TARGET_TESTS; 7 | 8 | import pl.mjedynak.idea.plugins.pit.cli.PitCommandLineArgumentsContainer; 9 | import pl.mjedynak.idea.plugins.pit.gui.PitConfigurationForm; 10 | 11 | public class PitConfigurationFormPopulator { 12 | 13 | public static final String OTHER_PARAMS = "--outputFormats XML,HTML"; 14 | 15 | public void populateTextFieldsInForm( 16 | PitConfigurationForm pitConfigurationForm, 17 | PitCommandLineArgumentsContainer pitCommandLineArgumentsContainer) { 18 | setReportDir(pitConfigurationForm, pitCommandLineArgumentsContainer); 19 | setSourceDir(pitConfigurationForm, pitCommandLineArgumentsContainer); 20 | setTargetClasses(pitConfigurationForm, pitCommandLineArgumentsContainer); 21 | setTargetTests(pitConfigurationForm, pitCommandLineArgumentsContainer); 22 | setOtherParams(pitConfigurationForm); 23 | } 24 | 25 | private void setTargetClasses( 26 | PitConfigurationForm pitConfigurationForm, 27 | PitCommandLineArgumentsContainer pitCommandLineArgumentsContainer) { 28 | String targetClasses = pitCommandLineArgumentsContainer.get(TARGET_CLASSES); 29 | pitConfigurationForm.setTargetClasses(targetClasses); 30 | } 31 | 32 | private void setTargetTests( 33 | PitConfigurationForm pitConfigurationForm, 34 | PitCommandLineArgumentsContainer pitCommandLineArgumentsContainer) { 35 | String targetTests = pitCommandLineArgumentsContainer.get(TARGET_TESTS); 36 | pitConfigurationForm.setTargetTests(targetTests); 37 | } 38 | 39 | private void setSourceDir( 40 | PitConfigurationForm pitConfigurationForm, 41 | PitCommandLineArgumentsContainer pitCommandLineArgumentsContainer) { 42 | String sourceDir = pitCommandLineArgumentsContainer.get(SOURCE_DIRS); 43 | pitConfigurationForm.setSourceDir(sourceDir); 44 | } 45 | 46 | private void setReportDir( 47 | PitConfigurationForm pitConfigurationForm, 48 | PitCommandLineArgumentsContainer pitCommandLineArgumentsContainer) { 49 | String reportDir = pitCommandLineArgumentsContainer.get(REPORT_DIR); 50 | pitConfigurationForm.setReportDir(reportDir); 51 | } 52 | 53 | private void setOtherParams(PitConfigurationForm pitConfigurationForm) { 54 | pitConfigurationForm.setOtherParams(OTHER_PARAMS); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/actions/DirectoryOrFilePitAction.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.actions; 2 | 3 | import com.intellij.openapi.actionSystem.AnActionEvent; 4 | import com.intellij.openapi.actionSystem.DataKeys; 5 | import com.intellij.openapi.module.Module; 6 | import com.intellij.openapi.project.Project; 7 | import com.intellij.openapi.vfs.VirtualFile; 8 | import com.intellij.psi.PsiDirectory; 9 | import com.intellij.psi.PsiFile; 10 | import com.intellij.psi.PsiManager; 11 | import java.util.List; 12 | import org.jetbrains.annotations.NotNull; 13 | import pl.mjedynak.idea.plugins.pit.configuration.PitRunConfiguration; 14 | 15 | public abstract class DirectoryOrFilePitAction extends PitAction { 16 | 17 | abstract String getTitleForItem(final String item); 18 | 19 | abstract boolean isEnabled( 20 | @NotNull final Project project, @NotNull final Module module, @NotNull final VirtualFile vfile); 21 | 22 | @Override 23 | public void update(@NotNull final AnActionEvent e) { 24 | final Project project = e.getData(DataKeys.PROJECT); 25 | final Module module = e.getData(DataKeys.MODULE); 26 | final VirtualFile vfile = e.getData(DataKeys.VIRTUAL_FILE); 27 | 28 | final boolean enabled = 29 | (project != null) && (module != null) && (vfile != null) && isEnabled(project, module, vfile); 30 | 31 | e.getPresentation().setEnabledAndVisible(enabled); 32 | if (enabled) { 33 | e.getPresentation().setText(getTitleForItem(vfile.getPresentableName())); 34 | } 35 | } 36 | 37 | abstract PitRunConfiguration makeConfigurationForClassList( 38 | @NotNull final String classList, @NotNull final Project project, @NotNull final String title); 39 | 40 | @Override 41 | protected PitRunConfiguration getConfigurationForActionEvent(final AnActionEvent e) { 42 | final Project project = e.getData(DataKeys.PROJECT); 43 | final Module module = e.getData(DataKeys.MODULE); 44 | final VirtualFile vfile = e.getData(DataKeys.VIRTUAL_FILE); 45 | 46 | if ((project == null) || (module == null) || (vfile == null) || !isEnabled(project, module, vfile)) { 47 | return null; 48 | } 49 | 50 | final List classNames; 51 | if (vfile.isDirectory()) { 52 | final PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(vfile); 53 | classNames = PitActionUtils.getClassNamesInDirectory(psiDirectory); 54 | } else { 55 | final PsiFile psiFile = PsiManager.getInstance(project).findFile(vfile); 56 | classNames = PitActionUtils.getClassNamesForFile(psiFile); 57 | } 58 | 59 | if (classNames.isEmpty()) { 60 | return null; 61 | } 62 | 63 | final String joinedString = String.join(",", classNames); 64 | 65 | return makeConfigurationForClassList(joinedString, project, vfile.getPresentableName()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/actions/RunSomeTestsPitAction.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.actions; 2 | 3 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.TARGET_TESTS; 4 | 5 | import com.intellij.openapi.fileTypes.StdFileTypes; 6 | import com.intellij.openapi.module.Module; 7 | import com.intellij.openapi.project.Project; 8 | import com.intellij.openapi.roots.ProjectRootManager; 9 | import com.intellij.openapi.vfs.VirtualFile; 10 | import com.intellij.psi.PsiManager; 11 | import org.jetbrains.annotations.NotNull; 12 | import pl.mjedynak.idea.plugins.pit.cli.PitCommandLineArgumentsContainer; 13 | import pl.mjedynak.idea.plugins.pit.cli.factory.DefaultArgumentsContainerFactory; 14 | import pl.mjedynak.idea.plugins.pit.cli.factory.DefaultArgumentsContainerPopulator; 15 | import pl.mjedynak.idea.plugins.pit.configuration.PitConfigurationType; 16 | import pl.mjedynak.idea.plugins.pit.configuration.PitRunConfiguration; 17 | 18 | /** 19 | * Runs pitest filtered to a directory of test files 20 | */ 21 | public class RunSomeTestsPitAction extends DirectoryOrFilePitAction { 22 | 23 | boolean isEnabled(@NotNull final Project project, @NotNull final Module module, @NotNull final VirtualFile vfile) { 24 | return (vfile.isDirectory() || (vfile.getFileType() == StdFileTypes.JAVA)) 25 | && module.getModuleTestsWithDependentsScope().contains(vfile); 26 | } 27 | 28 | @Override 29 | String getTitleForItem(final String item) { 30 | return "Pitest using tests in '" + item + "'"; 31 | } 32 | 33 | @Override 34 | PitRunConfiguration makeConfigurationForClassList( 35 | @NotNull final String classList, @NotNull final Project project, @NotNull final String title) { 36 | final DefaultArgumentsContainerPopulator defaultArgumentsContainerPopulator = 37 | new DefaultArgumentsContainerPopulator( 38 | ProjectRootManager.getInstance(project), PsiManager.getInstance(project)); 39 | 40 | final DefaultArgumentsContainerFactory defaultArgumentsContainerFactory = 41 | new DefaultArgumentsContainerFactory(defaultArgumentsContainerPopulator) { 42 | @Override 43 | public PitCommandLineArgumentsContainer createDefaultPitCommandLineArgumentsContainer( 44 | final Project proj) { 45 | final PitCommandLineArgumentsContainer container = 46 | super.createDefaultPitCommandLineArgumentsContainer(proj); 47 | container.put(TARGET_TESTS, classList); 48 | return container; 49 | } 50 | }; 51 | 52 | return new PitRunConfiguration( 53 | "PIT using tests in " + title, 54 | project, 55 | PitConfigurationType.getInstance().getConfigurationFactories()[0], 56 | defaultArgumentsContainerFactory); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/configuration/PitConfigurationType.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.configuration; 2 | 3 | import com.intellij.execution.configuration.ConfigurationFactoryEx; 4 | import com.intellij.execution.configurations.ConfigurationFactory; 5 | import com.intellij.execution.configurations.ConfigurationType; 6 | import com.intellij.execution.configurations.ModuleBasedConfiguration; 7 | import com.intellij.execution.configurations.RunConfiguration; 8 | import com.intellij.openapi.extensions.Extensions; 9 | import com.intellij.openapi.project.Project; 10 | import com.intellij.openapi.util.IconLoader; 11 | import com.intellij.util.containers.ContainerUtil; 12 | import javax.swing.*; 13 | import org.jetbrains.annotations.NonNls; 14 | import org.jetbrains.annotations.NotNull; 15 | import org.jetbrains.annotations.Nullable; 16 | 17 | public class PitConfigurationType implements ConfigurationType { 18 | 19 | private static final Icon ICON = IconLoader.getIcon("/pit.svg", PitConfigurationType.class); 20 | private static final String DISPLAY_NAME = "PIT Runner"; 21 | private static final String ID = "PIT"; 22 | private static final String CONFIGURATION_DESCRIPTION = "Executes PIT mutation testing"; 23 | 24 | private final ConfigurationFactory myFactory; 25 | 26 | public PitConfigurationType() { 27 | myFactory = new ConfigurationFactoryEx(this) { 28 | public RunConfiguration createTemplateConfiguration(Project project) { 29 | PitRunConfigurationFactory pitRunConfigurationFactory = new PitRunConfigurationFactory(); 30 | return pitRunConfigurationFactory.createConfiguration(project); 31 | } 32 | 33 | @Override 34 | public Icon getIcon(@NotNull final RunConfiguration configuration) { 35 | return getIcon(); 36 | } 37 | 38 | @Override 39 | public void onNewConfigurationCreated(@NotNull RunConfiguration configuration) { 40 | ((ModuleBasedConfiguration) configuration).onNewConfigurationCreated(); 41 | } 42 | 43 | @Override 44 | public @NotNull @NonNls String getId() { 45 | return getName(); 46 | } 47 | }; 48 | } 49 | 50 | @Override 51 | public String getDisplayName() { 52 | return DISPLAY_NAME; 53 | } 54 | 55 | @Override 56 | public String getConfigurationTypeDescription() { 57 | return CONFIGURATION_DESCRIPTION; 58 | } 59 | 60 | @Override 61 | public Icon getIcon() { 62 | return ICON; 63 | } 64 | 65 | @Override 66 | public ConfigurationFactory[] getConfigurationFactories() { 67 | return new ConfigurationFactory[] {myFactory}; 68 | } 69 | 70 | @Override 71 | @NotNull 72 | public String getId() { 73 | return ID; 74 | } 75 | 76 | @Nullable 77 | public static PitConfigurationType getInstance() { 78 | return ContainerUtil.findInstance(Extensions.getExtensions(CONFIGURATION_TYPE_EP), PitConfigurationType.class); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 1>&2 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 48 | echo. 1>&2 49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 50 | echo location of your Java installation. 1>&2 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 1>&2 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 62 | echo. 1>&2 63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 64 | echo location of your Java installation. 1>&2 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/actions/PitTestSomeClassesAction.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.actions; 2 | 3 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.TARGET_CLASSES; 4 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.TARGET_TESTS; 5 | 6 | import com.intellij.openapi.fileTypes.StdFileTypes; 7 | import com.intellij.openapi.module.Module; 8 | import com.intellij.openapi.project.Project; 9 | import com.intellij.openapi.roots.ProjectRootManager; 10 | import com.intellij.openapi.vfs.VirtualFile; 11 | import com.intellij.psi.PsiManager; 12 | import org.jetbrains.annotations.NotNull; 13 | import pl.mjedynak.idea.plugins.pit.cli.PitCommandLineArgumentsContainer; 14 | import pl.mjedynak.idea.plugins.pit.cli.factory.DefaultArgumentsContainerFactory; 15 | import pl.mjedynak.idea.plugins.pit.cli.factory.DefaultArgumentsContainerPopulator; 16 | import pl.mjedynak.idea.plugins.pit.configuration.PitConfigurationType; 17 | import pl.mjedynak.idea.plugins.pit.configuration.PitRunConfiguration; 18 | 19 | /** 20 | * Runs pitest filtered to a directory of code 21 | */ 22 | public class PitTestSomeClassesAction extends DirectoryOrFilePitAction { 23 | 24 | @Override 25 | String getTitleForItem(final String item) { 26 | return "Pitest classes in '" + item + "'"; 27 | } 28 | 29 | @Override 30 | boolean isEnabled(@NotNull final Project project, @NotNull final Module module, @NotNull final VirtualFile vfile) { 31 | return (vfile.isDirectory() || (vfile.getFileType() == StdFileTypes.JAVA)) 32 | && module.getModuleContentScope().contains(vfile) 33 | && !module.getModuleTestsWithDependentsScope().contains(vfile); 34 | } 35 | 36 | @Override 37 | PitRunConfiguration makeConfigurationForClassList( 38 | @NotNull final String classList, @NotNull final Project project, @NotNull final String title) { 39 | final DefaultArgumentsContainerPopulator defaultArgumentsContainerPopulator = 40 | new DefaultArgumentsContainerPopulator( 41 | ProjectRootManager.getInstance(project), PsiManager.getInstance(project)); 42 | 43 | final DefaultArgumentsContainerFactory defaultArgumentsContainerFactory = 44 | new DefaultArgumentsContainerFactory(defaultArgumentsContainerPopulator) { 45 | @Override 46 | public PitCommandLineArgumentsContainer createDefaultPitCommandLineArgumentsContainer( 47 | final Project proj) { 48 | final PitCommandLineArgumentsContainer container = 49 | super.createDefaultPitCommandLineArgumentsContainer(proj); 50 | container.put(TARGET_CLASSES, classList); 51 | container.put(TARGET_TESTS, "*"); 52 | return container; 53 | } 54 | }; 55 | 56 | return new PitRunConfiguration( 57 | "PIT for classes in " + title, 58 | project, 59 | PitConfigurationType.getInstance().getConfigurationFactories()[0], 60 | defaultArgumentsContainerFactory); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/groovy/pl/mjedynak/idea/plugins/pit/cli/factory/DefaultArgumentsContainerPopulator.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.cli.factory 2 | 3 | import com.intellij.openapi.project.Project 4 | import com.intellij.openapi.roots.ProjectRootManager 5 | import com.intellij.openapi.vfs.VirtualFile 6 | import com.intellij.psi.PsiDirectory 7 | import com.intellij.psi.PsiManager 8 | import groovy.transform.CompileStatic 9 | import pl.mjedynak.idea.plugins.pit.cli.PitCommandLineArgumentsContainer 10 | import pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument 11 | import pl.mjedynak.idea.plugins.pit.gradle.GradleProjectDeterminer 12 | import pl.mjedynak.idea.plugins.pit.maven.MavenPomReader 13 | import pl.mjedynak.idea.plugins.pit.maven.MavenProjectDeterminer 14 | 15 | import static org.apache.commons.lang3.ArrayUtils.isEmpty 16 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.SOURCE_DIRS 17 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.TARGET_CLASSES 18 | 19 | @CompileStatic 20 | class DefaultArgumentsContainerPopulator { 21 | 22 | static final String DEFAULT_REPORT_DIR = 'report' 23 | static final String MAVEN_REPORT_DIR = 'target/report' 24 | static final String GRADLE_REPORT_DIR = 'build/reports/pit' 25 | static final String ALL_CLASSES_SUFFIX = '.*' 26 | 27 | private ProjectRootManager projectRootManager 28 | private PsiManager psiManager 29 | private MavenProjectDeterminer mavenProjectDeterminer = new MavenProjectDeterminer() 30 | private GradleProjectDeterminer gradleProjectDeterminer = new GradleProjectDeterminer() 31 | private MavenPomReader mavenPomReader = new MavenPomReader() 32 | 33 | DefaultArgumentsContainerPopulator(ProjectRootManager projectRootManager, PsiManager psiManager) { 34 | this.projectRootManager = projectRootManager 35 | this.psiManager = psiManager 36 | } 37 | 38 | void addReportDir(Project project, PitCommandLineArgumentsContainer container) { 39 | VirtualFile baseDir = project.baseDir 40 | String reportDir 41 | if (baseDir != null) { 42 | String suffix = DEFAULT_REPORT_DIR 43 | if (mavenProjectDeterminer.isMavenProject(project)) { 44 | suffix = MAVEN_REPORT_DIR 45 | } else if (gradleProjectDeterminer.isGradleProject(project)) { 46 | suffix = GRADLE_REPORT_DIR 47 | } 48 | reportDir = baseDir.path + '/' + suffix 49 | container.put(PitCommandLineArgument.REPORT_DIR, reportDir) 50 | } 51 | } 52 | 53 | void addSourceDir(PitCommandLineArgumentsContainer container) { 54 | VirtualFile[] sourceRoots = projectRootManager.contentSourceRoots 55 | VirtualFile javaSrcFolder = sourceRoots.find { VirtualFile sourceRoot -> 56 | sourceRoot.path.contains('java') 57 | } 58 | if (javaSrcFolder != null) { 59 | container.put(SOURCE_DIRS, javaSrcFolder.path) 60 | } else if (hasAtLeastOneSourceRoot(sourceRoots)) { 61 | String sourceRootPath = sourceRoots[0].path 62 | container.put(SOURCE_DIRS, sourceRootPath) 63 | } 64 | } 65 | 66 | void addTargetClasses(Project project, PitCommandLineArgumentsContainer container) { 67 | if (mavenProjectDeterminer.isMavenProject(project)) { 68 | addTargetClassesForMavenProject(project, container) 69 | } else { 70 | addTargetClassesForNonMavenProject(container) 71 | } 72 | } 73 | 74 | private void addTargetClassesForMavenProject(Project project, PitCommandLineArgumentsContainer container) { 75 | VirtualFile baseDir = project.baseDir 76 | VirtualFile pomVirtualFile = baseDir.findChild(MavenProjectDeterminer.POM_FILE) 77 | String groupId = mavenPomReader.getGroupId(pomVirtualFile.inputStream) 78 | container.put(TARGET_CLASSES, groupId + ALL_CLASSES_SUFFIX) 79 | } 80 | 81 | private void addTargetClassesForNonMavenProject(PitCommandLineArgumentsContainer container) { 82 | VirtualFile[] sourceRoots = projectRootManager.contentSourceRoots 83 | if (hasAtLeastOneSourceRoot(sourceRoots)) { 84 | PsiDirectory directory = psiManager.findDirectory(sourceRoots[0]) 85 | addTargetClassesIfDirectoryExists(container, directory) 86 | } 87 | } 88 | 89 | private static void addTargetClassesIfDirectoryExists(PitCommandLineArgumentsContainer container, PsiDirectory directory) { 90 | if (directory != null) { 91 | PsiDirectory[] subdirectories = directory.subdirectories 92 | if (hasAtLeastOneSubdirectory(subdirectories)) { 93 | container.put(TARGET_CLASSES, subdirectories[0].name + ALL_CLASSES_SUFFIX) 94 | } 95 | } 96 | } 97 | 98 | private static boolean hasAtLeastOneSourceRoot(VirtualFile[] sourceRoots) { 99 | !isEmpty(sourceRoots) 100 | } 101 | 102 | private static boolean hasAtLeastOneSubdirectory(PsiDirectory[] subdirectories) { 103 | !isEmpty(subdirectories) 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/gui/PitConfigurationForm.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 |
99 | -------------------------------------------------------------------------------- /src/test/groovy/pl/mjedynak/idea/plugins/pit/cli/factory/DefaultArgumentsContainerPopulatorTest.groovy: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.cli.factory 2 | 3 | import com.intellij.openapi.project.Project 4 | import com.intellij.openapi.roots.ProjectRootManager 5 | import com.intellij.openapi.vfs.VirtualFile 6 | import com.intellij.psi.PsiDirectory 7 | import com.intellij.psi.PsiManager 8 | import pl.mjedynak.idea.plugins.pit.cli.PitCommandLineArgumentsContainer 9 | import pl.mjedynak.idea.plugins.pit.cli.PitCommandLineArgumentsContainerImpl 10 | import pl.mjedynak.idea.plugins.pit.gradle.GradleProjectDeterminer 11 | import pl.mjedynak.idea.plugins.pit.maven.MavenPomReader 12 | import pl.mjedynak.idea.plugins.pit.maven.MavenProjectDeterminer 13 | import spock.lang.Ignore 14 | import spock.lang.Specification 15 | 16 | import static DefaultArgumentsContainerPopulator.ALL_CLASSES_SUFFIX 17 | import static DefaultArgumentsContainerPopulator.DEFAULT_REPORT_DIR 18 | import static DefaultArgumentsContainerPopulator.MAVEN_REPORT_DIR 19 | import static MavenProjectDeterminer.POM_FILE 20 | import static pl.mjedynak.idea.plugins.pit.cli.factory.DefaultArgumentsContainerPopulator.GRADLE_REPORT_DIR 21 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.REPORT_DIR 22 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.SOURCE_DIRS 23 | import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.TARGET_CLASSES 24 | 25 | class DefaultArgumentsContainerPopulatorTest extends Specification { 26 | 27 | Project project = Mock() 28 | ProjectRootManager projectRootManager = Mock() 29 | PsiManager psiManager = Mock() 30 | MavenProjectDeterminer mavenProjectDeterminer = Mock() 31 | GradleProjectDeterminer gradleProjectDeterminer = Mock() 32 | MavenPomReader mavenPomReader = Mock() 33 | DefaultArgumentsContainerPopulator defaultArgumentsContainerPopulator = new DefaultArgumentsContainerPopulator(projectRootManager, psiManager) 34 | PitCommandLineArgumentsContainer container = new PitCommandLineArgumentsContainerImpl() 35 | 36 | def setup() { 37 | defaultArgumentsContainerPopulator.mavenProjectDeterminer = mavenProjectDeterminer 38 | defaultArgumentsContainerPopulator.mavenPomReader = mavenPomReader 39 | defaultArgumentsContainerPopulator.gradleProjectDeterminer = gradleProjectDeterminer 40 | } 41 | 42 | def "should create container with default report dir"() { 43 | String baseDirPath = 'app' 44 | VirtualFile baseDir = Mock() 45 | project.baseDir >> baseDir 46 | baseDir.path >> baseDirPath 47 | 48 | when: 49 | defaultArgumentsContainerPopulator.addReportDir(project, container) 50 | 51 | then: 52 | container.get(REPORT_DIR) == baseDirPath + '/' + DEFAULT_REPORT_DIR 53 | } 54 | 55 | def "should create container with maven default report dir for maven project"() { 56 | String baseDirPath = 'app' 57 | VirtualFile baseDir = Mock() 58 | project.baseDir >> baseDir 59 | baseDir.path >> baseDirPath 60 | mavenProjectDeterminer.isMavenProject(project) >> true 61 | 62 | when: 63 | defaultArgumentsContainerPopulator.addReportDir(project, container) 64 | 65 | then: 66 | container.get(REPORT_DIR) == baseDirPath + '/' + MAVEN_REPORT_DIR 67 | } 68 | 69 | def "should create container with gradle default report dir for gradle project"() { 70 | String baseDirPath = 'app' 71 | VirtualFile baseDir = Mock() 72 | project.baseDir >> baseDir 73 | baseDir.path >> baseDirPath 74 | gradleProjectDeterminer.isGradleProject(project) >> true 75 | 76 | when: 77 | defaultArgumentsContainerPopulator.addReportDir(project, container) 78 | 79 | then: 80 | container.get(REPORT_DIR) == baseDirPath + '/' + GRADLE_REPORT_DIR 81 | } 82 | 83 | def "should create container with default source dir"() { 84 | VirtualFile sourceRoot = Mock() 85 | VirtualFile[] sourceRoots = [sourceRoot] 86 | projectRootManager.contentSourceRoots >> sourceRoots 87 | String path = 'somePath' 88 | sourceRoot.path >> path 89 | 90 | when: 91 | defaultArgumentsContainerPopulator.addSourceDir(container) 92 | 93 | then: 94 | container.get(SOURCE_DIRS) == path 95 | } 96 | 97 | def "should prefer java as source dir"() { 98 | VirtualFile firstSourceRoot = Mock() 99 | VirtualFile secondSourceRoot = Mock() 100 | VirtualFile[] sourceRoots = [ 101 | firstSourceRoot, 102 | secondSourceRoot 103 | ] 104 | projectRootManager.contentSourceRoots >> sourceRoots 105 | String firstPath = 'src/main/resources' 106 | String secondPath = 'src/main/java' 107 | firstSourceRoot.path >> firstPath 108 | secondSourceRoot.path >> secondPath 109 | 110 | when: 111 | defaultArgumentsContainerPopulator.addSourceDir(container) 112 | 113 | then: 114 | container.get(SOURCE_DIRS) == secondPath 115 | } 116 | 117 | @Ignore 118 | def "should create container with default target classes"() { 119 | VirtualFile sourceRoot = Mock() 120 | PsiDirectory directory = Mock() 121 | PsiDirectory subdirectory = Mock() 122 | String packageName = 'com' 123 | VirtualFile[] sourceRoots = [sourceRoot] 124 | PsiDirectory[] subdirectories = [subdirectory] 125 | projectRootManager.contentSourceRoots >> sourceRoots 126 | sourceRoot.path >> 'anyPath' 127 | psiManager.findDirectory(sourceRoot) >> directory 128 | directory.subdirectories >> subdirectories 129 | subdirectory.name >> packageName 130 | 131 | when: 132 | defaultArgumentsContainerPopulator.addTargetClasses(project, container) 133 | 134 | then: 135 | container.get(TARGET_CLASSES) == packageName + ALL_CLASSES_SUFFIX 136 | } 137 | 138 | def "should create container with target classes from group id for maven project"() { 139 | VirtualFile baseDir = Mock() 140 | VirtualFile pomVirtualFile = Mock() 141 | InputStream pomFile = Mock() 142 | String groupId = 'pl.mjedynak' 143 | 144 | project.baseDir >> baseDir 145 | baseDir.findChild(POM_FILE) >> pomVirtualFile 146 | pomVirtualFile.inputStream >> pomFile 147 | mavenProjectDeterminer.isMavenProject(project) >> true 148 | mavenPomReader.getGroupId(pomFile) >> groupId 149 | 150 | when: 151 | defaultArgumentsContainerPopulator.addTargetClasses(project, container) 152 | 153 | then: 154 | container.get(TARGET_CLASSES) == groupId + ALL_CLASSES_SUFFIX 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | PIT Mutation Testing 3 | PIT mutation testing Idea plugin 4 | 7 | Bundled with PIT 1.20.0 and JUnit5 plugin 1.2.3 8 |

9 | Adds a 'Run configuration' that allows to execute PIT within IDE. 10 |

11 | Usage: Run->Edit Configurations->Defaults->Pit Runner 12 |

13 | ]]>
14 | 1.4.11 15 | 16 | 19 |
    20 |
  • Upgrade PIT version to 1.20.0 and JUnit5 plugin to 1.2.3
  • 21 |
22 | version 1.4.10 23 |
24 |
    25 |
  • Upgrade PIT version to 1.15.8
  • 26 |
  • Add required junit-platform-launcher dependency to classpath if it's not already present
  • 27 |
28 | version 1.4.9 29 |
30 |
    31 |
  • Upgrade PIT version to 1.15.2 and JUnit5 plugin to 1.2.1
  • 32 |
33 | version 1.4.8 34 |
35 |
    36 |
  • Upgrade PIT version to 1.11.6 and JUnit5 plugin to 1.1.2
  • 37 |
38 | version 1.4.7 39 |
40 |
    41 |
  • Upgrade PIT version to 1.9.5 and JUnit5 plugin to 1.0.0
  • 42 |
  • Visual additions and adjustments (contribution by JoaoCipriano)
  • 43 |
44 | version 1.4.6 45 |
46 |
    47 |
  • Upgrade PIT version to 1.7.4 and JUnit5 plugin to 0.15
  • 48 |
49 | version 1.4.5 50 |
51 |
    52 |
  • Upgrade PIT version to 1.6.3
  • 53 |
  • Improve JUnit 5 support (issue #46) (contribution by kbradl16)
  • 54 |
55 | version 1.4.4 56 |
57 | 61 | version 1.4.3 62 |
63 |
    64 |
  • Allow long classpath when running mutation tests (issue #31)
  • 65 |
66 | version 1.4.2 67 |
68 |
    69 |
  • Upgrade PIT version to 1.5.1
  • 70 |
71 | version 1.4.1 72 |
73 |
    74 |
  • Set working directory to project base path (issue #26) (contribution by mduggan)
  • 75 |
  • Add context menu actions allowing options for easier running (issue #6) (contribution by mduggan)
  • 76 |
77 | version 1.4.0 78 |
79 | 82 | version 1.3.10 83 |
84 |
    85 |
  • Upgrade PIT version to 1.4.3
  • 86 |
87 | version 1.3.9 88 |
89 |
    90 |
  • Upgrade PIT version to 1.4.2
  • 91 |
92 | version 1.3.8 93 |
94 | 97 | version 1.3.7 98 |
99 |
    100 |
  • Compatible IntelliJ version specified correctly
  • 101 |
102 | version 1.3.6 103 |
104 |
    105 |
  • Upgrade PIT version to 1.2.4
  • 106 |
107 | version 1.3.5 108 |
109 |
    110 |
  • Upgrade PIT version to 1.1.9
  • 111 |
112 | version 1.3.4 113 |
114 |
    115 |
  • Upgrade PIT version to 1.1.4
  • 116 |
117 | version 1.3.3 118 |
119 |
    120 |
  • Upgrade PIT version to 1.0.0
  • 121 |
122 | version 1.3.2 123 |
124 | 127 | version 1.3.1 128 |
129 |
    130 |
  • Default source dir is now preferred if it contains 'java' keyword
  • 131 |
132 | version 1.3.0 133 |
134 |
    135 |
  • PIT distribution is now bundled
  • 136 |
  • Report dir parameter for gradle project is set to 'build/reports/pit' by default
  • 137 |
  • PIT run configuration is now correctly saved
  • 138 |
139 | version 1.2.2 140 |
141 |
    142 |
  • Fixed a bug that caused throwing NPE during directory reading
  • 143 |
144 | version 1.2.1 145 |
146 |
    147 |
  • Small performance improvements, tested against PIT 0.30
  • 148 |
149 | version 1.2.0 150 |
151 |
    152 |
  • Pit output console produces a clickable link to the report
  • 153 |
154 | version 1.1.0 155 |
156 |
    157 |
  • Report dir parameter for maven project is set to 'target/report' by default
  • 158 |
  • Target classes parameter for maven project is set to 'groupId' by default
  • 159 |
160 | ]]> 161 |
162 | 163 | Michal Jedynak 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 179 | 180 | 181 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | com.intellij.modules.java 191 |
-------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/configuration/PitRunConfiguration.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.configuration; 2 | 3 | import static org.apache.commons.lang3.StringUtils.isEmpty; 4 | 5 | import com.google.common.base.Optional; 6 | import com.intellij.execution.DefaultExecutionResult; 7 | import com.intellij.execution.ExecutionBundle; 8 | import com.intellij.execution.ExecutionException; 9 | import com.intellij.execution.ExecutionResult; 10 | import com.intellij.execution.Executor; 11 | import com.intellij.execution.JavaRunConfigurationExtensionManager; 12 | import com.intellij.execution.configurations.ConfigurationFactory; 13 | import com.intellij.execution.configurations.JavaCommandLineState; 14 | import com.intellij.execution.configurations.JavaParameters; 15 | import com.intellij.execution.configurations.JavaRunConfigurationModule; 16 | import com.intellij.execution.configurations.ModuleBasedConfiguration; 17 | import com.intellij.execution.configurations.RunConfiguration; 18 | import com.intellij.execution.configurations.RunConfigurationModule; 19 | import com.intellij.execution.configurations.RunProfileState; 20 | import com.intellij.execution.filters.TextConsoleBuilderFactory; 21 | import com.intellij.execution.process.OSProcessHandler; 22 | import com.intellij.execution.process.ProcessAdapter; 23 | import com.intellij.execution.process.ProcessEvent; 24 | import com.intellij.execution.process.ProcessHandler; 25 | import com.intellij.execution.runners.ExecutionEnvironment; 26 | import com.intellij.execution.runners.ProgramRunner; 27 | import com.intellij.execution.ui.ConsoleView; 28 | import com.intellij.ide.browsers.OpenUrlHyperlinkInfo; 29 | import com.intellij.openapi.module.Module; 30 | import com.intellij.openapi.module.ModuleManager; 31 | import com.intellij.openapi.module.ModuleUtil; 32 | import com.intellij.openapi.options.SettingsEditor; 33 | import com.intellij.openapi.options.SettingsEditorGroup; 34 | import com.intellij.openapi.project.Project; 35 | import com.intellij.openapi.util.InvalidDataException; 36 | import com.intellij.openapi.util.WriteExternalException; 37 | import com.intellij.psi.search.GlobalSearchScope; 38 | import java.io.File; 39 | import java.util.Arrays; 40 | import java.util.Collection; 41 | import org.jdom.Element; 42 | import org.jetbrains.annotations.NotNull; 43 | import pl.mjedynak.idea.plugins.pit.JavaParametersCreator; 44 | import pl.mjedynak.idea.plugins.pit.cli.PitCommandLineArgumentsContainer; 45 | import pl.mjedynak.idea.plugins.pit.cli.factory.DefaultArgumentsContainerFactory; 46 | import pl.mjedynak.idea.plugins.pit.console.DirectoryReader; 47 | import pl.mjedynak.idea.plugins.pit.gui.PitConfigurationForm; 48 | import pl.mjedynak.idea.plugins.pit.gui.populator.PitConfigurationFormPopulator; 49 | 50 | public class PitRunConfiguration extends ModuleBasedConfiguration implements RunConfiguration { 51 | 52 | private PitConfigurationForm pitConfigurationForm = new PitConfigurationForm(); 53 | private PitConfigurationFormPopulator pitConfigurationFormPopulator = new PitConfigurationFormPopulator(); 54 | private DirectoryReader directoryReader = new DirectoryReader(); 55 | private JavaParametersCreator javaParametersCreator = new JavaParametersCreator(); 56 | private DefaultArgumentsContainerFactory defaultArgumentsContainerFactory; 57 | private PitRunConfigurationStorer pitRunConfigurationStorer = new PitRunConfigurationStorer(); 58 | 59 | public PitRunConfiguration( 60 | String name, 61 | Project project, 62 | ConfigurationFactory configurationFactory, 63 | DefaultArgumentsContainerFactory defaultArgumentsContainerFactory) { 64 | super(name, new JavaRunConfigurationModule(project, false), configurationFactory); 65 | this.defaultArgumentsContainerFactory = defaultArgumentsContainerFactory; 66 | } 67 | 68 | @Override 69 | public SettingsEditor getConfigurationEditor() { 70 | populateFormIfNeeded(); 71 | SettingsEditorGroup group = new SettingsEditorGroup(); 72 | group.addEditor(ExecutionBundle.message("run.configuration.configuration.tab.title"), pitConfigurationForm); 73 | JavaRunConfigurationExtensionManager.getInstance().appendEditors(this, group); 74 | return group; 75 | } 76 | 77 | @Override 78 | public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) 79 | throws ExecutionException { 80 | JavaCommandLineState javaCommandLineState = new JavaCommandLineState(env) { 81 | private ConsoleView consoleView; 82 | 83 | @Override 84 | protected JavaParameters createJavaParameters() throws ExecutionException { 85 | RunConfigurationModule runConfigurationModule = getConfigurationModule(); 86 | if (runConfigurationModule.getModule() 87 | == null) { // on IDEA fresh start, module can't be found in previously saved configuration 88 | Module module = ModuleUtil.findModuleForFile(getProject().getProjectFile(), getProject()); 89 | runConfigurationModule.setModule(module); 90 | populateFormIfNeeded(); 91 | } 92 | return javaParametersCreator.createJavaParameters(runConfigurationModule, pitConfigurationForm); 93 | } 94 | 95 | @NotNull 96 | @Override 97 | protected OSProcessHandler startProcess() throws ExecutionException { 98 | OSProcessHandler handler = super.startProcess(); 99 | handler.addProcessListener(new ProcessAdapter() { 100 | public void processTerminated(ProcessEvent event) { 101 | // TODO: parse result and highlight lines 102 | Optional reportDirectory = 103 | directoryReader.getLatestDirectoryFrom(new File(pitConfigurationForm.getReportDir())); 104 | if (reportDirectory.isPresent()) { 105 | String reportLink = 106 | "file:///" + reportDirectory.get().getAbsolutePath() + "/index.html"; 107 | consoleView.printHyperlink("Open report in browser", new OpenUrlHyperlinkInfo(reportLink)); 108 | } 109 | } 110 | }); 111 | return handler; 112 | } 113 | 114 | @NotNull 115 | @Override 116 | public ExecutionResult execute(@NotNull final Executor executor, @NotNull final ProgramRunner runner) 117 | throws ExecutionException { 118 | ProcessHandler processHandler = startProcess(); 119 | ConsoleView console = createConsole(executor); 120 | if (console != null) { 121 | console.attachToProcess(processHandler); 122 | } 123 | this.consoleView = console; 124 | return new DefaultExecutionResult( 125 | console, processHandler, createActions(console, processHandler, executor)); 126 | } 127 | }; 128 | javaCommandLineState.setConsoleBuilder( 129 | TextConsoleBuilderFactory.getInstance().createBuilder(getProject())); 130 | return javaCommandLineState; 131 | } 132 | 133 | @Override 134 | public Collection getValidModules() { 135 | return Arrays.asList(ModuleManager.getInstance(getProject()).getModules()); 136 | } 137 | 138 | @Override 139 | protected ModuleBasedConfiguration createInstance() { 140 | PitRunConfigurationFactory pitRunConfigurationFactory = new PitRunConfigurationFactory(); 141 | return pitRunConfigurationFactory.createConfiguration(getProject()); 142 | } 143 | 144 | private void populateFormIfNeeded() { 145 | if (formIsEmpty()) { 146 | PitCommandLineArgumentsContainer container = 147 | defaultArgumentsContainerFactory.createDefaultPitCommandLineArgumentsContainer(getProject()); 148 | pitConfigurationFormPopulator.populateTextFieldsInForm(pitConfigurationForm, container); 149 | } 150 | } 151 | 152 | private boolean formIsEmpty() { 153 | return isEmpty(pitConfigurationForm.getReportDir()) 154 | && isEmpty(pitConfigurationForm.getSourceDir()) 155 | && isEmpty(pitConfigurationForm.getTargetClasses()) 156 | && isEmpty(pitConfigurationForm.getOtherParams()); 157 | } 158 | 159 | @Override 160 | public GlobalSearchScope getSearchScope() { 161 | return null; 162 | } 163 | 164 | @Override 165 | public void readExternal(final Element element) throws InvalidDataException { 166 | super.readExternal(element); 167 | pitRunConfigurationStorer.readExternal(pitConfigurationForm, element); 168 | } 169 | 170 | @Override 171 | public void writeExternal(final Element element) throws WriteExternalException { 172 | pitRunConfigurationStorer.writeExternal(pitConfigurationForm, element); 173 | super.writeExternal(element); 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC2039,SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC2039,SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | -------------------------------------------------------------------------------- /src/main/java/pl/mjedynak/idea/plugins/pit/gui/PitConfigurationForm.java: -------------------------------------------------------------------------------- 1 | package pl.mjedynak.idea.plugins.pit.gui; 2 | 3 | import com.intellij.openapi.options.ConfigurationException; 4 | import com.intellij.openapi.options.SettingsEditor; 5 | import com.intellij.uiDesigner.core.GridConstraints; 6 | import com.intellij.uiDesigner.core.GridLayoutManager; 7 | import com.intellij.uiDesigner.core.Spacer; 8 | import java.awt.Dimension; 9 | import java.awt.Insets; 10 | import javax.swing.JComponent; 11 | import javax.swing.JLabel; 12 | import javax.swing.JPanel; 13 | import javax.swing.JTextField; 14 | import org.jetbrains.annotations.NotNull; 15 | import pl.mjedynak.idea.plugins.pit.configuration.PitRunConfiguration; 16 | 17 | public class PitConfigurationForm extends SettingsEditor { 18 | 19 | private JPanel panel; 20 | private JLabel targetClassesLabel; 21 | private JTextField targetClassesTextField; 22 | private JLabel sourceDirLabel; 23 | private JTextField sourceDirTextField; 24 | private JLabel reportDirLabel; 25 | private JTextField reportDirTextField; 26 | private JTextField otherParamsTextField; 27 | private JLabel otherParamsLabel; 28 | private JTextField targetTestsTextField; 29 | private JLabel targetTestsLabel; 30 | 31 | public String getReportDir() { 32 | return reportDirTextField.getText(); 33 | } 34 | 35 | public String getSourceDir() { 36 | return sourceDirTextField.getText(); 37 | } 38 | 39 | public String getTargetClasses() { 40 | return targetClassesTextField.getText(); 41 | } 42 | 43 | public String getTargetTests() { 44 | return targetTestsTextField.getText(); 45 | } 46 | 47 | public String getOtherParams() { 48 | return otherParamsTextField.getText(); 49 | } 50 | 51 | public void setReportDir(String reportDir) { 52 | reportDirTextField.setText(reportDir); 53 | } 54 | 55 | public void setSourceDir(String sourceDir) { 56 | sourceDirTextField.setText(sourceDir); 57 | } 58 | 59 | public void setTargetClasses(String targetClasses) { 60 | targetClassesTextField.setText(targetClasses); 61 | } 62 | 63 | public void setTargetTests(String targetTests) { 64 | targetTestsTextField.setText(targetTests); 65 | } 66 | 67 | public void setOtherParams(String otherParams) { 68 | otherParamsTextField.setText(otherParams); 69 | } 70 | 71 | @Override 72 | protected void resetEditorFrom(PitRunConfiguration s) {} 73 | 74 | @Override 75 | protected void applyEditorTo(PitRunConfiguration s) throws ConfigurationException {} 76 | 77 | @NotNull 78 | @Override 79 | protected JComponent createEditor() { 80 | return panel; 81 | } 82 | 83 | @Override 84 | protected void disposeEditor() {} 85 | 86 | { 87 | // GUI initializer generated by IntelliJ IDEA GUI Designer 88 | // >>> IMPORTANT!! <<< 89 | // DO NOT EDIT OR ADD ANY CODE HERE! 90 | $$$setupUI$$$(); 91 | } 92 | 93 | /** 94 | * Method generated by IntelliJ IDEA GUI Designer 95 | * >>> IMPORTANT!! <<< 96 | * DO NOT edit this method OR call it in your code! 97 | * 98 | * @noinspection ALL 99 | */ 100 | private void $$$setupUI$$$() { 101 | panel = new JPanel(); 102 | panel.setLayout(new GridLayoutManager(5, 2, new Insets(0, 0, 0, 0), -1, -1)); 103 | targetClassesTextField = new JTextField(); 104 | panel.add( 105 | targetClassesTextField, 106 | new GridConstraints( 107 | 0, 108 | 1, 109 | 1, 110 | 1, 111 | GridConstraints.ANCHOR_WEST, 112 | GridConstraints.FILL_HORIZONTAL, 113 | GridConstraints.SIZEPOLICY_WANT_GROW, 114 | GridConstraints.SIZEPOLICY_FIXED, 115 | null, 116 | new Dimension(150, -1), 117 | null, 118 | 0, 119 | false)); 120 | final Spacer spacer1 = new Spacer(); 121 | panel.add( 122 | spacer1, 123 | new GridConstraints( 124 | 4, 125 | 0, 126 | 1, 127 | 1, 128 | GridConstraints.ANCHOR_CENTER, 129 | GridConstraints.FILL_VERTICAL, 130 | 1, 131 | GridConstraints.SIZEPOLICY_WANT_GROW, 132 | null, 133 | null, 134 | null, 135 | 0, 136 | false)); 137 | targetClassesLabel = new JLabel(); 138 | targetClassesLabel.setText("Target classes"); 139 | panel.add( 140 | targetClassesLabel, 141 | new GridConstraints( 142 | 0, 143 | 0, 144 | 1, 145 | 1, 146 | GridConstraints.ANCHOR_WEST, 147 | GridConstraints.FILL_NONE, 148 | GridConstraints.SIZEPOLICY_FIXED, 149 | GridConstraints.SIZEPOLICY_FIXED, 150 | null, 151 | null, 152 | null, 153 | 0, 154 | false)); 155 | sourceDirTextField = new JTextField(); 156 | panel.add( 157 | sourceDirTextField, 158 | new GridConstraints( 159 | 1, 160 | 1, 161 | 1, 162 | 1, 163 | GridConstraints.ANCHOR_WEST, 164 | GridConstraints.FILL_HORIZONTAL, 165 | GridConstraints.SIZEPOLICY_WANT_GROW, 166 | GridConstraints.SIZEPOLICY_FIXED, 167 | null, 168 | new Dimension(150, -1), 169 | null, 170 | 0, 171 | false)); 172 | sourceDirLabel = new JLabel(); 173 | sourceDirLabel.setText("Source dir"); 174 | panel.add( 175 | sourceDirLabel, 176 | new GridConstraints( 177 | 1, 178 | 0, 179 | 1, 180 | 1, 181 | GridConstraints.ANCHOR_WEST, 182 | GridConstraints.FILL_NONE, 183 | GridConstraints.SIZEPOLICY_FIXED, 184 | GridConstraints.SIZEPOLICY_FIXED, 185 | null, 186 | null, 187 | null, 188 | 0, 189 | false)); 190 | reportDirTextField = new JTextField(); 191 | panel.add( 192 | reportDirTextField, 193 | new GridConstraints( 194 | 2, 195 | 1, 196 | 1, 197 | 1, 198 | GridConstraints.ANCHOR_WEST, 199 | GridConstraints.FILL_HORIZONTAL, 200 | GridConstraints.SIZEPOLICY_WANT_GROW, 201 | GridConstraints.SIZEPOLICY_FIXED, 202 | null, 203 | new Dimension(150, -1), 204 | null, 205 | 0, 206 | false)); 207 | reportDirLabel = new JLabel(); 208 | reportDirLabel.setText("Report dir"); 209 | panel.add( 210 | reportDirLabel, 211 | new GridConstraints( 212 | 2, 213 | 0, 214 | 1, 215 | 1, 216 | GridConstraints.ANCHOR_WEST, 217 | GridConstraints.FILL_NONE, 218 | GridConstraints.SIZEPOLICY_FIXED, 219 | GridConstraints.SIZEPOLICY_FIXED, 220 | null, 221 | null, 222 | null, 223 | 0, 224 | false)); 225 | otherParamsTextField = new JTextField(); 226 | panel.add( 227 | otherParamsTextField, 228 | new GridConstraints( 229 | 3, 230 | 1, 231 | 1, 232 | 1, 233 | GridConstraints.ANCHOR_WEST, 234 | GridConstraints.FILL_HORIZONTAL, 235 | GridConstraints.SIZEPOLICY_WANT_GROW, 236 | GridConstraints.SIZEPOLICY_FIXED, 237 | null, 238 | new Dimension(150, -1), 239 | null, 240 | 0, 241 | false)); 242 | otherParamsLabel = new JLabel(); 243 | otherParamsLabel.setText("Other params"); 244 | panel.add( 245 | otherParamsLabel, 246 | new GridConstraints( 247 | 3, 248 | 0, 249 | 1, 250 | 1, 251 | GridConstraints.ANCHOR_WEST, 252 | GridConstraints.FILL_NONE, 253 | GridConstraints.SIZEPOLICY_FIXED, 254 | GridConstraints.SIZEPOLICY_FIXED, 255 | null, 256 | null, 257 | null, 258 | 0, 259 | false)); 260 | } 261 | 262 | /** 263 | * @noinspection ALL 264 | */ 265 | public JComponent $$$getRootComponent$$$() { 266 | return panel; 267 | } 268 | } 269 | --------------------------------------------------------------------------------