Skip to content

Commit

Permalink
Merge pull request #1 from antohaby/minor-ux-fixes
Browse files Browse the repository at this point in the history
Update projectsDir option checker and make reporter to store all data in the reporterDir, instead of parent directory
  • Loading branch information
adam-enko authored Mar 11, 2024
2 parents 9cb438e + d2768ac commit fcd54fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/main/kotlin/DatalyzerCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class DatalyzerCommand : CliktCommand() {
private val gradleProjectDir: Path by option("--projectDir", help = "Location of the Gradle Project")
.path()
.default(Path(".").absolute())
.check("Must be a directory, but was a file") { it.isDirectory() }
.check("Must be a root directory of a Gradle Project") { it.exists() && it.isDirectory() }

private val reportsDir: Path by option("--reportsDir", help = "Output reports directory")
.path()
Expand Down
22 changes: 13 additions & 9 deletions src/main/kotlin/Reporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package org.jetbrains.experimental.gradle.datalyzer

import com.github.ajalt.mordant.terminal.Terminal
import org.jetbrains.experimental.gradle.datalyzer.utils.replaceNonAlphaNumeric
import java.io.BufferedOutputStream
import java.io.BufferedWriter
import java.io.File
Expand All @@ -13,19 +12,24 @@ import java.nio.file.StandardOpenOption.SYNC
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
import kotlin.io.path.*
import org.jetbrains.experimental.gradle.datalyzer.utils.replaceNonAlphaNumeric

/**
* Gather information about the Gradle project, and save it to disk.
*/
internal class Reporter(
private val reportsDir: Path,
reportsDir: Path,
private val terminal: Terminal,
) {
private val scripts = reportsDir.resolve("scripts.md")
private val log = reportsDir.resolve("output.log")
private val reportZip = reportsDir.resolve("${reportsDir.name}.zip")
private val dataDir = reportsDir.resolve("data")

private val scripts = dataDir.resolve("scripts.md")
private val log = dataDir.resolve("output.log")

init {
reportsDir.createDirectories()
dataDir.createDirectories()
scripts.createFile()
log.createFile()
}
Expand Down Expand Up @@ -67,15 +71,15 @@ internal class Reporter(


fun taskOutput(taskName: String): BufferedOutputStream {
return reportsDir
return dataDir
.resolve("task-stdout-${taskName.replaceNonAlphaNumeric()}-${System.currentTimeMillis()}.txt")
.createFile()
.outputStream()
.buffered()
}

fun taskData(taskName: String): BufferedWriter {
return reportsDir
return dataDir
.resolve("task-data-${taskName.replaceNonAlphaNumeric()}-${System.currentTimeMillis()}.txt")
.createFile()
.bufferedWriter()
Expand All @@ -100,15 +104,15 @@ internal class Reporter(
}

fun zip(): Path {
val zipFile = reportsDir.parent.resolve("${reportsDir.name}.zip").apply {
val zipFile = reportZip.apply {
if (exists()) deleteExisting()
createFile()
}

ZipOutputStream(zipFile.outputStream().buffered()).use { zip ->
reportsDir.walk().forEach { src ->
dataDir.walk().forEach { src ->
val zipFileName = src.absolute().invariantSeparatorsPathString
.removePrefix(reportsDir.absolute().invariantSeparatorsPathString)
.removePrefix(dataDir.absolute().invariantSeparatorsPathString)
.removePrefix("/")
.let { if (src.isDirectory()) "$it/" else it }

Expand Down

0 comments on commit fcd54fe

Please sign in to comment.