[ https://issues.apache.org/jira/browse/MNG-7541?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17837119#comment-17837119 ]
ASF GitHub Bot commented on MNG-7541: ------------------------------------- michael-o commented on code in PR #878: URL: https://github.com/apache/maven/pull/878#discussion_r1565386307 ########## apache-maven/src/assembly/shared/init.ps1: ########## @@ -0,0 +1,83 @@ +# ==== 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_config = $path + "\.mvn\jvm.config" + + if (Test-Path $jvm_config) { + return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_config) + } + 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) Review Comment: See above. ########## apache-maven/src/assembly/shared/init.ps1: ########## @@ -0,0 +1,83 @@ +# ==== 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_config = $path + "\.mvn\jvm.config" + + if (Test-Path $jvm_config) { + return $env:MAVEN_OPTS + " " + -Join (Get-Content $jvm_config) + } + return $env:MAVEN_OPTS Review Comment: That is not correct. If the file is empty then it is empty. See approach in `init`. ########## apache-maven/src/assembly/shared/init.ps1: ########## @@ -0,0 +1,83 @@ +# ==== END VALIDATION ==== + +$CLASSWORLDS_CONF = "$MAVEN_HOME\bin\m2.conf" Review Comment: I'd keep it identical to `init.cmd`. ########## apache-maven/src/assembly/maven/bin/mvnDebug.ps1: ########## @@ -0,0 +1,43 @@ +<# +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 8000 Review Comment: Default value in `.cmd` is `localhost:8000`, please fix. ########## apache-maven/src/assembly/shared/mvnvalidate.ps1: ########## @@ -0,0 +1,7 @@ +# 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 ($MAVEN_HOME\bin\mvn.ps1) cannot be found" -ErrorAction Stop +} Review Comment: I wonder whether this is a relic from the past. In `mvnvalidate` this check isn't present and this file is part of `mvn`/`mvn.cmd`/`mvn.ps1`. How can this fail?` ########## apache-maven/src/assembly/shared/validate.ps1: ########## @@ -0,0 +1,53 @@ +<# +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 } Review Comment: Why not `Test-File`? > Native support for PowerShell to start Maven > -------------------------------------------- > > Key: MNG-7541 > URL: https://issues.apache.org/jira/browse/MNG-7541 > Project: Maven > Issue Type: Improvement > Components: Command Line > Affects Versions: 3.8.3 > Environment: windows 10 / 11 > Reporter: Jurrian Fahner > Priority: Trivial > Labels: Script, Windows10, Windows11 > > Maven has two files in the bin dir: > ||command||its use|| > |mvn|POSIX shell| > |mvn.cmd|cmd.exe| > On windows there are two ways to write scripts, by using cmd.exe or using > powershell. > If you enter mvn in powershell it will look for `mvn.ps1` on the PATH first. > If it doesn't find anything it will execute `mvn.cmd` as fall-back. > When running maven for starting a server for development purposes and you do > ctrl-c to exit the server it will ask the question: Terminate batch job (Y/N)? > As far as I know it is default behaviour of cmd.exe. > Well if I don't want to terminate, I wouldn't press ctrl-c. ;) > It is not the case (as far as I know that Microsoft is going to deprecate > cmd.exe in favor of powershell: > [https://devblogs.microsoft.com/commandline/rumors-of-cmds-death-have-been-greatly-exaggerated/] > Allthough I think it would be a good move for maven to have also a powershell > script as well... It is possible to integrate elegant support for native help > in powershell, `get-help mvn`. > But it also increases the maintenance effort as well. I don't know whether > this cost outweigh the benefits, though... > By the way I would happy to contribute if it is appreciated. -- This message was sent by Atlassian Jira (v8.20.10#820010)