Shriram
Shriram

Reputation: 4411

Regular expression not working Maven fileset

I am trying use regular expression in maven-assembly-plugin which is shown below. There are files with the names starts with ABC502. I am trying to copy only the rpms with the 3 or 4 in suffix. Below one is not working. rpm names are given below

ABC5023-buildnumber.rpm

ABC5024-buildnumber.rpm

ABC5025-buildnumber.rpm

ABC5026-buildnumber.rpm

<fileSet>
    <directory>${project.build.directory}/tar_content/stackcontents/</directory>
    <outputDirectory>scripts/data/rpms/</outputDirectory>
    <includes>
        <include>%regex[ABC502(3|4)]-*.rpm</include>
    </includes>
    <fileMode>0755</fileMode>
    <directoryMode>0755</directoryMode>
</fileSet>

Upvotes: 5

Views: 2654

Answers (1)

Tunaki
Tunaki

Reputation: 137094

When you use a regular expression to include or exclude files with the %regex[...] syntax, all of the expression should be composed of the regular expression. You cannot mix a regular expression part with a normal part when it is used to match files.

Therefore, you need to use

<fileSet>
    <directory>${project.build.directory}/tar_content/stackcontents/</directory>
    <outputDirectory>scripts/data/rpms/</outputDirectory>
    <includes>
        <include>%regex[ABC502(3|4)-.*?\.rpm]</include>
    </includes>
    <fileMode>0755</fileMode>
    <directoryMode>0755</directoryMode>
</fileSet>

This will include all RPM files starting by ABC5023 or ABC5024.

Upvotes: 7

Related Questions