使用 Apache Maven 文件管理在 maven 插件中获取绝对文件路径 API

Get absolute filepath in maven-plugin using Apache Maven File Management API

我目前正在尝试编写一个 Maven 插件,它应该能够在 "generate-resources" 阶段 create/process 一些资源文件。一切正常,但在这个过程中我的插件需要读取一些其他文件作为输入,所以我决定使用 Apache Maven File Management API to specify the input file paths. I set up everything like described in the In a MOJO 示例。

<plugin>
    <groupId>my.groupId</groupId>
    <artifactId>my-maven-plugin</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <executions>
        <execution>
            <goals>
                <goal>mygoal</goal>
            </goals>
            <phase>generate-resources</phase>
        </execution>
    </executions>
    <configuration>
        <fileset>
            <directory>${basedir}/src/main/resources</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </fileset>
    </configuration>
</plugin>

但我无法检索文件的绝对文件路径:

public void execute() throws MojoExecutionException {
    FileSetManager fileSetManager = new FileSetManager();
    for (String includedFile : fileSetManager.getIncludedFiles(fileset)) {
        getLog().info(includedFile);
    }
}

...因为结果只是文件名,如:

[INFO] --- my-maven-plugin:0.0.1-SNAPSHOT:mygoal (default) ---
[INFO] some-file-A.xml
[INFO] some-file-B.xml

我也无法将 fileset.directory 与文件名连接起来,因为 FileSetManager 不包含检索 fileset.directory 值的方法。

那么如何检索包含的绝对文件路径?

我发现 fileset.getDirectory() 可以解决问题。

public void execute() throws MojoExecutionException {
    FileSetManager fileSetManager = new FileSetManager();
    for (String includedFile : fileSetManager.getIncludedFiles(fileset)) {
        getLog().info(fileset.getDirectory() + File.separator + includedFile);
    }
}