ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: Ant and paths
Date Wed, 22 Jan 2003 16:01:23 GMT
There! Did I miss the point this time ;-) --DD

P:\org_apache\antx>ant -f jarpath-script.xml
Buildfile: jarpath-script.xml

test:
Overriding previous definition of reference to jarpath
     [echo] jarpath = C:\pro\jdk1.4.0_01\jre\lib
     [echo]           C:\pro\ant1.5.1\lib
     [echo]           C:\pro\jython-2.1\jython.jar
     [echo] classpath = C:\pro\jdk1.4.0_01\jre\lib\charsets.jar
     [echo]             C:\pro\jdk1.4.0_01\jre\lib\jaws.jar
     [echo]             C:\pro\jdk1.4.0_01\jre\lib\jce.jar
     [echo]             C:\pro\jdk1.4.0_01\jre\lib\jsse.jar
     [echo]             C:\pro\jdk1.4.0_01\jre\lib\rt.jar
     [echo]             C:\pro\jdk1.4.0_01\jre\lib\sunrsasign.jar
     [echo]             C:\pro\ant1.5.1\lib\ant-contrib-0.1.jar
     [echo]             C:\pro\ant1.5.1\lib\ant.jar
     [echo]             C:\pro\ant1.5.1\lib\bsf.jar
     [echo]             C:\pro\ant1.5.1\lib\js.jar
     [echo]             C:\pro\ant1.5.1\lib\optional.jar
     [echo]             C:\pro\ant1.5.1\lib\pmd-1.01.jar
     [echo]             C:\pro\ant1.5.1\lib\xercesImpl.jar
     [echo]             C:\pro\ant1.5.1\lib\xml-apis.jar
     [echo]             C:\pro\jython-2.1\jython.jar

BUILD SUCCESSFUL
Total time: 1 second
P:\org_apache\antx>
P:\org_apache\antx>
P:\org_apache\antx>
P:\org_apache\antx>
P:\org_apache\antx>ant -f jarpath-script.xml
Buildfile: jarpath-script.xml

test:
     [echo] jarpath = C:\pro\jdk1.4.0_01\jre\lib
     [echo]           C:\pro\ant1.5.1\lib
     [echo]           C:\pro\jython-2.1\jython.jar
     [echo] classpath = C:\pro\jdk1.4.0_01\jre\lib\charsets.jar
     [echo]             C:\pro\jdk1.4.0_01\jre\lib\jaws.jar
     [echo]             C:\pro\jdk1.4.0_01\jre\lib\jce.jar
     [echo]             C:\pro\jdk1.4.0_01\jre\lib\jsse.jar
     [echo]             C:\pro\jdk1.4.0_01\jre\lib\rt.jar
     [echo]             C:\pro\jdk1.4.0_01\jre\lib\sunrsasign.jar
     [echo]             C:\pro\ant1.5.1\lib\ant-contrib-0.1.jar
     [echo]             C:\pro\ant1.5.1\lib\ant.jar
     [echo]             C:\pro\ant1.5.1\lib\bsf.jar
     [echo]             C:\pro\ant1.5.1\lib\js.jar
     [echo]             C:\pro\ant1.5.1\lib\optional.jar
     [echo]             C:\pro\ant1.5.1\lib\pmd-1.01.jar
     [echo]             C:\pro\ant1.5.1\lib\xercesImpl.jar
     [echo]             C:\pro\ant1.5.1\lib\xml-apis.jar
     [echo]             C:\pro\jython-2.1\jython.jar

BUILD SUCCESSFUL
Total time: 1 second
P:\org_apache\antx>type jarpath-script.xml
<?xml version="1.0"?>

<!-- ANT build file to test a specific feature or bug of ANT.
     Dominique Devienne <ddevienne@lgc.com>     January 2003
  -->
<project name="JarPath" default="test">

  <target name="test">
    <!-- Simulate user-supplied Jar-Path -->
    <path id="jarpath">
      <pathelement location="${java.home}/lib" />
      <pathelement location="${ant.home}/lib" />
      <pathelement location="C:/pro/jython-2.1/jython.jar" />
    </path>
    <property name="jarpath" refid="jarpath" />

    <!-- Pretty print jarpath-->
    <pathconvert property="formatted-jarpath"
                 pathsep="${line.separator}          "
                 refid="jarpath" />
    <echo message="jarpath = ${formatted-jarpath}" />

    <!-- Iterate over jarpath, adding all JARs/ZIPs there to classpath -->
    <script language="javascript"><![CDATA[
      prj = self.getProject();
      jarpath = prj.getProperty("jarpath");
      tokenizer = new java.util.StringTokenizer(jarpath,
                                                java.io.File.pathSeparator);
      importPackage(Packages.org.apache.tools.ant.types);
      path = new Path(prj);
      prj.addReference("classpath", path);
      while (tokenizer.hasMoreElements()) {
        dir = prj.resolveFile(tokenizer.nextToken());
        if (dir.exists()) {
          if (dir.isDirectory()) {
            fs = new FileSet();
            fs.setDir(dir);
            fs.setIncludes("*.jar, *.zip");
            path.addFileset(fs);
          }
          else {
            path.createPathElement().setLocation(dir);
          }
        }
      }
    ]]></script>

    <!-- Pretty print classpath-->
    <pathconvert property="formatted-classpath"
                 pathsep="${line.separator}            "
                 refid="classpath" />
    <echo message="classpath = ${formatted-classpath}" />
  </target>

</project>

P:\org_apache\antx>dir /B /S %ANT_HOME%\lib
C:\pro\ant1.5.1\lib\ant-contrib-0.1.jar
C:\pro\ant1.5.1\lib\ant.jar
C:\pro\ant1.5.1\lib\bsf.jar  <<<< REQUIRED FOR <SCRIPT> >>>>
C:\pro\ant1.5.1\lib\js.jar   <<<< REQUIRED FOR JavaScript >>>>
C:\pro\ant1.5.1\lib\optional.jar
C:\pro\ant1.5.1\lib\pmd-1.01.jar
C:\pro\ant1.5.1\lib\README
C:\pro\ant1.5.1\lib\xercesImpl.jar
C:\pro\ant1.5.1\lib\xml-apis.jar

P:\org_apache\antx>

-----Original Message-----
From: Dominique Devienne [mailto:DDevienne@lgc.com] 
Sent: Wednesday, January 22, 2003 9:06 AM
To: 'Ant Users List'
Subject: RE: Ant and paths

Sorry for that... I guess you have three options then:

1) Use Ant-contrib's <foreach>... Actually, I'm not sure this would work,
since calling another target within an <antcall>.
2) Use <script>. I think I could make it work if I took the time to do it.
Would create a new Path with an id and populate it programmatically.
3) Do the same as (2) but in code. You can have your new datatype derive
from Path, id it, and refid it where you need it (id/refid allows you to use
polymorphic datatypes).

--DD

-----Original Message-----
From: Mark Cooper [mailto:mark.cooper@microlise.com] 
Sent: Wednesday, January 22, 2003 9:11 AM
To: Ant Users List
Subject: RE: Ant and paths


Sorry, there again you fall into the trap of missing the point, as I've
seen so many others do in the archives I've read.

The 'dir' attribute of fileset takes ONE directory as a start point. The
${SuppliedDirectoryPath} is a path-like string of directory pathnames.

Thanks anyway.

Mark Cooper




Dominique Devienne <DDevienne@lgc.com>@jakarta.apache.org on 22/01/2003
14:47:33

Please respond to "Ant Users List" <ant-user@jakarta.apache.org>

Sent by:
       ant-user-return-28568-mark.cooper=microlise.com@jakarta.apache.org


To:    "'Ant Users List'" <ant-user@jakarta.apache.org>
cc:

Subject:    RE: Ant and paths


Just do:

<path id="classpath">
  <fileset dir="${SuppliedDirectoryPath}"
           includes="**/*.jar, **/*.zip" />
</path>

Just be aware that the order is unspecified. --DD

-----Original Message-----
From: Mark Cooper [mailto:mark.cooper@microlise.com]
Sent: Wednesday, January 22, 2003 8:30 AM
To: ant-user@jakarta.apache.org
Subject: Ant and paths

OK, I'm sure this must have come up before, but after trawling through the
archives for what seems like days, I've not seen an answer to this that
satisfies the problem.

What I need to be able to do is supply a path (delimited string of
directory names), and an 'includes' patternset and for Ant to be able to
construct from this a path consisting of absolute (or relative from build
root) pathnames of the matching files separated by whatever the OS path
separator is. An obvious example is to be able to set a path consisting of
the locations where executable jar files reside, and for an Ant task to
then construct a <classpath> containing the absolute paths including
filenames of every jar and zip file in the supplied locations.

The reason for doing this is so that individual developers can store their
third party components in any drive/directory structure they choose, and be
able to supply (as a property or environment variable) a path and let Ant
resolve it to include all of the zip and jar files.

What I would like to see is something like:
<classpath id="my-classpath" >
      <pathelement path="${SuppliedDirectoryPath}" includes="**/*.jar,
**/*.zip"/>
</classpath>

Any ideas?

Mark Cooper

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






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

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

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


Mime
View raw message