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 af11778 commit f7eff91
Show file tree
Hide file tree
Showing 21 changed files with 272 additions and 161 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 @@ -60,14 +69,14 @@ class NaiveTypeConverter implements TypeConverter {
return null
}

static ArrayList<String> trimArray(String value, defaultEmpty) {
static List<String> trimArray(String value, Object defaultEmpty) {
if (value == 'null' || value == '' || value == '[]' || value == '[:]') {
log.trace("Value '$value' is empty. Returning default value '$defaultEmpty'.")
return defaultEmpty
}
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,9 @@ class SystemPropertyOverrideReader implements OverrideReader {
*/
@Override
Map<String, String> parseProperties() {
def overrideProperties = System.properties.findAll { it.key.startsWith(OVERRIDE_PROPERTY_PREFIX) }
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)

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

import nebula.test.IntegrationSpec

abstract class BaseOverridePluginIntegrationTest extends IntegrationSpec {
/**
* Base class for integration tests.
*/
class BaseOverridePluginIntegrationTest extends IntegrationSpec {

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ package io.github.amosproj.pitmutationmate.override
import nebula.test.functional.internal.toolingapi.ToolingExecutionResult
import spock.lang.Unroll

/* groovylint-disable */

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

@Unroll("'#commandLineParameter' should be converted to '#expectedValue'")
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 f7eff91

Please sign in to comment.