[ 
https://issues.apache.org/jira/browse/MENFORCER-363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17386739#comment-17386739
 ] 

Robert Scholte commented on MENFORCER-363:
------------------------------------------

This bug is caused by MNG-7194. 

> Unexpected result from requireProperty with regex when the property is not 
> fully resolved
> -----------------------------------------------------------------------------------------
>
>                 Key: MENFORCER-363
>                 URL: https://issues.apache.org/jira/browse/MENFORCER-363
>             Project: Maven Enforcer Plugin
>          Issue Type: Bug
>          Components: Standard Rules
>    Affects Versions: 3.0.0-M3
>            Reporter: Bertrand Renuart
>            Priority: Major
>
> I was looking for a way to verify a property is defined and is fully 
> resolved. When it cannot resolve a placeholder, Maven usually leave it 
> unchanged. So if property "unknown" is not defined, 
> "<foo>pre-${unknown}</foo>" would not fully resolve and would left asis.
> With this in mind, I thought I could use the "requireProperty" with a regex 
> looking for "$" to check if a property is fully resolved or not. 
> Consider the following example:
> {code:java}
> <properties>
>   <foo>${unknown}</foo>
>   <bar>pre${unknown}</bar>
> </properties> 
> <plugin>
>   <artifactId>maven-enforcer-plugin</artifactId>
>   <version>3.0.0-M3</version>
>   <executions>
>     <execution>
>       <goals><goal>enforce</goal></goals>
>       <configuration>
>         <rules>
>           <requireProperty>
>             <property>foo</property>
>             <regex>[^$]*</regex>
>           </requireProperty>
>           <requireProperty>
>             <property>bar</property>
>             <regex>[^$]*</regex>
>           </requireProperty>
>         </rules>
> ...{code}
>  
> Here is what the execution reports:
> {code:java}
> [WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireProperty failed 
> with message:
> Property "foo" is required for this build.{code}
>  
> For the first rule, since "foo" refers to an _unknown_ property, I can 
> understand it is "not defined" and that the rule complains about it.
> However, I would expect the second rule to fail as well. Let's change its 
> regex to "[0-9]+" to see what happens:
> {code:java}
> [WARNING] Rule 1: org.apache.maven.plugins.enforcer.RequireProperty failed 
> with message:
> Property "bar" evaluates to "prenull".  This does not match the regular 
> expression "[0-9]+" {code}
> As we can see, the placeholder "${unknown}" has been resolved into "null" - 
> reason why the rule didn't fail initially...
>  
> IMHO this behaviour is not intuitive since Maven's standard behaviour is to 
> leave placeholders unchanged when they cannot be resolved.
>  
>  



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

Reply via email to