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

Replace scanner with reader #3406 #3422

Merged
merged 19 commits into from
Dec 6, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/)
- Fix file extensions of output files for merged projects [#3421](https://github.com/MaibornWolff/codecharta/pull/3421)
- Fix the ability for users to accidentally pass invalid metrics to the RawTextParser without it crashing [#3424](https://github.com/MaibornWolff/codecharta/pull/3424)
- Fix deselected buildings with green/red roof in delta mode do not reset their color roof [#3426](https://github.com/MaibornWolff/codecharta/pull/3426)
- Fix parser hang issue in interactive mode caused by unintentional "enter" input after the last question [#3422](https://github.com/MaibornWolff/codecharta/pull/3422)

### Chore ‍👨‍💻 👩‍💻

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import java.util.concurrent.Callable
description = [CSVExporter.DESCRIPTION],
footer = [CodeChartaConstants.General.GENERIC_FOOTER]
)
class CSVExporter() : Callable<Void>, InteractiveParser {
class CSVExporter() : Callable<Unit>, InteractiveParser {

@CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
private var help = false
Expand Down Expand Up @@ -65,7 +65,7 @@ class CSVExporter() : Callable<Void>, InteractiveParser {
}

@Throws(IOException::class)
override fun call(): Void? {
override fun call(): Unit? {
if (maxHierarchy < 0) {
throw IllegalArgumentException("depth-of-hierarchy must not be negative")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import java.util.concurrent.Callable
)
class EdgeFilter(
private val output: PrintStream = System.out
) : Callable<Void?>, InteractiveParser {
) : Callable<Unit?>, InteractiveParser {

@CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
var help: Boolean = false
Expand All @@ -45,7 +45,7 @@ class EdgeFilter(
}
}

override fun call(): Void? {
override fun call(): Unit? {
if (!InputHelper.isInputValidAndNotNull(arrayOf(source), canInputContainFolders = false)) {
throw IllegalArgumentException("Input invalid file for EdgeFilter, stopping execution...")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import java.util.concurrent.Callable
)
class MergeFilter(
private val output: PrintStream = System.out
) : Callable<Void?>, InteractiveParser {
) : Callable<Unit?>, InteractiveParser {

@CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
var help: Boolean = false
Expand Down Expand Up @@ -68,7 +68,7 @@ class MergeFilter(
}
}

override fun call(): Void? {
override fun call(): Unit? {
val nodeMergerStrategy =
when {
leafStrategySet -> LeafNodeMergerStrategy(addMissingNodes, ignoreCase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class StructureModifier(
private val input: InputStream = System.`in`,
private val output: PrintStream = System.out,
private val error: PrintStream = System.err
) : Callable<Void?>, InteractiveParser {
) : Callable<Unit?>, InteractiveParser {

@CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
var help: Boolean = false
Expand Down Expand Up @@ -69,7 +69,7 @@ class StructureModifier(
}
}

override fun call(): Void? {
override fun call(): Unit? {

project = readProject() ?: return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class StructureModifierTest {

@Test
fun `reads project piped input`() {
val input = File("src/test/resources/sample_project.cc.json").bufferedReader().readLines()
.joinToString(separator = "") { it }
val inputFilePath = "src/test/resources/sample_project.cc.json"
val input = File(inputFilePath).bufferedReader().readLines().joinToString(separator = "") { it }

val cliResult = executeForOutput(input, arrayOf("-r=/does/not/exist"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import java.util.concurrent.Callable
)
class CSVImporter(
private val output: PrintStream = System.out
) : Callable<Void>, InteractiveParser {
) : Callable<Unit>, InteractiveParser {

@CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
private var help = false
Expand Down Expand Up @@ -56,7 +56,7 @@ class CSVImporter(
}

@Throws(IOException::class)
override fun call(): Void? {
override fun call(): Unit? {
if (!InputHelper.isInputValid(files.toTypedArray(), canInputContainFolders = false)) {
throw IllegalArgumentException("Input invalid file for CSVImporter, stopping execution...")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.util.concurrent.Callable
)
class SourceMonitorImporter(
private val output: PrintStream = System.out
) : Callable<Void>, InteractiveParser {
) : Callable<Unit>, InteractiveParser {

@CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
private var help = false
Expand Down Expand Up @@ -53,7 +53,7 @@ class SourceMonitorImporter(
}

@Throws(IOException::class)
override fun call(): Void? {
override fun call(): Unit? {
if (!InputHelper.isInputValid(files.toTypedArray(), canInputContainFolders = false)) {
throw IllegalArgumentException("Input invalid file for SourceMonitorImporter, stopping execution...")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.util.concurrent.Callable
footer = [CodeChartaConstants.General.GENERIC_FOOTER]
)
class CodeMaatImporter(
private val output: PrintStream = System.out) : Callable<Void>, InteractiveParser {
private val output: PrintStream = System.out) : Callable<Unit>, InteractiveParser {

@CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
private var help = false
Expand Down Expand Up @@ -53,7 +53,7 @@ class CodeMaatImporter(
}

@Throws(IOException::class)
override fun call(): Void? {
override fun call(): Unit? {
if (!InputHelper.isInputValid(files.toTypedArray(), canInputContainFolders = false)) {
throw IllegalArgumentException("Input invalid file for CodeMaatImporter, stopping execution...")
}
Expand Down
1 change: 1 addition & 0 deletions analysis/import/GitLogParser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dependencies {
implementation project(':model')
implementation project(':filter:MergeFilter')
implementation project(':tools:InteractiveParser')
implementation project(':tools:PipeableParser')

implementation group: 'org.apache.commons', name: 'commons-lang3', version: commons_lang3_version
implementation group: 'info.picocli', name: 'picocli', version: picocli_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import de.maibornwolff.codecharta.serialization.ProjectSerializer
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.tools.pipeableparser.PipeableParser
import de.maibornwolff.codecharta.tools.pipeableparser.PipeableParserSyncFlag
import de.maibornwolff.codecharta.util.ResourceSearchHelper
import org.mozilla.universalchardet.UniversalDetector
import picocli.CommandLine
Expand All @@ -36,7 +38,7 @@ class GitLogParser(
private val input: InputStream = System.`in`,
private val output: PrintStream = System.out,
private val error: PrintStream = System.err
) : Callable<Void>, InteractiveParser {
) : Callable<Unit>, InteractiveParser, PipeableParser {

private val inputFormatNames = GIT_LOG_NUMSTAT_RAW_REVERSED

Expand Down Expand Up @@ -94,8 +96,8 @@ class GitLogParser(
}

@Throws(IOException::class)
override fun call(): Void? {
print(" ")
override fun call(): Unit? {
logPipeableParserSyncSignal(PipeableParserSyncFlag.SYNC_FLAG)
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import java.util.concurrent.Callable
footer = [CodeChartaConstants.General.GENERIC_FOOTER]
)

class LogScanCommand : Callable<Void>, InteractiveParser {
class LogScanCommand : Callable<Unit>, InteractiveParser {

@CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
private var help = false
Expand Down Expand Up @@ -62,7 +62,7 @@ class LogScanCommand : Callable<Void>, InteractiveParser {
const val DESCRIPTION = "git log parser log-scan - generates cc.json from a given git-log file"
}

override fun call(): Void? {
override fun call(): Unit? {
if (!InputHelper.isInputValidAndNotNull(arrayOf(gitLogFile), canInputContainFolders = false)) {
throw IllegalArgumentException("Input invalid file for GitLogScan, stopping execution...")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.util.concurrent.Callable
footer = ["Copyright(c) 2022, MaibornWolff GmbH"]
)

class RepoScanCommand : Callable<Void>, InteractiveParser {
class RepoScanCommand : Callable<Unit>, InteractiveParser {

@CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
private var help = false
Expand Down Expand Up @@ -53,7 +53,7 @@ class RepoScanCommand : Callable<Void>, InteractiveParser {
const val DESCRIPTION = "git log parser repo-scan - generates cc.json from an automatically generated git-log file"
}

override fun call(): Void? {
override fun call(): Unit? {
val repoPath: Path
if (repoPathName == null || !InputHelper.isInputValid(arrayOf(File(repoPathName!!)), canInputContainFolders = true)) {
throw IllegalArgumentException("Input invalid file for GitRepoScan, stopping execution...")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import java.util.concurrent.Callable

class MetricGardenerImporter(
private val output: PrintStream = System.out
) : Callable<Void>, InteractiveParser {
) : Callable<Unit>, InteractiveParser {

private val mapper = jacksonObjectMapper()

Expand Down Expand Up @@ -71,7 +71,7 @@ class MetricGardenerImporter(
}

@Throws(IOException::class)
override fun call(): Void? {
override fun call(): Unit? {
if (!InputHelper.isInputValidAndNotNull(arrayOf(inputFile), canInputContainFolders = true)) {
throw IllegalArgumentException("Input invalid file for MetricGardenerImporter, stopping execution...")
}
Expand Down
1 change: 1 addition & 0 deletions analysis/import/SVNLogParser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dependencies {
implementation project(':model')
implementation project(':filter:MergeFilter')
implementation project(':tools:InteractiveParser')
implementation project(':tools:PipeableParser')

implementation group: 'org.apache.commons', name: 'commons-lang3', version: commons_lang3_version
implementation group: 'info.picocli', name: 'picocli', version: picocli_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import de.maibornwolff.codecharta.serialization.ProjectSerializer
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.tools.pipeableparser.PipeableParser
import de.maibornwolff.codecharta.tools.pipeableparser.PipeableParserSyncFlag
import de.maibornwolff.codecharta.util.InputHelper
import de.maibornwolff.codecharta.util.ResourceSearchHelper
import org.mozilla.universalchardet.UniversalDetector
Expand All @@ -22,7 +24,6 @@ import java.io.InputStream
import java.io.PrintStream
import java.nio.charset.Charset
import java.nio.file.Files
import java.util.Arrays
import java.util.concurrent.Callable
import java.util.stream.Stream

Expand All @@ -35,7 +36,7 @@ class SVNLogParser(
private val input: InputStream = System.`in`,
private val output: PrintStream = System.out,
private val error: PrintStream = System.err
) : Callable<Void>, InteractiveParser {
) : Callable<Unit>, InteractiveParser, PipeableParser {

@CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
private var help = false
Expand Down Expand Up @@ -64,7 +65,7 @@ class SVNLogParser(

private val metricsFactory: MetricsFactory
get() {
val nonChurnMetrics = Arrays.asList(
val nonChurnMetrics = listOf(
"age_in_weeks",
"number_of_authors",
"number_of_commits",
Expand Down Expand Up @@ -107,8 +108,8 @@ class SVNLogParser(
}

@Throws(IOException::class)
override fun call(): Void? {
print(" ")
override fun call(): Unit? {
logPipeableParserSyncSignal(PipeableParserSyncFlag.SYNC_FLAG)

if (!InputHelper.isInputValidAndNotNull(arrayOf(file), canInputContainFolders = false)) {
throw IllegalArgumentException("Input invalid file for SVNLogParser, stopping execution...")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import java.util.concurrent.Callable
class SonarImporterMain(
private val input: InputStream = System.`in`,
private val output: PrintStream = System.out
) : Callable<Void>, InteractiveParser {
) : Callable<Unit>, InteractiveParser {

@CommandLine.Option(
names = ["-h", "--help"], usageHelp = true, description = [
Expand Down Expand Up @@ -88,7 +88,7 @@ class SonarImporterMain(
return SonarMeasuresAPIImporter(measuresDatasource, metricsDatasource, sonarCodeURLLinker, translator, usePath)
}

override fun call(): Void? {
override fun call(): Unit? {
if (url == "" || projectId == "") {
throw IllegalArgumentException("Input invalid Url or ProjectID for SonarImporter, stopping execution...")
}
Expand Down
1 change: 1 addition & 0 deletions analysis/import/SourceCodeParser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dependencies {
implementation project(':model')
implementation project(':filter:MergeFilter')
implementation project(':tools:InteractiveParser')
implementation project(':tools:PipeableParser')

implementation group: 'info.picocli', name: 'picocli', version: picocli_version

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ 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.tools.pipeableparser.PipeableParser
import de.maibornwolff.codecharta.tools.pipeableparser.PipeableParserSyncFlag
import de.maibornwolff.codecharta.util.InputHelper
import de.maibornwolff.codecharta.util.ResourceSearchHelper
import mu.KotlinLogging
Expand All @@ -30,10 +32,10 @@ import java.util.concurrent.Callable
footer = [SourceCodeParserMain.FOOTER]
)
class SourceCodeParserMain(
private val outputStream: PrintStream,
private val input: InputStream = System.`in`,
private val error: PrintStream = System.err
) : Callable<Void>, InteractiveParser {
private val output: PrintStream,
private val input: InputStream = System.`in`,
private val error: PrintStream = System.err
) : Callable<Unit>, InteractiveParser, PipeableParser {
// we need this constructor because ccsh requires an empty constructor
constructor() : this(System.out)

Expand Down Expand Up @@ -103,8 +105,9 @@ class SourceCodeParserMain(
}

@Throws(IOException::class)
override fun call(): Void? {
print(" ")
override fun call(): Unit? {
logPipeableParserSyncSignal(PipeableParserSyncFlag.SYNC_FLAG)

if (!InputHelper.isInputValidAndNotNull(arrayOf(file), canInputContainFolders = true)) {
throw IllegalArgumentException("Input invalid file for SourceCodeParser, stopping execution...")
}
Expand Down Expand Up @@ -134,7 +137,7 @@ class SourceCodeParserMain(

private fun getCsvOutputWriter(): Writer {
return if (outputFile == null) {
OutputStreamWriter(outputStream)
OutputStreamWriter(output)
} else {
val outputName = outputFile!!.name
BufferedWriter(FileWriter(OutputFileHandler.checkAndFixFileExtension(outputName, false, FileExtension.CSV)))
Expand All @@ -152,7 +155,7 @@ class SourceCodeParserMain(
}
}

private fun getJsonOutputStream() = OutputFileHandler.stream(outputFile?.absolutePath, outputStream, compress)
private fun getJsonOutputStream() = OutputFileHandler.stream(outputFile?.absolutePath, output, compress)

override fun getDialog(): ParserDialogInterface = ParserDialog
override fun isApplicable(resourceToBeParsed: String): Boolean {
Expand Down
1 change: 1 addition & 0 deletions analysis/import/TokeiImporter/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dependencies {
implementation project(':model')
implementation project(':tools:InteractiveParser')
implementation project(':tools:PipeableParser')

implementation group: 'info.picocli', name: 'picocli', version: picocli_version
implementation group: 'io.fastjson', name: 'boon', version: boon_version
Expand Down
Loading
Loading