Repository navigation
[#8909] Implement powershell command - #878
JurrianFahner wants to merge 13 commits into
Conversation
|
Has this been tested with Windows PowerShell or PowerShell 7? |
Mainly with powershell 7.3.0, but now also with powershell 5.1.22621.608. The test is done by running |
|
This is at least what I have, although I work from Windows Terminal with PowerShell 7 only: I'd expect that on a Windows CI Agent only the Windows PS will be used. Thus, this should be our minimum requirement. |
|
Try the Maven Core ITs with this. Make sure that |
|
The CoreIT tests have run well. |
|
@michael-o From my perspective this PR is ready. What's your perspective on this position? |
I want to get back to this end of month. |
|
@michael-o Gentle reminder |
|
@Giovds @michael-o This branch contains the latest improvements from #982. |
| #> | ||
|
|
||
| # set title | ||
| $Host.UI.RawUI.WindowTitle = $MyInvocation.MyCommand |
There was a problem hiding this comment.
This probably has the same 'issue' as as 3.x script: #982 (comment)?
| @@ -0,0 +1,83 @@ | |||
| # ==== END VALIDATION ==== | |||
|
|
|||
| $CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf" | |||
There was a problem hiding this comment.
Should this be part of mvnlauncher.ps1 as it is never used in this file?
There was a problem hiding this comment.
I'd keep it identical to init.cmd.
Giovds
left a comment
There was a problem hiding this comment.
It would be nice to fix the command terminal title, the rest LGTM
@Giovds I've created an issue to improve the command terminal title: https://issues.apache.org/jira/browse/MNG-7907 The description is a little bit rough right now and needs some extra refinement. |
| @@ -0,0 +1,83 @@ | |||
| # ==== END VALIDATION ==== | |||
|
|
|||
| $CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf" | |||
There was a problem hiding this comment.
I'd keep it identical to init.cmd.
| if (Test-Path $jvm_config) { | ||
| return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_config) | ||
| } | ||
| return $env:MAVEN_OPTS |
There was a problem hiding this comment.
That is not correct. If the file is empty then it is empty. See approach in init.
There was a problem hiding this comment.
I don't understand your comment.
There was a problem hiding this comment.
You are joining the content of the jvm.config file with MAVEN_OPTS variable in one guy. From a caller's perspective that should not be done and it is not obvious from where the config comes. Look at the original files, they do not merge them.
| } | ||
| } | ||
|
|
||
| $MAVEN_OPTS = (RetrieveContentsJvmConfig $basedir) |
| # check if maven command exists | ||
| if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) { | ||
| Write-Error -Message "Maven command ($MAVEN_HOME\bin\mvn.ps1) cannot be found" -ErrorAction Stop | ||
| } |
There was a problem hiding this comment.
I wonder whether this is a relic from the past. In mvnvalidate this check isn't present and this file is part of mvn/mvn.cmd/mvn.ps1. How can this fail?`
There was a problem hiding this comment.
If mvn.ps1 or mvn.cmd is removed or not accessible.
But it is indeed a corner case, shall we remove it?
There was a problem hiding this comment.
But how can this happen at all? This is a chicken-and-egg issue. This block is part of the merged mvn.ps1. If the file is not present that check will never happen, no? This confuses me.
|
Resolve #8909 |
gnodet
left a comment
There was a problem hiding this comment.
AI Review — PR #878: [MNG-7541] Implement powershell command (master)
This PR adds PowerShell scripts for Maven using a shared-sources assembly pattern (5 .ps1 files concatenated into mvn.ps1). It has been through multiple review cycles with michael-o and Giovds, last updated April 2024. The PR is fundamentally stale due to the MNG-8346 restructuring and Maven 4.x evolution.
Critical Issues
1. Assembly directory removed — apache-maven/src/assembly/shared/ no longer exists on master. Current scripts live under apache-maven/src/assembly/maven/bin/. The source-concatenation <sources> pattern in component.xml has been entirely removed in favor of direct <fileSet> inclusion.
2. Missing Maven 4.x features — Current mvn.cmd on master includes features absent from these scripts:
--enable-native-access=ALL-UNNAMED(required for JLine terminal on Java 17+)-Dmaven.mainClasswith class selection (MavenCling,MavenEncCling,MavenShellCling,MavenUpCling) based on--enc/--shell/--upflags- Java 17 version check (Maven 4.x minimum)
JvmConfigParser.javafor robust.mvn/jvm.configparsing-Dlibrary.jline.path(PR uses obsolete-Dlibrary.jansi.path)- Internal argument handling (
--debug,--enc,--shell,--up,--yjp)
3. Missing launcher scripts — Current master has mvnenc.cmd, mvnsh.cmd, mvnup.cmd alongside mvn.cmd. No PS1 equivalents are provided.
Bugs
4. Syntax error — unbalanced parentheses in init.ps1:
$root_path_base_name = ((get-item $path).Root.BaseName # 2 open, 1 close
$path_base_name = ((get-item $path).BaseName # 2 open, 1 closeParse error — same bug exists in PR #982.
5. Missing exit code propagation — No exit $LASTEXITCODE after Java invocation. CI systems won't detect build failures via mvn.ps1.
Other Issues
$env:MAVEN_OPTShandling may produce leading/trailing spaces (flagged by michael-o)$env:MAVEN_ARGSvs$MAVEN_ARGSscope inconsistency inrun.ps1
Recommendation
A complete rewrite is needed to match the current master. The recommended approach:
- Create self-contained
mvn.ps1underapache-maven/src/assembly/maven/bin/ - Use current
mvn.cmdas the reference for feature parity (Java 17 check, mainClass selection, jline, native-access, argument handling, error propagation) - Add PS1 equivalents for
mvnenc,mvnsh,mvnup - Update
component.xmlwith<fileSet>for*.ps1
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
Reviewed 3 PRs: apache#982 (PowerShell 3.9.x, syntax bugs), apache#878 (PowerShell master, needs Maven 4 rewrite), #33 (qualityManagement, oldest PR at 11 years). 45 reviews posted total. Only 3 truly unreviewed PRs remain: apache#2277, apache#1774, #71 (all large). Co-Authored-By: Claude Opus 4.6 <[email protected]>
gnodet
left a comment
There was a problem hiding this comment.
This PR (opened November 2022) adds PowerShell support (mvn.ps1 / mvnDebug.ps1). After 3.5+ years, the codebase has evolved significantly, making this PR unmergeable in its current state:
-
shared/ directory removed: All 5 shared PS1 files target
apache-maven/src/assembly/shared/which was removed from master. Master now uses standalone scripts directly inapache-maven/src/assembly/maven/bin/. -
Fragment concatenation mechanism removed: The
component.xml<file><sources>concatenation block the PR relies on was completely removed from master. Master'scomponent.xmlhas zero<file>or<sources>elements. -
Obsolete library path: The PR uses
-Dlibrary.jansi.path/jansi-native, but master migrated from Jansi to JLine for native terminal support and now uses-Dlibrary.jline.path/jline-native. -
PowerShell syntax error: The
IsNotRootfunction ininit.ps1has unbalanced parentheses — two lines have 2 opening parens but only 1 closing paren, which would cause a parse-time failure.
The PR is in a CONFLICTING merge state. It would need a complete rewrite to align with the current Maven 4 architecture (standalone scripts, JLine native support, --enable-native-access, MavenCling launcher class, etc.).
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of gnodet
gnodet-bot
left a comment
There was a problem hiding this comment.
Review: [MNG-7541] PowerShell launcher — Maven 4.x architecture gaps
This PR has been reviewed multiple times and michael-o's nits are still pending. Beyond those, there are critical Maven 4.x compatibility issues that block this from merging even if all existing review threads are resolved.
Critical: Assembly architecture mismatch
The PR adds a <file><sources> block to component.xml referencing src/assembly/shared/*.ps1. However, current master's component.xml has zero <file> or <sources> elements — this concatenation mechanism was removed entirely from the Maven 4.x assembly descriptor. The only mechanism for bin/ content is <fileSet>. The assembled mvn.ps1 will not be produced.
The correct approach is: put a self-contained mvn.ps1 directly in apache-maven/src/assembly/maven/bin/ and add <include>*.ps1</include> to the existing <fileSet> for that directory (which the PR already does in the first hunk — that part is correct).
Critical: Missing Maven 4.x JVM flags and class selection
Current mvn.cmd (the parity reference) passes:
--enable-native-access=ALL-UNNAMED # required for JLine terminal on Java 17+
-Dmaven.mainClass=%MAVEN_MAIN_CLASS% # supports --enc/--shell/--up routing
-Dlibrary.jline.path=%MAVEN_HOME%\lib\jline-native # JLine native, NOT jansi
run.ps1 has none of these. It also uses the obsolete -Dlibrary.jansi.path which references a native lib (jansi-native) that no longer ships.
Critical: No exit code propagation
run.ps1 invokes Java but discards $LASTEXITCODE. Maven build failures (non-zero exit) are silently swallowed — CI systems relying on mvn.ps1 will report success on failing builds.
Critical: PowerShell parse error in init.ps1
The IsNotRoot function has unbalanced parentheses that cause a parse-time failure — the script will not load at all.
Missing companion scripts
Master now ships mvnenc.cmd, mvnsh.cmd, mvnup.cmd alongside mvn.cmd. The PS1 set needs equivalent scripts for full parity.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
| </file> | ||
| <file> | ||
| <sources> | ||
| <source>src/assembly/shared/validate.ps1</source> |
There was a problem hiding this comment.
⛔ Architecture mismatch — this won't work on master.
The <file><sources> concatenation pattern was removed from component.xml in Maven 4.x. Current master's descriptor has zero <file> elements. The assembled mvn.ps1 will not be generated.
The correct approach is a self-contained mvn.ps1 placed directly in apache-maven/src/assembly/maven/bin/ — the <fileSet> hunk in this same PR (adding *.ps1 to the existing bin/ fileSet) is the right mechanism. The <file><sources> block must be removed entirely.
| -classpath $LAUNCHER_JAR ` | ||
| "-Dclassworlds.conf=$CLASSWORLDS_CONF" ` | ||
| "-Dmaven.home=$MAVEN_HOME" ` | ||
| "-Dlibrary.jansi.path=$MAVEN_HOME\lib\jansi-native" ` |
There was a problem hiding this comment.
⛔ Obsolete library path — Jansi is gone in Maven 4.x.
Master migrated from Jansi to JLine native terminal support. The native library path should be:
| "-Dlibrary.jansi.path=$MAVEN_HOME\lib\jansi-native" ` | |
| "-Dlibrary.jline.path=$MAVEN_HOME\lib\jline-native" ` |
The jansi-native directory no longer ships in the Maven 4.x distribution.
| @@ -0,0 +1,13 @@ | |||
| & $JAVACMD ` | |||
There was a problem hiding this comment.
⛔ Missing --enable-native-access=ALL-UNNAMED.
This JVM flag is required for JLine terminal support on Java 17+ and is always passed by mvn.cmd:
| & $JAVACMD ` | |
| & $JAVACMD ` | |
| --enable-native-access=ALL-UNNAMED ` |
Without it, JLine's native terminal detection fails and Maven 4.x renders degraded console output (no colors, no progress bars) on PowerShell.
| $LAUNCHER_CLASS ` | ||
| $env:MAVEN_ARGS ` | ||
| $args | ||
|
|
There was a problem hiding this comment.
⛔ Exit code not propagated — CI cannot detect build failures.
After the Java invocation, $LASTEXITCODE must be forwarded. Without it, mvn.ps1 always exits 0 regardless of whether the Maven build succeeded or failed.
| $args | |
| exit $LASTEXITCODE |
| "-Dlibrary.jansi.path=$MAVEN_HOME\lib\jansi-native" ` | ||
| "-Dmaven.multiModuleProjectDirectory=$basedir" ` | ||
| $LAUNCHER_CLASS ` | ||
| $env:MAVEN_ARGS ` |
There was a problem hiding this comment.
$env:MAVEN_ARGS scope inconsistency.
$env:MAVEN_ARGS is an environment variable (persistent, inherited by child processes), while $MAVEN_OPTS, $MAVEN_DEBUG_OPTS, $LAUNCHER_JAR etc. are local script variables. This is inconsistent: if a user sets $MAVEN_ARGS as a local variable in their session, it won't be picked up here.
Decide on one scope. mvn.cmd uses %MAVEN_ARGS% as an environment variable — using $env:MAVEN_ARGS here is the correct parity choice, but it should be declared explicitly (matching validate.ps1's header comment) and the other MAVEN_* variables that are currently local should be evaluated for consistency.
| $root_path_base_name = ((get-item $path).Root.BaseName | ||
| $path_base_name = ((get-item $path).BaseName |
There was a problem hiding this comment.
⛔ PowerShell syntax error — unbalanced parentheses — script will NOT parse.
Both lines open two (( but close only one ). This causes a parse-time error before the script runs.
| $root_path_base_name = ((get-item $path).Root.BaseName | |
| $path_base_name = ((get-item $path).BaseName | |
| $root_path_base_name = (get-item $path).Root.BaseName | |
| $path_base_name = (get-item $path).BaseName |
| $jvm_config = $path + "\.mvn\jvm.config" | ||
|
|
||
| if (Test-Path $jvm_config) { | ||
| return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_config) |
There was a problem hiding this comment.
$env:MAVEN_OPTS is empty.
$env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_config) produces a leading space ( -Xmx512m) when $env:MAVEN_OPTS is unset/empty. Some JVM implementations reject arguments with leading whitespace.
Use conditional concatenation or @() + -join pattern:
| return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_config) | |
| $opts = @() | |
| if ($env:MAVEN_OPTS) { $opts += $env:MAVEN_OPTS } | |
| $opts += (Get-Content $jvm_config) | |
| return $opts -join ' ' |
|
|
||
| $mvnCmd = join-path -Path $PSScriptRoot -ChildPath "mvn.ps1" | ||
|
|
||
| &$mvnCmd $args |
There was a problem hiding this comment.
⛔ Exit code not propagated.
Same issue as run.ps1 — mvnDebug.ps1 exits with code 0 even when the Maven build fails.
| &$mvnCmd $args | |
| &$mvnCmd $args | |
| exit $LASTEXITCODE |
|
Superseded by #12541 |
JIRA issue: #8909
Following this checklist to help us incorporate your
contribution quickly and easily:
for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
[MNG-XXX] SUMMARY, where you replaceMNG-XXXand
SUMMARYwith the appropriate JIRA issue. Best practice is to use the JIRA issuetitle in the pull request title and in the first line of the commit message.
mvn clean verifyto make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.