Skip to content

[#8909] Implement powershell command - #878

Closed
JurrianFahner wants to merge 13 commits into
apache:masterfrom
JurrianFahner:master
Closed

JurrianFahner wants to merge 13 commits into
apache:masterfrom
JurrianFahner:master

Conversation

@JurrianFahner

@JurrianFahner JurrianFahner commented Nov 19, 2022 •

Copy link
Copy Markdown

JIRA issue: #8909

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    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.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MNG-XXX] SUMMARY, where you replace MNG-XXX
    and SUMMARY with the appropriate JIRA issue. Best practice is to use the JIRA issue
    title in the pull request title and in the first line of the commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the Core IT successfully.

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.

@michael-o

Copy link
Copy Markdown
Member

Has this been tested with Windows PowerShell or PowerShell 7?

@JurrianFahner

Copy link
Copy Markdown
Author

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 mvn clean package on a simple project. It will not cover all use-cases for the scripts that have been changed. Is there an example project to check all of these?

@michael-o

Copy link
Copy Markdown
Member

This is at least what I have, although I work from Windows Terminal with PowerShell 7 only:

C:\Users\mosipov> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1682
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1682
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

I'd expect that on a Windows CI Agent only the Windows PS will be used. Thus, this should be our minimum requirement.

@michael-o

Copy link
Copy Markdown
Member

Try the Maven Core ITs with this. Make sure that .cmd isn't included, just in case.

@JurrianFahner

JurrianFahner commented Feb 7, 2023 •

Copy link
Copy Markdown
Author

The CoreIT tests have run well.

@michael-o
michael-o removed their request for review February 20, 2023 22:33
@JurrianFahner

Copy link
Copy Markdown
Author

@michael-o From my perspective this PR is ready. What's your perspective on this position?

@michael-o

Copy link
Copy Markdown
Member

@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.

@JurrianFahner

Copy link
Copy Markdown
Author

@michael-o Gentle reminder

@JurrianFahner

Copy link
Copy Markdown
Author

@Giovds @michael-o This branch contains the latest improvements from #982.

#>

# set title
$Host.UI.RawUI.WindowTitle = $MyInvocation.MyCommand

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be part of mvnlauncher.ps1 as it is never used in this file?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep it identical to init.cmd.

@Giovds Giovds left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to fix the command terminal title, the rest LGTM

@JurrianFahner

JurrianFahner commented Oct 14, 2023 •

Copy link
Copy Markdown
Author

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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not correct. If the file is empty then it is empty. See approach in init.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand your comment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

# 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
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?`

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If mvn.ps1 or mvn.cmd is removed or not accessible.

But it is indeed a corner case, shall we remove it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@michael-o
michael-o self-requested a review April 28, 2024 09:53
@michael-o
michael-o removed their request for review November 20, 2024 15:19
@slachiewicz slachiewicz added the enhancement New feature or request label Dec 8, 2024
@jira-importer

Copy link
Copy Markdown

Resolve #8909

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.mainClass with class selection (MavenCling, MavenEncCling, MavenShellCling, MavenUpCling) based on --enc/--shell/--up flags
  • Java 17 version check (Maven 4.x minimum)
  • JvmConfigParser.java for robust .mvn/jvm.config parsing
  • -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 close

Parse 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_OPTS handling may produce leading/trailing spaces (flagged by michael-o)
  • $env:MAVEN_ARGS vs $MAVEN_ARGS scope inconsistency in run.ps1

Recommendation

A complete rewrite is needed to match the current master. The recommended approach:

  1. Create self-contained mvn.ps1 under apache-maven/src/assembly/maven/bin/
  2. Use current mvn.cmd as the reference for feature parity (Java 17 check, mainClass selection, jline, native-access, argument handling, error propagation)
  3. Add PS1 equivalents for mvnenc, mvnsh, mvnup
  4. Update component.xml with <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

gnodet added a commit to gnodet/maven that referenced this pull request Jul 10, 2026
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 gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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 in apache-maven/src/assembly/maven/bin/.

  2. Fragment concatenation mechanism removed: The component.xml <file><sources> concatenation block the PR relies on was completely removed from master. Master's component.xml has zero <file> or <sources> elements.

  3. 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.

  4. PowerShell syntax error: The IsNotRoot function in init.ps1 has 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

@wilx wilx mentioned this pull request Jul 25, 2026
5 of 8 tasks

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔ 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" `

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔ 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:

Suggested change
"-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 `

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔ 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:

Suggested change
& $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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔ 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.

Suggested change
$args
exit $LASTEXITCODE

"-Dlibrary.jansi.path=$MAVEN_HOME\lib\jansi-native" `
"-Dmaven.multiModuleProjectDirectory=$basedir" `
$LAUNCHER_CLASS `
$env:MAVEN_ARGS `

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ $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.

Comment on lines +27 to +28
$root_path_base_name = ((get-item $path).Root.BaseName
$path_base_name = ((get-item $path).BaseName

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔ 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.

Suggested change
$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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Leading-space bug when $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:

Suggested change
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔ Exit code not propagated.

Same issue as run.ps1 — mvnDebug.ps1 exits with code 0 even when the Maven build fails.

Suggested change
&$mvnCmd $args
&$mvnCmd $args
exit $LASTEXITCODE

@gnodet gnodet changed the title [MNG-7541] Implement powershell command [#8909] Implement powershell command Nov 9, 2026
@gnodet

gnodet commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Superseded by #12541

@gnodet gnodet closed this Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants