Skip to content

Commit

Permalink
fix linting errors
Browse files Browse the repository at this point in the history
Signed-off-by: Lennart Heimbs <[email protected]>
  • Loading branch information
lheimbs committed Dec 1, 2023
1 parent 949c56a commit c7e12de
Show file tree
Hide file tree
Showing 21 changed files with 270 additions and 168 deletions.
2 changes: 1 addition & 1 deletion pitmutationmate-override-plugin/plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ gradlePlugin {
listOf(
"pitmutationmate", "pitest", "mutation", "mutation testing", "mutation testing tool",
"mutation testing framework", "mutation testing gradle plugin", "mutation testing ide plugin",
"mutation testing intellij plugin", "mutation testing intellij idea plugin",
"mutation testing intellij plugin", "mutation testing intellij idea plugin"
)
implementationClass = "io.github.amosproj.pitmutationmate.override.PITSettingOverridePlugin"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ package io.github.amosproj.pitmutationmate.override

import org.gradle.api.file.Directory

/**
* Configuration values for the PIT plugin.
*/
class PITConfigurationValues {

Integer threads = 4
boolean verbose = true
boolean includeLaunchClasspath = true
boolean timestampedReports = true
Set<String> targetClasses = ["test", "test2"]
Set<String> targetTests = ["test", "test2"]
Set<String> outputFormats = ["XML", "HTML"]
Directory reportDir = new File("build/reports/pitest") as Directory
}
Set<String> targetClasses = ['test1', 'test2']
Set<String> targetTests = ['test3', 'test4']
Set<String> outputFormats = ['XML', 'HTML']
Directory reportDir = new File('build/reports/pitest') as Directory // groovylint-disable-line

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
//
// SPDX-License-Identifier: MIT

/*
* This Groovy source file was generated by the Gradle 'init' task.
*/
package io.github.amosproj.pitmutationmate.override

import io.github.amosproj.pitmutationmate.override.reader.OverrideReader
Expand All @@ -20,6 +17,7 @@ import org.gradle.api.logging.Logging
* Partner Plugin to the PITmutationmate Plugin to allow overriding of specific PITest configuration values.
*/
class PITSettingOverridePlugin implements Plugin<Project> {

@SuppressWarnings("FieldName")
private final static Logger log = Logging.getLogger(PITSettingOverridePlugin)

Expand All @@ -36,5 +34,5 @@ class PITSettingOverridePlugin implements Plugin<Project> {
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ import org.gradle.api.file.Directory
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging

/**
* NaiveTypeConverter
*
* This class is responsible for converting a string value to a given type.
* It is used by the [PITSettingOverridePlugin] to convert the values of the
* gradle-pitest-plugin extension to the correct type.
*
* @see [PITSettingOverridePlugin]
*/
class NaiveTypeConverter implements TypeConverter {
@SuppressWarnings("FieldName")

@SuppressWarnings('FieldName')
private final static Logger log = Logging.getLogger(PITSettingOverridePlugin)
private final ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean()

@Override
Object convert(String value, Class<?> clazz, Project project) {

switch (clazz) {
case Integer:
log.trace("Converting Integer value '$value' to type '$clazz'.")
Expand Down Expand Up @@ -66,6 +75,7 @@ class NaiveTypeConverter implements TypeConverter {
}
value = value.replace('[', '')
.replace(']', '')
return value.split(",").collect { it.trim() }
return value.split(',')*.trim()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ package io.github.amosproj.pitmutationmate.override.converter

import org.gradle.api.Project

/**
* TypeConverter
*
* This interface is responsible for converting a string value to a given type.
* It is used by the [PITSettingOverridePlugin] to convert the values of the
* gradle-pitest-plugin extension to the correct type.
*
* @see [PITSettingOverridePlugin]
*/
interface TypeConverter {

Object convert(String value, Class<?> clazz, Project project)

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

package io.github.amosproj.pitmutationmate.override.reader

/**
* OverrideReader
*
* This interface is responsible for reading the override properties.
* It is used by the [PITSettingOverridePlugin] to read the values of the
* gradle-pitest-plugin extension.
*
* @see [PITSettingOverridePlugin]
*/
interface OverrideReader {

Map<String, String> parseProperties()

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2023 Netflix, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Modified by Lennart Heimbs, 2023

package io.github.amosproj.pitmutationmate.override.reader

Expand All @@ -14,6 +16,7 @@ package io.github.amosproj.pitmutationmate.override.reader
* </pre>
*/
class SystemPropertyOverrideReader implements OverrideReader {

static final String OVERRIDE_PROPERTY_PREFIX = 'pitmutationmate.override.'

/**
Expand All @@ -23,8 +26,10 @@ class SystemPropertyOverrideReader implements OverrideReader {
*/
@Override
Map<String, String> parseProperties() {
def overrideProperties = System.properties.findAll { property -> property.key.startsWith(OVERRIDE_PROPERTY_PREFIX) }
def overrideProperties = System.properties.findAll { property ->
property.key.startsWith(OVERRIDE_PROPERTY_PREFIX) }
// Remove property prefix
overrideProperties.collectEntries { key, value -> [key - OVERRIDE_PROPERTY_PREFIX, value] }
return overrideProperties.collectEntries { key, value -> [key - OVERRIDE_PROPERTY_PREFIX, value] }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,28 @@ import org.gradle.api.Project
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging

/**
* GradlePitestPluginOverrideStrategy
*
* This class is responsible for overriding the properties of the gradle-pitest-plugin.
* It is used by the [PITSettingOverridePlugin] to override the values of the
* gradle-pitest-plugin extension.
*
* @see [PITSettingOverridePlugin]
*/
class GradlePitestPluginOverrideStrategy implements OverrideStrategy {
@SuppressWarnings("FieldName")

static final String OVERRIDE_SECTION = 'pitest'

@SuppressWarnings('FieldName')
private final static Logger log = Logging.getLogger(PITSettingOverridePlugin)
TypeConverter typeConverter = new NaiveTypeConverter() as TypeConverter

@Override
void apply(Project project, String propertyName, String overrideValue) {
log.debug("Overriding property '$propertyName' with '$overrideValue'.")

def pitestExtension = project.extensions.findByName("pitest")
def pitestExtension = project.extensions.findByName(OVERRIDE_SECTION)
if (pitestExtension == null) {
throw new GradleException("PITest extension not found. Please apply the PITest plugin first.")
}
Expand All @@ -34,7 +46,8 @@ class GradlePitestPluginOverrideStrategy implements OverrideStrategy {
PITConfigurationValues overrideFields = new PITConfigurationValues()
def overrideProperty = overrideFields.properties.find { it.key == propertyName }
if (overrideProperty == null) {
throw new GradleException("Cannot override property '$propertyName' for pitest extension: Unknown Property.")
throw new GradleException(
"Cannot override property '$propertyName' for pitest extension: Unknown Property.")
}

Class clazz = overrideProperty.value.getClass()
Expand All @@ -43,5 +56,5 @@ class GradlePitestPluginOverrideStrategy implements OverrideStrategy {

log.debug("Property '$propertyName' successfully overwritten with '$newValue'.")
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ package io.github.amosproj.pitmutationmate.override.strategy

import org.gradle.api.Project

/**
* OverrideStrategy
*
* This interface is responsible for applying the override value to the gradle-pitest-plugin extension.
* It is used by the [PITSettingOverridePlugin] to apply the values of the
* gradle-pitest-plugin extension.
*
* @see [PITSettingOverridePlugin]
*/
interface OverrideStrategy {

void apply(Project project, String propertyName, String overrideValue)

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,28 @@
// Modifications by: Lennart Heimbs
// - Adapt to pitest specific use case

/* groovylint-disable */

package io.github.amosproj.pitmutationmate.override

import nebula.test.IntegrationSpec
import nebula.test.functional.internal.toolingapi.ToolingExecutionResult
import org.gradle.api.logging.LogLevel
import spock.lang.Unroll

class TypesPropertyIntegrationTest extends BaseOverridePluginIntegrationTest {
/**
* Integration tests for the plugin.
*/
class TypesPropertyIntegrationTest extends IntegrationSpec {

/* groovylint-disable JUnitPublicNonTestMethod, MethodReturnTypeRequired, NoDef */
def setup() {
logLevel = LogLevel.DEBUG
fork = true
buildFile << """
apply plugin: 'io.github.amosproj.pitmutationmate.override'
"""
}

@Unroll("'#commandLineParameter' should be converted to '#expectedValue'")
def "Should allow to override Set property"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@

package io.github.amosproj.pitmutationmate.override.converter


import spock.lang.Specification
import spock.lang.Unroll

/* groovylint-disable JUnitPublicNonTestMethod, MethodName */

/**
* NaiveTypeConverterTest
*
* This class is responsible for testing the [NaiveTypeConverter].
*
* @see [NaiveTypeConverter]
*/
class NaiveTypeConverterTest extends Specification {

@Unroll
Expand Down Expand Up @@ -77,7 +85,8 @@ class NaiveTypeConverterTest extends Specification {
'false' | 'boolean' || false
'1' | 'integer' || 1
'999' | 'integer' || 999
'foobar' | 'string' || 'foobar' as String
'9999999999999.999' | 'BigDec' || new BigDecimal('9999999999999.999')
'foobar' | 'string' || 'foobar'
'9999999999999.999' | 'BigDec' || 9999999999999.999G
}

}
Loading

0 comments on commit c7e12de

Please sign in to comment.