ant-ivy-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Xavier Hanin" <xavier.ha...@gmail.com>
Subject Re: accessing project dependencies in custom ant task
Date Tue, 16 Oct 2007 06:50:20 GMT
On 10/16/07, Torsten Curdt <tcurdt@apache.org> wrote:
>
> Hm ...I had a look into the testcases but I still find the API not
> that straight forward.


I agree, using Ivy as an API has not been very well thought, and is very
badly documented. This is something we still need to improve.

Could you guys please help me to fill in the
> missing bits?
>
>                 final String config = "default";
>                 final ResolveReport report = ivy.resolve(
>                         new File("ivy.xml").toURL(),
>                         null,
>                         new String[] { config },
>                         ivy.getDefaultCache(),
>                         null,
>                         true);
>
>                 final ArtifactDownloadReport[] reports =
> report.getConfigurationReport(config).getDownloadReports(
> ===>                    ivy.?????()
>                         );


Here you should provide the module revision id (ie organization / module /
revision uple) of the module for which you want to know the downloaded
artifacts (in Ivy one module may have several artifacts). To know the list
of module revision ids in the configuration report, you can use
getDependencies() (which returns a collection of IvyNode), then on each
IvyNode call getResolvedId() which returns a ModuleRevisionId.

Then you can iterate over the ArtifactDownloadReport[], and for each do what
you do here:

                final Artifact artifact = reports[0].getArtifact();
>                 final File artifactFile = ivy.getArchiveFileInCache
> (ivy.getDefaultCache(), artifact);


For another way to do similar things, you can have a look at the
IvyArtifactReport which generates an xml file containing exactly the
information you want. So you can get the information you want from the xml
file (advantage: it will work both with Ivy 1.4 and Ivy 2.0) or use the same
code as this task do.

HTH,

Xavier



                final List nodes = report.getDependencies();
>                 for (Iterator it = nodes.iterator(); it.hasNext();) {
>                         final IvyNode node = (IvyNode) it.next();
> ===>                    final Artifact dep = ???
> ===>                    final File depFile = ??
>                 }
> cheers
> --
> Torsten
>



-- 
Xavier Hanin - Independent Java Consultant
http://xhab.blogspot.com/
http://ant.apache.org/ivy/
http://www.xoocode.org/

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message