Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/3338/improve parser suggestion 3 #3414

Merged
merged 20 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/)

- Changed short form of parameter `--file-extensions` of RawTextParser from `-f` to `-fe` [#3405](https://github.com/MaibornWolff/codecharta/pull/3405)
- Update readme and gh-pages for RawTextParser [#3405](https://github.com/MaibornWolff/codecharta/pull/3405)
- Changed the `--format` flag for csv-output in SourceCodeParser from `table` to `csv` [#3414](https://github.com/MaibornWolff/codecharta/pull/3414)

### Fixed 🐞

- Fix RawTextParser producing incorrect output when no (or multiple) file extensions were specified in interactive mode [#3405](https://github.com/MaibornWolff/codecharta/pull/3405)
- Fix handling of empty inputs for the `--metrics`, `--exclude`, `--file-extensions` flags in the RawTextParser [#3415](https://github.com/MaibornWolff/codecharta/pull/3415)
- Fix the csv-exporter so that it exports multiple projects instead of just one when multiple projects are specified [#3414](https://github.com/MaibornWolff/codecharta/pull/3414)

### Added 🚀

- Add logging of absolute file paths of output files [#3414](https://github.com/MaibornWolff/codecharta/pull/3414)

## [1.120.1] - 2023-11-17

Expand Down
1 change: 1 addition & 0 deletions analysis/export/CSVExporter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dependencies {
implementation project(':tools:InteractiveParser')

implementation group: 'com.univocity', name: 'univocity-parsers', version: univocity_parsers_version
implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlin_logging_version
implementation group: 'info.picocli', name: 'picocli', version: picocli_version
implementation group: 'io.fastjson', name: 'boon', version: boon_version
implementation group: 'com.github.kotlin-inquirer', name: 'kotlin-inquirer', version: kotlin_inquirer_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import com.univocity.parsers.csv.CsvWriterSettings
import de.maibornwolff.codecharta.model.Node
import de.maibornwolff.codecharta.model.Path
import de.maibornwolff.codecharta.model.Project
import de.maibornwolff.codecharta.serialization.FileExtension
import de.maibornwolff.codecharta.serialization.OutputFileHandler
import de.maibornwolff.codecharta.serialization.ProjectDeserializer
import de.maibornwolff.codecharta.tools.interactiveparser.InteractiveParser
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import de.maibornwolff.codecharta.tools.interactiveparser.util.CodeChartaConstants
import de.maibornwolff.codecharta.util.InputHelper
import mu.KotlinLogging
import picocli.CommandLine
import java.io.BufferedWriter
import java.io.File
Expand Down Expand Up @@ -41,6 +44,8 @@ class CSVExporter() : Callable<Void>, InteractiveParser {
override val name = NAME
override val description = DESCRIPTION

private val logger = KotlinLogging.logger {}

companion object {
const val NAME = "csvexport"
const val DESCRIPTION = "generates csv file with header"
Expand All @@ -51,11 +56,11 @@ class CSVExporter() : Callable<Void>, InteractiveParser {
}
}

private fun writer(): Writer {
private fun writer(append: Boolean): Writer {
return if (outputFile.isEmpty()) {
OutputStreamWriter(System.out)
} else {
BufferedWriter(FileWriter(outputFile))
BufferedWriter(FileWriter(outputFile, append))
}
}

Expand All @@ -66,12 +71,23 @@ class CSVExporter() : Callable<Void>, InteractiveParser {
}

if (!InputHelper.isInputValid(sources, canInputContainFolders = false)) {
throw IllegalArgumentException("Input invalid file for CSVExporter, stopping execution...")
throw IllegalArgumentException("Invalid input file for CSVExporter, stopping execution...")
}

if (outputFile.isNotEmpty()) {
outputFile = OutputFileHandler.checkAndFixFileExtension(outputFile, false, FileExtension.CSV)
}

val projects = sources.map { ProjectDeserializer.deserializeProject(it.inputStream()) }
projects.forEachIndexed { index, project ->
val append = index > 0
writeUsingWriter(project, writer(append))
}

projects.forEach { writeUsingWriter(it, writer()) }
if (outputFile.isNotEmpty()) {
val absoluteFilePath = File(outputFile).absolutePath
logger.info("Created output file at $absoluteFilePath")
}

return null
}
Expand All @@ -84,11 +100,11 @@ class CSVExporter() : Callable<Void>, InteractiveParser {

val header = listOf("path", "name", "type")
.plus(attributeNames)
.plus(List(maxHierarchy, { "dir$it" }))
.plus(List(maxHierarchy) { "dir$it" })

writer.writeHeaders(header)

project.rootNode.nodes.forEach({ path: Path, node: Node -> writer.writeRow(row(path, node, attributeNames)) })
project.rootNode.nodes.forEach { (path: Path, node: Node) -> writer.writeRow(row(path, node, attributeNames)) }

writer.close()
}
Expand All @@ -101,10 +117,9 @@ class CSVExporter() : Callable<Void>, InteractiveParser {
val dirs = path.edgesList.dropLast(1)

return when {
values.distinct().none { !it.isBlank() } -> listOf()
values.distinct().none { it.isNotBlank() } -> listOf()
dirs.size < maxHierarchy -> rowWithoutDirs.plus(dirs).plus(
List(maxHierarchy - dirs.size, { "" })
)
List(maxHierarchy - dirs.size) { "" })
else -> rowWithoutDirs.plus(dirs.subList(0, maxHierarchy))
}
}
Expand Down
Loading
Loading