Skip to content
Open
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
7 changes: 7 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"permissions": {
"allow": [
"Bash(ls -lh c:/repository/manifest-parser/test/resources/*.gradle* c:/repository/manifest-parser/test/resources/gradle.properties c:/repository/manifest-parser/test/resources/gradle/)"
]
}
}
110 changes: 110 additions & 0 deletions GRADLE_PARSER_IMPLEMENTATION_PLAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Gradle Parser Implementation Plan

## Overview
This document describes the implementation plan and execution steps for adding Gradle manifest parsing support to the `manifest-parser` repository.

The parser was extended to support static Gradle dependency declarations in both Groovy and Kotlin DSL, including common production patterns such as multi-line dependencies and conditional `if` blocks.

---

## Implementation Plan

### 1. Analyze existing code flow
- Inspect `cmd/main.go` to understand entrypoint behavior.
- Review `pkg/parser/parser.go` and `pkg/parser/parser_factory.go` to understand the parser interface and factory logic.
- Review `pkg/parser/manifest-file-selector.go` to see how manifest types are detected.
- Review existing language parser implementations for style and output format.

### 2. Add Gradle manifest detection
- Extend `pkg/parser/manifest-file-selector.go` to recognize `build.gradle` and `build.gradle.kts` files.
- Add a new `Manifest` type for Gradle.

### 3. Add factory support for Gradle
- Update `pkg/parser/parser_factory.go` to import the new Gradle parser.
- Return the Gradle parser instance when the selected manifest is Gradle.

### 4. Implement Gradle parser
- Create `internal/parsers/gradle/gradle_parser.go`.
- Implement the `Parser` interface for Gradle.
- Parse dependencies into `models.Package` entries.

### 5. Add variable resolution
- Read `gradle.properties` values.
- Parse Groovy `ext {}` blocks and `ext.key` assignments.
- Parse Kotlin DSL `val` and `const val` declarations.
- Resolve `${var}` and `$var` references in dependency strings.

### 6. Add support for multi-line dependency declarations
- Detect dependency statements spanning multiple lines.
- Join logical dependency lines before parsing.
- Support both string notation and map notation across line breaks.

### 7. Add conditional dependency support
- Parse dependencies inside conditional blocks such as `if (...) { ... }`.
- Treat static declarations inside conditionals as valid parse targets.

### 8. Add Kotlin DSL support
- Support Kotlin string syntax: `implementation("group:name:version")`.
- Support Kotlin map syntax: `implementation(group = "group", name = "name", version = "version")`.
- Support Kotlin-style dependency declarations in `build.gradle.kts`.

### 9. Write regression tests
- Create or update `internal/parsers/gradle/gradle_parser_test.go`.
- Add tests for:
- basic Groovy dependencies
- multi-line dependencies
- conditional `if` block dependencies
- Kotlin DSL dependency syntax

### 10. Validate
- Run `go test ./internal/parsers/gradle`.
- Confirm Gradle parser tests pass.
- Optionally run `go test ./...` to verify broader repository compatibility, noting existing unrelated test failures.

---

## Files created or modified

- `pkg/parser/manifest-file-selector.go`
- `pkg/parser/parser_factory.go`
- `internal/parsers/gradle/gradle_parser.go`
- `internal/parsers/gradle/gradle_parser_test.go`
- `test/resources/build.gradle` (sample Gradle fixture)

---

## Supported Gradle parser features

- Detection of `build.gradle` and `build.gradle.kts` files
- Parsing of common dependency configurations:
- `implementation`, `api`, `compile`, `compileOnly`, `runtime`, `runtimeOnly`
- `testImplementation`, `testCompile`, `testRuntimeOnly`
- `androidTestImplementation`, `annotationProcessor`, `classpath`, `kapt`
- String-style dependency declarations
- Map-style dependency declarations
- Multi-line dependency statements
- Dependencies inside `if (...) { ... }` blocks
- Variable resolution from:
- `gradle.properties`
- Groovy `ext` property blocks
- Groovy `ext.key = value` syntax
- Kotlin DSL `val` / `const val`
- Kotlin DSL dependency syntax
- Version cleanup for simple ranges and classifiers

---

## Known limitations

- Dynamic dependencies generated by build logic, loops, or plugin APIs are not resolved.
- Complex Kotlin DSL constructs beyond common forms may not be fully parsed.
- Conditional branch logic is not evaluated; all static declarations are treated as present.
- Deep nested DSL or custom Gradle extension syntax may be missed.
- Computed or function-based version expressions are not evaluated.
- Multi-project and included-build dependency resolution is not supported.

---

## Notes

The Gradle parser is now suitable for many production scanning scenarios in AST-CLI where static dependency declarations are present. For full Gradle model accuracy, additional Gradle-aware parsing or integration with Gradle tooling would be required.
Loading
Loading