2016-09-05 9 views
0

正規表現に基づいてMavenのプロパティを置きたい。そのために私はregex-propertyプラグインを使用しています。プロパティはスペースで区切られたエントリを含み、それぞれからxml "ノード"を作成する必要があります。ビルドヘルパーのエスケープ置換値を無効にする:regex-property

"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> 
    <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>&lt;fileset dir="$1" includes="*.myext" /&gt;</replacement> 
       <failIfNoMatch>false</failIfNoMatch> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

しかし、問題をreplacementがあるということである。

<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> 

私はほとんど働く何かを持っています途中でどこかで逃げた。結果として得られるプロパティには<fileset dir\="C\:\\some\\entry" includes\="*.myext" />が含まれますが、これは望ましくありません。

このアプローチは厄介なようですが、プロパティで指定されたディレクトリからファイルをコピーできるような方法はありませんでした。

答えて

0

私は重要なことは言及していませんでした。このプロジェクトは原型から作成されています。アーキタイプからプロジェクトを生成すると、Velocity syntaxを使うことができます。これは私の特定の用途をかなり単純化します。 pom.xmlの作業抜粋は次のようになります。

<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}"> 
         #foreach($file in $filesPath.split(",")) 
         <fileset dir="$file.trim()" includes="*.myext"/> 
         #end 
        </copy> 
       </tasks> 
      </configuration> 
      <goals> 
       <goal>run</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

#foreachディレクティブはベロシティによってピックアップされ、$filesPathプロパティの各カンマで区切られたエントリの<fileset ...行を出力します。

そしてarchetype-metadata.xml

が宣言されています。

<copy todir="${project.basedir}/${somedir}"> 
    <fileset dir="/some/path" includes="*.myext"/> 
    <fileset dir="/other/path" includes="*.myext"/> 
</copy> 

<requiredProperty key="filesPath"/> 

は、正しいノードを生成しますmvn archetype:generate ... "-DfilesPath=/some/path/, /other/path"を呼び出します

関連する問題