How can I "extend" the ant path (access with refId = ..) to all files on the path, except for some?

I am trying to get ant4eclipse to work, and I used ant a little, but not much higher than a simple scripting language. We have several source folders in our Eclipse projects, so the example in the ant4eclipse documentation needs to be adapted:

I currently have the following:

<target name="build">

  <!-- resolve the eclipse output location -->
  <getOutputpath property="classes.dir" workspace="${workspace}" projectName="${project.name}" />

  <!-- init output location -->
  <delete dir="${classes.dir}" />
  <mkdir dir="${classes.dir}" />

  <!-- resolve the eclipse source location -->
  <getSourcepath pathId="source.path" project="." allowMultipleFolders='true'/>

  <!-- read the eclipse classpath -->
  <getEclipseClasspath pathId="build.classpath" 
                          workspace="${workspace}" projectName="${project.name}" />

  <!-- compile -->
  <javac destdir="${classes.dir}" classpathref="build.classpath" verbose="false" encoding="iso-8859-1">
    <src refid="source.path" />
    </javac>

  <!-- copy resources from src to bin -->
  <copy todir="${classes.dir}" preservelastmodified="true">
    <fileset refid="source.path">
        <include name="**/*"/>
        <!--
        patternset refid="not.java.files"/>
        -->
    </fileset>
  </copy>
</target>

The task succeeds, but I cannot get it to work - it must also copy all files other than java to emulate the behavior of eclipse.

So, I have a pathId named source.path that contains several directories that I somehow need to massage into something like a copy task. I tried nesting, which is invalid, and some other wild guesses.

- .

+3
2

foreach ant-contrib:

<target name="build">
    ...

    <!-- copy resources from src to bin -->
    <foreach target="copy.resources" param="resource.dir">
        <path refid="source.path"/>
    </foreach>
</target>

<target name="copy.resources">
    <copy todir="${classes.dir}" preservelastmodified="true">
        <fileset dir="${resource.dir}" exclude="**/*.java">
    </copy>
</target>

source.path , if ( ant -contrib) ,

<target name="copy.resources">
    <if>
        <available file="${classes.dir}" type="dir"/>
        <then>
            <copy todir="${classes.dir}" preservelastmodified="true">
                <fileset dir="${resource.dir}" exclude="**/*.java">
            </copy>
        </then>
    </if>
</target>
+2

pathconvert , fileset includes.

<pathconvert pathsep="/**/*," refid="source.path" property="my_fileset_pattern">
    <filtermapper>
        <replacestring from="${basedir}/" to="" />
    </filtermapper>
</pathconvert>

${my_fileset_pattern} :

1/**/*,2/**/*,3

source.path 1, 2 3 . pathsep , .

. , /**/*. .

<fileset dir="." id="my_fileset" includes="${my_fileset_pattern}/**/*">
    <exclude name="**/*.java" />
</fileset>

, java, :

<copy todir="${classes.dir}" preservelastmodified="true">
    <fileset refid="my_fileset" />
</copy>

todir. , flatten , todir.

, pathconvert unix, . - , file.separator:

<property name="wildcard" value="${file.separator}**${file.separator}*" />
<pathconvert pathsep="${wildcard}," refid="source.path" property="my_fileset">
...
+3

Source: https://habr.com/ru/post/1705397/


All Articles