More maven parsing fix for experiment detector#1724
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the experimental MavenWithFallbackDetector to improve static POM parsing behavior by introducing “smart” POM preloading intended to help cross-document property/version resolution during fallback parsing.
Changes:
- Added per-scan state to support preloading all POM
XmlDocuments for variable resolution. - Wired preloading into the fallback path and variable-replacement path to enable cross-document lookups.
src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs
Outdated
Show resolved
Hide resolved
981dd8d to
6f27926
Compare
|
👋 Hi! It looks like you modified some files in the
If none of the above scenarios apply, feel free to ignore this comment 🙂 |
There was a problem hiding this comment.
Pull request overview
This PR updates the Maven detector flow to avoid .mvndeps file cleanup races by deferring cleanup until detector execution completes, and enhances the experimental Maven fallback detector’s static parsing to better handle version variables.
Changes:
- Add orchestrator-level cleanup of Maven
.mvndepsfiles after all detectors finish. - Refactor Maven detectors to remove per-file reader coordination and introduce a two-pass static POM parsing approach (collect variables, then resolve pending components).
- Add orchestrator unit tests covering Maven cleanup behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs | Adds tests validating .mvndeps cleanup behavior depending on whether Maven detectors ran. |
| src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs | Adds post-processing cleanup routine for Maven .mvndeps files after detector execution completes. |
| src/Microsoft.ComponentDetection.Detectors/maven/PendingComponent.cs | Introduces a record type to queue unresolved Maven components for second-pass resolution. |
| src/Microsoft.ComponentDetection.Detectors/maven/MvnCliComponentDetector.cs | Removes reader registration/unregistration logic and tweaks debug logging. |
| src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs | Implements two-pass variable collection + pending component resolution and updates telemetry/logging. |
| src/Microsoft.ComponentDetection.Detectors/maven/MavenCommandService.cs | Removes file-reader coordination and deletion logic from the command service. |
| src/Microsoft.ComponentDetection.Detectors/maven/IMavenCommandService.cs | Removes file-reader coordination APIs from the service interface. |
test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs
Show resolved
Hide resolved
test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR updates Maven detector behavior to avoid Maven CLI dependency-file cleanup races, and improves MavenWithFallback static parsing by deferring variable-based version resolution to a second pass.
Changes:
- Add orchestrator-level cleanup of Maven CLI
*.mvndepsfiles after all detectors complete. - Rework
MavenWithFallbackDetectorstatic parsing to collect variables first and resolve variable-based versions in a second pass (viaPendingComponent). - Remove Maven CLI file-reader registration/unregistration coordination APIs from
IMavenCommandService/MavenCommandService, and update detectors accordingly.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs | Adds tests asserting Maven deps files are deleted only when Maven detectors run. |
| src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs | Adds post-scan Maven deps file cleanup in the orchestrator. |
| src/Microsoft.ComponentDetection.Detectors/maven/PendingComponent.cs | Introduces a record to hold unresolved Maven components for second-pass processing. |
| src/Microsoft.ComponentDetection.Detectors/maven/MvnCliComponentDetector.cs | Removes per-file reader unregister logic; adds additional debug logging. |
| src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs | Implements two-pass variable collection + resolution for static parsing. |
| src/Microsoft.ComponentDetection.Detectors/maven/MavenCommandService.cs | Removes file-reader reference counting/cleanup logic. |
| src/Microsoft.ComponentDetection.Detectors/maven/IMavenCommandService.cs | Removes file-reader coordination methods from the interface. |
src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs
Show resolved
Hide resolved
test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR tightens Maven detection behavior by (1) improving MavenWithFallback’s static POM parsing to resolve variables across parent/child hierarchies using multi-pass processing, and (2) moving Maven CLI .mvndeps cleanup to the orchestrator after all detectors complete to avoid cross-detector races.
Changes:
- Add orchestrator-level cleanup of Maven CLI-generated dependency files after detector execution.
- Implement multi-pass variable collection + hierarchy-aware resolution in
MavenWithFallbackDetectorand add aPendingComponentmodel for deferred registrations. - Expand test coverage for variable resolution edge cases and new cleanup behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs | Adds tests validating post-processing cleanup of .mvndeps files depending on which detectors ran. |
| test/Microsoft.ComponentDetection.Detectors.Tests/MavenWithFallbackDetectorTests.cs | Adds many tests covering parent/child/sibling variable resolution, deferred resolution, and traversal robustness. |
| src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs | Adds CleanupMavenFilesAsync and invokes it after all detectors finish. |
| src/Microsoft.ComponentDetection.Detectors/maven/PendingComponent.cs | Introduces a record to hold unresolved components for second/third-pass resolution. |
| src/Microsoft.ComponentDetection.Detectors/maven/MvnCliComponentDetector.cs | Removes per-file reader unregister logic and adds debug logging around contribution counts. |
| src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs | Introduces multi-pass parsing with concurrent state structures, hierarchy tracking, and deferred resolution. |
| src/Microsoft.ComponentDetection.Detectors/maven/MavenCommandService.cs | Removes file-reader tracking/cleanup coordination APIs (cleanup is now orchestrator-driven). |
| src/Microsoft.ComponentDetection.Detectors/maven/IMavenCommandService.cs | Removes file-reader tracking/cleanup coordination API from the interface. |
test/Microsoft.ComponentDetection.Detectors.Tests/MavenWithFallbackDetectorTests.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Detectors/maven/MavenWithFallbackDetector.cs
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1724 +/- ##
============================
============================
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
PR: Maven Detection Improvements - Variable Resolution & Centralized Cleanup
Summary
This PR addresses two critical issues in the Maven detection system:
MvnCliComponentDetectorandMavenWithFallbackDetectorProblem Statement
Issue 1: Variable Resolution Order Dependency
Before: The variable resolution logic processed POM files in arbitrary order and used a flat
ConcurrentDictionary<string, string>for variable storage. When the same variable (e.g.,${revision}) was defined in multiple POM files (parent and child), the resolution result depended on processing order—whichever file was processed last would overwrite the variable value.Example scenario:
If parent was processed after child, the child's dependency would incorrectly resolve to
1.0.0instead of2.0.0(Maven's rule: child properties take precedence over parent).Issue 2: Premature bcde.mvndeps File Cleanup
Before: Each detector (
MvnCliComponentDetectorandMavenWithFallbackDetector) independently tracked and cleaned upbcde.mvndepsfiles it created. Since both detectors run concurrently and share the same temporary files, one detector could delete files before the other finished reading them.Technical Changes
1. Hierarchy-Aware Variable Resolution
New approach: Variables are now stored with file path context:
Resolution algorithm:
<parent>declarations${variable}for a file, walk up the Maven hierarchy (child → parent → grandparent)Key methods:
FindVariableInMavenHierarchy()- Walks Maven parent chain to find variable definitionResolveVersionWithHierarchyAwareness()- Resolves version templates using hierarchy searchResolveDeferredParentRelationships()- Second pass to resolve parent relationships when POMs are processed out-of-order2. Three-Pass Processing Model
The static parser now uses three passes:
3. Centralized Cleanup in DetectorProcessingService
Before: Cleanup was distributed across detectors
After: Cleanup moved to
DetectorProcessingService.CleanupMavenFiles()Benefits:
CleanupCreatedFilessettingFastDirectoryWalkerFactory)4. Shared Constants
Created
MavenConstants.csto keep detector IDs and filenames in sync:5. Telemetry Improvements
UnresolvedVariableCounttelemetry (aggregated count instead of per-variable warnings)PendingComponentCountto capture count before draining the queue6. Symlink-Safe File Enumeration
The cleanup logic now uses the same symlink handling pattern as
FastDirectoryWalkerFactory:IPathUtilityServiceBehavioral Changes
Testing
Files Changed
MavenWithFallbackDetector.csMavenConstants.csMavenCliCleanupTelemetryRecord.csDetectorProcessingService.csMavenCommandService.csMvnCliComponentDetector.cs