ant-ivy-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Archie Cobbs" <archie.co...@gmail.com>
Subject Re: Packager Resolver: Simple and Complete example please.
Date Tue, 30 Dec 2008 21:53:47 GMT
On Tue, Dec 30, 2008 at 3:18 PM, Eric Berry <elberry@gmail.com> wrote:

>   I'm new to Ivy and I'm trying to use the Packager Resolver to download
> and unzip some bundled jars on Sourceforge. I'm looking for a simple yet
> complete example of how to set up Ivy to download a zip file from
> Sourceforge and extract it's jar files, and include them as part of my
> projects classpath.
> Things I need are?


You can find lots of examples
here<http://ivyroundup.googlecode.com/svn/trunk/repo/modules.xml>in
the Ivy RoundUp repository. Note: your browser will style the files
into
HTML; use "view source" to see them.

1. local ant build.xml file for my project.
>    a. Calls ivy:retrieve, and uses ivy:cachepath to find resultant jar
> artifacts, and adds them to my projects classpath?
>

Here are some ant macros that I use for this stuff:

<!--
        Macro for resolving a classpath by naming the module, etc. directly.
        Defines classpath "@{pathid}" and sets property
"@{pathid}.resolved".
-->
<macrodef uri="urn:org.dellroad.ant" name="ivymodpath">
  <attribute name="pathid" description="Classpath reference id to define"/>
  <attribute name="org" description="Module organisation name"/>
  <attribute name="mod" description="Module module name"/>
  <attribute name="rev" description="Module revision"/>
  <attribute name="conf" default="default" description="Name of the ivy
configuration to resolve"/>
  <attribute name="type" default="jar" description="Type of artifact to
resolve"/>
  <attribute name="settingsRef" default="build-macros-ivy-settings"
description="Reference to ivy settings"/>
  <attribute name="transitive" default="true" description="Whether to
resolve dependencies transitively"/>
  <attribute name="log" default="download-only" description="When to log
activity"/>
  <sequential>
    <ivy:resolve settingsRef="@{settingsRef}" organisation="@{org}"
module="@{mod}" revision="@{rev}" type="@{type}" inline="true"
transitive="@{transitive}" conf="@{conf}" log="@{log}"/>
    <ivy:cachepath settingsRef="@{settingsRef}" organisation="@{org}"
module="@{mod}" revision="@{rev}" type="@{type}" inline="true"
transitive="@{transitive}" conf="@{conf}" log="@{log}" pathid="@{pathid}"/>
    <property name="@{pathid}.resolved" value="true"/>
  </sequential>
</macrodef>

<!--
        Macro for resolving a classpath using a named configuration in
ivy.xml.
        Defines classpath "@{pathid}" and sets property
"@{pathid}.resolved".
-->
<macrodef uri="urn:org.dellroad.ant" name="ivypath">
  <attribute name="pathid" description="Classpath reference id to define"/>
  <attribute name="ivyfile" default="${basedir}/src/ivy/ivy.xml"
description="ivy.xml defining the named configuration"/>
  <attribute name="conf" description="Name of the ivy configuration to
resolve"/>
  <attribute name="type" default="jar" description="Type of artifact to
resolve"/>
  <attribute name="settingsRef" default="build-macros-ivy-settings"
description="Reference to ivy settings"/>
  <attribute name="transitive" default="true" description="Whether to
resolve dependencies transitively"/>
  <attribute name="log" default="download-only" description="When to log
activity"/>
  <sequential>
    <ivy:resolve file="@{ivyfile}" settingsRef="@{settingsRef}"
type="@{type}" transitive="@{transitive}" conf="@{conf}" log="@{log}"/>
    <ivy:cachepath file="@{ivyfile}" settingsRef="@{settingsRef}"
type="@{type}" transitive="@{transitive}" conf="@{conf}" log="@{log}"
pathid="@{pathid}"/>
    <property name="@{pathid}.resolved" value="true"/>
  </sequential>
</macrodef>

<!--
        Macro for resolving a fileset using a named configuration in
ivy.xml.
        Defines fileset "@{setid}" and sets property "@{setid}.resolved".
-->
<macrodef uri="urn:org.dellroad.ant" name="ivyfileset">
  <attribute name="setid" description="Fileset reference id to define"/>
  <attribute name="ivyfile" default="${basedir}/src/ivy/ivy.xml"
description="ivy.xml defining the named configuration"/>
  <attribute name="conf" description="Name of the ivy configuration to
resolve"/>
  <attribute name="type" default="jar" description="Type of artifact to
resolve"/>
  <attribute name="settingsRef" default="build-macros-ivy-settings"
description="Reference to ivy settings"/>
  <attribute name="transitive" default="true" description="Whether to
resolve dependencies transitively"/>
  <attribute name="log" default="download-only" description="When to log
activity"/>
  <sequential>
    <ivy:resolve file="@{ivyfile}" settingsRef="@{settingsRef}"
type="@{type}" transitive="@{transitive}" conf="@{conf}" log="@{log}"/>
    <ivy:cachefileset file="@{ivyfile}" settingsRef="@{settingsRef}"
type="@{type}" transitive="@{transitive}" conf="@{conf}" log="@{log}"
setid="@{setid}"/>
    <property name="@{setid}.resolved" value="true"/>
  </sequential>
</macrodef>

I use them like this in build.xml:

<target name="javac.classpath" unless="javac.classpath.resolved">
  <dellroad:ivypath pathid="javac.classpath" conf="javac"
transitive="false"/>
</target>

This assumes your ivy.xml is in src/ivy/ivy.xml and you have defined a
configuration named "javac" with the appropriate dependencies.

2. local ivy.xml for my project which defines the dependency.
>    a. Do I define the dependency on the zip file?
>    b. or on the zip's contents?
>    c. both?


Here's a src/ivy/ivy.xml example from one of my random projects:

<!-- $Id: ivy.xml 222 2008-07-19 21:56:09Z archie $ -->
<ivy-module version="1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">

    <info organisation="org.dellroad" module="ijh">
        <license name="Commercial"/>
        <description homepage="http://www.dellroad.org/ivymodules/ijh">
            ItJustHappened.com
        </description>
    </info>

    <configurations>
        <conf name="base" description="JARs required at both compile
and runtime"/>
        <conf name="javac" extends="base" description="JARs required
at compile time"/>
        <conf name="runtime" extends="base" description="JARs required
at execution time"/>
        <conf name="schemagen" description="JARs needed to generate
database schema"/>
        <conf name="gwtcompile" description="JARs needed to compile
GWT modules"/>
    </configurations>

    <publications>

        <artifact/>
        <artifact name="javadoc" type="javadoc" ext="zip"/>
    </publications>

    <dependencies>
        <dependency name="log4j" org="org.apache.log4j" rev="1.2.15"
conf="base->default"/>
        <dependency name="spring" org="org.springframework"
rev="2.5.4" conf="base->context-support,orm,tx,web,webmvc"/>
        <dependency name="spring-security" org="org.springframework"
rev="2.0.3" conf="base,schemagen->default,taglibs"/>
        <dependency name="jetty" org="org.mortbay" rev="6.1.9"
conf="base->core,jsp-2.1,naming,servlet-api"/>

        <dependency name="jta" org="javax.transaction" rev="1.1"
conf="base->default"/>
        <dependency name="mysql-connector-java" org="com.mysql"
rev="5.1.6" conf="base->default"/>
        <dependency name="hibernate" org="org.hibernate" rev="3.2.6"
conf="base->default,c3p0,cglib"/>
        <dependency name="hibernate-annotations" org="org.hibernate"
rev="3.3.1" conf="base->default"/>
        <dependency name="hibernate-entitymanager" org="org.hibernate"
rev="3.3.2" conf="base->default"/>
        <dependency name="hibernate-tools" org="org.hibernate"
rev="[3.2,4.0[" conf="schemagen->default"/>
        <dependency name="gwt" org="com.google" rev="1.5m2"
conf="javac,gwtcompile->compile;runtime->runtime"/>
        <dependency name="gwt-sl" org="net.sourceforge.gwt-widget"
rev="0.1.4e" conf="base->default"/>
        <dependency name="recaptcha4j" org="net.tanesha.recaptcha"
rev="0.0.7" conf="base->default"/>
 </dependencies>
</ivy-module>


3. remote ivy.xml file for dependency?
>    a. Do I need to define the jar files as the publications?
> 4. remote packager.xml file for dependency?
>    a. This should have instructions on how to download and unzip the file,
> and where to put the resultant jars (artifacts)?


See Ivy RoundUp for lots of examples.


>    b. The resource tag requires a sha1, which I do not have - does this
> mean I cannot use the Packager Resolver?


This is just the SHA1 checksum of the thing you are downloading. On Linux
compute this using "openssl sha1 filename".

-Archie

-- 
Archie L. Cobbs

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