From d9f5dc724dcb2ca4b919130f33f8eef52a655898 Mon Sep 17 00:00:00 2001 From: Simon Priadka Date: Thu, 16 Nov 2017 12:51:47 +0100 Subject: [PATCH] validation refactoring, packaging --- .../pitest/functional/ScmPitestSpec.groovy | 13 ---- .../pitest/ConnectionTypeValidator.groovy | 23 ------- .../gradle/pitest/GoalValidator.groovy | 22 ------- .../gradle/pitest/PitestPlugin.groovy | 4 +- .../ChangeLogException.groovy | 2 +- .../InvalidChangeLogStrategyException.groovy | 2 +- .../PitestTaskValidationException.groovy | 8 +++ .../extension/PitestPluginExtension.groovy | 1 - .../extension/ScmPitestPluginExtension.groovy | 1 - .../AbstractChangeLogStrategyFactory.groovy | 5 -- .../scm/ChangeLogStrategyFactory.groovy | 28 --------- .../scm/PathToClassNameConverter.groovy | 13 ++-- .../solidsoft/gradle/pitest/scm/Sample.groovy | 20 ------- .../gradle/pitest/scm/ScmContext.groovy | 60 +++++++++++++++++++ .../AbstractChangeLogStrategy.groovy | 6 +- .../{ => strategy}/ChangeLogStrategy.groovy | 2 +- .../CustomChangeLogStrategy.groovy | 14 +++-- .../{ => strategy}/LastCommitStrategy.groovy | 3 +- .../LocalChangesStrategy.groovy | 3 +- .../AbstractChangeLogStrategyFactory.groovy | 7 +++ .../factory/ChangeLogStrategyFactory.groovy | 37 ++++++++++++ .../gradle/pitest/task/PitestTask.groovy | 3 - .../gradle/pitest/task/ScmPitestTask.groovy | 34 +++++++---- .../validation/AbstractTaskValidator.groovy | 9 +++ .../validation/ConnectionTypeValidator.groovy | 20 +++++++ .../CustomStrategyValidator.groovy | 33 +++++----- .../pitest/validation/GoalValidator.groovy | 19 ++++++ .../validation/ScmPitestTaskValidator.groovy | 27 +++++++++ .../validation/TaskPropertyValidator.groovy | 7 +++ .../pitest/validation/TaskValidator.groovy | 7 +++ .../gradle/pitest/CustomStrategyTest.groovy | 4 +- .../pitest/LastCommitStrategyTest.groovy | 6 +- .../pitest/LocalChangesStrategyTest.groovy | 6 +- 33 files changed, 266 insertions(+), 183 deletions(-) delete mode 100644 functional-tests/src/test/groovy/info/solidsoft/gradle/pitest/functional/ScmPitestSpec.groovy delete mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/ConnectionTypeValidator.groovy delete mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/GoalValidator.groovy rename plugin/src/main/groovy/info/solidsoft/gradle/pitest/{scm => exception}/ChangeLogException.groovy (80%) rename plugin/src/main/groovy/info/solidsoft/gradle/pitest/{scm => exception}/InvalidChangeLogStrategyException.groovy (84%) create mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/exception/PitestTaskValidationException.groovy delete mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/AbstractChangeLogStrategyFactory.groovy delete mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ChangeLogStrategyFactory.groovy delete mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/Sample.groovy create mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ScmContext.groovy rename plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/{ => strategy}/AbstractChangeLogStrategy.groovy (75%) rename plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/{ => strategy}/ChangeLogStrategy.groovy (77%) rename plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/{ => strategy}/CustomChangeLogStrategy.groovy (93%) rename plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/{ => strategy}/LastCommitStrategy.groovy (93%) rename plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/{ => strategy}/LocalChangesStrategy.groovy (91%) create mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/factory/AbstractChangeLogStrategyFactory.groovy create mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/factory/ChangeLogStrategyFactory.groovy create mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/AbstractTaskValidator.groovy create mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/ConnectionTypeValidator.groovy rename plugin/src/main/groovy/info/solidsoft/gradle/pitest/{ => validation}/CustomStrategyValidator.groovy (53%) create mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/GoalValidator.groovy create mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/ScmPitestTaskValidator.groovy create mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/TaskPropertyValidator.groovy create mode 100644 plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/TaskValidator.groovy diff --git a/functional-tests/src/test/groovy/info/solidsoft/gradle/pitest/functional/ScmPitestSpec.groovy b/functional-tests/src/test/groovy/info/solidsoft/gradle/pitest/functional/ScmPitestSpec.groovy deleted file mode 100644 index d7c6190b..00000000 --- a/functional-tests/src/test/groovy/info/solidsoft/gradle/pitest/functional/ScmPitestSpec.groovy +++ /dev/null @@ -1,13 +0,0 @@ -package info.solidsoft.gradle.pitest.functional - -class ScmPitestSpec extends AbstractPitestFunctionalSpec { - - def "Last commit strategy" () { - given: - copyResources("testProjects/scmProject","") - when: - def result = runTasksSuccessfully("scmPitest") - then: - result.standardOutput.isEmpty() - } -} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/ConnectionTypeValidator.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/ConnectionTypeValidator.groovy deleted file mode 100644 index 91aa3886..00000000 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/ConnectionTypeValidator.groovy +++ /dev/null @@ -1,23 +0,0 @@ -package info.solidsoft.gradle.pitest - -import info.solidsoft.gradle.pitest.task.ScmPitestTask -import org.gradle.api.internal.TaskInternal -import org.gradle.api.internal.tasks.execution.TaskValidator - -class ConnectionTypeValidator implements TaskValidator { - - private ScmPitestTask scmPitestTask - - ConnectionTypeValidator(ScmPitestTask scmPitestTask) { - this.scmPitestTask = scmPitestTask - } - - @Override - void validate(TaskInternal task, Collection messages) { - def supportedConnectionTypes = ['connection','developerConnection'] - if (!supportedConnectionTypes.contains(scmPitestTask.getConnectionType())) { - messages.add("Invalid connectionType specified, expected one of $supportedConnectionTypes," + - " got ${scmPitestTask.getConnectionType()}".toString()) - } - } -} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/GoalValidator.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/GoalValidator.groovy deleted file mode 100644 index 5c81ce71..00000000 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/GoalValidator.groovy +++ /dev/null @@ -1,22 +0,0 @@ -package info.solidsoft.gradle.pitest - -import info.solidsoft.gradle.pitest.task.ScmPitestTask -import org.gradle.api.internal.TaskInternal -import org.gradle.api.internal.tasks.execution.TaskValidator - -class GoalValidator implements TaskValidator { - - ScmPitestTask scmPitestTask - - GoalValidator(ScmPitestTask scmPitestTask) { - this.scmPitestTask = scmPitestTask - } - - @Override - void validate(TaskInternal task, Collection messages) { - def supportedGoals = ['custom','localChanges','lastCommit'] - if (!supportedGoals.contains(scmPitestTask.getGoal())) { - messages.add("Invalid goal specified, expected one of ${supportedGoals}, got ${scmPitestTask.getGoal()}".toString()) - } - } -} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/PitestPlugin.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/PitestPlugin.groovy index dc21f42f..1450b1cf 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/PitestPlugin.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/PitestPlugin.groovy @@ -22,6 +22,7 @@ import info.solidsoft.gradle.pitest.extension.ScmPitestPluginExtension import info.solidsoft.gradle.pitest.task.AbstractPitestTask import info.solidsoft.gradle.pitest.task.PitestTask import info.solidsoft.gradle.pitest.task.ScmPitestTask +import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.FileCollection @@ -65,9 +66,6 @@ class PitestPlugin implements Plugin { pitestTask = project.tasks.create(PluginConstants.PITEST_TASK_NAME, PitestTask) scmPitestTask = project.tasks.create(PluginConstants.SCM_PITEST_TASK_NAME, ScmPitestTask) configurePitestTaskFromExtension(pitestTask, pitestExtension) - scmPitestTask.addValidator(new GoalValidator(scmPitestTask)) - scmPitestTask.addValidator(new ConnectionTypeValidator(scmPitestTask)) - scmPitestTask.addValidator(new CustomStrategyValidator(scmPitestTask)) configureScmTaskFromExtension(scmPitestTask, scmPitestExtension) } project.afterEvaluate { diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ChangeLogException.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/exception/ChangeLogException.groovy similarity index 80% rename from plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ChangeLogException.groovy rename to plugin/src/main/groovy/info/solidsoft/gradle/pitest/exception/ChangeLogException.groovy index b97e5fca..3cd8eef0 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ChangeLogException.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/exception/ChangeLogException.groovy @@ -1,4 +1,4 @@ -package info.solidsoft.gradle.pitest.scm +package info.solidsoft.gradle.pitest.exception class ChangeLogException extends Exception { ChangeLogException(String var1) { diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/InvalidChangeLogStrategyException.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/exception/InvalidChangeLogStrategyException.groovy similarity index 84% rename from plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/InvalidChangeLogStrategyException.groovy rename to plugin/src/main/groovy/info/solidsoft/gradle/pitest/exception/InvalidChangeLogStrategyException.groovy index 71e17b4f..ba7e4e58 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/InvalidChangeLogStrategyException.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/exception/InvalidChangeLogStrategyException.groovy @@ -1,4 +1,4 @@ -package info.solidsoft.gradle.pitest.scm +package info.solidsoft.gradle.pitest.exception class InvalidChangeLogStrategyException extends Exception { InvalidChangeLogStrategyException(String message) { diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/exception/PitestTaskValidationException.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/exception/PitestTaskValidationException.groovy new file mode 100644 index 00000000..dafb8e1d --- /dev/null +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/exception/PitestTaskValidationException.groovy @@ -0,0 +1,8 @@ +package info.solidsoft.gradle.pitest.exception + +class PitestTaskValidationException extends Exception { + + PitestTaskValidationException(String var1) { + super(var1) + } +} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/extension/PitestPluginExtension.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/extension/PitestPluginExtension.groovy index e9cfd692..5b680926 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/extension/PitestPluginExtension.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/extension/PitestPluginExtension.groovy @@ -21,7 +21,6 @@ import org.gradle.api.Incubating import org.gradle.api.Project import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.tasks.SourceSet -import org.gradle.api.tasks.TaskInstantiationException /** * Extension class with configurable parameters for Pitest plugin. diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/extension/ScmPitestPluginExtension.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/extension/ScmPitestPluginExtension.groovy index fdea8098..f49a0b72 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/extension/ScmPitestPluginExtension.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/extension/ScmPitestPluginExtension.groovy @@ -1,6 +1,5 @@ package info.solidsoft.gradle.pitest.extension -import info.solidsoft.gradle.pitest.scm.ChangeLogStrategy import info.solidsoft.gradle.pitest.scm.ScmConnection import org.gradle.api.Project import org.gradle.api.file.FileCollection diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/AbstractChangeLogStrategyFactory.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/AbstractChangeLogStrategyFactory.groovy deleted file mode 100644 index 0a3dcd43..00000000 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/AbstractChangeLogStrategyFactory.groovy +++ /dev/null @@ -1,5 +0,0 @@ -package info.solidsoft.gradle.pitest.scm - -interface AbstractChangeLogStrategyFactory { - ChangeLogStrategy fromType(String type) -} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ChangeLogStrategyFactory.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ChangeLogStrategyFactory.groovy deleted file mode 100644 index 6b039db7..00000000 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ChangeLogStrategyFactory.groovy +++ /dev/null @@ -1,28 +0,0 @@ -package info.solidsoft.gradle.pitest.scm - -class ChangeLogStrategyFactory implements AbstractChangeLogStrategyFactory{ - - private File rootFileSet - - ChangeLogStrategyFactory (String filePath) { - this(new File(filePath)) - } - - ChangeLogStrategyFactory (File file) { - rootFileSet = file - } - - @Override - ChangeLogStrategy fromType(String typeName) { - switch (typeName) { - case 'lastCommit': - return new LastCommitStrategy(rootFileSet) - case 'localChanges': - return new LocalChangesStrategy(rootFileSet) - case 'custom': - return new CustomChangeLogStrategy(rootFileSet) - default: - throw new InvalidChangeLogStrategyException("Invalid goal, received: $typeName, possible goals are [lastCommit, localChanges, custom]") - } - } -} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/PathToClassNameConverter.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/PathToClassNameConverter.groovy index 77491c0b..028ad11f 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/PathToClassNameConverter.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/PathToClassNameConverter.groovy @@ -1,29 +1,26 @@ package info.solidsoft.gradle.pitest.scm -import java.util.logging.Logger - class PathToClassNameConverter { - Set sourceSets + + Set sourceSetsPaths PathToClassNameConverter(Collection sourceSets) { - this.sourceSets = new HashSet<>(sourceSets) + this.sourceSetsPaths = new HashSet<>(sourceSets) } List convertPathNamesToClassName(List pathNames) { def result = [] pathNames.each { pathName -> - def sourceRoot = sourceSets.find { pathName.contains(it)} + def sourceRoot = sourceSetsPaths.find { pathName.contains(it)} if (sourceRoot && pathName.indexOf(".") != -1) { result.add(transformToCanonicalName(sourceRoot, pathName)) } } - Logger.getLogger(PathToClassNameConverter.getClass().getName()).info("@@@@@@@@RESULT: $result") - Logger.getLogger("$pathNames") return result } - private String transformToCanonicalName(String sourceSet, String path) { + private static String transformToCanonicalName(String sourceSet, String path) { def pathWithoutSourceRootPrefix = path.substring(sourceSet.length() + 1, path.length()) def pathWithoutExtension = pathWithoutSourceRootPrefix.substring(0, pathWithoutSourceRootPrefix.lastIndexOf(".")) return pathWithoutExtension.replaceAll("/",".") diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/Sample.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/Sample.groovy deleted file mode 100644 index f7337d3e..00000000 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/Sample.groovy +++ /dev/null @@ -1,20 +0,0 @@ -package info.solidsoft.gradle.pitest.scm - -import org.apache.maven.scm.ScmFileSet -import org.apache.maven.scm.manager.BasicScmManager -import org.apache.maven.scm.provider.git.gitexe.GitExeScmProvider - - -def manager = new BasicScmManager() -def root = new File("/home/spriadka/Documents/School/gradle-pitest-plugin/") -manager.setScmProvider("git", new GitExeScmProvider()) -def scmRoot = new ScmFileSet(root) -def sourcesRoot = "/home/spriadka/Documents/School/gradle-pitest-plugin/plugin/src/main/groovy" -def repository = manager.makeScmRepository("scm:git:git@github.com/szpak/gradle-pitest-plugin") -def result = manager.status(repository, scmRoot) -result.changedFiles.each { - file -> - def modified = "$scmRoot.basedir.absolutePath/$file.path" - def withExtension = modified.substring(sourcesRoot.length() + 1, modified.length()) - println withExtension.substring(0, withExtension.lastIndexOf(".")).replaceAll("/",".") -} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ScmContext.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ScmContext.groovy new file mode 100644 index 00000000..54643800 --- /dev/null +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ScmContext.groovy @@ -0,0 +1,60 @@ +package info.solidsoft.gradle.pitest.scm + +class ScmContext { + + File scmRoot + String startVersion + String startVersionType + String endVersion + String endVersionType + + private ScmContext(Builder builder) { + this.scmRoot = builder.scmRoot + this.startVersionType = builder.startVersionType + this.startVersion = builder.startVersion + this.endVersionType = builder.endVersionType + this.endVersion = builder.endVersion + } + + static class Builder { + File scmRoot + String startVersion + String startVersionType + String endVersion + String endVersionType + + Builder scmRoot(String scmRootPath) { + this.scmRoot = new File(scmRootPath) + return this + } + + Builder scmRoot(File scmRoot) { + this.scmRoot = scmRoot + return this + } + + Builder startVersion(String startVersion) { + this.startVersion = startVersion + return this + } + + Builder startVersionType(String startVersionType) { + this.startVersionType = startVersionType + return this + } + + Builder endVersion(String endVersion) { + this.endVersion = endVersion + return this + } + + Builder endVersionType(String endVersionType) { + this.endVersionType = endVersionType + return this + } + + ScmContext build() { + return new ScmContext(this) + } + } +} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/AbstractChangeLogStrategy.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/AbstractChangeLogStrategy.groovy similarity index 75% rename from plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/AbstractChangeLogStrategy.groovy rename to plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/AbstractChangeLogStrategy.groovy index e38b12f8..f30a075d 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/AbstractChangeLogStrategy.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/AbstractChangeLogStrategy.groovy @@ -1,10 +1,8 @@ -package info.solidsoft.gradle.pitest.scm +package info.solidsoft.gradle.pitest.scm.strategy +import info.solidsoft.gradle.pitest.exception.ChangeLogException import org.apache.maven.scm.ScmFileSet -import org.apache.maven.scm.manager.NoSuchScmProviderException import org.apache.maven.scm.manager.ScmManager -import org.apache.maven.scm.repository.ScmRepository -import org.apache.maven.scm.repository.ScmRepositoryException abstract class AbstractChangeLogStrategy implements ChangeLogStrategy { diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ChangeLogStrategy.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/ChangeLogStrategy.groovy similarity index 77% rename from plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ChangeLogStrategy.groovy rename to plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/ChangeLogStrategy.groovy index cce1869c..91282eb6 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/ChangeLogStrategy.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/ChangeLogStrategy.groovy @@ -1,4 +1,4 @@ -package info.solidsoft.gradle.pitest.scm +package info.solidsoft.gradle.pitest.scm.strategy import org.apache.maven.scm.manager.ScmManager diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/CustomChangeLogStrategy.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/CustomChangeLogStrategy.groovy similarity index 93% rename from plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/CustomChangeLogStrategy.groovy rename to plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/CustomChangeLogStrategy.groovy index 4760554c..ba62ac59 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/CustomChangeLogStrategy.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/CustomChangeLogStrategy.groovy @@ -1,10 +1,7 @@ -package info.solidsoft.gradle.pitest.scm +package info.solidsoft.gradle.pitest.scm.strategy -import org.apache.maven.scm.ScmBranch -import org.apache.maven.scm.ScmFileSet -import org.apache.maven.scm.ScmRevision -import org.apache.maven.scm.ScmTag -import org.apache.maven.scm.ScmVersion +import info.solidsoft.gradle.pitest.exception.ChangeLogException +import org.apache.maven.scm.* import org.apache.maven.scm.command.changelog.ChangeLogScmRequest import org.apache.maven.scm.command.changelog.ChangeLogScmResult import org.apache.maven.scm.manager.ScmManager @@ -24,6 +21,11 @@ class CustomChangeLogStrategy extends AbstractChangeLogStrategy { String endVersionType String endVersion + Builder fileSet(File fileSet) { + this.scmFileSet = new ScmFileSet(fileSet) + return this + } + Builder fileSet(String path) { this.scmFileSet = new ScmFileSet(new File(path)) return this diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/LastCommitStrategy.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/LastCommitStrategy.groovy similarity index 93% rename from plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/LastCommitStrategy.groovy rename to plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/LastCommitStrategy.groovy index 5dace39c..3b40ce45 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/LastCommitStrategy.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/LastCommitStrategy.groovy @@ -1,5 +1,6 @@ -package info.solidsoft.gradle.pitest.scm +package info.solidsoft.gradle.pitest.scm.strategy +import info.solidsoft.gradle.pitest.exception.ChangeLogException import org.apache.maven.scm.ChangeSet import org.apache.maven.scm.ScmFileSet import org.apache.maven.scm.command.changelog.ChangeLogScmRequest diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/LocalChangesStrategy.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/LocalChangesStrategy.groovy similarity index 91% rename from plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/LocalChangesStrategy.groovy rename to plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/LocalChangesStrategy.groovy index 158cebf0..89326cf0 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/LocalChangesStrategy.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/LocalChangesStrategy.groovy @@ -1,5 +1,6 @@ -package info.solidsoft.gradle.pitest.scm +package info.solidsoft.gradle.pitest.scm.strategy +import info.solidsoft.gradle.pitest.exception.ChangeLogException import org.apache.maven.scm.ScmFileSet import org.apache.maven.scm.command.status.StatusScmResult import org.apache.maven.scm.manager.ScmManager diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/factory/AbstractChangeLogStrategyFactory.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/factory/AbstractChangeLogStrategyFactory.groovy new file mode 100644 index 00000000..c1a37399 --- /dev/null +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/factory/AbstractChangeLogStrategyFactory.groovy @@ -0,0 +1,7 @@ +package info.solidsoft.gradle.pitest.scm.strategy.factory + +import info.solidsoft.gradle.pitest.scm.strategy.ChangeLogStrategy + +interface AbstractChangeLogStrategyFactory { + ChangeLogStrategy fromType(String type) +} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/factory/ChangeLogStrategyFactory.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/factory/ChangeLogStrategyFactory.groovy new file mode 100644 index 00000000..0a3c4e5c --- /dev/null +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/scm/strategy/factory/ChangeLogStrategyFactory.groovy @@ -0,0 +1,37 @@ +package info.solidsoft.gradle.pitest.scm.strategy.factory + +import info.solidsoft.gradle.pitest.exception.InvalidChangeLogStrategyException +import info.solidsoft.gradle.pitest.scm.ScmContext +import info.solidsoft.gradle.pitest.scm.strategy.ChangeLogStrategy +import info.solidsoft.gradle.pitest.scm.strategy.CustomChangeLogStrategy +import info.solidsoft.gradle.pitest.scm.strategy.LastCommitStrategy +import info.solidsoft.gradle.pitest.scm.strategy.LocalChangesStrategy + +class ChangeLogStrategyFactory implements AbstractChangeLogStrategyFactory{ + + private ScmContext scmContext + + ChangeLogStrategyFactory (ScmContext scmContext) { + this.scmContext = scmContext + } + + @Override + ChangeLogStrategy fromType(String goal) { + switch (goal) { + case 'lastCommit': + return new LastCommitStrategy(scmContext.getScmRoot()) + case 'localChanges': + return new LocalChangesStrategy(scmContext.getScmRoot()) + case 'custom': + return new CustomChangeLogStrategy.Builder() + .fileSet(scmContext.getScmRoot()) + .startVersion(scmContext.getStartVersion()) + .startVersionType(scmContext.getStartVersionType()) + .endVersion(scmContext.getEndVersion()) + .endVersionType(scmContext.getEndVersionType()) + .build() + default: + throw new InvalidChangeLogStrategyException("Invalid goal, received: $goal, possible goals are [lastCommit, localChanges, custom]") + } + } +} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/task/PitestTask.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/task/PitestTask.groovy index 7244d8c2..513b91c7 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/task/PitestTask.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/task/PitestTask.groovy @@ -16,11 +16,8 @@ package info.solidsoft.gradle.pitest.task import groovy.transform.CompileStatic -import groovy.transform.PackageScope import info.solidsoft.gradle.pitest.PitestPlugin -import java.util.logging.Logger - /** * Gradle task implementation for Pitest. */ diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/task/ScmPitestTask.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/task/ScmPitestTask.groovy index ab721573..9a747d4a 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/task/ScmPitestTask.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/task/ScmPitestTask.groovy @@ -1,24 +1,16 @@ package info.solidsoft.gradle.pitest.task -import info.solidsoft.gradle.pitest.ConnectionTypeValidator -import info.solidsoft.gradle.pitest.CustomStrategyValidator -import info.solidsoft.gradle.pitest.GoalValidator import info.solidsoft.gradle.pitest.PitestPlugin -import info.solidsoft.gradle.pitest.extension.ScmPitestPluginExtension -import info.solidsoft.gradle.pitest.scm.ChangeLogStrategy -import info.solidsoft.gradle.pitest.scm.ChangeLogStrategyFactory -import info.solidsoft.gradle.pitest.scm.ManagerService -import info.solidsoft.gradle.pitest.scm.PathToClassNameConverter -import info.solidsoft.gradle.pitest.scm.ScmConnection -import org.apache.maven.scm.manager.BasicScmManager +import info.solidsoft.gradle.pitest.scm.* +import info.solidsoft.gradle.pitest.scm.strategy.ChangeLogStrategy +import info.solidsoft.gradle.pitest.scm.strategy.factory.ChangeLogStrategyFactory +import info.solidsoft.gradle.pitest.validation.ScmPitestTaskValidator import org.apache.maven.scm.manager.ScmManager -import org.apache.maven.scm.provider.git.gitexe.GitExeScmProvider import org.gradle.api.file.FileCollection import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Optional - class ScmPitestTask extends AbstractPitestTask { @Input @@ -64,8 +56,10 @@ class ScmPitestTask extends AbstractPitestTask { @Override void exec() { + validateTaskConfiguration() ScmManager manager = getManager() - ChangeLogStrategy strategy = new ChangeLogStrategyFactory(getScmRoot()).fromType(getGoal()) + ScmContext scmContext = createScmContext() + ChangeLogStrategy strategy = new ChangeLogStrategyFactory(scmContext).fromType(getGoal()) String url = getConnectionUrl() def modifiedFilePaths = strategy.getModifiedFilenames(manager, getIncludes(), url) def classNames = new PathToClassNameConverter(sourceDirs.collect { @@ -79,6 +73,20 @@ class ScmPitestTask extends AbstractPitestTask { super.exec() } + void validateTaskConfiguration() { + new ScmPitestTaskValidator().validate(this) + } + + private ScmContext createScmContext() { + new ScmContext.Builder() + .scmRoot(getScmRoot()) + .startVersionType(getStartVersionType()) + .startVersion(getStartVersion()) + .endVersionType(getEndVersionType()) + .endVersion(getEndVersion()) + .build() + } + private ScmManager getManager() { def currentClassloader = this.class.classLoader if (getManagerClasspath()) { diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/AbstractTaskValidator.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/AbstractTaskValidator.groovy new file mode 100644 index 00000000..2209d999 --- /dev/null +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/AbstractTaskValidator.groovy @@ -0,0 +1,9 @@ +package info.solidsoft.gradle.pitest.validation + +import org.gradle.api.Task + +abstract class AbstractTaskValidator implements TaskValidator { + + protected List errorMessages + +} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/ConnectionTypeValidator.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/ConnectionTypeValidator.groovy new file mode 100644 index 00000000..70245570 --- /dev/null +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/ConnectionTypeValidator.groovy @@ -0,0 +1,20 @@ +package info.solidsoft.gradle.pitest.validation + +import info.solidsoft.gradle.pitest.task.ScmPitestTask + +class ConnectionTypeValidator implements TaskPropertyValidator { + + private final List supportedConnectionTypes = ['connection', 'developerConnection'] + + @Override + void validateProperty(ScmPitestTask task, List errorMessages) { + if (!isSupportedConnectionType(task.getConnectionType())) { + errorMessages.add("Invalid connectionType specified, expected one of $supportedConnectionTypes," + + " got ${task.getConnectionType()}".toString()) + } + } + + private boolean isSupportedConnectionType(String connectionType) { + return supportedConnectionTypes.contains(connectionType) + } +} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/CustomStrategyValidator.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/CustomStrategyValidator.groovy similarity index 53% rename from plugin/src/main/groovy/info/solidsoft/gradle/pitest/CustomStrategyValidator.groovy rename to plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/CustomStrategyValidator.groovy index d988200e..df671cbf 100644 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/CustomStrategyValidator.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/CustomStrategyValidator.groovy @@ -1,36 +1,33 @@ -package info.solidsoft.gradle.pitest +package info.solidsoft.gradle.pitest.validation import info.solidsoft.gradle.pitest.task.ScmPitestTask -import org.gradle.api.internal.TaskInternal -import org.gradle.api.internal.tasks.execution.TaskValidator -class CustomStrategyValidator implements TaskValidator { +class CustomStrategyValidator implements TaskPropertyValidator { - ScmPitestTask scmPitestTask - - CustomStrategyValidator(ScmPitestTask scmPitestTask) { - this.scmPitestTask = scmPitestTask - } + private final List supportedVersionTypes = ['tag', 'revision', 'branch'] @Override - void validate(TaskInternal task, Collection messages) { - if (scmPitestTask.getGoal() == 'custom') { - validatePresence(messages) - validateTypes(messages) + void validateProperty(ScmPitestTask task, List messages) { + if (task.getGoal() == 'custom') { + validateVersionPresence(task, messages) + validateTypes(task, messages) } } - void validateTypes(Collection messages) { - def supportedVersionTypes = ['tag','revision','branch'] - if (!supportedVersionTypes.contains(scmPitestTask.getStartVersionType())) { + void validateTypes(ScmPitestTask scmPitestTask, List messages) { + if (!isSupportedVersionType(scmPitestTask.getStartVersionType())) { messages.add("Invalid start version type, expected one of $supportedVersionTypes, got ${scmPitestTask.getStartVersionType()}".toString()) } - if (!supportedVersionTypes.contains(scmPitestTask.getEndVersionType())) { + if (!isSupportedVersionType(scmPitestTask.getEndVersionType())) { messages.add("Invalid end version type, expected one of $supportedVersionTypes, got ${scmPitestTask.getEndVersionType()}".toString()) } } - private void validatePresence(Collection messages) { + private boolean isSupportedVersionType(String versionType) { + return supportedVersionTypes.contains(versionType) + } + + private void validateVersionPresence(ScmPitestTask scmPitestTask, Collection messages) { if (scmPitestTask.getStartVersion() == null) { messages.add("Start version for 'custom' goal must be specified") } diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/GoalValidator.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/GoalValidator.groovy new file mode 100644 index 00000000..f769014a --- /dev/null +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/GoalValidator.groovy @@ -0,0 +1,19 @@ +package info.solidsoft.gradle.pitest.validation + +import info.solidsoft.gradle.pitest.task.ScmPitestTask + +class GoalValidator implements TaskPropertyValidator { + + private final List supportedGoals = ['custom', 'localChanges', 'lastCommit'] + + @Override + void validateProperty(ScmPitestTask task, List messages) { + if (!isSupportedGoal(task.getGoal())) { + messages.add("Invalid goal specified, expected one of ${supportedGoals}, got ${task.getGoal()}".toString()) + } + } + + private boolean isSupportedGoal(String goal) { + return supportedGoals.contains(goal) + } +} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/ScmPitestTaskValidator.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/ScmPitestTaskValidator.groovy new file mode 100644 index 00000000..5734f1d5 --- /dev/null +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/ScmPitestTaskValidator.groovy @@ -0,0 +1,27 @@ +package info.solidsoft.gradle.pitest.validation + +import info.solidsoft.gradle.pitest.exception.PitestTaskValidationException +import info.solidsoft.gradle.pitest.task.ScmPitestTask + +class ScmPitestTaskValidator extends AbstractTaskValidator { + + List propertyValidators = new ArrayList<>() + + ScmPitestTaskValidator() { + errorMessages = new ArrayList<>() + propertyValidators.addAll(new ConnectionTypeValidator(), + new GoalValidator(), + new CustomStrategyValidator()) + } + + @Override + void validate(ScmPitestTask task) { + propertyValidators.each { + propertyValidator -> + propertyValidator.validateProperty(task, errorMessages) + } + if (!errorMessages.isEmpty()) { + throw new PitestTaskValidationException(errorMessages.first()) + } + } +} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/TaskPropertyValidator.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/TaskPropertyValidator.groovy new file mode 100644 index 00000000..5f7bc3d8 --- /dev/null +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/TaskPropertyValidator.groovy @@ -0,0 +1,7 @@ +package info.solidsoft.gradle.pitest.validation + +import org.gradle.api.Task + +interface TaskPropertyValidator { + void validateProperty(T task, List errorMessages) +} diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/TaskValidator.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/TaskValidator.groovy new file mode 100644 index 00000000..72cff66e --- /dev/null +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/validation/TaskValidator.groovy @@ -0,0 +1,7 @@ +package info.solidsoft.gradle.pitest.validation + +import org.gradle.api.Task + +interface TaskValidator { + void validate(T task) +} diff --git a/plugin/src/test/groovy/info/solidsoft/gradle/pitest/CustomStrategyTest.groovy b/plugin/src/test/groovy/info/solidsoft/gradle/pitest/CustomStrategyTest.groovy index 33a18aa3..1180ca8f 100644 --- a/plugin/src/test/groovy/info/solidsoft/gradle/pitest/CustomStrategyTest.groovy +++ b/plugin/src/test/groovy/info/solidsoft/gradle/pitest/CustomStrategyTest.groovy @@ -1,7 +1,7 @@ package info.solidsoft.gradle.pitest -import info.solidsoft.gradle.pitest.scm.ChangeLogException -import info.solidsoft.gradle.pitest.scm.CustomChangeLogStrategy +import info.solidsoft.gradle.pitest.exception.ChangeLogException +import info.solidsoft.gradle.pitest.scm.strategy.CustomChangeLogStrategy import org.apache.maven.scm.ChangeFile import org.apache.maven.scm.ChangeSet import org.apache.maven.scm.ScmFileStatus diff --git a/plugin/src/test/groovy/info/solidsoft/gradle/pitest/LastCommitStrategyTest.groovy b/plugin/src/test/groovy/info/solidsoft/gradle/pitest/LastCommitStrategyTest.groovy index 477d72e2..050abc71 100644 --- a/plugin/src/test/groovy/info/solidsoft/gradle/pitest/LastCommitStrategyTest.groovy +++ b/plugin/src/test/groovy/info/solidsoft/gradle/pitest/LastCommitStrategyTest.groovy @@ -1,7 +1,7 @@ package info.solidsoft.gradle.pitest -import info.solidsoft.gradle.pitest.scm.ChangeLogException -import info.solidsoft.gradle.pitest.scm.LastCommitStrategy +import info.solidsoft.gradle.pitest.exception.ChangeLogException +import info.solidsoft.gradle.pitest.scm.strategy.LastCommitStrategy import org.apache.maven.scm.ChangeFile import org.apache.maven.scm.ChangeSet import org.apache.maven.scm.ScmFileStatus @@ -9,9 +9,7 @@ import org.apache.maven.scm.ScmResult import org.apache.maven.scm.command.changelog.ChangeLogScmRequest import org.apache.maven.scm.command.changelog.ChangeLogScmResult import org.apache.maven.scm.command.changelog.ChangeLogSet -import org.apache.maven.scm.manager.NoSuchScmProviderException import org.apache.maven.scm.manager.ScmManager -import org.apache.maven.scm.repository.ScmRepositoryException import spock.lang.Specification class LastCommitStrategyTest extends Specification { diff --git a/plugin/src/test/groovy/info/solidsoft/gradle/pitest/LocalChangesStrategyTest.groovy b/plugin/src/test/groovy/info/solidsoft/gradle/pitest/LocalChangesStrategyTest.groovy index 05b31157..4228e78a 100644 --- a/plugin/src/test/groovy/info/solidsoft/gradle/pitest/LocalChangesStrategyTest.groovy +++ b/plugin/src/test/groovy/info/solidsoft/gradle/pitest/LocalChangesStrategyTest.groovy @@ -1,13 +1,11 @@ package info.solidsoft.gradle.pitest -import info.solidsoft.gradle.pitest.scm.ChangeLogException -import info.solidsoft.gradle.pitest.scm.LocalChangesStrategy +import info.solidsoft.gradle.pitest.exception.ChangeLogException +import info.solidsoft.gradle.pitest.scm.strategy.LocalChangesStrategy import org.apache.maven.scm.ScmFile import org.apache.maven.scm.ScmFileStatus import org.apache.maven.scm.command.status.StatusScmResult -import org.apache.maven.scm.manager.NoSuchScmProviderException import org.apache.maven.scm.manager.ScmManager -import org.apache.maven.scm.repository.ScmRepositoryException import spock.lang.Specification class LocalChangesStrategyTest extends Specification {