Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
9603fc4
build(analysis): bundle the tree-sitter-angular grammar
christian-huehn-mw Oct 16, 2026
6a636cb
feat(analysis): parse Angular templates in the tree-sitter module
christian-huehn-mw Oct 16, 2026
2f758a2
feat(analysis): read Angular selectors and pipe names of TypeScript c…
christian-huehn-mw Oct 16, 2026
1490ee5
feat(analysis): measure Angular templates in the unified parser
christian-huehn-mw Oct 16, 2026
db9cf42
feat(analysis): read the domain words of Angular templates
christian-huehn-mw Oct 16, 2026
6e3fa52
feat(analysis): link Angular templates to their components and pipes
christian-huehn-mw Oct 16, 2026
eb8b131
fix(analysis): ignore comment markers in Angular template strings
christian-huehn-mw Oct 16, 2026
be076f2
fix(analysis): drop literals and emit from the words of Angular templ…
christian-huehn-mw Oct 16, 2026
ec1e8bb
test(analysis): add an Angular sample project
christian-huehn-mw Oct 16, 2026
43c9bc6
docs(analysis): add the findings of the Angular sample project
christian-huehn-mw Oct 16, 2026
81e6d00
docs(analysis): note that attribute interpolations stay uncounted in …
christian-huehn-mw Oct 16, 2026
0241fbb
refactor(analysis): share the string fragment node type of the JavaSc…
christian-huehn-mw Oct 16, 2026
fab9197
feat(analysis): read the user-facing attribute texts of Angular templ…
christian-huehn-mw Oct 16, 2026
945477b
feat(analysis): add an island grammar for SQL of all common dialects
christian-huehn-mw Oct 16, 2026
64b6998
feat(analysis): bundle the native SQL island grammar for all platforms
christian-huehn-mw Oct 16, 2026
42e7386
refactor(analysis): run the dependency golden file tests as one param…
christian-huehn-mw Oct 16, 2026
a02f4d8
feat(analysis): measure SQL and extract its names and dependencies
christian-huehn-mw Oct 16, 2026
34cb767
feat(analysis): resolve inheritance, synonyms and type anchors in SQL
christian-huehn-mw Oct 16, 2026
8122db7
feat(analysis): read SQL in the unified, dependency and domain parsers
christian-huehn-mw Oct 16, 2026
ea839a5
docs(analysis): add a SQL sample project with its findings
christian-huehn-mw Oct 16, 2026
29f7bdb
ci(analysis): keep the generated SQL parser out of the quality gate
christian-huehn-mw Oct 16, 2026
084cc58
refactor(analysis): register tree-sitter languages in tables instead …
christian-huehn-mw Oct 16, 2026
41ddc28
ci(analysis): keep the tree-sitter grammars out of the quality gate
christian-huehn-mw Oct 16, 2026
198f638
feat(analysis): parse legacy SQL that left error nodes and whole rout…
christian-huehn-mw Oct 16, 2026
a41316c
feat(analysis): count IIF, EXIT WHEN and CONTINUE WHEN for SQL comple…
christian-huehn-mw Oct 16, 2026
89e2750
refactor(analysis): name the file a declaration joins without saying …
christian-huehn-mw Oct 16, 2026
b7fe21b
feat(analysis): resolve SQL objects to their latest file and quoted n…
christian-huehn-mw Oct 16, 2026
603face
feat(analysis): leave SQL dialect names, catalog words and id out of …
christian-huehn-mw Oct 16, 2026
d265455
refactor(analysis): count functions with a calculator for any node type
christian-huehn-mw Oct 16, 2026
0027a3d
feat(analysis): count the stored procedures, triggers, views and tabl…
christian-huehn-mw Oct 16, 2026
26f7885
refactor(analysis): keep two new comments within the gate's comment l…
christian-huehn-mw Oct 16, 2026
27b79d5
docs(analysis): report the second round of the SQL sample and its cha…
christian-huehn-mw Oct 16, 2026
6ddbda8
build(analysis): vendor the tree-sitter-angular grammar
christian-huehn-mw Oct 16, 2026
6119299
fix(analysis): parse more of Angular templates with a patched grammar
christian-huehn-mw Oct 16, 2026
01e8cba
feat(analysis): count the cases of ICU messages in Angular templates
christian-huehn-mw Oct 16, 2026
311a351
feat(analysis): weigh the text of Angular templates like identifiers
christian-huehn-mw Oct 16, 2026
b084660
refactor(analysis): group what an Angular decorator declares
christian-huehn-mw Oct 16, 2026
a13acf3
feat(analysis): link an Angular component to its template file
christian-huehn-mw Oct 16, 2026
a241b2b
feat(analysis): read the inline templates of Angular components
christian-huehn-mw Oct 16, 2026
4be8981
feat(analysis): resolve ambiguous Angular selectors by the component'…
christian-huehn-mw Oct 16, 2026
9a72d02
docs(analysis): record the Angular gap fixes in the sample project
christian-huehn-mw Oct 16, 2026
3a470ed
refactor(analysis): move the Angular declaration and its tests into o…
christian-huehn-mw Oct 16, 2026
478fe83
fix(analysis): parse the remaining Angular template expressions
christian-huehn-mw Oct 16, 2026
ea599a7
refactor(analysis): let each metric condition match a node itself
christian-huehn-mw Oct 16, 2026
bb747ff
refactor(analysis): name the per-file calculator type and share the S…
christian-huehn-mw Oct 16, 2026
06cc397
refactor(analysis): drop the test-only extension mapping and register…
christian-huehn-mw Oct 16, 2026
704de77
fix(analysis): close dollar quotes by their exact tag and keep column…
christian-huehn-mw Oct 16, 2026
8a990cf
test(analysis): pin how SQL names find the object of their schema
christian-huehn-mw Oct 16, 2026
b06b231
fix(analysis): order SQL migrations by the numbers in their names
christian-huehn-mw Oct 16, 2026
f5c65c0
fix(analysis): report the SQL object counts only for SQL files
christian-huehn-mw Oct 16, 2026
759c99e
test(analysis): measure a SQL sample end to end in the unified parser
christian-huehn-mw Oct 16, 2026
efc32e9
fix(analysis): count each SQL object once and leave out temporary and…
christian-huehn-mw Oct 16, 2026
0284d89
fix(analysis): keep the domain words that SQL also uses as keywords
christian-huehn-mw Oct 16, 2026
66c8ffa
test(analysis): name what the SQL collector test checks and measure p…
christian-huehn-mw Oct 16, 2026
1182986
docs(analysis): describe where SQL bodies end and split the SQL chang…
christian-huehn-mw Oct 16, 2026
922e588
fix(analysis): keep the names of common SQL functions out of the doma…
christian-huehn-mw Oct 16, 2026
a87ce7e
docs(analysis): report the third round of the SQL sample
christian-huehn-mw Oct 16, 2026
546b772
refactor(analysis): let the natural path order compare plain segments
christian-huehn-mw Oct 16, 2026
736e539
refactor(analysis): share the node types of the Angular grammar
christian-huehn-mw Oct 16, 2026
bca3618
test(analysis): read the file edges of a dependency map in one helper
christian-huehn-mw Oct 16, 2026
0c1fc69
refactor(analysis): combine embedded metrics and texts in the facades
christian-huehn-mw Oct 16, 2026
e3e7b4f
refactor(analysis): wrap the Angular declaration in the node's metadata
christian-huehn-mw Oct 16, 2026
bf797a2
refactor(analysis): find the embedded sources of dependencies like th…
christian-huehn-mw Oct 16, 2026
2aa4da1
refactor(analysis): return the declarations of an inline template
christian-huehn-mw Oct 16, 2026
1a9440b
fix(analysis): resolve the escapes of a quoted Angular inline template
christian-huehn-mw Oct 16, 2026
552fecc
fix(analysis): tell same-named Angular classes apart by their files
christian-huehn-mw Oct 16, 2026
c4bd8f6
fix(analysis): add the exports of a module a standalone component imp…
christian-huehn-mw Oct 16, 2026
df887f4
fix(analysis): follow Angular module re-exports to any depth
christian-huehn-mw Oct 16, 2026
5c1462f
fix(analysis): keep Angular's own names out of template identifiers
christian-huehn-mw Oct 16, 2026
68b72eb
refactor(analysis): extract the text of a template as text, not as st…
christian-huehn-mw Oct 16, 2026
dafce34
fix(analysis): weigh only the text a template user reads like identif…
christian-huehn-mw Oct 16, 2026
27cff99
fix(analysis): match a text word only as the last word of an attribut…
christian-huehn-mw Oct 16, 2026
0a34368
refactor(analysis): keep only alt as a named user-facing attribute
christian-huehn-mw Oct 16, 2026
88a70b1
fix(analysis): leave out only Angular's own ng- elements of a template
christian-huehn-mw Oct 16, 2026
ee92bd4
docs(analysis): say that every .html file is read as an Angular template
christian-huehn-mw Oct 16, 2026
e2b2f49
docs(analysis): record review round 1 in the Angular sample findings
christian-huehn-mw Oct 16, 2026
eb5d4c1
refactor(analysis): return embedded declarations beside the declarations
christian-huehn-mw Oct 16, 2026
db33ce6
refactor(analysis): name metric condition types and categories consis…
christian-huehn-mw Oct 16, 2026
5383bf9
refactor(analysis): spell the names of the SQL object counts once
christian-huehn-mw Oct 16, 2026
b32f7c1
refactor(analysis): let the language supply the key that tells counte…
christian-huehn-mw Oct 16, 2026
5d7357b
fix(analysis): tell SQL objects apart by their names as dependencies …
christian-huehn-mw Oct 16, 2026
a4021e2
fix(analysis): read prompt, remark and delimiter inside a statement a…
christian-huehn-mw Oct 16, 2026
9c94a5d
docs: list SQL among the sources and its object counts among the metrics
christian-huehn-mw Oct 16, 2026
8c3b461
refactor(analysis): share the JavaScript node types the extractors re…
christian-huehn-mw Oct 16, 2026
bfede5f
refactor(analysis): keep every Angular node type and field name in on…
christian-huehn-mw Oct 16, 2026
fb1a673
refactor(analysis): register the inline templates of TypeScript once
christian-huehn-mw Oct 16, 2026
4dab1ab
test(analysis): check strings of Angular, 21 languages and two inline…
christian-huehn-mw Oct 16, 2026
4ac71b4
perf(analysis): read inline templates off the tree the file is parsed…
christian-huehn-mw Oct 16, 2026
221fee9
refactor(analysis): read Angular components in TypeScript only
christian-huehn-mw Oct 16, 2026
742e8b4
fix(analysis): keep a code point escape beyond Unicode as written
christian-huehn-mw Oct 16, 2026
9a1ae18
fix(analysis): skip a file unifiedparser cannot analyse instead of st…
christian-huehn-mw Oct 16, 2026
2d5b1f6
fix(analysis): take only the decorator's own template as an inline te…
christian-huehn-mw Oct 16, 2026
d8a4b3e
fix(analysis): read Angular selectors, template files and pipe names …
christian-huehn-mw Oct 16, 2026
1970e4c
fix(analysis): resolve Angular selectors without a hyphen
christian-huehn-mw Oct 16, 2026
7b9a28f
fix(analysis): read a text attribute name written in capitals as one …
christian-huehn-mw Oct 16, 2026
9253bc8
fix(analysis): read the html entities of a text attribute as spaces
christian-huehn-mw Oct 16, 2026
c8002c0
docs(analysis): say in one plain sentence what the Angular support adds
christian-huehn-mw Oct 16, 2026
5324683
refactor(analysis): register the tree-sitter languages in an exhausti…
christian-huehn-mw Oct 16, 2026
bacb2d8
fix(analysis): keep SHOW statements and name the table of a trigger
christian-huehn-mw Oct 16, 2026
07375da
refactor(analysis): count the objects with a key once the whole file …
christian-huehn-mw Oct 16, 2026
7fcf1b2
fix(analysis): count SQL objects per schema, triggers per table and o…
christian-huehn-mw Oct 16, 2026
b5740be
fix(analysis): count the tables a PostgreSQL DO block creates like a …
christian-huehn-mw Oct 16, 2026
a3875f5
fix(analysis): order Flyway's repeatable migrations after the version…
christian-huehn-mw Oct 16, 2026
82aa071
docs(analysis): say that a MySQL procedure recreated with other param…
christian-huehn-mw Oct 16, 2026
7b8759e
refactor(analysis): measure the files of unifiedparser through one seam
christian-huehn-mw Oct 16, 2026
5a36b7e
refactor(analysis): raise a grammar that does not fit the core as its…
christian-huehn-mw Oct 16, 2026
add4599
fix(analysis): name why unifiedparser skipped files and fail when all…
christian-huehn-mw Oct 16, 2026
7f2883a
fix(analysis): read the backslashes of template text as text
christian-huehn-mw Oct 16, 2026
360f73b
fix(analysis): keep the words of a template whole around letter entities
christian-huehn-mw Oct 16, 2026
dbe6b80
fix(analysis): extract the strings of exported JavaScript and TypeScr…
christian-huehn-mw Oct 16, 2026
5f4c5fb
docs(analysis): record review round 3 in the Angular sample findings
christian-huehn-mw Oct 16, 2026
046f4a8
fix(analysis): count Oracle's global temporary table as a table
christian-huehn-mw Oct 16, 2026
9a1530e
refactor(analysis): extract the text of a node in a helper like the o…
christian-huehn-mw Oct 16, 2026
5eb12c7
refactor(analysis): end a unifiedparser run without throwing and catc…
christian-huehn-mw Oct 16, 2026
870b341
refactor(analysis): share how a parser reports files it could not ana…
christian-huehn-mw Oct 16, 2026
39c28ce
fix(analysis): report the files dependencyparser skips by their cause
christian-huehn-mw Oct 16, 2026
13de94e
fix(analysis): report the files domainlanguageparser skips by their c…
christian-huehn-mw Oct 16, 2026
db7e6a9
docs(analysis): describe how the three parsers handle files they cann…
christian-huehn-mw Oct 16, 2026
586c73f
fix(analysis): read GLOBAL TEMP as a session table and ON COMMIT as n…
christian-huehn-mw Oct 16, 2026
7541b97
docs(analysis): bring the SQL sample findings up to the fifth review …
christian-huehn-mw Oct 16, 2026
0a87f71
fix(analysis): count a file dependencyparser cannot read as a failed …
christian-huehn-mw Oct 16, 2026
d1e2be5
fix(analysis): name why an analyser failed in the quality gate
christian-huehn-mw Oct 16, 2026
98e11a6
docs(analysis): count the member procedures of an Oracle type body
christian-huehn-mw Oct 16, 2026
3c33843
fix(analysis): read a temporary view as an object of the session
christian-huehn-mw Oct 16, 2026
41cedf2
docs(analysis): trace the public counts of the SQL sample to their ch…
christian-huehn-mw Oct 16, 2026
c31462a
fix(analysis): name the cause in the error of a run that analysed no …
christian-huehn-mw Oct 16, 2026
04908a3
docs(analysis): add the plans for Angular template and SQL support
christian-huehn-mw Oct 16, 2026
e8de7bc
build(analysis): keep the grammar sources out of the repository
christian-huehn-mw Oct 17, 2026
dffb5f6
feat(analysis): accept known cycles and upward dependencies in the gate
christian-huehn-mw Oct 18, 2026
e6e7b04
ci(visualization): accept the cycle of the recursive explorer tree level
christian-huehn-mw Oct 18, 2026
79beecf
refactor(analysis): write the collector measurer as a lambda
christian-huehn-mw Oct 18, 2026
b979729
refactor(analysis): collect what domainlanguageparser processes in on…
christian-huehn-mw Oct 18, 2026
abeddb0
feat(visualization): make the dependency view a regular view
christian-huehn-mw Oct 18, 2026
cc72353
build(analysis): ship the licenses of the bundled grammar jars
christian-huehn-mw Oct 19, 2026
489843f
refactor(visualization): give every stored-state migration its own file
christian-huehn-mw Oct 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Ideas/
.codecharta-gate-output/
.scannerwork

# sources of the tree-sitter grammars CodeCharta builds itself; only their jars in
# analysis/treeSitterExcavationSite/libs belong in the repo
/tree-sitter-grammars/

# claude
/.claude

Expand Down Expand Up @@ -149,7 +153,7 @@ fabric.properties
# Package Files #
*.jar
!gradle-wrapper.jar
# tree-sitter-tsx and tree-sitter-pascal are not published to Maven Central
# tree-sitter-tsx, tree-sitter-pascal and tree-sitter-angular are not published to Maven Central
!analysis/treeSitterExcavationSite/libs/*.jar
*.war
*.ear
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ There is no analytics, tracking or telemetry.

| | |
| --- | --- |
| **Source code** | [Unified parser](https://maibornwolff.github.io/codecharta/docs/parser/unified): Java, Kotlin, TypeScript, JavaScript, Python, C#, C, C++, Go, Rust, PHP, Ruby, Swift, Objective-C, Vue, Bash, Delphi |
| **Source code** | [Unified parser](https://maibornwolff.github.io/codecharta/docs/parser/unified): Java, Kotlin, TypeScript, JavaScript, Python, C#, C, C++, Go, Rust, PHP, Ruby, Swift, Objective-C, Vue, Bash, Delphi, Angular templates, SQL |
| **Domain language** | [Domain language parser](https://maibornwolff.github.io/codecharta/docs/parser/domain-language): words and phrases with frequency and TF-IDF |
| **Version control** | [Git log](https://maibornwolff.github.io/codecharta/docs/parser/git-log), [SVN log](https://maibornwolff.github.io/codecharta/docs/parser/svn-log) |
| **Any text** | [Raw text](https://maibornwolff.github.io/codecharta/docs/parser/raw-text): indentation levels for any language |
Expand Down
21 changes: 20 additions & 1 deletion analysis/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/)
### Added 🚀

- **Quality gate (experimental)**: `ccsh gate` checks a project against the metric limits and dependency rules
in its `.codecharta.yml` and reports every broken rule on the console, as JSON and through an exit code you choose.
in its `.codecharta.yml`, which can accept single known cycles and upward dependencies, and reports every broken
rule on the console, as JSON and through an exit code you choose.

- **Switching off comments or strings**: `domainlanguageparser` accepts a comment or string weight of 0 to leave those
words out.

- **Angular templates**: `unifiedparser`, `domainlanguageparser` and `dependencyparser` measure Angular templates, in
`.html` files and inline, and link them to the components and pipes they use.

- **SQL**: `unifiedparser`, `dependencyparser` and `domainlanguageparser` read `.sql`, `.pks`, `.pkb` and `.pls` files
of ANSI SQL, T-SQL, PL/SQL, PL/pgSQL and MySQL without being told the dialect.

- **SQL object counts**: `unifiedparser` shows for each SQL file how many stored procedures, triggers, views and
tables it creates.

### Changed

- **Java 22 or newer (breaking)**: `ccsh` no longer starts on Java 17 or 21; the Docker image already ships a
Expand All @@ -29,6 +39,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/)

### Fixed 🐞

- **Strings of exported code**: `domainlanguageparser` reads the strings of exported JavaScript and TypeScript code.

- **Files a parser cannot analyse**: `unifiedparser`, `dependencyparser` and `domainlanguageparser` skip a file they
cannot analyse with a warning that names the cause, and end with an error instead of an empty map when no file could
be analysed at all.

- **Kotlin dependencies**: `dependencyparser` finds the Kotlin dependencies it missed, such as casts and type checks,
caught exceptions, type bounds, lambda and function types, class literals, objects used as values, aliased imports,
fully qualified names, delegated interfaces and `fun interface`s; an inner class depends on the class around it.
Expand Down Expand Up @@ -140,6 +156,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/)

### Chore 👨‍💻 👩‍💻

- **Grammar licenses**: `ccsh` ships the license notices of the Angular, HTML, TypeScript and Pascal grammars it
bundles.

- **TreeSitterExcavationSite is now a module of the analysis build instead of an external library.** The code of
`v0.12.0` moved into `analysis/treeSitterExcavationSite` unchanged, so the three parsers that use it compile
against `project(":treeSitterExcavationSite")` rather than a JitPack artifact and its grammar versions are
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package de.maibornwolff.codecharta.analysers.analyserinterface.failures

import de.maibornwolff.codecharta.util.Logger

/** A file whose analysis failed, relative to the analysed folder, with the reason it failed. */
data class FailedFile(val path: String, val cause: Exception)

/**
* Words the failed files as warnings, one per distinct cause, most frequent first: a broken grammar or extractor that
* fails every file of a language shows as one cause with its count instead of a count without a reason.
*/
object FailureReport {
private const val MAX_LISTED_FILES = 5

fun warnAbout(failures: List<FailedFile>) = warningsOf(failures).forEach { warning -> Logger.warn { warning } }

fun warningsOf(failures: List<FailedFile>): List<String> =
byCause(failures).map { (cause, failed) -> warningOf(cause, failed.map { it.path }.sorted()) }

private fun byCause(failures: List<FailedFile>): List<Pair<String, List<FailedFile>>> = failures
.groupBy { describe(it.cause) }
.toList()
.sortedByDescending { (_, failed) -> failed.size }

private fun warningOf(cause: String, paths: List<String>): String {
val subject = if (paths.size == 1) "1 file could not be analysed and is" else "${paths.size} files could not be analysed and are"
val unlisted = paths.size - MAX_LISTED_FILES
val andMore = if (unlisted > 0) " and $unlisted more" else ""
return "$subject missing from the output ($cause): ${paths.take(MAX_LISTED_FILES).joinToString()}$andMore"
}

// Names the cause itself, as the warnings may not be shown, such as by `ccsh gate --quiet`
fun nothingAnalysed(failures: List<FailedFile>): String {
val causes = byCause(failures)
val (mostFrequentCause, failedByIt) = causes.first()
val failedAll = "No file could be analysed: all ${failures.size} failed"
if (causes.size == 1) return "$failedAll with $mostFrequentCause"
return "$failedAll, ${failedByIt.size} with $mostFrequentCause, the others as the warnings above say"
}

// A native library that cannot be loaded fails every language, a grammar that does not fit the core only its own
fun unusableParser(failure: Throwable): String = if (failure is LinkageError) {
"Cannot load the native tree-sitter libraries: ${failure.message}"
} else {
"Cannot parse the files of a language: ${failure.message}"
}

private fun describe(cause: Exception): String = listOfNotNull(cause::class.simpleName, cause.message).joinToString(": ")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.maibornwolff.codecharta.analysers.analyserinterface.failures

import de.maibornwolff.codecharta.util.Logger
import picocli.CommandLine

/** An analyser run that can end with an error instead of writing its output, and that tells why it did. */
interface FailableRun : CommandLine.IExitCodeGenerator {
/** Why the run ended with an error, null for a run that did not. */
val failureMessage: String?
}

/** The exit code of an analyser run: 0, or 1 once the run ends with an error instead of writing its output. */
class RunExitCode : FailableRun {
private var exitCode = SUCCEEDED

override var failureMessage: String? = null
private set

override fun getExitCode(): Int = exitCode

fun failWith(message: String) {
Logger.error { message }
failureMessage = message
exitCode = FAILED
}

private companion object {
const val SUCCEEDED = 0
const val FAILED = 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ class SourceFileScanner(
}

fun readFileContent(file: File, charset: Charset = Charsets.UTF_8): Result<String> = runCatching {
require(file.exists()) { "File does not exist: ${file.absolutePath}" }
require(file.isFile) { "Path is not a file: ${file.absolutePath}" }
file.readText(charset).withoutByteOrderMarks()
readContent(file, charset)
}.onFailure { error ->
Logger.error(error) { "Failed to read file: ${file.absolutePath}" }
}

/** The text of a file without its byte order marks; a file it cannot read throws, for the caller to report. */
fun readContent(file: File, charset: Charset = Charsets.UTF_8): String {
require(file.exists()) { "File does not exist: ${file.absolutePath}" }
require(file.isFile) { "Path is not a file: ${file.absolutePath}" }
return file.readText(charset).withoutByteOrderMarks()
}

// TreeSitter treats a byte order mark as source text and mis-tokenizes the identifiers around it.
private fun String.withoutByteOrderMarks(): String = replace(BYTE_ORDER_MARK, "")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package de.maibornwolff.codecharta.analysers.analyserinterface.failures

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class FailureReportTest {
@Test
fun `should name the cause and the one file it made fail`() {
// Arrange
val failures = listOf(FailedFile("src/Broken.kt", IllegalStateException("broken extractor")))

// Act
val warnings = FailureReport.warningsOf(failures)

// Assert
assertThat(warnings).containsExactly(
"1 file could not be analysed and is missing from the output (IllegalStateException: broken extractor): src/Broken.kt"
)
}

@Test
fun `should list five files of a cause and count the others`() {
// Arrange
val cause = IllegalArgumentException("unexpected node")
val failures = (1..7).map { FailedFile("src/File$it.kt", cause) }

// Act
val warnings = FailureReport.warningsOf(failures)

// Assert
assertThat(warnings).containsExactly(
"7 files could not be analysed and are missing from the output (IllegalArgumentException: unexpected node): " +
"src/File1.kt, src/File2.kt, src/File3.kt, src/File4.kt, src/File5.kt and 2 more"
)
}

@Test
fun `should warn once per distinct cause, the most frequent first`() {
// Arrange
val failures = listOf(
FailedFile("a.kt", IllegalStateException("one")),
FailedFile("b.kt", IllegalStateException("two")),
FailedFile("c.kt", IllegalStateException("two"))
)

// Act
val warnings = FailureReport.warningsOf(failures)

// Assert
assertThat(warnings).containsExactly(
"2 files could not be analysed and are missing from the output (IllegalStateException: two): b.kt, c.kt",
"1 file could not be analysed and is missing from the output (IllegalStateException: one): a.kt"
)
}

@Test
fun `should name the one cause that made every file fail`() {
// Arrange
val failures = listOf(
FailedFile("a.kt", IllegalStateException("broken extractor")),
FailedFile("b.kt", IllegalStateException("broken extractor"))
)

// Act
val message = FailureReport.nothingAnalysed(failures)

// Assert
assertThat(message).isEqualTo("No file could be analysed: all 2 failed with IllegalStateException: broken extractor")
}

@Test
fun `should name the most frequent of several causes that made every file fail and point to the others`() {
// Arrange
val failures = listOf(
FailedFile("a.kt", IllegalStateException("one")),
FailedFile("b.kt", IllegalStateException("two")),
FailedFile("c.kt", IllegalStateException("two"))
)

// Act
val message = FailureReport.nothingAnalysed(failures)

// Assert
assertThat(message).isEqualTo(
"No file could be analysed: all 3 failed, 2 with IllegalStateException: two, the others as the warnings above say"
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.maibornwolff.codecharta.analysers.analyserinterface.scan

import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import java.io.File
Expand Down Expand Up @@ -240,4 +241,15 @@ class SourceFileScannerTest {
assertThat(missing.exceptionOrNull()).isInstanceOf(IllegalArgumentException::class.java)
assertThat(directory.exceptionOrNull()).isInstanceOf(IllegalArgumentException::class.java)
}

@Test
fun `should throw for a missing file when reading its content for the caller to report`() {
// Arrange
val scanner = SourceFileScanner(listOf("txt"))

// Act & Assert
assertThatThrownBy { scanner.readContent(File(projectDirectory, "missing.txt")) }
.isInstanceOf(IllegalArgumentException::class.java)
.hasMessageContaining("missing.txt")
}
}
38 changes: 35 additions & 3 deletions analysis/analysers/parsers/DependencyParser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ works in. `leaves` are the individual declarations, `namespaces` the packages co
- **`namespaces`** lists the packages with their level and their `parent`, the package containing them.
The hierarchy comes from `parent`, never from the dots of a key.
- **`language`** is the language the declaration is written in, lower case: `java`, `kotlin`, `csharp`,
`cpp`, `go`, `php`, `python`, `typescript`, `javascript`, `vue`, `delphi` or `rust`.
`cpp`, `go`, `php`, `python`, `typescript`, `javascript`, `vue`, `delphi`, `rust`, `angular` or `sql`.
- **`usage`** names how the source declaration uses the target: `usage`, `inheritance`,
`implementation`, `instantiation`, `argument`, `return_value`, `constant_access`. A pair carries one
kind, the first the extractor found, because a used type is identified by its name alone — the same
Expand Down Expand Up @@ -139,7 +139,7 @@ edges on common project layouts; every item below is a bug in DependaCharta that
- Every PHP grouped `use` contributes, not only the first in the file.
- A Module Federation producer is looked up in name order, preferring a federation-name match over a
directory-name match, so the result does not depend on how the file system lists directories.
- A file that fails to parse or exceeds `--file-timeout` is reported in one warning naming the files;
- A file that fails to parse or exceeds `--file-timeout` is reported in a warning per cause naming the files;
a tsconfig or package.json that fails to parse is warned about as well.

`script/compare_dependency_parsers.py` produces this comparison for any project: it runs both tools (or
Expand Down Expand Up @@ -187,7 +187,32 @@ differ from the namespace levels in the logical layer — which are DependaChart

## Supported languages

Java, Kotlin, C#, C/C++, Go, Python, PHP, TypeScript, JavaScript, Vue, Delphi and Rust.
Java, Kotlin, C#, C/C++, Go, Python, PHP, TypeScript, JavaScript, Vue, Delphi, Rust, Angular templates and SQL.

An Angular template (`.html`) depends on each component it names by the element of its selector and on each pipe it
names, as the `@Component` and `@Pipe` decorators in the TypeScript files declare them. A name that several classes
declare means the one in the scope of the template's component, as Angular decides it: the `imports` of a standalone
component, or the `declarations` and `imports` of the `@NgModule` that declares the component, where an imported
module adds what it exports, a module it exports in turn included. A class a decorator names is the one its file
imports, so two classes of the same name in different folders are told apart. A name that no class declares, such as a
library component, or that the scope does not decide draws no edge. A component depends on the template file its
`templateUrl` names; the inline `template` of a component is read like a template file, and its edges leave the `.ts`
file of the component. Every `.html` file is read as an Angular template, by this parser as by `unifiedparser` and
`domainlanguageparser`; exclude the `.html` files that are no templates of an Angular application, such as reports or
documentation, with `-e`.

SQL has no imports: a table, view, synonym, package or routine is found by its name, whatever file creates it and
in whatever dialect. A name with a schema (`dbo.orders`) finds the object of that schema, or else one created
without a schema; a name without one finds the object of the same schema first, then one created without a schema,
then one of any schema. Names compare without
regard to case, like the database does with unquoted names and with names in brackets or backticks; a name in
double quotes keeps its case (`"Orders"` is not `orders`), unless it is written all in one case (`"orders"`,
`"ORDERS"`), which is how PostgreSQL and Oracle store an unquoted name. An object created in several files, such as
a view that migrations recreate, is one leaf per file, and a use points at the last of these files, the latest
migration: paths are ordered folder by folder and name by name, with the numbers in them compared as numbers, so
`V10__orders.sql` comes after `V9__orders.sql`, and a later folder wins over an earlier one whatever the file names.
Flyway's repeatable migrations (`R__views.sql`) come after the versioned ones of their folder, as Flyway runs them
last.

## Usage and parameters

Expand Down Expand Up @@ -232,6 +257,13 @@ levels.
timeout abandons *waiting* for it: the file is skipped with a warning while the parse runs to
completion in the background.

### Files that cannot be analysed

A file whose analysis fails is left out of the map. Once the analysis is over, the parser warns once per cause, with
the number of files it hit and the first five of them; a file that takes longer than `--file-timeout` is such a file,
with the timeout as its cause. It ends with an error and exit code 1, and writes no map, when no file could be analysed
at all, or when a grammar or the native tree-sitter library cannot be used.

## Examples

Analyze a project folder and write a compressed cc.json:
Expand Down
Loading
Loading