You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Bela Ban <be...@nms.fnc.fujitsu.com> on 2002/06/18 19:07:55 UTC

Mapping src to dest files in Javac

I have read through the FAQs and mailing list archives, but haven't been
able to find an answer to the problem below.

It boils down to (a) whether mapper elements now allowed / implemented
inside FileSets (proposed by Stefan Bodewig) and (b) whether <javac>
allows for nested <mapper> elements.

I have a directory structure as follows (JG=/home/bela/JavaGroups-2.0):

  $JG/src: (source files)
  e.g. $JG/src/org/javagroups/...

  and

  $JG/classes (class files)
  e.g. $JG/classes/org/javagroups/...

  I have a build.xml file in $JG.

  Now my problem: I want to go into any directory
  (e.g. $JG/org/javagroups/util/) and invoke 'ant -find build.xml
compile',
  which should use the build.xml file in $JG and recompile ONLY THE
  FILES IN THE CURRENT DIRECTORY WHICH CHANGED.

  So when I set destdir in <Javac> to $JG/classes and srcdir to
  $JG/src, I want to say includes="*.java", so that only the Java
  files in the current directory are included.

  Let's say I have A.java and B.java in
  $JG/src/org/javagroups/util. The <javac> task now compares these
  files against $JG/classes: it checks for $JG/classes/A.class and
  $JG/classes/B.class instead of
  $JG/classes/org/javagroups/util/A.class and
  $JG/classes/org/javagroups/util/B.class. Therefore it will not find
  the class files and always recompile A.java and B.java, which is not
needed.

  My solution was to use includes="${user.dir}/*.java" (which is
  $JG/src/org/javagroups/util/*.java) and write a custom task which
  removed $JG/src from this string and added the resulting string to
  the properties, so that the include string would
  be org/javagroups/util/*.java, which - compared against
  $JG/classes/org/javagroups/util - yields the correct result.

  However, this is a kludge, and I think there must be a better
  solution.

  I was thinking if <mapper> elements were allowed inside fileset (or
  directly inside <javac>), then we could specify the following:

   <javac srcdir="${JG}/src"
       destdir="${JG}/classes">
       <include dir="${user.dir}">
           <mapper id="bla" type="regexp" from="*org/javagroups*"
to="org/javagroups\2"/>
       </include>
       <classpath refid="netsmart.classpath"/>
   </javac>

  Anyone ?

--
Bela Ban
Fujitsu Network Communications
(408) 895-1732



Re: Mapping src to dest files in Javac

Posted by Diane Holt <ho...@yahoo.com>.
--- Bela Ban <be...@yahoo.com> wrote:
> we still have the problem of removing the ${basedir}
> prefix from the resulting string, e.g. if 'includes'
> is /home/bela/JavaGroups-2.0/src/org/javagroups/util/*.java,
> we need to convert it to org/javagroups/util/*.java.

But that wouldn't be what the 'includes' would be -- it'd be what my
example showed: includes="${cur.dir}/**/*.java", and ${cur.dir} is set to
the (relative path to the) directory you were in when you ran 'ant', so
you would only be including the .java files in the current directory (and
down, which I assumed you wanted -- if you only want the files in the
current directory, then you'd do includes="${cur.dir}/*.java).

Did you try implementing the example, and did it not work for you (it
worked in my little test-bed).

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Mapping src to dest files in Javac

Posted by Bela Ban <be...@yahoo.com>.
--- Diane Holt <ho...@yahoo.com> wrote:
> Well, the built-in solution would be much the same
> approach, but using
> <dirset> and <pathconvert> (you need the <dirset> so
> you have a datatype
> to pass to <pathconvert>):
> 
>   <dirset id="user.dir" dir="${user.dir}"/>
>   <pathconvert property="cur.dir" pathsep=""
> refid="user.dir">
>     <map from="${basedir}${file.separator}" to=""/>
>   </pathconvert>
>   <javac srcdir=... destdir=...
> includes="${cur.dir}/**/*.java"/>
> 
> [Note: <dirset is only available as of 1.5]
> 
> Diane
> 
> =====
> (holtdl@yahoo.com)


Hi Diane,

we still have the problem of removing the ${basedir}
prefix from the resulting string, e.g. if 'includes'
is
/home/bela/JavaGroups-2.0/src/org/javagroups/util/*.java,
we need to convert it to org/javagroups/util/*.java.

The basic problem is:
- I want to use 1 build.xml file located at the root
of my src directory
- I want to cd to ANY directory below the root and do
an 'ant -find build.xml compile'. This compile should
only compile the files in the current directory (if
needed). An eval of all files (e.g.
includes="**/*.java") would be too costly in a large
project

I guess I'll leave my <trim> task in there for now...


BTW: congrats to the whole team for an excellent job
!!!

Bela Ban


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Mapping src to dest files in Javac

Posted by Diane Holt <ho...@yahoo.com>.
Well, the built-in solution would be much the same approach, but using
<dirset> and <pathconvert> (you need the <dirset> so you have a datatype
to pass to <pathconvert>):

  <dirset id="user.dir" dir="${user.dir}"/>
  <pathconvert property="cur.dir" pathsep="" refid="user.dir">
    <map from="${basedir}${file.separator}" to=""/>
  </pathconvert>
  <javac srcdir=... destdir=... includes="${cur.dir}/**/*.java"/>

[Note: <dirset is only available as of 1.5]

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>