You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "JurrianFahner (via GitHub)" <gi...@apache.org> on 2023/02/05 21:57:26 UTC
[GitHub] [maven] JurrianFahner opened a new pull request, #982: [MNG-7541] Implement powershell mvn command
JurrianFahner opened a new pull request, #982:
URL: https://github.com/apache/maven/pull/982
Following this checklist to help us incorporate your
contribution quickly and easily:
- [x] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/MNG) 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.
- [x] Each commit in the pull request should have a meaningful subject line and body.
- [x] Format the pull request title like `[MNG-XXX] SUMMARY`,
where you replace `MNG-XXX` and `SUMMARY` with the appropriate JIRA issue.
- [x] Also format the first line of the commit message like `[MNG-XXX] SUMMARY`.
Best practice is to use the JIRA issue title in both the pull request title and in the first line of the commit message.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] 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][core-its] successfully.
If your pull request is about ~20 lines of code you don't need to sign an
[Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) 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](http://www.apache.org/licenses/LICENSE-2.0)
you have to acknowledge this by using the following check-box.
- [x] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
- [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
[core-its]: https://maven.apache.org/core-its/core-it-suite/
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] michael-o commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1718967878
As a matter of fact, this implemenation should copy the approach from `mvn.cmd` from `master`, not from `maven-3.9.x`. It does not matter to add something new and then skim a bit later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1325152454
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+
+ return -not $path.endsWith(":\")
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + (Get-Content $jvm_location).Replace("`n", "").Replace("`r", "");
+ }
+ return $env:MAVEN_OPTS;
+}
+
+$basedir = ""
+
+if ($file_flag_found) {
+ # we need to assess if the file exists
+ # and then search for the maven project base dir.
+ $pom_file_reference = $args[$i + 1]
+
+ if (Test-Path $pom_file_reference) {
+ $basedir = (Get-Item $pom_file_reference).DirectoryName
+ }
+ else {
+ $pom_file_error = "POM file " + $pom_file_reference + " specified the -f/--file command-line argument does not exist"
+ Write-Error -Message $pom_file_error -ErrorAction Stop
+ }
+}
+else {
+ # if file flag is not found, then the pom.xml is relative to the working dir
+ # and the jvm.config can be found in the maven project base dir.
+
+ $basedir = $WDIR
+
+ while (IsNotRoot($WDIR.Path)) {
+ if (Test-Path "$WDIR\.mvn") {
+ $basedir = $WDIR
+ break
+ }
+
+ if ($WDIR) {
+ $WDIR = Split-Path $WDIR
+ }
+ else {
+ break
+ }
+ }
+}
+
+$MAVEN_OPTS = (RetrieveContentsJvmConfig $basedir)
+
+$LAUNCHER_JAR = Get-Item $MAVEN_HOME"\boot\plexus-classworlds*.jar"
Review Comment:
No, there is one jar. This is to be sure it can find the classworlds jar (even when the version changes).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] michael-o commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1532797801
Not now, ATM. I need to consult also a colleague who's proficient in PowerShell.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MNG-7541] Implement powershell mvn command [maven]
Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r4018684980
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+ $root_path_base_name = ((get-item $path).Root.BaseName
+ $path_base_name = ((get-item $path).BaseName
+
+ return $root_path_base_name -ne $path_base_name
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_location)
+ }
+ return $env:MAVEN_OPTS
+}
+
+$basedir = ""
+
+if ($file_flag_found) {
+ # we need to assess if the file exists
+ # and then search for the maven project base dir.
+ $pom_file_reference = $args[$i + 1]
+
+ if (Test-Path $pom_file_reference) {
+ $basedir = (Get-Item $pom_file_reference).DirectoryName
+ }
+ else {
+ $pom_file_error = "POM file " + $pom_file_reference + " specified the -f/--file command-line argument does not exist"
+ Write-Error -Message $pom_file_error -ErrorAction Stop
+ }
+}
+else {
+ # if file flag is not found, then the pom.xml is relative to the working dir
+ # and the jvm.config can be found in the maven project base dir.
+
+ $basedir = $WDIR
+
+ while (IsNotRoot($WDIR.Path)) {
+ if (Test-Path "$WDIR\.mvn") {
+ $basedir = $WDIR
+ break
+ }
+
+ if ($WDIR) {
+ $WDIR = Split-Path $WDIR
+ }
+ else {
+ break
+ }
+ }
+}
+
+$MAVEN_OPTS = (RetrieveContentsJvmConfig $basedir)
+
+$LAUNCHER_JAR = Get-Item $MAVEN_HOME"\boot\plexus-classworlds*.jar"
+$LAUNCHER_CLASS = "org.codehaus.plexus.classworlds.launcher.Launcher"
+
+& $JAVACMD `
+ $MAVEN_OPTS `
+ $MAVEN_DEBUG_OPTS `
+ -classpath $LAUNCHER_JAR `
+ "-Dclassworlds.conf=$CLASSWORLDS_CONF" `
+ "-Dmaven.home=$MAVEN_HOME" `
+ "-Dlibrary.jansi.path=$MAVEN_HOME\lib\jansi-native" `
+ "-Dmaven.multiModuleProjectDirectory=$basedir" `
+ $LAUNCHER_CLASS `
+ $MAVEN_ARGS `
Review Comment:
test 155
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] michael-o commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1728951967
> > As a matter of fact, this implemenation should copy the approach from mvn.cmd from master, not from maven-3.9.x. It does not matter to add something new and then skim a bit later. Then it would be back ported to 3.9.x as-is logically.
>
> Wouldn't it not be better to get [master](https://github.com/apache/maven/pull/878) reviewed first and then retrofit the approach in master to the 3.9.x branch? Please be aware that there will be two different approaches in the component.xml, which makes reviewing a little bit harder.
True, but the content of the script won't change, only its arrangement.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] michael-o commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1712797058
For the time being, I want work on this since I don't have the capacity nor decent PowerShell scripting skill set. My knowledge in PS humble.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] yeikel commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "yeikel (via GitHub)" <gi...@apache.org>.
yeikel commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1421331792
> I wonder if it would make sense to remove the `.cmd` script instead of keeping both `.ps1` and `.cmd` scripts.
That will likely break things so maybe that should be targeted for v4
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1714361609
@michael-o I understand your reserves, certainly if your see your PS knowledge as humble (I don't see myself as an expert either).
At the same time @slachiewicz has given an approval. What's needed in order to get this PR merged?
Please let me know what is needed, then I can specifically ask for input/help on the mailing list.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1730072787
> > > As a matter of fact, this implemenation should copy the approach from mvn.cmd from master, not from maven-3.9.x. It does not matter to add something new and then skim a bit later. Then it would be back ported to 3.9.x as-is logically.
> >
> >
> > Wouldn't it not be better to get [master](https://github.com/apache/maven/pull/878) reviewed first and then retrofit the approach in master to the 3.9.x branch? Please be aware that there will be two different approaches in the component.xml, which makes reviewing a little bit harder.
>
> True, but the content of the script won't change, only its arrangement.
Ok, in that case we are aligned. I'll update the master branch with the improvements on this branch. When the master is merged, I'll retrofit the changes into this branch.
@Giovds Are you available for reviewing the master PR? I first need to apply the changes on this branch to the master (#878).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] michael-o commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1099091278
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
Review Comment:
Don't waste your time. This won't happen.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1660960598
> > > Not now, ATM. I need to consult also a colleague who's proficient in PowerShell.
> >
> >
> > Is there some progress?
>
> I hope to pick this up when my round with reporting stack is complete for next milestone. I guess somewere end of month. Please also raise your voice on dev@ to drag more attraction to this topic.
Is there some progress?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1728462781
> As a matter of fact, this implemenation should copy the approach from mvn.cmd from master, not from maven-3.9.x. It does not matter to add something new and then skim a bit later. Then it would be back ported to 3.9.x as-is logically.
Wouldn't it not be better to get [master](https://github.com/apache/maven/pull/878) reviewed first and then retrofit the approach in master to the 3.9.x branch? Please be aware that there will be two different approaches in the component.xml, which makes reviewing a little bit harder.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1421478703
@michael-o Should we remove `.cmd` in https://github.com/apache/maven/pull/877?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MNG-7541] Implement powershell mvn command [maven]
Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r4018672086
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+ $root_path_base_name = ((get-item $path).Root.BaseName
+ $path_base_name = ((get-item $path).BaseName
+
+ return $root_path_base_name -ne $path_base_name
+}
+
+function RetrieveContentsJvmConfig {
Review Comment:
test comment on line 92
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1509736721
@michael-o Can I do something to make this pull request merged?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] Giovds commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "Giovds (via GitHub)" <gi...@apache.org>.
Giovds commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1325500076
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+
+ return -not $path.endsWith(":\")
Review Comment:
Me neither, but you never know what you find in the wild 🙈
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+
+ return -not $path.endsWith(":\")
Review Comment:
Me neither, but you never know what you find in the wild 🙈
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1325153454
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+
+ return -not $path.endsWith(":\")
Review Comment:
I wouldn't recommend using maven on a share, it would be not the fastest experience. 😉
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+
+ return -not $path.endsWith(":\")
Review Comment:
I wouldn't recommend using maven on a share, it would be not the fastest experience. 😉
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1332118562
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
Review Comment:
- Just dived into this topic. The difference between with `throw` and `write-error` is that `write-error` writes to the error stream and `throw` doesn't.
- Since PowerShell 7.2 the default `$errorView` is set to ConciseView. Your example would show something like this:

Based on the above I think I don't need to change the implementation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MNG-7541] Implement powershell mvn command [maven]
Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r4018697069
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+ $root_path_base_name = ((get-item $path).Root.BaseName
+ $path_base_name = ((get-item $path).BaseName
Review Comment:
⛔ **Parse error — unbalanced parentheses.** Both lines have two opening parens and one closing paren. PowerShell will refuse to parse this script entirely — `IsNotRoot` never loads, the `.mvn` directory traversal never executes, and `$basedir` is never set correctly.
```suggestion
$root_path_base_name = (Get-Item $path).Root.BaseName
$path_base_name = (Get-Item $path).BaseName
```
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+ $root_path_base_name = ((get-item $path).Root.BaseName
+ $path_base_name = ((get-item $path).BaseName
+
+ return $root_path_base_name -ne $path_base_name
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_location)
+ }
+ return $env:MAVEN_OPTS
+}
+
+$basedir = ""
+
+if ($file_flag_found) {
+ # we need to assess if the file exists
+ # and then search for the maven project base dir.
+ $pom_file_reference = $args[$i + 1]
+
+ if (Test-Path $pom_file_reference) {
+ $basedir = (Get-Item $pom_file_reference).DirectoryName
+ }
+ else {
+ $pom_file_error = "POM file " + $pom_file_reference + " specified the -f/--file command-line argument does not exist"
+ Write-Error -Message $pom_file_error -ErrorAction Stop
+ }
+}
+else {
+ # if file flag is not found, then the pom.xml is relative to the working dir
+ # and the jvm.config can be found in the maven project base dir.
+
+ $basedir = $WDIR
+
+ while (IsNotRoot($WDIR.Path)) {
+ if (Test-Path "$WDIR\.mvn") {
+ $basedir = $WDIR
+ break
+ }
+
+ if ($WDIR) {
+ $WDIR = Split-Path $WDIR
+ }
+ else {
+ break
+ }
+ }
+}
+
+$MAVEN_OPTS = (RetrieveContentsJvmConfig $basedir)
+
+$LAUNCHER_JAR = Get-Item $MAVEN_HOME"\boot\plexus-classworlds*.jar"
+$LAUNCHER_CLASS = "org.codehaus.plexus.classworlds.launcher.Launcher"
+
+& $JAVACMD `
+ $MAVEN_OPTS `
+ $MAVEN_DEBUG_OPTS `
+ -classpath $LAUNCHER_JAR `
+ "-Dclassworlds.conf=$CLASSWORLDS_CONF" `
+ "-Dmaven.home=$MAVEN_HOME" `
+ "-Dlibrary.jansi.path=$MAVEN_HOME\lib\jansi-native" `
+ "-Dmaven.multiModuleProjectDirectory=$basedir" `
+ $LAUNCHER_CLASS `
+ $MAVEN_ARGS `
Review Comment:
⛔ **`$MAVEN_ARGS` is an unset local variable — `MAVEN_ARGS` environment variable is silently ignored.** The correct form is `$env:MAVEN_ARGS`. PR #878 (`run.ps1`) already has this fix.
```suggestion
$env:MAVEN_ARGS `
```
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+ $root_path_base_name = ((get-item $path).Root.BaseName
+ $path_base_name = ((get-item $path).BaseName
+
+ return $root_path_base_name -ne $path_base_name
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_location)
+ }
+ return $env:MAVEN_OPTS
+}
+
+$basedir = ""
+
+if ($file_flag_found) {
+ # we need to assess if the file exists
+ # and then search for the maven project base dir.
+ $pom_file_reference = $args[$i + 1]
+
+ if (Test-Path $pom_file_reference) {
+ $basedir = (Get-Item $pom_file_reference).DirectoryName
+ }
+ else {
+ $pom_file_error = "POM file " + $pom_file_reference + " specified the -f/--file command-line argument does not exist"
+ Write-Error -Message $pom_file_error -ErrorAction Stop
+ }
+}
+else {
+ # if file flag is not found, then the pom.xml is relative to the working dir
+ # and the jvm.config can be found in the maven project base dir.
+
+ $basedir = $WDIR
+
+ while (IsNotRoot($WDIR.Path)) {
+ if (Test-Path "$WDIR\.mvn") {
+ $basedir = $WDIR
+ break
+ }
+
+ if ($WDIR) {
+ $WDIR = Split-Path $WDIR
+ }
+ else {
+ break
+ }
+ }
+}
+
+$MAVEN_OPTS = (RetrieveContentsJvmConfig $basedir)
+
+$LAUNCHER_JAR = Get-Item $MAVEN_HOME"\boot\plexus-classworlds*.jar"
+$LAUNCHER_CLASS = "org.codehaus.plexus.classworlds.launcher.Launcher"
+
+& $JAVACMD `
+ $MAVEN_OPTS `
+ $MAVEN_DEBUG_OPTS `
Review Comment:
⛔ **Scope mismatch with `mvnDebug.ps1`.** `mvnDebug.ps1` sets `$env:MAVEN_DEBUG_OPTS` (an environment variable), but this line reads `$MAVEN_DEBUG_OPTS` (a local PowerShell variable never assigned in `mvn.ps1`). Debug JVM flags are silently dropped when launching via `mvnDebug.ps1`.
```suggestion
$env:MAVEN_DEBUG_OPTS `
```
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
Review Comment:
⚠️ **Use `Join-Path` instead of string concatenation.** PR #878 already uses `Join-Path $env:JAVA_HOME bin java.exe`, which is idiomatic PowerShell.
```suggestion
$JAVACMD = Join-Path $env:JAVA_HOME bin java.exe
```
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+ $root_path_base_name = ((get-item $path).Root.BaseName
+ $path_base_name = ((get-item $path).BaseName
+
+ return $root_path_base_name -ne $path_base_name
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_location)
+ }
+ return $env:MAVEN_OPTS
+}
+
+$basedir = ""
+
+if ($file_flag_found) {
+ # we need to assess if the file exists
+ # and then search for the maven project base dir.
+ $pom_file_reference = $args[$i + 1]
+
+ if (Test-Path $pom_file_reference) {
+ $basedir = (Get-Item $pom_file_reference).DirectoryName
+ }
+ else {
+ $pom_file_error = "POM file " + $pom_file_reference + " specified the -f/--file command-line argument does not exist"
+ Write-Error -Message $pom_file_error -ErrorAction Stop
+ }
+}
+else {
+ # if file flag is not found, then the pom.xml is relative to the working dir
+ # and the jvm.config can be found in the maven project base dir.
+
+ $basedir = $WDIR
+
+ while (IsNotRoot($WDIR.Path)) {
+ if (Test-Path "$WDIR\.mvn") {
+ $basedir = $WDIR
+ break
+ }
+
+ if ($WDIR) {
+ $WDIR = Split-Path $WDIR
+ }
+ else {
+ break
+ }
+ }
+}
+
+$MAVEN_OPTS = (RetrieveContentsJvmConfig $basedir)
+
+$LAUNCHER_JAR = Get-Item $MAVEN_HOME"\boot\plexus-classworlds*.jar"
+$LAUNCHER_CLASS = "org.codehaus.plexus.classworlds.launcher.Launcher"
+
+& $JAVACMD `
+ $MAVEN_OPTS `
+ $MAVEN_DEBUG_OPTS `
+ -classpath $LAUNCHER_JAR `
+ "-Dclassworlds.conf=$CLASSWORLDS_CONF" `
+ "-Dmaven.home=$MAVEN_HOME" `
+ "-Dlibrary.jansi.path=$MAVEN_HOME\lib\jansi-native" `
+ "-Dmaven.multiModuleProjectDirectory=$basedir" `
+ $LAUNCHER_CLASS `
+ $MAVEN_ARGS `
+ $args
Review Comment:
⚠️ **Missing exit code propagation.** The Maven process exit code is available in `$LASTEXITCODE` after the `& $JAVACMD` invocation, but it is not propagated to the caller. Any script or CI pipeline invoking `mvn.ps1` will receive exit code 0 even when Maven fails.
```suggestion
$args
exit $LASTEXITCODE
```
##########
apache-maven/src/bin/mvnDebug.ps1:
##########
@@ -0,0 +1,42 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Debug Script
+
+Environment Variable Prerequisites
+
+JAVA_HOME (Optional) Points to a Java installation.
+MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+MAVEN_DEBUG_ADDRESS (Optional) Set the debug address. Default value is localhost:8000
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = $MyInvocation.MyCommand
+
+if (-not $env:MAVEN_DEBUG_ADDRESS ) {
+ $env:MAVEN_DEBUG_ADDRESS = "8000"
Review Comment:
⚠️ **Debug address defaults to all interfaces.** Setting `MAVEN_DEBUG_ADDRESS = "8000"` (bare port, no hostname) causes the JVM debug agent to listen on all network interfaces on Java 9+, exposing the debug port on non-loopback interfaces. The header comment says the default is `localhost:8000` — the code disagrees. PR #878 correctly uses `"localhost:8000"`.
```suggestion
$env:MAVEN_DEBUG_ADDRESS = "localhost:8000"
```
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
Review Comment:
⚠️ **`Test-Path` on potentially null `$env:JAVA_HOME`.** When `JAVA_HOME` is not set, `$env:JAVA_HOME` is `$null`. On PowerShell 5.x, `Test-Path -Path $null` throws `ParameterBindingValidationException` instead of returning `$false`, bypassing the `Get-Command java` fallback. Guard with an explicit null/empty check:
```suggestion
if (-not $env:JAVA_HOME -or -not (Test-Path $env:JAVA_HOME)) {
```
##########
apache-maven/src/bin/mvnDebug.ps1:
##########
@@ -0,0 +1,42 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Debug Script
+
+Environment Variable Prerequisites
+
+JAVA_HOME (Optional) Points to a Java installation.
+MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+MAVEN_DEBUG_ADDRESS (Optional) Set the debug address. Default value is localhost:8000
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = $MyInvocation.MyCommand
+
+if (-not $env:MAVEN_DEBUG_ADDRESS ) {
+ $env:MAVEN_DEBUG_ADDRESS = "8000"
+}
+
+$env:MAVEN_DEBUG_OPTS = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=$env:MAVEN_DEBUG_ADDRESS"
+
+$mvnCmd = $PSScriptRoot + "\mvn.ps1"
Review Comment:
💡 **Use `Join-Path` for path construction.** Consistent with the fix needed in `mvn.ps1` and already done in PR #878.
```suggestion
$mvnCmd = Join-Path -Path $PSScriptRoot -ChildPath "mvn.ps1"
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1421297178
I wonder if it would make sense to remove the `.cmd` script instead of keeping both `.ps1` and `.cmd` scripts.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1418284036
Core IT tests fails currently on
`MavenITmng6609ProfileActivationForPackagingTest.testitMojoExecution:42->AbstractMavenIntegrationTestCase.assertEquals:668->AbstractMavenIntegrationTestCase.assertEquals:673 expected: <pom> but was: <null>`
It doesn't seem to be related to the changes made in this pull request.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] michael-o commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1421460834
> > > I wonder if it would make sense to remove the `.cmd` script instead of keeping both `.ps1` and `.cmd` scripts.
> >
> >
> > That will likely break things so maybe that should be targeted for v4
>
> Yes, I had not seen this PR was targeting 3.9.x specifically.
I'd require this to be on master first and then backported...at most
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1325161599
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+
+ return -not $path.endsWith(":\")
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + (Get-Content $jvm_location).Replace("`n", "").Replace("`r", "");
+ }
+ return $env:MAVEN_OPTS;
+}
+
+$basedir = ""
+
+if ($file_flag_found) {
+ # we need to assess if the file exists
+ # and then search for the maven project base dir.
+ $pom_file_reference = $args[$i + 1]
+
+ if (Test-Path $pom_file_reference) {
+ $basedir = (Get-Item $pom_file_reference).DirectoryName
+ }
+ else {
+ $pom_file_error = "POM file " + $pom_file_reference + " specified the -f/--file command-line argument does not exist"
+ Write-Error -Message $pom_file_error -ErrorAction Stop
+ }
+}
+else {
+ # if file flag is not found, then the pom.xml is relative to the working dir
+ # and the jvm.config can be found in the maven project base dir.
+
+ $basedir = $WDIR
+
+ while (IsNotRoot($WDIR.Path)) {
+ if (Test-Path "$WDIR\.mvn") {
+ $basedir = $WDIR
+ break
+ }
+
+ if ($WDIR) {
+ $WDIR = Split-Path $WDIR
+ }
+ else {
+ break
+ }
+ }
+}
+
+$MAVEN_OPTS = (RetrieveContentsJvmConfig $basedir)
+
+$LAUNCHER_JAR = Get-Item $MAVEN_HOME"\boot\plexus-classworlds*.jar"
Review Comment:
No there is only one jar. The * is there if the version changes, the script will stil work.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MNG-7541] Implement powershell mvn command [maven]
Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r4018679175
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
Review Comment:
test 42
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
Review Comment:
test 50
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+ $root_path_base_name = ((get-item $path).Root.BaseName
+ $path_base_name = ((get-item $path).BaseName
+
+ return $root_path_base_name -ne $path_base_name
+}
+
+function RetrieveContentsJvmConfig {
Review Comment:
test 92
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+ $root_path_base_name = ((get-item $path).Root.BaseName
+ $path_base_name = ((get-item $path).BaseName
+
+ return $root_path_base_name -ne $path_base_name
+}
+
+function RetrieveContentsJvmConfig {
+ param (
Review Comment:
test 93
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+ $root_path_base_name = ((get-item $path).Root.BaseName
+ $path_base_name = ((get-item $path).BaseName
+
+ return $root_path_base_name -ne $path_base_name
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_location)
+ }
+ return $env:MAVEN_OPTS
+}
+
+$basedir = ""
+
+if ($file_flag_found) {
+ # we need to assess if the file exists
+ # and then search for the maven project base dir.
+ $pom_file_reference = $args[$i + 1]
+
+ if (Test-Path $pom_file_reference) {
+ $basedir = (Get-Item $pom_file_reference).DirectoryName
+ }
+ else {
+ $pom_file_error = "POM file " + $pom_file_reference + " specified the -f/--file command-line argument does not exist"
+ Write-Error -Message $pom_file_error -ErrorAction Stop
+ }
+}
+else {
+ # if file flag is not found, then the pom.xml is relative to the working dir
+ # and the jvm.config can be found in the maven project base dir.
+
+ $basedir = $WDIR
+
+ while (IsNotRoot($WDIR.Path)) {
+ if (Test-Path "$WDIR\.mvn") {
+ $basedir = $WDIR
+ break
+ }
+
+ if ($WDIR) {
+ $WDIR = Split-Path $WDIR
+ }
+ else {
+ break
+ }
+ }
+}
+
+$MAVEN_OPTS = (RetrieveContentsJvmConfig $basedir)
+
+$LAUNCHER_JAR = Get-Item $MAVEN_HOME"\boot\plexus-classworlds*.jar"
+$LAUNCHER_CLASS = "org.codehaus.plexus.classworlds.launcher.Launcher"
+
+& $JAVACMD `
+ $MAVEN_OPTS `
+ $MAVEN_DEBUG_OPTS `
+ -classpath $LAUNCHER_JAR `
+ "-Dclassworlds.conf=$CLASSWORLDS_CONF" `
+ "-Dmaven.home=$MAVEN_HOME" `
+ "-Dlibrary.jansi.path=$MAVEN_HOME\lib\jansi-native" `
+ "-Dmaven.multiModuleProjectDirectory=$basedir" `
+ $LAUNCHER_CLASS `
Review Comment:
test 154
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1579424801
> Not now, ATM. I need to consult also a colleague who's proficient in PowerShell.
Is there some progress?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] Giovds commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "Giovds (via GitHub)" <gi...@apache.org>.
Giovds commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1324860640
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
Review Comment:
It would be nice to reset the title, otherwise your shell will keep showing `some-path\mvn.p1` long after maven is done unless you open a new window. It could also act as a visual indication maven is done if you have multiple tabs open.
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
Review Comment:
I'm pretty sure `Get-Command` throws an exception if a command is not found. This would hard exit here and not show the clearer error on line 42
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
Review Comment:
Should, at least for `3.9.x`, it still support the `mavenrc_pre.ps1` and `mavenrc_post.ps1` [convention](https://maven.apache.org/ref/3.9.4/apache-maven/), as they are also still supported (with deprecation warning) in `4.x`. @michael-o @slachiewicz ?
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+
+ return -not $path.endsWith(":\")
Review Comment:
I'm not sure if it can/will be run on a share. _If_ that happens I think `:\` is not sufficient, as a share starts with `\\share\some\path`.
I believe `$path` is always a folder in this script, so we could use `(Get-Item $path).Root` instead.
_I've never tried how this behaves on a share though... I would expect it to return `\\share\` as it normally returns the drive e.g. `C:\`._
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
Review Comment:
Small detail, but kind of required. Either `JAVA_HOME` or a `java` command has to be present otherwise it throws an error.
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
Review Comment:
You could consider using named parameters here.
If we start the script with `param ($file, $f)` we can use auto completion from the command line. We could also get rid of the loop and the index `$i`. Throughout the script you can just reference `$file` and/or `$f`.
*Do note it will behave a little different on line 156 as the $args does not contain the named parameters. Also `mvnDebug.ps1` needs a different invocation.*
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+
+ return -not $path.endsWith(":\")
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + (Get-Content $jvm_location).Replace("`n", "").Replace("`r", "");
Review Comment:
Is this to replace windows line endings (`\r\n`)? I think this won't work as it tries to replace `'n` as literal 2 character combination, never tried it though.
I would suggest the following:
`Get-Content` is an array of objects. You can simply `-Join (Get-Content $filePath)` and it will be put into 1 string as arguments.
It might also need to have an additional space in front?
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
Review Comment:
I personally prefer to use `Throw` over `Write-Error -ErrorAction Stop` as it will result in a more clouded `$Error` object.

##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+
+ return -not $path.endsWith(":\")
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + (Get-Content $jvm_location).Replace("`n", "").Replace("`r", "");
+ }
+ return $env:MAVEN_OPTS;
+}
+
+$basedir = ""
+
+if ($file_flag_found) {
+ # we need to assess if the file exists
+ # and then search for the maven project base dir.
+ $pom_file_reference = $args[$i + 1]
+
+ if (Test-Path $pom_file_reference) {
+ $basedir = (Get-Item $pom_file_reference).DirectoryName
+ }
+ else {
+ $pom_file_error = "POM file " + $pom_file_reference + " specified the -f/--file command-line argument does not exist"
+ Write-Error -Message $pom_file_error -ErrorAction Stop
+ }
+}
+else {
+ # if file flag is not found, then the pom.xml is relative to the working dir
+ # and the jvm.config can be found in the maven project base dir.
+
+ $basedir = $WDIR
+
+ while (IsNotRoot($WDIR.Path)) {
Review Comment:
If we do not find `.mvn` directory it will use the root directory as `$basedir` and as `-Dmaven.multiModuleProjectDirectory`?
I'm not entirely sure what the [`.cmd`](https://github.com/apache/maven/blob/0c8b7dfc605ce906f6c73db0aeab1735759da890/apache-maven/src/bin/mvn.cmd#L153) does though, I'm not as familiar with `.cmd`.
##########
apache-maven/src/bin/mvnDebug.ps1:
##########
@@ -0,0 +1,42 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Debug Script
+
+Environment Variable Prerequisites
+
+JAVA_HOME (Optional) Points to a Java installation.
+MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+MAVEN_DEBUG_ADDRESS (Optional) Set the debug address. Default value is localhost:8000
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = $MyInvocation.MyCommand
+
+if (-not $env:MAVEN_DEBUG_ADDRESS ) {
+ $env:MAVEN_DEBUG_ADDRESS = "localhost:8000"
+}
+
+$env:MAVEN_DEBUG_OPTS = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=$env:MAVEN_DEBUG_ADDRESS"
Review Comment:
I'm not as familiar with `.cmd` files, but I believe the [current](https://github.com/apache/maven/blob/maven-3.9.x/apache-maven/src/bin/mvnDebug.cmd) `.cmd` just makes it port `8000` (no `localhost`).
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+
+ return -not $path.endsWith(":\")
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + (Get-Content $jvm_location).Replace("`n", "").Replace("`r", "");
+ }
+ return $env:MAVEN_OPTS;
+}
+
+$basedir = ""
+
+if ($file_flag_found) {
+ # we need to assess if the file exists
+ # and then search for the maven project base dir.
+ $pom_file_reference = $args[$i + 1]
+
+ if (Test-Path $pom_file_reference) {
+ $basedir = (Get-Item $pom_file_reference).DirectoryName
+ }
+ else {
+ $pom_file_error = "POM file " + $pom_file_reference + " specified the -f/--file command-line argument does not exist"
+ Write-Error -Message $pom_file_error -ErrorAction Stop
+ }
+}
+else {
+ # if file flag is not found, then the pom.xml is relative to the working dir
+ # and the jvm.config can be found in the maven project base dir.
+
+ $basedir = $WDIR
+
+ while (IsNotRoot($WDIR.Path)) {
+ if (Test-Path "$WDIR\.mvn") {
+ $basedir = $WDIR
+ break
+ }
+
+ if ($WDIR) {
+ $WDIR = Split-Path $WDIR
+ }
+ else {
+ break
+ }
+ }
+}
+
+$MAVEN_OPTS = (RetrieveContentsJvmConfig $basedir)
+
+$LAUNCHER_JAR = Get-Item $MAVEN_HOME"\boot\plexus-classworlds*.jar"
Review Comment:
If there are multiple jars (as the `*` suggests), I think this will fail as the separator would be a space.
(Note the [`.cmd`](https://github.com/apache/maven/blob/0c8b7dfc605ce906f6c73db0aeab1735759da890/apache-maven/src/bin/mvn.cmd#L169C1-L170C1) has an extra `-` and does not filter on `.jar`)
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
Review Comment:
You could consider using `Join-Path` so that we don't have to worry about manually inserting `/` or `\` and the direction they are pointing. To go up a directory you could use `(Get-Item $path).Parent` (only works on directories).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] michael-o commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1421484979
> @michael-o Should we remove `.cmd` in #877?
No, since the PR is only about addtion of a PS-based solution. No more, no less.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1099043083
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
Review Comment:
@yeikel Good point. But why would we do it only in this occurrence? At this moment in time the http link is used in 1,663 places (it redirects properly to https). What would you think about the idea to create a separate pull request to resolve this for the whole codebase? For instance for the `3.9.x` and `master` branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1419692902
After pulling the latest version of the core-its, it was running fine. So the core-its ran successfully.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] michael-o commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1332140137
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
Review Comment:
I wouldn't do it. New script, new behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1325162239
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
Review Comment:
Just tried to find an answer from the powershell community which would might give a best practice.
I don't have a strong opinion on this one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1325147437
##########
apache-maven/src/bin/mvnDebug.ps1:
##########
@@ -0,0 +1,42 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Debug Script
+
+Environment Variable Prerequisites
+
+JAVA_HOME (Optional) Points to a Java installation.
+MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+MAVEN_DEBUG_ADDRESS (Optional) Set the debug address. Default value is localhost:8000
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = $MyInvocation.MyCommand
+
+if (-not $env:MAVEN_DEBUG_ADDRESS ) {
+ $env:MAVEN_DEBUG_ADDRESS = "localhost:8000"
+}
+
+$env:MAVEN_DEBUG_OPTS = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=$env:MAVEN_DEBUG_ADDRESS"
Review Comment:
Yes, you are right. I made here the assumption that people would use java > 9. However earlier versions of java seems not to support this notation.
Please bear in mind that the behavior changes with java > 9, it will bind to only localhost instead of all internet interfaces.
I'll change it, to bring it line with the .cmd file.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1325164293
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
Review Comment:
I agree! We need to do a try-catch here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1419694222
@slachiewicz see here the pull request concerning the 3.9.x branch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1332158623
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
Review Comment:
The `JAVA_HOME` variable is set as optional, in a similar way as the cmd implmentation. the cmd implementation also resolves the java exe on path.
I consider this out of scope of this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1332195898
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
Review Comment:
The nice thing about the choice I made is that the command line parameters are consistent through all shells. With using named parameters, the parameters will have only one `-`.
It would also require changing `CLIManager`, the changes would become bigger than I anticipated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1332066994
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
Review Comment:
@Giovds It is only part of mvnDebug, it shouldn't be part of mvn.ps1 IMHO. I like your idea, but it shouldn't be part of this PR, but in a separate issue.
For now I'll remove this from mvn.ps1.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1325148568
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+# set title
+$Host.UI.RawUI.WindowTitle = (Get-Variable MyInvocation -Scope Script).Value.InvocationName
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ $JAVACMD = (get-command java).Source
+ if (-not $JAVACMD) {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot"\..")
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+
+ return -not $path.endsWith(":\")
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + (Get-Content $jvm_location).Replace("`n", "").Replace("`r", "");
+ }
+ return $env:MAVEN_OPTS;
+}
+
+$basedir = ""
+
+if ($file_flag_found) {
+ # we need to assess if the file exists
+ # and then search for the maven project base dir.
+ $pom_file_reference = $args[$i + 1]
+
+ if (Test-Path $pom_file_reference) {
+ $basedir = (Get-Item $pom_file_reference).DirectoryName
+ }
+ else {
+ $pom_file_error = "POM file " + $pom_file_reference + " specified the -f/--file command-line argument does not exist"
+ Write-Error -Message $pom_file_error -ErrorAction Stop
+ }
+}
+else {
+ # if file flag is not found, then the pom.xml is relative to the working dir
+ # and the jvm.config can be found in the maven project base dir.
+
+ $basedir = $WDIR
+
+ while (IsNotRoot($WDIR.Path)) {
Review Comment:
Nope, it would use the current working directory as basedir.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] michael-o commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1579987124
> > Not now, ATM. I need to consult also a colleague who's proficient in PowerShell.
>
> Is there some progress?
I hope to pick this up when my round with reporting stack is complete for next milestone. I guess somewere end of month. Please also raise your voice on dev@ to drag more attraction to this topic.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1421459223
> > I wonder if it would make sense to remove the `.cmd` script instead of keeping both `.ps1` and `.cmd` scripts.
>
> That will likely break things so maybe that should be targeted for v4
Yes, I had not seen this PR was targeting 3.9.x specifically.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] yeikel commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "yeikel (via GitHub)" <gi...@apache.org>.
yeikel commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1099048520
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
Review Comment:
That's fair. I don't see any issue with that
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
Review Comment:
That's fair. I don't see any issue with that plan
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] yeikel commented on a diff in pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "yeikel (via GitHub)" <gi...@apache.org>.
yeikel commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r1098831110
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
Review Comment:
Can we make this `https`?
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
Review Comment:
Can we set this to `https`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] JurrianFahner commented on pull request #982: [MNG-7541] Implement powershell mvn command
Posted by "JurrianFahner (via GitHub)" <gi...@apache.org>.
JurrianFahner commented on PR #982:
URL: https://github.com/apache/maven/pull/982#issuecomment-1474351004
@michael-o @slachiewicz What do we need to do to merge this merge request?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MNG-7541] Implement powershell mvn command [maven]
Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #982:
URL: https://github.com/apache/maven/pull/982#discussion_r4169950226
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+ $root_path_base_name = ((get-item $path).Root.BaseName
+ $path_base_name = ((get-item $path).BaseName
+
+ return $root_path_base_name -ne $path_base_name
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_location)
+ }
+ return $env:MAVEN_OPTS
+}
+
+$basedir = ""
+
+if ($file_flag_found) {
+ # we need to assess if the file exists
+ # and then search for the maven project base dir.
+ $pom_file_reference = $args[$i + 1]
+
+ if (Test-Path $pom_file_reference) {
+ $basedir = (Get-Item $pom_file_reference).DirectoryName
+ }
+ else {
+ $pom_file_error = "POM file " + $pom_file_reference + " specified the -f/--file command-line argument does not exist"
+ Write-Error -Message $pom_file_error -ErrorAction Stop
+ }
+}
+else {
+ # if file flag is not found, then the pom.xml is relative to the working dir
+ # and the jvm.config can be found in the maven project base dir.
+
+ $basedir = $WDIR
+
+ while (IsNotRoot($WDIR.Path)) {
+ if (Test-Path "$WDIR\.mvn") {
+ $basedir = $WDIR
+ break
+ }
+
+ if ($WDIR) {
+ $WDIR = Split-Path $WDIR
+ }
+ else {
+ break
+ }
+ }
+}
+
+$MAVEN_OPTS = (RetrieveContentsJvmConfig $basedir)
+
+$LAUNCHER_JAR = Get-Item $MAVEN_HOME"\boot\plexus-classworlds*.jar"
+$LAUNCHER_CLASS = "org.codehaus.plexus.classworlds.launcher.Launcher"
+
+& $JAVACMD `
+ $MAVEN_OPTS `
+ $MAVEN_DEBUG_OPTS `
+ -classpath $LAUNCHER_JAR `
+ "-Dclassworlds.conf=$CLASSWORLDS_CONF" `
+ "-Dmaven.home=$MAVEN_HOME" `
+ "-Dlibrary.jansi.path=$MAVEN_HOME\lib\jansi-native" `
Review Comment:
🔴 **Critical: JVM options passed as a single string argument instead of individual args.**
`$MAVEN_OPTS` is a string like `"-Xmx512m -Dfoo=bar"`. When PowerShell invokes `& $JAVACMD $MAVEN_OPTS`, the entire string is passed as **one argument** to `java.exe`, not split into individual flags. Java will fail with `Unrecognized option`.
Same problem applies to `$MAVEN_DEBUG_OPTS`.
Fix: split the string into an array before passing it.
```suggestion
$MAVEN_OPTS_ARRAY = if ($MAVEN_OPTS) { $MAVEN_OPTS.Split(' ', [System.StringSplitOptions]::RemoveEmptyEntries) } else { @() }
$MAVEN_DEBUG_ARRAY = if ($env:MAVEN_DEBUG_OPTS) { $env:MAVEN_DEBUG_OPTS.Split(' ', [System.StringSplitOptions]::RemoveEmptyEntries) } else { @() }
& $JAVACMD `
@MAVEN_OPTS_ARRAY `
@MAVEN_DEBUG_ARRAY `
-classpath $LAUNCHER_JAR `
"-Dclassworlds.conf=$CLASSWORLDS_CONF" `
"-Dmaven.home=$MAVEN_HOME" `
"-Dlibrary.jansi.path=$MAVEN_HOME\lib\jansi-native" `
"-Dmaven.multiModuleProjectDirectory=$basedir" `
$LAUNCHER_CLASS `
$env:MAVEN_ARGS `
$args
```
(Note: this also fixes the `$MAVEN_ARGS` → `$env:MAVEN_ARGS` and `$MAVEN_DEBUG_OPTS` → `$env:MAVEN_DEBUG_OPTS` scope issues from the previous review.)
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+ $root_path_base_name = ((get-item $path).Root.BaseName
+ $path_base_name = ((get-item $path).BaseName
+
+ return $root_path_base_name -ne $path_base_name
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_location)
+ }
+ return $env:MAVEN_OPTS
+}
+
+$basedir = ""
+
+if ($file_flag_found) {
+ # we need to assess if the file exists
+ # and then search for the maven project base dir.
+ $pom_file_reference = $args[$i + 1]
+
+ if (Test-Path $pom_file_reference) {
Review Comment:
⚠️ **`-f <directory>` is mishandled.** `mvn.cmd` accepts both files and directories as `-f` arguments. Here, `(Get-Item $pom_file_reference).DirectoryName` only works for files — for a directory, `.DirectoryName` returns the **parent** directory, so the basedir will be wrong.
```suggestion
if (Test-Path $pom_file_reference) {
$item = Get-Item $pom_file_reference
if ($item.PSIsContainer) {
$basedir = $item.FullName
} else {
$basedir = $item.DirectoryName
}
```
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
Review Comment:
⚠️ **Missing `MAVEN_BASEDIR` support.** `mvn.cmd` checks `%MAVEN_BASEDIR%` to allow users/CI to override project basedir detection entirely (skips the `.mvn` directory walk). This script ignores `$env:MAVEN_BASEDIR`.
Add before the basedir detection block:
```powershell
if ($env:MAVEN_BASEDIR) {
$basedir = $env:MAVEN_BASEDIR
} else {
# ... existing detection logic
}
```
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+ $root_path_base_name = ((get-item $path).Root.BaseName
+ $path_base_name = ((get-item $path).BaseName
+
+ return $root_path_base_name -ne $path_base_name
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_location)
+ }
+ return $env:MAVEN_OPTS
+}
Review Comment:
⚠️ **Missing `${MAVEN_PROJECTBASEDIR}` substitution in jvm.config.** `mvn.cmd` replaces `${MAVEN_PROJECTBASEDIR}` and `$MAVEN_PROJECTBASEDIR` placeholders in each line of `.mvn/jvm.config`. This function reads the file as-is, so projects relying on this substitution will get literal placeholder strings passed to the JVM.
```suggestion
function RetrieveContentsJvmConfig {
param (
[String] $path
)
$jvm_location = Join-Path $path ".mvn\jvm.config"
if (Test-Path $jvm_location) {
$lines = Get-Content $jvm_location | ForEach-Object {
$_ -replace '\$\{MAVEN_PROJECTBASEDIR\}', $path -replace '\$MAVEN_PROJECTBASEDIR', $path
}
return ($env:MAVEN_OPTS + " " + ($lines -join " ")).Trim()
}
return $env:MAVEN_OPTS
}
```
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
Review Comment:
💡 **mavenrc.ps1 invocation syntax.** `&$env:PROGRAMDATA"\mavenrc.ps1"` concatenates the call operator `&` with the variable, which doesn't work as intended. Should be:
```suggestion
if (Test-Path -Path "$env:PROGRAMDATA\mavenrc.ps1" -PathType Leaf) { & "$env:PROGRAMDATA\mavenrc.ps1" $args }
if (Test-Path -Path "$env:USERPROFILE\mavenrc.ps1" -PathType Leaf) { & "$env:USERPROFILE\mavenrc.ps1" $args }
```
##########
apache-maven/src/bin/mvn.ps1:
##########
@@ -0,0 +1,158 @@
+<#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+
+-----------------------------------------------------------------------------
+Apache Maven Startup Script
+
+Environment Variable Prerequisites
+
+ JAVA_HOME (Optional) Points to a Java installation.
+ MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
+ MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
+ MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
+-----------------------------------------------------------------------------
+#>
+
+if (-not $env:MAVEN_SKIP_RC) {
+ if (Test-Path -Path $env:PROGRAMDATA\mavenrc.ps1 -PathType Leaf) { &$env:PROGRAMDATA"\mavenrc.ps1" $args }
+ if (Test-Path -Path $env:USERPROFILE\mavenrc.ps1 -PathType Leaf) { &$env:USERPROFILE"\mavenrc.ps1" $args }
+}
+
+if (-not (Test-path $env:JAVA_HOME)) {
+ try {
+ $JAVACMD = (get-command java).Source
+ } catch {
+ Write-Error -ErrorAction Stop -Message "The $env:JAVA_HOME has not been set, JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ }
+}
+else {
+ $JAVACMD = $env:JAVA_HOME + "\bin\java.exe"
+}
+
+if (-not (Test-Path $JAVACMD)) {
+ Write-Error -Message "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started."
+ $ERROR_MESSAGE = "JAVA_HOME is set to " + $env:JAVA_HOME + ", but " + $JAVACMD + " does not exist."
+ Write-Error -ErrorAction Stop -Message $ERROR_MESSAGE
+}
+
+# check mvn home
+$MAVEN_HOME = (Get-Item $PSScriptRoot).Parent
+
+# check if maven command exists
+if (-not (Test-path "$MAVEN_HOME\bin\mvn.ps1")) {
+ Write-Error -Message "maven command (\bin\mvn.ps1) cannot be found" -ErrorAction Stop
+}
+# ==== END VALIDATION ====
+
+$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf"
+
+# Find the project basedir, i.e., the directory that contains the directory ".mvn".
+# Fallback to current working directory if not found.
+
+$WDIR = Get-Location
+
+# Look for the --file switch and start the search for the .mvn directory from the specified
+# POM location, if supplied.
+
+$i = 0
+$file_flag_found = $false
+foreach ($arg in $args) {
+ if (($arg -ceq "-f") -or ($arg -ceq "--file")) {
+ $file_flag_found = $true
+ break
+ }
+ $i += 1
+}
+
+function IsNotRoot {
+ param (
+ [String] $path
+ )
+ $root_path_base_name = ((get-item $path).Root.BaseName
+ $path_base_name = ((get-item $path).BaseName
+
+ return $root_path_base_name -ne $path_base_name
+}
+
+function RetrieveContentsJvmConfig {
+ param (
+ [String] $path
+ )
+
+ $jvm_location = $path + "\.mvn\jvm.config"
+
+ if (Test-Path $jvm_location) {
+ return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_location)
+ }
+ return $env:MAVEN_OPTS
+}
+
+$basedir = ""
+
+if ($file_flag_found) {
+ # we need to assess if the file exists
+ # and then search for the maven project base dir.
+ $pom_file_reference = $args[$i + 1]
+
+ if (Test-Path $pom_file_reference) {
+ $basedir = (Get-Item $pom_file_reference).DirectoryName
+ }
+ else {
+ $pom_file_error = "POM file " + $pom_file_reference + " specified the -f/--file command-line argument does not exist"
+ Write-Error -Message $pom_file_error -ErrorAction Stop
+ }
+}
+else {
+ # if file flag is not found, then the pom.xml is relative to the working dir
+ # and the jvm.config can be found in the maven project base dir.
+
+ $basedir = $WDIR
+
+ while (IsNotRoot($WDIR.Path)) {
+ if (Test-Path "$WDIR\.mvn") {
+ $basedir = $WDIR
+ break
+ }
+
+ if ($WDIR) {
+ $WDIR = Split-Path $WDIR
+ }
+ else {
+ break
+ }
+ }
+}
+
+$MAVEN_OPTS = (RetrieveContentsJvmConfig $basedir)
+
+$LAUNCHER_JAR = Get-Item $MAVEN_HOME"\boot\plexus-classworlds*.jar"
+$LAUNCHER_CLASS = "org.codehaus.plexus.classworlds.launcher.Launcher"
+
+& $JAVACMD `
+ $MAVEN_OPTS `
+ $MAVEN_DEBUG_OPTS `
+ -classpath $LAUNCHER_JAR `
+ "-Dclassworlds.conf=$CLASSWORLDS_CONF" `
+ "-Dmaven.home=$MAVEN_HOME" `
+ "-Dlibrary.jansi.path=$MAVEN_HOME\lib\jansi-native" `
+ "-Dmaven.multiModuleProjectDirectory=$basedir" `
+ $LAUNCHER_CLASS `
+ $MAVEN_ARGS `
+ $args
+
+
Review Comment:
⚠️ **Missing `--enable-native-access=ALL-UNNAMED` probe (MNG-8248).** `mvn.cmd` probes whether the JVM supports `--enable-native-access` and adds it to avoid illegal-access warnings on Java 17+. This script has no equivalent.
Add before the java invocation:
```powershell
$INTERNAL_OPTS = @()
try {
& $JAVACMD --enable-native-access=ALL-UNNAMED -version 2>&1 | Out-Null
$INTERNAL_OPTS += '--enable-native-access=ALL-UNNAMED'
} catch { }
```
Then include `@INTERNAL_OPTS` in the java invocation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org