Skip to content

Commit

Permalink
Always run the request task and fix up-to-date check for the test task
Browse files Browse the repository at this point in the history
  • Loading branch information
rubengees committed Jun 7, 2018
1 parent 7e61340 commit 668bb1f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/de/smartsquare/squit/SquitPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SquitPlugin : Plugin<Project> {
it.extension = extension

it.dependsOn("squitPreProcess")
it.outputs.upToDateWhen { false }
}

project.tasks.create("squitPostProcess", SquitPostProcessTask::class.java) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ open class SquitPostProcessTask : DefaultTask() {
/**
* The directory of the test sources.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@InputDirectory
val processedSourcesPath: Path = Paths.get(project.buildDir.path,
SQUIT_DIRECTORY, SOURCES_DIRECTORY)

/**
* The directory of the previously requested responses.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@InputDirectory
val actualResponsesPath: Path = Paths.get(project.buildDir.path,
SQUIT_DIRECTORY, RESPONSES_DIRECTORY, RAW_DIRECTORY)

/**
* The directory to save the results in.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@OutputDirectory
val processedActualResponsesPath: Path = Paths.get(project.buildDir.path,
SQUIT_DIRECTORY, RESPONSES_DIRECTORY, PROCESSED_DIRECTORY)
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/de/smartsquare/squit/task/SquitPreProcessTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ open class SquitPreProcessTask : DefaultTask() {
/**
* The tags to filter by.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@get:Input
val tags = when (project.hasProperty("tags")) {
true -> project.property("tags") as String?
Expand All @@ -53,14 +53,14 @@ open class SquitPreProcessTask : DefaultTask() {
/**
* If all excluded or ignored tests should be run nevertheless.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@get:Input
val shouldUnexclude by lazy { project.properties.containsKey("unexclude") }

/**
* The properties of the project parsed into a [Config] object.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@get:Input
val projectConfig: Config by lazy {
ConfigValueFactory.fromMap(project.properties
Expand All @@ -72,14 +72,14 @@ open class SquitPreProcessTask : DefaultTask() {
/**
* The directory of the test sources.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@get:InputDirectory
val sourcesPath by lazy { extension.sourcesPath }

/**
* The directory to save the results in.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@get:OutputDirectory
val processedSourcesPath: Path = Paths.get(project.buildDir.path,
SQUIT_DIRECTORY, SOURCES_DIRECTORY)
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/de/smartsquare/squit/task/SquitRequestTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ open class SquitRequestTask : DefaultTask() {
/**
* The class name of the jdbc [Driver] to use.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@get:Input
val jdbcDriverClassNames by lazy {
extension.jdbcDrivers
Expand All @@ -73,15 +73,15 @@ open class SquitRequestTask : DefaultTask() {
/**
* The directory of the test sources.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@get:InputDirectory
val processedSourcesPath: Path = Paths.get(project.buildDir.path,
SQUIT_DIRECTORY, SOURCES_DIRECTORY)

/**
* The directory to save the results in.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@get:OutputDirectory
val actualResponsesPath: Path = Paths.get(project.buildDir.path,
SQUIT_DIRECTORY, RESPONSES_DIRECTORY, RAW_DIRECTORY)
Expand Down
35 changes: 29 additions & 6 deletions src/main/kotlin/de/smartsquare/squit/task/SquitTestTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.smartsquare.squit.task

import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import com.typesafe.config.Optional
import de.smartsquare.squit.SquitExtension
import de.smartsquare.squit.entity.SquitResult
import de.smartsquare.squit.io.FilesUtils
Expand All @@ -11,7 +12,9 @@ import de.smartsquare.squit.report.XmlReportWriter
import de.smartsquare.squit.util.Constants.CONFIG
import de.smartsquare.squit.util.Constants.DIFF
import de.smartsquare.squit.util.Constants.ERROR
import de.smartsquare.squit.util.Constants.META
import de.smartsquare.squit.util.Constants.PROCESSED_DIRECTORY
import de.smartsquare.squit.util.Constants.RAW_DIRECTORY
import de.smartsquare.squit.util.Constants.RESPONSES_DIRECTORY
import de.smartsquare.squit.util.Constants.SOURCES_DIRECTORY
import de.smartsquare.squit.util.Constants.SQUIT_DIRECTORY
Expand All @@ -22,6 +25,7 @@ import okhttp3.MediaType
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.OutputFile
Expand All @@ -31,6 +35,7 @@ import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.properties.Delegates
import kotlin.streams.toList

/**
* Task for comparing the actual responses to the expected responses and generating a report.
Expand All @@ -43,23 +48,41 @@ open class SquitTestTask : DefaultTask() {
/**
* The directory of the test sources.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@get:InputDirectory
val processedSourcesPath: Path = Paths.get(project.buildDir.path,
SQUIT_DIRECTORY, SOURCES_DIRECTORY)

/**
* The directory of the previously requested responses.
* The directory of the previously (processed) requested responses.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@get:InputDirectory
val processedResponsesPath: Path = Paths.get(project.buildDir.path,
SQUIT_DIRECTORY, RESPONSES_DIRECTORY, PROCESSED_DIRECTORY)

/**
* Collection of meta.json files for up-to-date checking.
*/
@Suppress("MemberVisibilityCanBePrivate", "unused")
@get:InputFiles
@get:Optional
val metaPaths: List<Path> by lazy {
val rawDirectoryPath = Paths.get(project.buildDir.path, SQUIT_DIRECTORY, RESPONSES_DIRECTORY, RAW_DIRECTORY)

if (Files.exists(rawDirectoryPath)) {
Files.walk(rawDirectoryPath).use { stream ->
stream.filter { Files.isRegularFile(it) && it.fileName.toString() == META }.toList()
}
} else {
emptyList<Path>()
}
}

/**
* The directory to generate the xml report file into.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@get:OutputFile
val xmlReportFilePath: Path by lazy {
extension.reportsPath.resolve("xml").resolve("main.xml")
Expand All @@ -68,7 +91,7 @@ open class SquitTestTask : DefaultTask() {
/**
* The directory to generate the xml report file into.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@get:OutputDirectory
val htmlReportDirectoryPath: Path by lazy {
extension.reportsPath.resolve("html")
Expand All @@ -77,7 +100,7 @@ open class SquitTestTask : DefaultTask() {
/**
* The directory to copy failed tests into.
*/
@Suppress("MemberVisibilityCanPrivate")
@Suppress("MemberVisibilityCanBePrivate")
@get:OutputDirectory
val failureResultDirectory by lazy {
extension.reportsPath.resolve("failures") ?: throw IllegalArgumentException("reportPath cannot be null")
Expand Down

0 comments on commit 668bb1f

Please sign in to comment.