Skip to content

Commit

Permalink
create root report dir before creating any outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
sergii.gnatiuk committed Aug 4, 2021
1 parent 1bcb38d commit 00b2fed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ subprojects {
apply plugin: 'maven-publish'
apply plugin: 'jacoco'

version '0.7.3-SNAPSHOT'
version '0.7.3'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ open class DiffCoverageTask : DefaultTask() {

@OutputDirectory
fun getOutputDir(): File {
return project.getReportOutputDir().toFile()
return project.getReportOutputDir().toFile().apply {
log.debug("Diff Coverage output dir: $absolutePath, " +
"exists=${exists()}, isDir=$isDirectory, canRead=${canRead()}, canWrite=${canWrite()}")
}
}

init {
Expand All @@ -57,10 +60,7 @@ open class DiffCoverageTask : DefaultTask() {
@TaskAction
fun executeAction() {
log.info("DiffCoverage configuration: $diffCoverageReport")
val fileNameToModifiedLineNumbers = obtainUpdatesInfo(
project.rootProject.projectDir,
diffCoverageReport
)
val fileNameToModifiedLineNumbers = obtainUpdatesInfo(diffCoverageReport)
fileNameToModifiedLineNumbers.forEach { (file, rows) ->
log.info("File $file has ${rows.size} modified lines")
log.debug("File $file has modified lines $rows")
Expand Down Expand Up @@ -99,13 +99,14 @@ open class DiffCoverageTask : DefaultTask() {
return project.tasks.findByName("jacocoTestReport") as? JacocoReport
}

private fun obtainUpdatesInfo(
projectRoot: File,
configuration: ChangesetCoverageConfiguration
): Map<String, Set<Int>> {
val diffSource = getDiffSource(projectRoot, configuration.diffSource).apply {
private fun obtainUpdatesInfo(configuration: ChangesetCoverageConfiguration): Map<String, Set<Int>> {
val reportDir: File = getOutputDir().apply {
val isCreated = mkdirs()
log.debug("Creating of report dir '$absolutePath' is successful: $isCreated")
}
val diffSource = getDiffSource(project.rootProject.projectDir, configuration.diffSource).apply {
log.debug("Starting to retrieve modified lines from $sourceDescription'")
saveDiffTo(projectRoot.resolve(configuration.reportConfiguration.baseReportDir)).apply {
saveDiffTo(reportDir).apply {
log.info("diff content saved to '$absolutePath'")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface DiffSource {
}

internal class FileDiffSource(
private val filePath: String
private val filePath: String
) : DiffSource {

override val sourceDescription = "File: $filePath"
Expand All @@ -34,7 +34,7 @@ internal class FileDiffSource(
}

internal class UrlDiffSource(
private val url: String
private val url: String
) : DiffSource {
override val sourceDescription = "URL: $url"

Expand All @@ -50,8 +50,8 @@ internal class UrlDiffSource(
}

internal class GitDiffSource(
private val projectRoot: File,
private val compareWith: String
private val projectRoot: File,
private val compareWith: String
) : DiffSource {

private val diffContent: String by lazy {
Expand All @@ -70,13 +70,13 @@ internal class GitDiffSource(
}

fun getDiffSource(
projectRoot: File,
diffConfig: DiffSourceConfiguration
projectRoot: File,
diffConfig: DiffSourceConfiguration
): DiffSource = when {

diffConfig.file.isNotBlank() && diffConfig.url.isNotBlank() -> throw IllegalStateException(
"Expected only Git configuration or file or URL diff source more than one: " +
"git.diffBase=${diffConfig.git.diffBase} file=${diffConfig.file}, url=${diffConfig.url}"
"Expected only Git configuration or file or URL diff source more than one: " +
"git.diffBase=${diffConfig.git.diffBase} file=${diffConfig.file}, url=${diffConfig.url}"
)

diffConfig.file.isNotBlank() -> FileDiffSource(diffConfig.file)
Expand Down

0 comments on commit 00b2fed

Please sign in to comment.