Skip to content

Commit

Permalink
chore: apply spotless plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mjedynak committed Feb 18, 2024
1 parent cb7648a commit fc5a528
Show file tree
Hide file tree
Showing 31 changed files with 777 additions and 619 deletions.
61 changes: 38 additions & 23 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
plugins {
id 'groovy'
id 'org.jetbrains.intellij' version '1.17.1'
id 'groovy'
id 'org.jetbrains.intellij' version '1.17.1'
id 'com.diffplug.spotless' version '6.25.0'
}

intellij {
version = '2023.3'
plugins = ['java']
version = '2023.3'
plugins = ['java']
}


Expand All @@ -21,33 +22,47 @@ sourceSets.main.java.srcDirs = []
sourceSets.main.groovy.srcDir 'src/main/java'

repositories {
mavenCentral()
mavenLocal()
mavenCentral()
mavenLocal()
}


dependencies {
implementation("org.pitest:pitest-command-line:$pitVersion") { transitive = false }
implementation("org.pitest:pitest-entry:$pitVersion") { transitive = false }
implementation("org.pitest:pitest:$pitVersion") { transitive = false }
implementation "org.pitest:pitest-junit5-plugin:$pitJunit5PluginVersion"
implementation 'org.apache.commons:commons-text:1.10.0'
compileOnly 'org.codehaus.groovy:groovy-all:3.0.19'
testCompileOnly 'org.codehaus.groovy:groovy-all:3.0.19'
testImplementation('org.spockframework:spock-core:2.3-groovy-3.0') {
exclude group: 'org.codehaus.groovy'
}
implementation("org.pitest:pitest-command-line:$pitVersion") { transitive = false }
implementation("org.pitest:pitest-entry:$pitVersion") { transitive = false }
implementation("org.pitest:pitest:$pitVersion") { transitive = false }
implementation "org.pitest:pitest-junit5-plugin:$pitJunit5PluginVersion"
implementation 'org.apache.commons:commons-text:1.10.0'
compileOnly 'org.codehaus.groovy:groovy-all:3.0.19'
testCompileOnly 'org.codehaus.groovy:groovy-all:3.0.19'
testImplementation('org.spockframework:spock-core:2.3-groovy-3.0') {
exclude group: 'org.codehaus.groovy'
}
}

jar {
metaInf {
from('META-INF') {
include 'plugin.xml'
include 'pluginIcon.svg'
}
}
metaInf {
from('META-INF') {
include 'plugin.xml'
include 'pluginIcon.svg'
}
}
}

wrapper {
gradleVersion "8.6"
gradleVersion "8.6"
}

spotless {
java {
palantirJavaFormat()
}
groovy {
greclipse()
excludeJava()
}
groovyGradle {
target '*.gradle'
greclipse()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ import groovy.transform.CompileStatic
@CompileStatic
class ClassPathPopulator {

static final String PITEST_VERSION = '1.15.8'
static final String PITEST_JUNIT5_PLUGIN_VERSION = '1.2.1'
static final String SEPARATOR = System.getProperty('file.separator')
static final String PLUGIN_NAME = 'pit-idea-plugin'
static final String LIB_DIR = 'lib'
static final String PITEST_VERSION = '1.15.8'
static final String PITEST_JUNIT5_PLUGIN_VERSION = '1.2.1'
static final String SEPARATOR = System.getProperty('file.separator')
static final String PLUGIN_NAME = 'pit-idea-plugin'
static final String LIB_DIR = 'lib'

void populateClassPathWithPitJar(PathsList classPath) {
String pluginsPath = PathManager.pluginsPath
String path = pluginsPath + SEPARATOR + PLUGIN_NAME + SEPARATOR + LIB_DIR + SEPARATOR
classPath.with {
addFirst(path + "pitest-${PITEST_VERSION}.jar")
addFirst(path + "pitest-command-line-${PITEST_VERSION}.jar")
addFirst(path + "pitest-entry-${PITEST_VERSION}.jar")
addFirst(path + 'commons-lang3-3.12.0.jar')
addFirst(path + 'commons-text-1.10.0.jar')
addFirst(path + "pitest-junit5-plugin-${PITEST_JUNIT5_PLUGIN_VERSION}.jar")
if (noPlatformLauncherDependency(classPath)) {
addFirst(path + 'junit-platform-launcher-1.9.2.jar')
}
}
}
void populateClassPathWithPitJar(PathsList classPath) {
String pluginsPath = PathManager.pluginsPath
String path = pluginsPath + SEPARATOR + PLUGIN_NAME + SEPARATOR + LIB_DIR + SEPARATOR
classPath.with {
addFirst(path + "pitest-${PITEST_VERSION}.jar")
addFirst(path + "pitest-command-line-${PITEST_VERSION}.jar")
addFirst(path + "pitest-entry-${PITEST_VERSION}.jar")
addFirst(path + 'commons-lang3-3.12.0.jar')
addFirst(path + 'commons-text-1.10.0.jar')
addFirst(path + "pitest-junit5-plugin-${PITEST_JUNIT5_PLUGIN_VERSION}.jar")
if (noPlatformLauncherDependency(classPath)) {
addFirst(path + 'junit-platform-launcher-1.9.2.jar')
}
}
}

private static boolean noPlatformLauncherDependency(PathsList classPath) {
return !classPath.pathList.find { it.contains("junit-platform-launcher") }
}
private static boolean noPlatformLauncherDependency(PathsList classPath) {
return !classPath.pathList.find { it.contains("junit-platform-launcher") }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,27 @@ import pl.mjedynak.idea.plugins.pit.gui.populator.ProgramParametersListPopulator
@CompileStatic
class JavaParametersCreator {

private static final String PIT_MAIN_CLASS = 'org.pitest.mutationtest.commandline.MutationCoverageReport'
private static final String PIT_MAIN_CLASS = 'org.pitest.mutationtest.commandline.MutationCoverageReport'

ProgramParametersListPopulator programParametersListPopulator = new ProgramParametersListPopulator()
ClassPathPopulator classPathPopulator = new ClassPathPopulator()
ProgramParametersListPopulator programParametersListPopulator = new ProgramParametersListPopulator()
ClassPathPopulator classPathPopulator = new ClassPathPopulator()

JavaParameters createJavaParameters(RunConfigurationModule runConfigurationModule, PitConfigurationForm pitConfigurationForm) {
JavaParameters javaParameters = new JavaParameters()
javaParameters.setUseClasspathJar(true)
ModuleManager moduleManager = ModuleManager.getInstance(runConfigurationModule.project)
configureModules(moduleManager, javaParameters)
programParametersListPopulator.populateProgramParametersList(javaParameters.programParametersList, pitConfigurationForm)
javaParameters.setWorkingDirectory(runConfigurationModule.project.getBasePath())
javaParameters.setMainClass(PIT_MAIN_CLASS)
classPathPopulator.populateClassPathWithPitJar(javaParameters.classPath)
javaParameters
}

private static void configureModules(ModuleManager moduleManager, JavaParameters javaParameters) {
Module[] modules = moduleManager.modules
modules.each { Module module ->
JavaParametersUtil.configureModule(module, javaParameters, JavaParameters.JDK_AND_CLASSES_AND_TESTS, null)
}
}
JavaParameters createJavaParameters(RunConfigurationModule runConfigurationModule, PitConfigurationForm pitConfigurationForm) {
JavaParameters javaParameters = new JavaParameters()
javaParameters.setUseClasspathJar(true)
ModuleManager moduleManager = ModuleManager.getInstance(runConfigurationModule.project)
configureModules(moduleManager, javaParameters)
programParametersListPopulator.populateProgramParametersList(javaParameters.programParametersList, pitConfigurationForm)
javaParameters.setWorkingDirectory(runConfigurationModule.project.getBasePath())
javaParameters.setMainClass(PIT_MAIN_CLASS)
classPathPopulator.populateClassPathWithPitJar(javaParameters.classPath)
javaParameters
}

private static void configureModules(ModuleManager moduleManager, JavaParameters javaParameters) {
Module[] modules = moduleManager.modules
modules.each { Module module ->
JavaParametersUtil.configureModule(module, javaParameters, JavaParameters.JDK_AND_CLASSES_AND_TESTS, null)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,87 +19,87 @@ import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.TARG
@CompileStatic
class DefaultArgumentsContainerPopulator {

static final String DEFAULT_REPORT_DIR = 'report'
static final String MAVEN_REPORT_DIR = 'target/report'
static final String GRADLE_REPORT_DIR = 'build/reports/pit'
static final String ALL_CLASSES_SUFFIX = '.*'
static final String DEFAULT_REPORT_DIR = 'report'
static final String MAVEN_REPORT_DIR = 'target/report'
static final String GRADLE_REPORT_DIR = 'build/reports/pit'
static final String ALL_CLASSES_SUFFIX = '.*'

private ProjectRootManager projectRootManager
private PsiManager psiManager
private MavenProjectDeterminer mavenProjectDeterminer = new MavenProjectDeterminer()
private GradleProjectDeterminer gradleProjectDeterminer = new GradleProjectDeterminer()
private MavenPomReader mavenPomReader = new MavenPomReader()
private ProjectRootManager projectRootManager
private PsiManager psiManager
private MavenProjectDeterminer mavenProjectDeterminer = new MavenProjectDeterminer()
private GradleProjectDeterminer gradleProjectDeterminer = new GradleProjectDeterminer()
private MavenPomReader mavenPomReader = new MavenPomReader()

DefaultArgumentsContainerPopulator(ProjectRootManager projectRootManager, PsiManager psiManager) {
this.projectRootManager = projectRootManager
this.psiManager = psiManager
}
DefaultArgumentsContainerPopulator(ProjectRootManager projectRootManager, PsiManager psiManager) {
this.projectRootManager = projectRootManager
this.psiManager = psiManager
}

void addReportDir(Project project, PitCommandLineArgumentsContainer container) {
VirtualFile baseDir = project.baseDir
String reportDir
if (baseDir != null) {
String suffix = DEFAULT_REPORT_DIR
if (mavenProjectDeterminer.isMavenProject(project)) {
suffix = MAVEN_REPORT_DIR
} else if (gradleProjectDeterminer.isGradleProject(project)) {
suffix = GRADLE_REPORT_DIR
}
reportDir = baseDir.path + '/' + suffix
container.put(PitCommandLineArgument.REPORT_DIR, reportDir)
}
}
void addReportDir(Project project, PitCommandLineArgumentsContainer container) {
VirtualFile baseDir = project.baseDir
String reportDir
if (baseDir != null) {
String suffix = DEFAULT_REPORT_DIR
if (mavenProjectDeterminer.isMavenProject(project)) {
suffix = MAVEN_REPORT_DIR
} else if (gradleProjectDeterminer.isGradleProject(project)) {
suffix = GRADLE_REPORT_DIR
}
reportDir = baseDir.path + '/' + suffix
container.put(PitCommandLineArgument.REPORT_DIR, reportDir)
}
}

void addSourceDir(PitCommandLineArgumentsContainer container) {
VirtualFile[] sourceRoots = projectRootManager.contentSourceRoots
VirtualFile javaSrcFolder = sourceRoots.find { VirtualFile sourceRoot ->
sourceRoot.path.contains('java')
}
if (javaSrcFolder != null) {
container.put(SOURCE_DIRS, javaSrcFolder.path)
} else if (hasAtLeastOneSourceRoot(sourceRoots)) {
String sourceRootPath = sourceRoots[0].path
container.put(SOURCE_DIRS, sourceRootPath)
}
}
void addSourceDir(PitCommandLineArgumentsContainer container) {
VirtualFile[] sourceRoots = projectRootManager.contentSourceRoots
VirtualFile javaSrcFolder = sourceRoots.find { VirtualFile sourceRoot ->
sourceRoot.path.contains('java')
}
if (javaSrcFolder != null) {
container.put(SOURCE_DIRS, javaSrcFolder.path)
} else if (hasAtLeastOneSourceRoot(sourceRoots)) {
String sourceRootPath = sourceRoots[0].path
container.put(SOURCE_DIRS, sourceRootPath)
}
}

void addTargetClasses(Project project, PitCommandLineArgumentsContainer container) {
if (mavenProjectDeterminer.isMavenProject(project)) {
addTargetClassesForMavenProject(project, container)
} else {
addTargetClassesForNonMavenProject(container)
}
}
void addTargetClasses(Project project, PitCommandLineArgumentsContainer container) {
if (mavenProjectDeterminer.isMavenProject(project)) {
addTargetClassesForMavenProject(project, container)
} else {
addTargetClassesForNonMavenProject(container)
}
}

private void addTargetClassesForMavenProject(Project project, PitCommandLineArgumentsContainer container) {
VirtualFile baseDir = project.baseDir
VirtualFile pomVirtualFile = baseDir.findChild(MavenProjectDeterminer.POM_FILE)
String groupId = mavenPomReader.getGroupId(pomVirtualFile.inputStream)
container.put(TARGET_CLASSES, groupId + ALL_CLASSES_SUFFIX)
}
private void addTargetClassesForMavenProject(Project project, PitCommandLineArgumentsContainer container) {
VirtualFile baseDir = project.baseDir
VirtualFile pomVirtualFile = baseDir.findChild(MavenProjectDeterminer.POM_FILE)
String groupId = mavenPomReader.getGroupId(pomVirtualFile.inputStream)
container.put(TARGET_CLASSES, groupId + ALL_CLASSES_SUFFIX)
}

private void addTargetClassesForNonMavenProject(PitCommandLineArgumentsContainer container) {
VirtualFile[] sourceRoots = projectRootManager.contentSourceRoots
if (hasAtLeastOneSourceRoot(sourceRoots)) {
PsiDirectory directory = psiManager.findDirectory(sourceRoots[0])
addTargetClassesIfDirectoryExists(container, directory)
}
}
private void addTargetClassesForNonMavenProject(PitCommandLineArgumentsContainer container) {
VirtualFile[] sourceRoots = projectRootManager.contentSourceRoots
if (hasAtLeastOneSourceRoot(sourceRoots)) {
PsiDirectory directory = psiManager.findDirectory(sourceRoots[0])
addTargetClassesIfDirectoryExists(container, directory)
}
}

private static void addTargetClassesIfDirectoryExists(PitCommandLineArgumentsContainer container, PsiDirectory directory) {
if (directory != null) {
PsiDirectory[] subdirectories = directory.subdirectories
if (hasAtLeastOneSubdirectory(subdirectories)) {
container.put(TARGET_CLASSES, subdirectories[0].name + ALL_CLASSES_SUFFIX)
}
}
}
private static void addTargetClassesIfDirectoryExists(PitCommandLineArgumentsContainer container, PsiDirectory directory) {
if (directory != null) {
PsiDirectory[] subdirectories = directory.subdirectories
if (hasAtLeastOneSubdirectory(subdirectories)) {
container.put(TARGET_CLASSES, subdirectories[0].name + ALL_CLASSES_SUFFIX)
}
}
}

private static boolean hasAtLeastOneSourceRoot(VirtualFile[] sourceRoots) {
!isEmpty(sourceRoots)
}
private static boolean hasAtLeastOneSourceRoot(VirtualFile[] sourceRoots) {
!isEmpty(sourceRoots)
}

private static boolean hasAtLeastOneSubdirectory(PsiDirectory[] subdirectories) {
!isEmpty(subdirectories)
}
private static boolean hasAtLeastOneSubdirectory(PsiDirectory[] subdirectories) {
!isEmpty(subdirectories)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@ import static pl.mjedynak.idea.plugins.pit.cli.model.PitCommandLineArgument.TARG
@CompileStatic
class PitRunConfigurationStorer {

static final String OTHER_PARAMS = 'otherParams'
static final String OTHER_PARAMS = 'otherParams'

void readExternal(PitConfigurationForm pitConfigurationForm, Element element) {
pitConfigurationForm.setReportDir(element.getAttribute(REPORT_DIR.toString())?.value)
pitConfigurationForm.setSourceDir(element.getAttribute(SOURCE_DIRS.toString())?.value)
pitConfigurationForm.setTargetClasses(element.getAttribute(TARGET_CLASSES.toString())?.value)
pitConfigurationForm.setTargetTests(element.getAttribute(TARGET_TESTS.toString())?.value)
pitConfigurationForm.setOtherParams(element.getAttribute(OTHER_PARAMS)?.value)
}

void writeExternal(PitConfigurationForm pitConfigurationForm, Element element) {
element.setAttribute(REPORT_DIR.toString(), pitConfigurationForm.reportDir)
element.setAttribute(SOURCE_DIRS.toString(), pitConfigurationForm.sourceDir)
element.setAttribute(TARGET_CLASSES.toString(), pitConfigurationForm.targetClasses)
element.setAttribute(TARGET_TESTS.toString(), pitConfigurationForm.targetTests)
element.setAttribute(OTHER_PARAMS, pitConfigurationForm.otherParams)
}
void readExternal(PitConfigurationForm pitConfigurationForm, Element element) {
pitConfigurationForm.setReportDir(element.getAttribute(REPORT_DIR.toString())?.value)
pitConfigurationForm.setSourceDir(element.getAttribute(SOURCE_DIRS.toString())?.value)
pitConfigurationForm.setTargetClasses(element.getAttribute(TARGET_CLASSES.toString())?.value)
pitConfigurationForm.setTargetTests(element.getAttribute(TARGET_TESTS.toString())?.value)
pitConfigurationForm.setOtherParams(element.getAttribute(OTHER_PARAMS)?.value)
}

void writeExternal(PitConfigurationForm pitConfigurationForm, Element element) {
element.setAttribute(REPORT_DIR.toString(), pitConfigurationForm.reportDir)
element.setAttribute(SOURCE_DIRS.toString(), pitConfigurationForm.sourceDir)
element.setAttribute(TARGET_CLASSES.toString(), pitConfigurationForm.targetClasses)
element.setAttribute(TARGET_TESTS.toString(), pitConfigurationForm.targetTests)
element.setAttribute(OTHER_PARAMS, pitConfigurationForm.otherParams)
}
}
Loading

0 comments on commit fc5a528

Please sign in to comment.