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

Karl Heinz Marbaise commented on MNG-8095:
------------------------------------------

Apart from that the branch on 3.9.X contains refererences like this:
{code:java}
    @Test
    public void testPropertiesInterpolation() throws Exception {
        // Arrange
        CliRequest request = new CliRequest(
                new String[] {
                    "-Dfoo=bar",
                    "-DvalFound=s${foo}i",
                    "-DvalNotFound=s${foz}i",
                    "-DvalRootDirectory=${session.rootDirectory}/.mvn/foo",
                    "-DvalTopDirectory=${session.topDirectory}/pom.xml",
                    "-f",
                    "${session.rootDirectory}/my-child",
                    "prefix:3.0.0:${foo}",
                    "validate"
                },
                null);
        request.rootDirectory = Paths.get("myRootDirectory");
        request.topDirectory = Paths.get("myTopDirectory");
{code}
and also the code in {{MavenCli.java}} contains 
((https://github.com/apache/maven/blob/maven-3.9.x/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java#L1563):
{code:java}
    protected static StringSearchInterpolator createInterpolator(CliRequest 
cliRequest, Properties... properties) {
        StringSearchInterpolator interpolator = new StringSearchInterpolator();
        interpolator.addValueSource(new AbstractValueSource(false) {
            @Override
            public Object getValue(String expression) {
                if ("session.topDirectory".equals(expression)) {
                    Path topDirectory = cliRequest.topDirectory;
                    if (topDirectory != null) {
                        return topDirectory.toString();
                    } else {
                        throw new IllegalUseOfUndefinedProperty(expression);
                    }
                } else if ("session.rootDirectory".equals(expression)) {
                    Path rootDirectory = cliRequest.rootDirectory;
                    if (rootDirectory != null) {
                        return rootDirectory.toString();
                    } else {
                        throw new IllegalUseOfUndefinedProperty(expression);
                    }
                }
                return null;
            }
        });
... 
{code}


> Usage of session.rootDirectory / session.topDirectory does not work
> -------------------------------------------------------------------
>
>                 Key: MNG-8095
>                 URL: https://issues.apache.org/jira/browse/MNG-8095
>             Project: Maven
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 3.9.2, 3.9.3, 3.9.4, 3.9.5, 3.9.6
>            Reporter: Karl Heinz Marbaise
>            Priority: Minor
>
> I have setup a project which uses the following parts 
> (https://maven.apache.org/docs/3.9.2/release-notes.html)
> * {{${session.topDirectory}}} 
> * {{${session.rootDirectory}}} 
> * {{${project.rootDirectory}}} 
> but unfortately they are not being replaced during the run of the project... 
> A small excerpt from the project... using the following simple configuration:
> {code:xml}
>       <plugin>
>         <groupId>com.soebes.maven.plugins</groupId>
>         <artifactId>echo-maven-plugin</artifactId>
>         <version>0.5.0</version>
>         <executions>
>           <execution>
>             <phase>initialize</phase>
>             <goals>
>               <goal>echo</goal>
>             </goals>
>             <configuration>
>               <echos>
> </echo>
>                 <echo>project.rootDirectory: '${project.rootDirectory}'</echo>
>                 <echo>session.rootDirectory: '${session.rootDirectory}'</echo>
>                 <echo>session.topDirectory: '${session.topDirectory}'</echo>
>                 <echo>project.basedir: '${project.basedir}'</echo>
>                 <echo>project.build.directory: 
> '${project.build.directory}'</echo>
> </echo>
>               </echos>
>             </configuration>
>           </execution>
>         </executions>
>       </plugin>
> {code}
> My expectation is that during the build the values should be replaced with 
> the appropriate values which works with Maven 4 (Tested with Maven 
> 4-alpha-13) like this:
> {code}
> [INFO] --- echo:0.5.0:echo (default) @ sub-mod-2 ---
> [INFO] =========================================================
> [INFO] project.rootDirectory: '/projects/props'
> [INFO] session.rootDirectory: '/projects/props'
> [INFO] session.topDirectory: '/projects/props'
> [INFO] project.basedir: '/projects/props/sub-mod-2'
> [INFO] project.build.directory: '/projects/props/sub-mod-2/target'
> [INFO] =========================================================
> {code}
> But the run with Maven 3.9.X it looks like this:
> {code}
> [INFO] --- echo:0.5.0:echo (default) @ sub-mod-2 ---
> [INFO] =========================================================
> [INFO] project.rootDirectory: '${project.rootDirectory}'
> [INFO] session.rootDirectory: '${session.rootDirectory}'
> [INFO] session.topDirectory: '${session.topDirectory}'
> [INFO] project.basedir: '/projects/props/sub-mod-2'
> [INFO] project.build.directory: '/projects/props/sub-mod-2/target'
> [INFO] =========================================================
> {code}
> I have setup a full working example here:
> https://github.com/khmarbaise/maven-bugs/tree/master/MNG-8095



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to