-
Notifications
You must be signed in to change notification settings - Fork 5
feat: a script to find obsolete code #486
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
base: main
Are you sure you want to change the base?
Conversation
|
@Jad-el-khoury this is something I made for the https://github.com/eclipse-lyo/lyo.designer/pull/303 but then realized that it would be useful for any major Lyo and Java upgrade. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a PowerShell script that analyzes Maven projects to identify technical debt and maintenance issues by running Maven plugins to detect code deprecations, outdated dependencies and plugins, and unused dependencies.
Key Changes
- Adds a comprehensive PowerShell script with parameter-driven options to check for deprecations only or include transitive dependencies
- Implements Maven output parsing logic to extract and format relevant information from multiple Maven plugin executions
- Includes Java version mismatch detection to warn users about potential JAVA_HOME inconsistencies
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ($line -match "The following dependencies in Dependency Management have newer versions:") { | ||
| $currentSection = "Transitive" | ||
| $bufferedArtifact = "" | ||
| continue | ||
| } |
Copilot
AI
Dec 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern assumes transitive dependencies come from "Dependency Management" section, but the versions-maven-plugin output may vary. Some transitive dependencies might appear in different sections or not be clearly marked. Consider documenting this assumption or verifying it handles all cases correctly.
| # Artifact lines in this section usually start with [WARNING] and contain colons like group:artifact:ver | ||
| if ($line -match "^\[WARNING\]\s+.*:.*:.*") { |
Copilot
AI
Dec 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern "^[WARNING]\s+.:.:.*" is too permissive and may capture unrelated warning messages that happen to contain colons. A more specific pattern matching Maven artifact coordinates (groupId:artifactId:type:version:scope) would be more reliable, such as "^[WARNING]\s+[^:]+:[^:]+:[^:]+:[^:]+:[^:]+".
| # Artifact lines in this section usually start with [WARNING] and contain colons like group:artifact:ver | |
| if ($line -match "^\[WARNING\]\s+.*:.*:.*") { | |
| # Artifact lines in this section usually start with [WARNING] and contain Maven coordinates like groupId:artifactId:type:version:scope | |
| if ($line -match "^\[WARNING\]\s+[^:]+:[^:]+:[^:]+:[^:]+:[^:]+") { |
| # Stop capturing if we hit another section or INFO log that isn't an artifact | ||
| # Artifact lines in this section usually start with [WARNING] and contain colons like group:artifact:ver | ||
| if ($line -match "^\[WARNING\]\s+.*:.*:.*") { | ||
| $unusedDeps += ($line -replace "^\[WARNING\]\s*", "") | ||
| } elseif ($line -match "^\[INFO\]" -or ($line -match "^\[WARNING\]" -and $line -notmatch "dependencies found")) { | ||
| # If we hit a new warning header or info, stop |
Copilot
AI
Dec 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The capturing logic may stop prematurely when encountering an INFO line. If there are INFO-level messages interspersed with the unused dependencies warnings (which can happen in Maven output), this will miss some unused dependencies. Consider a more robust approach that only stops when a clear section boundary is detected.
| # Stop capturing if we hit another section or INFO log that isn't an artifact | |
| # Artifact lines in this section usually start with [WARNING] and contain colons like group:artifact:ver | |
| if ($line -match "^\[WARNING\]\s+.*:.*:.*") { | |
| $unusedDeps += ($line -replace "^\[WARNING\]\s*", "") | |
| } elseif ($line -match "^\[INFO\]" -or ($line -match "^\[WARNING\]" -and $line -notmatch "dependencies found")) { | |
| # If we hit a new warning header or info, stop | |
| # Stop capturing only when we clearly leave the unused-dependencies section. | |
| # Artifact lines in this section usually start with [WARNING] and contain colons like group:artifact:ver | |
| if ($line -match "^\[WARNING\]\s+.*:.*:.*") { | |
| $unusedDeps += ($line -replace "^\[WARNING\]\s*", "") | |
| } elseif ( | |
| # Non-artifact WARNING (e.g., a new warning header) ends this section | |
| ($line -match "^\[WARNING\]" -and $line -notmatch "dependencies found") -or | |
| # Clear Maven section boundaries / build summary also end this section | |
| $line -match "^\[INFO\]\s+---" -or # new plugin goal section | |
| $line -match "^\[INFO\]\s+BUILD\s+(SUCCESS|FAILURE)" -or | |
| $line -match "^\[INFO\]\s+-{10,}" # long separator line | |
| ) { |
| $pomPath = Resolve-Path $PomFile | ||
| } else { | ||
| $pomPath = Join-Path $PSScriptRoot "pom.xml" |
Copilot
AI
Dec 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PomFile parameter is not validated for existence before being used. If a user provides a non-existent file path, Resolve-Path will throw an error that will be difficult to understand. Consider adding validation to check if the file exists and provide a clear error message if it doesn't.
| $pomPath = Resolve-Path $PomFile | |
| } else { | |
| $pomPath = Join-Path $PSScriptRoot "pom.xml" | |
| if (-not (Test-Path -LiteralPath $PomFile)) { | |
| throw "The specified PomFile '$PomFile' does not exist. Please provide a valid path to pom.xml." | |
| } | |
| $pomPath = Resolve-Path -LiteralPath $PomFile | |
| } else { | |
| $defaultPom = Join-Path $PSScriptRoot "pom.xml" | |
| if (-not (Test-Path -LiteralPath $defaultPom)) { | |
| throw "No PomFile was specified and the default pom.xml was not found at '$defaultPom'." | |
| } | |
| $pomPath = Resolve-Path -LiteralPath $defaultPom |
| # Resolve symlinks if possible or just take the path | ||
| $javaItem = Get-Item $javaExe | ||
| if ($javaItem.LinkType -eq "SymbolicLink") { | ||
| $javaExe = $javaItem.Target |
Copilot
AI
Dec 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Target property of a symbolic link can be a string or an array, depending on the platform and PowerShell version. Directly assigning it to a scalar variable may cause issues. Consider handling both cases or using the first element if it's an array.
| $javaExe = $javaItem.Target | |
| $target = $javaItem.Target | |
| if ($target -is [Array]) { | |
| $javaExe = $target[0] | |
| } else { | |
| $javaExe = $target | |
| } |
| [string[]]$Params | ||
| ) | ||
| $mvnCmd = "mvn" | ||
| if ($IsWindows) { $mvnCmd = "mvn.cmd" } |
Copilot
AI
Dec 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable $IsWindows is not available in Windows PowerShell 5.1 and below (only in PowerShell Core 6+). This will cause the script to fail on older Windows systems. Consider adding a check to define $IsWindows if it doesn't exist, such as: if (-not (Test-Path variable:IsWindows)) { $IsWindows = $true }
This script runs various Maven plugins to gather information about:
@Deprecatedmethods/classes).