[ 
https://issues.apache.org/jira/browse/MENFORCER-370?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Robert Scholte closed MENFORCER-370.
------------------------------------
      Assignee: Robert Scholte
    Resolution: Won't Fix

This is actually a "Can't fix". The conditon is first evaluated by the 
[PluginParameterExpressionEvaluator|https://maven.apache.org/ref/current/maven-core/apidocs/org/apache/maven/plugin/PluginParameterExpressionEvaluator.html]
 to replace the known expressions. This result, a script, is being fed to 
Beanshell.
The PluginParameterExpressionEvaluator only works with getters, so 
${project.basedir.path.replace('\\','/')} won't work either.

Instead I suggest to switch to the [Maven Scripting 
Plguin|http://maven.apache.org/plugins/maven-scripting-plugin/index.html]. I'm 
not sure if there's a JSR223 Scripting engine available for BeanShell, but at 
least there's one for Groovy.
This uses a 
[context|https://maven.apache.org/plugins/maven-scripting-plugin/script-context.html],
 so values are Objects instead of preresolved Strings.

> <condition/> should not take resolved properties as Java string, but escape 
> backslashes
> ---------------------------------------------------------------------------------------
>
>                 Key: MENFORCER-370
>                 URL: https://issues.apache.org/jira/browse/MENFORCER-370
>             Project: Maven Enforcer Plugin
>          Issue Type: Bug
>          Components: Plugin
>    Affects Versions: 3.0.0-M2
>         Environment: Apache Maven 3.6.3 
> (cecedd343002696d0abb50b32b541b8a6ba2883f)
> Java version: 11.0.9.1, vendor: ojdkbuild
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
>            Reporter: Damian
>            Assignee: Robert Scholte
>            Priority: Major
>
> Running Maven with {{${project.basedir}}} in the 
> {{<evaluateBeanshell><condition>}} in a pom.xml fails under Windows, while 
> Linux is fine.
> Already
> {code:xml}
>     <evaluateBeanshell>
>         <condition>
>             print(java.nio.file.Paths.get("${project.basedir}/".replace("\\", 
> "/"));
>             1==1
>         </condition>
>     </evaluateBeanshell>
> {code}
> fails with {{Couldn't evaluate condition...}} as {{$\{project.basedir}}} is 
> apparently taken as a Java string directly, w/o escaping the backslashes.
>  While the {{message}} part
> {code:xml}
>     <evaluateBeanshell>
>         <condition>
>             1==0
>         </condition>
>         <message>condition failed, 
> project.basedir=${project.basedir}</message>
>     </evaluateBeanshell>
> {code}
> logs the Windows path correctly:
> {code:bash}
>     [WARNING] Rule 2: org.apache.maven.plugins.enforcer.EvaluateBeanshell 
> failed with message:
>     condition failed, 
> project.basedir=C:\Users\me\git\project\dir_with_pom_file
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to