It is difficult to tell what you are trying to accomplish here. Are you trying to switch only directories, or do you also want file-level filtering?

For directories, there is a slight impedance mismatch you need to deal with between the javac and the javadoc tasks. You can reuse sets of directories in javac by using the <src> nested element. But these take paths, not dirsets. The javadoc task, though, uses a nested packageset that requires a dirset. So the way to get reuse is to define a dirset, and then define a path that contains that dirset. Like this:

   <dirset dir="${top.dir} id="src.dirs">
     <include name="src/**" />
   </dirset>

   <path id="path.src.dirs">
     <dirset refid="src.dirs">
   </path>

This example has a slight bug, in that the dirset will contain all directories in the tree. The javadoc task needs all the directories which contain Java code, while javac needs only the top ones and will recurse through the tree by default. This doesn't cause a problem for javac, as it will know a directory is already specified and will ignore it. It does cause a problem with the count of files to be compiled, though.

For filtering individual files in the two tasks rather than just changing directories, the javac task is itself a fileset meaning that you can specify a selector or patternset as a nested element. These can be referenced from patternsets or selectors that are defined elsewhere, and can be reused by specifying them in the fileset nested element of the the javadoc task.

Note that a common mistake is to think that javac will only compile the files you specify. The javac program does its own dependency checking, so you may end up getting more files compiled than you expected. Even if you exclude a java file with a selector or patternset, it could still end up getting compiled if the javac compiler decides it is necessary.

Rick Moynihan wrote:
Hi all,

I'm just wondering if it's possible to have the javac & javadoc tasks share a common fileset.

I have a series of builds with more than one source directory. I would ideally like a mechanism to specify the directories/files for both of these once and reuse that definition in both the javadoc and javac tasks.

We have quite a complex build where we import a base ant file which we override selectively depending on the build. What I'd like to do is specify once in base.xml something like (abbreviated):

<!-- override src.dirs in top level build when we want multiple directories etc... -->
    <fileset dir="${src.dir}" id="src.dirs">
      <include name="**/*.java"/>
    </fileset>

    <target name="build">
        <javac...>
          <fileset refid="src.dirs"/> <!-- problem -->
          <classpath refid="build.classpath"/>
        </javac>
    </target>

    <target name="java-doc">
        <javadoc...>
          <classpath refid="build.classpath"/>
          <fileset refid="src.dirs"/> <!-- works ok -->
        </javadoc>
    </target>

Unfortunately the above doesn't work as javac won't accept a fileset in order to specify it's source directories (where as javadoc does). Ideally I'd like to keep things DRY and not have to resort to duplicating the specification of my src directories. Is this possible?

Thanks in advance,

R.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to