You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-user@ant.apache.org by Torsten Curdt <tc...@apache.org> on 2007/10/13 21:48:41 UTC

accessing project dependencies in custom ant task

In a custom ant task I would like to get the dependencies (and the  
paths to the artifacts) of the project as defined in the ivy.xml.  
When writing a maven mojo =:-o I would use

   Set projectArtifacts = getProject().getArtifacts();

How could I get the dependencies from ivy in my ant task?

cheers
--
Torsten


Re: accessing project dependencies in custom ant task

Posted by Xavier Hanin <xa...@gmail.com>.
On 10/16/07, Torsten Curdt <tc...@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/

Re: accessing project dependencies in custom ant task

Posted by Torsten Curdt <tc...@apache.org>.
Hm ...I had a look into the testcases but I still find the API not  
that straight forward. 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.?????()
			);
	        final Artifact artifact = reports[0].getArtifact();
	        final File artifactFile = ivy.getArchiveFileInCache 
(ivy.getDefaultCache(), artifact);
	
	        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

Re: accessing project dependencies in custom ant task

Posted by Gilles Scokart <gs...@gmail.com>.
I would advice to look in the ivy source code for an example.  There is
certainly a task that already do something similar to what you want to do.

Gilles

2007/10/13, Torsten Curdt <tc...@apache.org>:
>
> In a custom ant task I would like to get the dependencies (and the
> paths to the artifacts) of the project as defined in the ivy.xml.
> When writing a maven mojo =:-o I would use
>
>    Set projectArtifacts = getProject().getArtifacts();
>
> How could I get the dependencies from ivy in my ant task?
>
> cheers
> --
> Torsten
>
>


-- 
Gilles SCOKART

Re: accessing project dependencies in custom ant task

Posted by Johannes Stamminger <Jo...@astrium.eads.net>.
Hi!

On Saturday 13 October 2007, Torsten Curdt wrote:
> In a custom ant task I would like to get the dependencies (and the
> paths to the artifacts) of the project as defined in the ivy.xml.
> When writing a maven mojo =:-o I would use
>
>    Set projectArtifacts = getProject().getArtifacts();
>
> How could I get the dependencies from ivy in my ant task?

After a resolve (by way of ivy ant task) you may ask ant to provide you the 
Ivy instance with:
  final Ivy ivy = (Ivy) antProject.getReference("ivy.instance");

That one you can interate e.g. the IvyNodes on. But you should have a look to 
the sources (or in my case most understandable was to debug through it) to 
see, how to access the informations needed for your purposes.

Hih,
Johannes Stamminger

This email (including any attachments) may contain confidential and/or privileged information or information otherwise protected from disclosure. If you are not the intended recipient, please notify the sender immediately, do not copy this message or any attachments and do not use it for any purpose or disclose its content to any person, but delete this message and any attachments from your system. Astrium disclaims any and all liability if this email transmission was virus corrupted, altered or falsified.
---------------------------------------------------------
Astrium GmbH Vorsitzender des Aufsichtsrates: Thomas Mueller - Geschaeftsfuehrung: Evert Dudok (Vorsitzender), Dr. Reinhold Lutz, Pablo Salame Fischer
Sitz der Gesellschaft: Muenchen - Registergericht: Amtsgericht Muenchen, HRB Nr. 107 647

Re: accessing project dependencies in custom ant task

Posted by Torsten Curdt <tc...@apache.org>.
Better to ask on the dev list maybe?

cheers
--
Torsten

On 13.10.2007, at 21:48, Torsten Curdt wrote:

> In a custom ant task I would like to get the dependencies (and the  
> paths to the artifacts) of the project as defined in the ivy.xml.  
> When writing a maven mojo =:-o I would use
>
>   Set projectArtifacts = getProject().getArtifacts();
>
> How could I get the dependencies from ivy in my ant task?
>
> cheers
> --
> Torsten
>