Условно включить файлы в набор файлов - PullRequest
2 голосов
/ 04 февраля 2010

Можно ли сделать что-то вроде следующего?

<target name="path-test">
   <property name="d.file" value="ant/d.fileset" />
   <property name="c.file" value="ant/c.fileset" />
   <property name="e.file" value="ant/e.fileset" />

   <available property="c.file.exists" file="${c.file}" />
   <available property="d.file.exists" file="${d.file}" />
   <available property="e.file.exists" file="${e.file}" />

   <path id="classPathRef">
     <fileset dir="${depot.dir}">
       <include name="${c.file}" if="c.file.exists" />
       <include name="${d.file}" if="d.file.exists" />
       <include name="${e.file}" if="e.file.exists" />
     </fileset>
   </path>
 </target> 

В этом сценарии каждый файл набора файлов будет содержать список jar-файлов, которые я хочу добавить в classPathRef.

Ответы [ 2 ]

4 голосов
/ 05 февраля 2010

Doh!

<target name="path-test">
   <property name="d.file" value="ant/d.fileset" />
   <property name="c.file" value="ant/c.fileset" />
   <property name="e.file" value="ant/e.fileset" />

   <available property="c.file.exists" file="${c.file}" />
   <available property="d.file.exists" file="${d.file}" />
   <available property="e.file.exists" file="${e.file}" />

   <path id="classPathRef">
     <fileset dir="${depot.dir}">
       <includesfile name="${c.file}" if="c.file.exists" />
       <includesfile name="${d.file}" if="d.file.exists" />
       <includesfile name="${e.file}" if="e.file.exists" />
     </fileset>
   </path>
 </target> 
1 голос
/ 07 февраля 2010

Я бы порекомендовал проверить использование плюща для управления вашими classpath.

В вашем файле сборки используйте команду retrieve , чтобы скопировать файлы JAR в специальные каталоги:

<ivy:retrieve pattern="${lib.dir}/[conf]/[artifact].[ext]"/>

Обратите внимание на параметр conf . Это относится к конфигурации плюща (аналогично scope в Maven). Это позволяет вам классифицировать каждую из банок, от которых вы зависите.

Теперь, когда каждая коллекция jar удобно расположена в отдельных каталогах, объявление путей в вашем файле сборки становится тривиальным:

<path id="compile.path">
    <fileset dir="${lib.dir}/compile"/>
</path>

<path id="test.path">
    <fileset dir="${lib.dir}/test"/>
</path>

<path id="runtime.path">
    <fileset dir="${lib.dir}/runtime"/>
</path>

Сложность определения групп jar делегирована ivy и управлению ее конфигурацией:

Вот пример управляющего ivy.xml file

<ivy-module version="2.0">
    <info organisation="apache" module="hello-ivy"/>
    <configurations>
        <conf name="compile" description="Libraries needed for compilation"/>
        <conf name="runtime" extends="compile" description="Libraries that should be included when deploying the code" />
        <conf name="test" extends="runtime" description="Additional test libraries, not deployed" />
    </configurations>
    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.0" conf="build->default"/>
        <dependency org="commons-cli" name="commons-cli" rev="1.0" conf="build->default"/>
        <dependency org="junit" name="junit" rev="4.7" conf="test->default"/>
    </dependencies>
</ivy-module>

Магические биты - это атрибуты conf , связанные с каждой зависимостью. Например, Junit объявлен частью test , что означает, что он появляется только в пути тестирования. Остальные будут отображаться во всех трех путях из-за способа объявления конфигураций.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...