我想根据正则表达式替换 Maven 中的属性。为此,我正在使用该regex-property
插件。属性将包含以空格分隔的条目,我需要从每个条目创建一个 xml“节点”。
"C:\some\entry D:\another\entry"
(processing here ... below is the content of variable after processing)
<fileset dir="C:\some\entry" includes="*.myext" />
<fileset dir="D:\another\entry" includes="*.myext" />
替换后的属性应稍后用于复制给定的工件:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>copy files</id>
<phase>initialize</phase>
<configuration>
<tasks>
<copy todir="${project.basedir}/somedir">
${processedPaths} <!-- THIS WILL EXPAND TO <fileset ... /> -->
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
我有一些几乎可以工作的东西:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>regex-property</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>testprop</name>
<value>${testprop}</value>
<regex>([^\s]+)</regex>
<replacement><fileset dir="$1" includes="*.myext" /></replacement>
<failIfNoMatch>false</failIfNoMatch>
</configuration>
</execution>
</executions>
</plugin>
但这里的问题是,它replacement
在途中的某个地方逃脱了。因此生成的属性将包含<fileset dir\="C\:\\some\\entry" includes\="*.myext" />
,这是不希望的。
这种方法确实看起来很老套,但我找不到任何其他方法可以让我从属性中指定的目录中复制文件。