You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by timt asml <ti...@gmail.com> on 2005/08/18 14:05:49 UTC

Removing duplicate jars from classpath

Hi,

  We've recently moved part of our build environment from traditional
unix make to
  ant, and we're encountering some problems (ant 1.6.2, by the way)

  - We have an hierachical archive organization, in which individual
programmers only work on
    single components of the product. Typically, a single component is
a single jar.
     
  - Each developer works in a partial cpy of a so-called gate archive.
This gate-archive contains
    the jar's for all components in the archive.

  We  now build a class path using the following snippet:
<available file="${jlib.ws}" type="dir" property="jlib.ws.available"/>
<available file="${jlib.gate}" type="dir" property="jlib.gate.available"/>

  <path id="cmgr.classpath">
    <fileset dir="${jlib.ws}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${basedir}">
      <include name="${jlib.gate}/*.jar" if="jlib.gate.available"/>
     </fileset>
  </path>

  Clearly, this leads to some duplication: the gate archive also
contains the component jar, and we're
 somewhat worried about picking up the wrong version of the jar file.

  How do I exclude a file which is already in the path from being
added to the path ?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Removing duplicate jars from classpath

Posted by "Alexey N. Solofnenko" <A....@mdl.com>.
I do it with Jython as following, but, depending on what you actually 
need to do, it can be done easier by filtering all values via LinkedHashSet:

  <scriptdef name="setpath" language="jython">
    <attribute name="name" />
    <attribute name="path" />
    <![CDATA[# setpath
import os
import java

name=str(attributes.get("name"))
path=attributes.get("path")

pathList=[]
pathSet={}

for elem0 in path.split(';'):
  for elem in elem0.split(java.io.File.pathSeparator):
    canon_elem=java.io.File(elem).canonicalPath
    if not pathSet.has_key(canon_elem):
      pathSet[canon_elem]=None
      pathList.append(java.io.File(elem).absolutePath)

path=os.pathsep.join(pathList)
project.setProperty(name, path)]]>
  </scriptdef>


timt asml wrote:
> Hi,
>
>   We've recently moved part of our build environment from traditional
> unix make to
>   ant, and we're encountering some problems (ant 1.6.2, by the way)
>
>   - We have an hierachical archive organization, in which individual
> programmers only work on
>     single components of the product. Typically, a single component is
> a single jar.
>      
>   - Each developer works in a partial cpy of a so-called gate archive.
> This gate-archive contains
>     the jar's for all components in the archive.
>
>   We  now build a class path using the following snippet:
> <available file="${jlib.ws}" type="dir" property="jlib.ws.available"/>
> <available file="${jlib.gate}" type="dir" property="jlib.gate.available"/>
>
>   <path id="cmgr.classpath">
>     <fileset dir="${jlib.ws}">
>       <include name="*.jar"/>
>     </fileset>
>     <fileset dir="${basedir}">
>       <include name="${jlib.gate}/*.jar" if="jlib.gate.available"/>
>      </fileset>
>   </path>
>
>   Clearly, this leads to some duplication: the gate archive also
> contains the component jar, and we're
>  somewhat worried about picking up the wrong version of the jar file.
>
>   How do I exclude a file which is already in the path from being
> added to the path ?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>   

-- 
------------------------------------------------------------------------
/ Alexey N. Solofnenko
MDL Information Systems, Inc.
work: 510-357-2222x1726
home: http://trelony.cjb.net/
/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Removing duplicate jars from classpath

Posted by Matt Benson <gu...@yahoo.com>.
--- timt asml <ti...@gmail.com> wrote:

> Hi,
> 
>   We've recently moved part of our build environment
> from traditional
> unix make to
>   ant, and we're encountering some problems (ant
> 1.6.2, by the way)

You are encountering problems, or you are anticipating
problems?  <path> preserves order, so simply
specifying your files in order of precedence should be
sufficient.  This answer ignores the fact that your
question was actually:

>   How do I exclude a file which is already in the
> path from being
> added to the path ?

-I believe you meant the _simple name_ of the file;
your example showed that the files would (apparently)
live in different directories, therefore the answer
above applies.  Incidentally it is not possible to add
the same (full path) file to an Ant path > once; the
first occurrence will be the only one retained.

HTH,
Matt

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Removing duplicate jars from classpath

Posted by Dominique Devienne <dd...@gmail.com>.
Probably by using the <not>+<present> selectors in your second <fileset>.

Note that your jlib.gate property will need to be relative to basedir for
your scheme to work correctly, but I suspect you already know that. --DD

> -----Original Message-----
> From: timt asml [mailto:timt.asml@gmail.com]
>   We've recently moved part of our build environment from traditional
> unix make to
>   ant, and we're encountering some problems (ant 1.6.2, by the way)
> 
>   - We have an hierachical archive organization, in which individual
> programmers only work on
>     single components of the product. Typically, a single component is
> a single jar.
> 
>   - Each developer works in a partial cpy of a so-called gate archive.
> This gate-archive contains
>     the jar's for all components in the archive.
> 
>   We  now build a class path using the following snippet:
> <available file="${jlib.ws}" type="dir" property="jlib.ws.available"/>
> <available file="${jlib.gate}" type="dir" property="jlib.gate.available"/>
> 
>   <path id="cmgr.classpath">
>     <fileset dir="${jlib.ws}">
>       <include name="*.jar"/>
>     </fileset>
>     <fileset dir="${basedir}">
>       <include name="${jlib.gate}/*.jar" if="jlib.gate.available"/>
>      </fileset>
>   </path>
> 
>   Clearly, this leads to some duplication: the gate archive also
> contains the component jar, and we're
>  somewhat worried about picking up the wrong version of the jar file.
> 
>   How do I exclude a file which is already in the path from being
> added to the path ?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org