Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using maven replacer plugin to list files in a folder

I'd like to use the maven-replacer-plugin to replace $file-list$ in a file with a comma separated list of files in a folder of my project. Is this possible?

thanks

like image 387
Gootik Avatar asked Nov 29 '12 23:11

Gootik


1 Answers

Here is what I did :

using the antrun plugin create a temp file with the list in it :

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <configuration>
                <target>
                    <fileset id="my-fileset" dir="src/main/resources" />
                    <pathconvert targetos="unix" pathsep=","
                        property="my-file-list" refid="my-fileset">
                        <map from="${basedir}\src\main\resources\" to="" />
                    </pathconvert>
                    <echo file="${basedir}\target\file-list.txt">${my-file-list}</echo>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

then using the replacer plugin I replace the list in the file that I want :

<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>maven-replacer-plugin</artifactId>
    <executions>
        <execution>
            <id>replace-file-list</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>replace</goal>
            </goals>
            <configuration>
                <ignoreMissingFile>false</ignoreMissingFile>
                <file>target/MY_FILE.TXT</file>
                <regex>false</regex>
                <token>$file-list$</token>
                <valueFile>target/file-list.txt</valueFile>
            </configuration>
        </execution>
    </executions>
</plugin>

I'm sure there must be a better way, but hope this helps someone.

like image 135
Gootik Avatar answered Sep 28 '22 01:09

Gootik