You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by xa...@apache.org on 2008/06/24 04:44:05 UTC

svn commit: r670997 [1/2] - in /ant/ivy/core/trunk: ./ doc/ doc/configuration/ doc/resolver/ src/example/packager-resolver/ src/java/org/apache/ivy/core/settings/ src/java/org/apache/ivy/plugins/resolver/packager/ test/java/org/apache/ivy/plugins/resol...

Author: xavier
Date: Mon Jun 23 19:44:04 2008
New Revision: 670997

URL: http://svn.apache.org/viewvc?rev=670997&view=rev
Log:
NEW: Add new packager resolver (IVY-829) (thanks to Archie Cobbs)

Added:
    ant/ivy/core/trunk/doc/resolver/packager.html   (with props)
    ant/ivy/core/trunk/src/example/packager-resolver/
    ant/ivy/core/trunk/src/example/packager-resolver/ivysettings.xml   (with props)
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/BuiltFileResource.java   (with props)
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerCacheEntry.java   (with props)
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerResolver.java   (with props)
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/SubProcess.java   (with props)
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/build.xml   (with props)
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager-1.0.xsd   (with props)
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager.xsl   (with props)
    ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/PackagerResolverTest.java   (with props)
    ant/ivy/core/trunk/test/repositories/packager/
    ant/ivy/core/trunk/test/repositories/packager/repo/
    ant/ivy/core/trunk/test/repositories/packager/repo/org/
    ant/ivy/core/trunk/test/repositories/packager/repo/org/mod/
    ant/ivy/core/trunk/test/repositories/packager/repo/org/mod/1.0/
    ant/ivy/core/trunk/test/repositories/packager/repo/org/mod/1.0/ivy.xml   (with props)
    ant/ivy/core/trunk/test/repositories/packager/repo/org/mod/1.0/packager.xml   (with props)
    ant/ivy/core/trunk/test/repositories/packager/website/
    ant/ivy/core/trunk/test/repositories/packager/website/dist/
    ant/ivy/core/trunk/test/repositories/packager/website/dist/mod-1.0.tar.gz   (with props)
Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/doc/configuration/resolvers.html
    ant/ivy/core/trunk/doc/toc.json
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/typedef.properties

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=670997&r1=670996&r2=670997&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Mon Jun 23 19:44:04 2008
@@ -23,6 +23,7 @@
 	Mirko Bulovic
 	Kristian Cibulskis
 	Andrea Bernardo Ciddio
+	Archie Cobbs
 	Danno Ferrin
 	Benjamin Francisoud	
 	Jacob Grydholt Jensen
@@ -72,6 +73,7 @@
 - NEW: Retain original dependency constraint rules in resolved ivy file (IVY-739)
 - NEW: Add a new resolve mode (optionally per module) to utilize dynamic constraint rule metadata (IVY-740)
 - NEW: Add transitive dependency version and branch override mechanism (IVY-784)
+- NEW: Add new packager resolver (IVY-829) (thanks to Archie Cobbs)
 
 - IMPROVEMENT: Install task fails but reason is not displayed without using -debug or -verbose (IVY-834)
 - IMPROVEMENT: SSH resolver doesn't support keyboard-interactive authentication (IVY-836) (thanks to Tobias Himstedt)

Modified: ant/ivy/core/trunk/doc/configuration/resolvers.html
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/configuration/resolvers.html?rev=670997&r1=670996&r2=670997&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/configuration/resolvers.html (original)
+++ ant/ivy/core/trunk/doc/configuration/resolvers.html Mon Jun 23 19:44:04 2008
@@ -63,6 +63,7 @@
 <tbody>
 <tr><td><a href="../resolver/ivyrep.html">IvyRep</a></td><td>Standard</td><td>Finds ivy files on ivyrep and artifacts on ibiblio.</td></tr>
 <tr><td><a href="../resolver/ibiblio.html">IBiblio</a></td><td>Standard</td><td>Finds artifacts on ibiblio.</td></tr>
+<tr><td><a href="../resolver/packager.html">Packager</a></td><td>Standard</td><td>Finds ivy files and packaging instructions via URLs, then creates artifacts by following the instructions.</td></tr>
 <tr><td><a href="../resolver/filesystem.html">FileSystem</a></td><td>Standard</td><td>This very performant resolver finds ivy files and artifacts in your file system.</td></tr>
 <tr><td><a href="../resolver/url.html">Url</a></td><td>Standard</td><td>Finds ivy files and artifacts in any repository accessible with urls.</td></tr>
 <tr><td><a href="../resolver/vfs.html">Vfs</a></td><td>Standard</td><td>Finds ivy files and artifacts in any repository accessible with <a href="http://jakarta.apache.org/commons/vfs/">apache commons vfs</a>.</td></tr>

Added: ant/ivy/core/trunk/doc/resolver/packager.html
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/resolver/packager.html?rev=670997&view=auto
==============================================================================
--- ant/ivy/core/trunk/doc/resolver/packager.html (added)
+++ ant/ivy/core/trunk/doc/resolver/packager.html Mon Jun 23 19:44:04 2008
@@ -0,0 +1,396 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.    
+-->
+<html>
+<head>
+	<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
+	<script type="text/javascript">var xookiConfig = {level: 1};</script>	
+	<script type="text/javascript" src="../xooki/xooki.js"></script>
+</head>
+<body>
+	<textarea id="xooki-source">
+<table class="resolver">
+<tr><td class="title">Tag</td><td class="value">packager</td></tr>
+<tr><td class="title">Handle latest</td><td class="value">yes with http urls (and apache server) and with file urls, no with other urls</td></tr>
+<tr><td class="title">Handle publish</td><td class="value">no</td></tr>
+</table>
+
+<br/>
+<p>
+<span class="since">Since 2.0</span>.
+</p>
+
+<p>
+This resolver accesses ivy files and "packaging instructions" from an online "packager" repository. "Packager" repositories contain no actual artifacts. To get the artifacts, the packaging instructions are downloaded from the repository and executed locally. These instructions specify additional resource(s) to download and how to create the artifacts from them, for example, by downloading a project's original distribution archive directly from their web site and extracting the desired artifacts.
+</p>
+
+<p>
+The only packaging operations currently supported are downloading files, extracting files from archives, packaging files into archives, and moving and copying files. In the future more general operations may be supported, once appropriate security controls are in place.
+</p>
+
+<p>
+Packager repositories allow the creation of Ivy repositories that require neither the participation of any of the modules' creators nor setting up a huge mirror site. One such repository on the web is <a href="http://ivyroundup.googlecode.com/">Ivy RoundUp</a>. Of course, private packager repositories are feasible as well.
+</p>
+
+<p>
+The Packager resolver supports a "resource cache", where downloaded archives can be stored to avoid duplicate downloads. This cache is entirely separate from the <a href="../concept.html#cache">normal Ivy cache</a>: it is "private" to the Packager resolver, and it stores unmodified original software archives, not Ivy artifacts. See the <span class="ivy-att">resourceCache</span> attribute below for details.
+</p>
+
+<p>
+The packaging instructions are contained in "packager.xml" in a simple XML format. At resolve time this file gets converted into a "build.xml" file via XSLT and then executed using <a href="http://ant.apache.org/">ant</a>. Therefore, ant must be available as an executable on the platform. The ant task executes in a separate process and so is not affected by properties, etc. that may be set in any existing ant environment in which Ivy is running. However, Ivy will define a few properties for convenience; see the "Properties" listed below.
+</p>
+
+<p>
+For security reasons, the XSLT transform ensures that (a) all downloaded archives have verified SHA1 checksums (including cached resources); and (b) only a very limited set of ant tasks can be performed during the artifact "build" phase; currently these include move, copy, mkdir, zip, unzip, tar, and untar.
+</p>
+
+<p>
+The Packager resolver is based on the <a href="url.html">URL resolver</a> and is configured similarly, except the artifact child tags specify where to find the packager.xml files, rather than the artifacts themselves.
+</p>
+
+<p>
+Because the downloading and packaging process is relatively slow, it is important to use <a href="../concept.html#cache">Ivy's caching support</a> to avoid repeated execution of the packaging instructions.
+</p>
+
+<h1>Attributes</h1>
+This resolver shares the <a href="../configuration/resolvers.html#common">common attributes</a> of standard resolvers.
+<table class="ivy-attributes">
+<thead>
+    <tr><th class="ivy-att">Attribute</th><th class="ivy-att-desc">Description</th><th class="ivy-att-req">Required</th></tr>
+</thead>
+<tbody>
+  <tr>
+    <td>buildRoot</td>
+    <td>Defines the root of the temporary build directory hierarchy</td>
+    <td>Yes</td>
+  </tr>
+  <tr>
+    <td>resourceCache</td>
+    <td>Directory where downloaded resources should be cached</td>
+    <td>No; defaults to none</td>
+  </tr>
+  <tr>
+    <td>resourceURL</td>
+    <td>Ivy pattern that specifies a base URL to use for downloading <i>all</i> resources; overrides the URLs in the packaging instructions</td>
+    <td>No; defaults to none</td>
+  </tr>
+  <tr>
+    <td>verbose</td>
+    <td>True to run ant with the -verbose flag</td>
+    <td>No; defaults to false</td>
+  </tr>
+  <tr>
+    <td>quiet</td>
+    <td>True to run ant with the -quiet flag</td>
+    <td>No; defaults to false</td>
+  </tr>
+  <tr>
+    <td>validate</td>
+    <td>True if this resolver should validate (via XSD) the downloaded XML packaging instructions</td>
+    <td>No; defaults to true</td>
+  </tr>
+  <tr>
+    <td>preserveBuildDirectories</td>
+    <td>True if this resolver should not delete the temporary build directories in which the ant tasks are executed (for debugging purposes)</td>
+    <td>No; defaults to false</td>
+  </tr>
+</tbody>
+</table>
+<br />
+<p>
+Setting a resourceURL will cause the resolver to override the URLs for resources specified by the packaging instructions. Instead, all resources will be downloaded from an URL constructed by first resolving the resourceURL pattern into a base URL, and then resolving the resource filename relative to that base URL. In other words, the resourceURL pattern specifies the URL "directory", so it should always end in a forward slash.
+</p>
+
+<p>
+If a resourceURL download fails, the resolver will fall back to the original URL from the packaging instructions.
+</p>
+
+<p>
+Configure a resourceURL in situations where you don't want to rely on (or wait for) the web sites configured in the packaging instructions, and have access to a better (perhaps private) mirror site.
+</p>
+
+<h1>Child elements</h1>
+<table class="ivy-children">
+<thead>
+    <tr><th class="ivy-chld">Element</th><th class="ivy-chld-desc">Description</th><th class="ivy-chld-card">Cardinality</th></tr>
+</thead>
+<tbody>
+    <tr><td>ivy</td><td>Defines a pattern for ivy.xml files, using the pattern attribute</td>
+    <td>1..n</td></tr>
+    <tr><td>artifact</td><td>Defines a pattern for packager.xml files, using the pattern attribute</td>
+    <td>1..n</td></tr>
+</tbody>
+</table>
+
+<h1>Examples</h1>
+<code type="xml">
+<packager name="ivyroundup"
+         buildRoot="${user.home}/.ivy2/packager/build"
+         resourceCache="${user.home}/.ivy2/packager/cache"
+         resourceURL="ftp://mirror.example.com/pub/resources/[organisation]/[module]/">
+    <ivy pattern="http://ivyroundup.googlecode.com/svn/trunk/repo/modules/[organisation]/[module]/[revision]/ivy.xml"/>
+    <artifact pattern="http://ivyroundup.googlecode.com/svn/trunk/repo/modules/[organisation]/[module]/[revision]/packager.xml"/>
+</packager>
+</code>
+Defines a packager resolver which points to the <a href="http://ivyroundup.googlecode.com/">Ivy RoundUp</a> online repository. Builds will occur in a subdirectory of <code>${user.home}/.ivy2/packager/build</code> downloaded resources will be cached in <code>${user.home}/.ivy2/packager/cache</code> and the mirror site <code>ftp://mirror.example.com/pub/resources/[organisation]/[module]/ </code> will be tried first for all resources.
+
+<h1>Packaging Instructions</h1>
+<p>
+The goal of the packaging instructions is to download the required archives, extract the artifacts, and put the artifacts into a subdirectory. Each artifact should be written to artifacts/[type]s/[artifact].[ext] when the ant build completes.
+</p>
+
+<p>
+Below is an example of packaging instructions for <a href="http://testng.org/">TestNG 2.5</a>:
+<code type="xml">
+<packager-module version="1.0">
+
+    <property name="name" value="${ivy.packager.module}"/>
+    <property name="version" value="${ivy.packager.revision}"/>
+    <property name="zipname" value="${name}-${version}"/>
+
+    <resource dest="archive" url="http://testng.org/${zipname}.zip" sha1="2ea19275dc17453306f8bb780fe6ef6e9af7756b">
+        <url href="http://mirror.example.com/archives/${zipname}.zip"/>
+        <include name="${zipname}/src/main/**/*"/>
+        <include name="${zipname}/src/jdk15/**/*"/>
+        <include name="${zipname}/javadocs/**/*"/>
+        <include name="${zipname}/*.jar"/>
+    </resource>
+
+    <build>
+
+        <!-- jar  -->
+        <move file="archive/${zipname}/${zipname}-jdk14.jar" tofile="artifacts/jars/${name}-jdk14.jar"/>
+        <move file="archive/${zipname}/${zipname}-jdk15.jar" tofile="artifacts/jars/${name}-jdk15.jar"/>
+
+        <!-- source -->
+        <zip destfile="artifacts/sources/${name}.zip">
+            <fileset dir="archive/${zipname}/src/main">
+                <include name="**/*.java"/>
+            </fileset>
+            <fileset dir="archive/${zipname}/src/jdk15">
+                <include name="**/*.java"/>
+            </fileset>
+        </zip>
+
+        <!-- javadoc -->
+        <zip destfile="artifacts/javadocs/javadoc.zip">
+            <fileset dir="archive/${zipname}/javadocs"/>
+        </zip>
+    </build>
+</packager-module>
+</code>
+Of course, packaging instructions must produce artifacts consistent with those listed in the associated ivy.xml file.
+</p>
+
+<h1>Build-time properties</h1>
+This resolver ensures following ant properties are defined when it executes the ant build task.
+<table class="ivy-attributes">
+<thead>
+    <tr><th class="ivy-att">Property</th><th class="ivy-att-desc">Description</th>
+</thead>
+<tbody>
+  <tr>
+    <td>ivy.packager.organisation</td>
+    <td>Organization of the ivy module whose artifacts are being built</td>
+  </tr>
+  <tr>
+    <td>ivy.packager.module</td>
+    <td>Module of the ivy module whose artifacts are being built</td>
+  </tr>
+  <tr>
+    <td>ivy.packager.revision</td>
+    <td>Revision of the ivy module whose artifacts are being built</td>
+  </tr>
+  <tr>
+    <td>ivy.packager.branch</td>
+    <td>Branch of the ivy module whose artifacts are being built</td>
+  </tr>
+  <tr>
+    <td>ivy.packager.resourceCache</td>
+    <td>The configured <span class="ivy-att">resourceCache</span> if any; otherwise not defined</td>
+  </tr>
+  <tr>
+    <td>ivy.packager.resourceURL</td>
+    <td>The resolved <span class="ivy-att">resourceURL</span> pattern if any; otherwise not defined</td>
+  </tr>
+</tbody>
+</table>
+
+<h1>Packager XML Elements</h1>
+The packager.xml document element can contain the following child tags.
+<table class="ivy-children">
+<thead>
+    <tr><th class="ivy-chld">Element</th><th class="ivy-chld-desc">Description</th><th class="ivy-chld-card">Cardinality</th></tr>
+</thead>
+<tbody>
+  <tr>
+    <td>property</td>
+    <td>Set an ant property</td>
+    <td>0..n</td>
+  </tr>
+  <tr>
+    <td>resource</td>
+    <td>Define a resource to download and (optionally) unpack</td>
+    <td>0..n</td>
+  </tr>
+  <tr>
+    <td>m2resource</td>
+    <td>Define a Maven2 resource to download and (optionally) unpack</td>
+    <td>0..n</td>
+  </tr>
+  <tr>
+    <td>build</td>
+    <td>Specify move, copy, and/or archiving ant tasks that ultimately result in each artifact being placed into artifacts/[type]s/[artifact].[ext]</td>
+    <td>0..1</td>
+  </tr>
+</tbody>
+</table>
+
+<h1>Resource XML Elements</h1>
+The resource XML tag supports the following attributes:
+<table class="ivy-attributes">
+<thead>
+    <tr><th class="ivy-att">Attribute</th><th class="ivy-att-desc">Description</th><th class="ivy-att-req">Required</th></tr>
+</thead>
+<tbody>
+  <tr>
+    <td>url</td>
+    <td>Primary URL for the resource</td>
+    <td>Yes</td>
+  </tr>
+  <tr>
+    <td>sha1</td>
+    <td>SHA1 checksum of the resource</td>
+    <td>Yes</td>
+  </tr>
+  <tr>
+    <td>dest</td>
+    <td>Defines the name of the subdirectory into which the artifact should be unpacked</td>
+    <td>No; defaults to "archive"</td>
+  </tr>
+  <tr>
+    <td>tofile</td>
+    <td>Where to put the file directly; if present no extraction will be performed</td>
+    <td>No; if present, "dest" is ignored</td>
+  </tr>
+  <tr>
+    <td>filename</td>
+    <td>Name of the file to download</td>
+    <td>No; if not present, same as the last component of the URL</td>
+  </tr>
+  <tr>
+    <td>type</td>
+    <td>Type of archive: "zip", "jar", "war", "tar", "tgz", "tar.gz", "tar.bz2"</td>
+    <td>No; if not present, will be automatically determined from the filename suffix</td>
+  </tr>
+</tbody>
+</table>
+<br />
+The resource XML tag may contain child elements. An url tag with an href attribute specifies an alternate URL for the resource (see TestNG example above). Any other tags will be included as children of an automatically generated fileset tag.
+
+<h1>Maven2 Resources</h1>
+Special support is included for maven2 resources. For these resources, use the m2resource tag instead of the resource tag. Each m2resource tag specifies one or more artifacts that are downloaded from the Maven2 repository.
+
+<h1>M2Resource XML Elements</h1>
+The m2resource XML tag supports the following attributes:
+<table class="ivy-attributes">
+<thead>
+    <tr><th class="ivy-att">Attribute</th><th class="ivy-att-desc">Description</th><th class="ivy-att-req">Required</th></tr>
+</thead>
+<tbody>
+  <tr>
+    <td>groupId</td>
+    <td>Maven group ID</td>
+    <td>No; defaults to ${ivy.packager.organisation}</td>
+  </tr>
+  <tr>
+    <td>artifactId</td>
+    <td>Maven artifact ID</td>
+    <td>No; defaults to ${ivy.packager.module}</td>
+  </tr>
+  <tr>
+    <td>version</td>
+    <td>Maven version</td>
+    <td>No; defaults to ${ivy.packager.revision}</td>
+  </tr>
+  <tr>
+    <td>repo</td>
+    <td>Maven repository URL</td>
+    <td>No; defaults to http://repo1.maven.org/maven2/ </td>
+  </tr>
+</tbody>
+</table>
+<br />
+Each m2resource XML tag must have one or more artifact tags that define the artifacts to directly download. The URL for each artifact is constructed automatically based on the attributes in the m2resource and artifact tags.
+
+<h1>M2Resource Artifact Attributes</h1>
+The artifact children of m2resource tags support the following attributes:
+<table class="ivy-attributes">
+<thead>
+    <tr><th class="ivy-att">Attribute</th><th class="ivy-att-desc">Description</th><th class="ivy-att-req">Required</th></tr>
+</thead>
+<tbody>
+  <tr>
+    <td>ext</td>
+    <td>Maven filename extension</td>
+    <td>No; defaults to "jar"</td>
+  </tr>
+  <tr>
+    <td>classifier</td>
+    <td>Maven classifier (e.g., "sources", "javadoc")</td>
+    <td>No; defaults to none</td>
+  </tr>
+  <tr>
+    <td>sha1</td>
+    <td>SHA1 checksum of the resource</td>
+    <td>Yes</td>
+  </tr>
+  <tr>
+    <td>dest</td>
+    <td>Defines the name of the subdirectory into which the artifact should be unpacked</td>
+    <td rowspan="2">Exactly one of "dest" or "tofile" must be supplied</td>
+  </tr>
+  <tr>
+    <td>tofile</td>
+    <td>Where to put the file; no extraction will be performed</td>
+  </tr>
+  <tr>
+    <td>type</td>
+    <td>Type of archive: "zip", "jar", "war", "tar", "tgz", "tar.gz", "tar.bz2"</td>
+    <td>No; if not present, will be automatically determined from the filename suffix</td>
+  </tr>
+</tbody>
+</table>
+<br />
+Below is an example of packaging instructions for the <a href="http://commons.apache.org/email/">Apache Commons Email</a> module. Note that no build tag is required because all of the maven2 artifacts are usable directly (i.e., without unpacking anything).
+<code type="xml">
+<packager-module version="1.0">
+    <m2resource>
+        <artifact tofile="artifacts/jars/${ivy.packager.module}.jar" sha1="a05c4de7bf2e0579ac0f21e16f3737ec6fa0ff98"/>
+        <artifact classifier="javadoc" tofile="artifacts/javadocs/javadoc.zip" sha1="8f09630f1600bcd0472a36fb2fa2d2a6f2836535"/>
+        <artifact classifier="sources" tofile="artifacts/sources/source.zip" sha1="15d67ca689a792ed8f29d0d21e2d0116fa117b7e"/>
+    </m2resource>
+</packager-module>
+</code>
+</p>
+
+	</textarea>
+<script type="text/javascript">xooki.postProcess();</script>
+</body>
+</html>

Propchange: ant/ivy/core/trunk/doc/resolver/packager.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/doc/resolver/packager.html
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ant/ivy/core/trunk/doc/toc.json
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/toc.json?rev=670997&r1=670996&r2=670997&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/toc.json (original)
+++ ant/ivy/core/trunk/doc/toc.json Mon Jun 23 19:44:04 2008
@@ -295,6 +295,13 @@
                                   ]
                               },
                               {
+                                "id":"resolver/packager",
+                                "title":"Packager resolver",
+                                "children": [
+
+                                  ]
+                              },
+                              {
                                 "id":"resolver/filesystem",
                                 "title":"File System resolver",
                                 "children": [

Added: ant/ivy/core/trunk/src/example/packager-resolver/ivysettings.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/example/packager-resolver/ivysettings.xml?rev=670997&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/example/packager-resolver/ivysettings.xml (added)
+++ ant/ivy/core/trunk/src/example/packager-resolver/ivysettings.xml Mon Jun 23 19:44:04 2008
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!--
+    Licensed under the Apache License, Version 2.0 (the "License"); you may
+    not use this file except in compliance with the License. You may obtain
+    a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+    License for the specific language governing permissions and limitations
+    under the License.
+-->
+
+<!-- $Id$ -->
+<ivysettings>
+    <resolvers>
+        <packager name="ivyroundup" buildRoot="${user.home}/.ivy2/packager/build" resourceCache="${user.home}/.ivy2/packager/cache">
+
+            <!-- This defines the Ivy file location as is normally done -->
+            <ivy pattern="http://ivyroundup.googlecode.com/svn/trunk/repo/modules/[organisation]/[module]/[revision]/ivy.xml"/>
+
+            <!-- This defines the location of the build instructions -->
+            <artifact pattern="http://ivyroundup.googlecode.com/svn/trunk/repo/modules/[organisation]/[module]/[revision]/packager.xml"/>
+        </packager>
+    </resolvers>
+    <modules>
+        <module organisation=".*" name=".*" resolver="ivyroundup"/>
+    </modules>
+    <caches useOrigin="true"/>
+</ivysettings>
+

Propchange: ant/ivy/core/trunk/src/example/packager-resolver/ivysettings.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/src/example/packager-resolver/ivysettings.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/typedef.properties
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/typedef.properties?rev=670997&r1=670996&r2=670997&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/typedef.properties (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/typedef.properties Mon Jun 23 19:44:04 2008
@@ -27,6 +27,7 @@
 vsftp       = org.apache.ivy.plugins.resolver.VsftpResolver
 vfs         = org.apache.ivy.plugins.resolver.VfsResolver
 cache		= org.apache.ivy.plugins.resolver.CacheResolver
+packager	= org.apache.ivy.plugins.resolver.packager.PackagerResolver
 
 latest-revision = org.apache.ivy.plugins.latest.LatestRevisionStrategy
 latest-lexico   = org.apache.ivy.plugins.latest.LatestLexicographicStrategy

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/BuiltFileResource.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/BuiltFileResource.java?rev=670997&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/BuiltFileResource.java (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/BuiltFileResource.java Mon Jun 23 19:44:04 2008
@@ -0,0 +1,85 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ivy.plugins.resolver.packager;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.ivy.core.IvyPatternHelper;
+import org.apache.ivy.core.module.descriptor.Artifact;
+import org.apache.ivy.plugins.repository.Resource;
+
+/**
+ * Represents an artifact built by a {@link PackagerResolver}.
+ */
+public class BuiltFileResource implements Resource {
+
+    /**
+     * Where the build file should put built artifacts (relative
+     * to the build directory). Value is: {@value}
+     */
+    public static final String BUILT_ARTIFACT_PATTERN = "artifacts/[type]s/[artifact].[ext]";
+
+    private final File file;
+
+    public BuiltFileResource(File file) {
+        this.file = file;
+    }
+
+    public BuiltFileResource(File dir, Artifact artifact) {
+        this(new File(dir, IvyPatternHelper.substitute(BUILT_ARTIFACT_PATTERN, artifact)));
+    }
+
+    public String getName() {
+        return file.toURI().toString();
+    }
+
+    public Resource clone(String name) {
+        return new BuiltFileResource(new File(name));
+    }
+
+    public long getLastModified() {
+        return file.lastModified();
+    }
+
+    public long getContentLength() {
+        return file.length();
+    }
+
+    public boolean exists() {
+        return file.exists();
+    }
+
+    public String toString() {
+        return getName();
+    }
+
+    public File getFile() {
+        return file;
+    }
+
+    public boolean isLocal() {
+        return false;
+    }
+
+    public InputStream openStream() throws IOException {
+        return new FileInputStream(file);
+    }
+}

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/BuiltFileResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/BuiltFileResource.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerCacheEntry.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerCacheEntry.java?rev=670997&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerCacheEntry.java (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerCacheEntry.java Mon Jun 23 19:44:04 2008
@@ -0,0 +1,212 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ivy.plugins.resolver.packager;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+import org.apache.ivy.core.IvyPatternHelper;
+import org.apache.ivy.core.module.descriptor.Artifact;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.plugins.resolver.util.ResolvedResource;
+
+/**
+ * Represents one entry in the cache of a {@link PackagerResolver}.
+ */
+public class PackagerCacheEntry {
+
+    private final ModuleRevisionId mr;
+    private final File dir;
+    private final File resourceCache;
+    private final String resourceURL;
+    private final boolean validate;
+    private final boolean preserve;
+    private final boolean verbose;
+    private final boolean quiet;
+
+    private boolean built;
+
+    // CheckStyle:ParameterNumber OFF
+    public PackagerCacheEntry(ModuleRevisionId mr, File rootDir,
+      File resourceCache, String resourceURL, boolean validate,
+      boolean preserve, boolean verbose, boolean quiet) {
+        this.mr = mr;
+        this.dir = getSubdir(rootDir, this.mr);
+        this.resourceCache = resourceCache;
+        this.resourceURL = resourceURL;
+        this.validate = validate;
+        this.preserve = preserve;
+        this.verbose = verbose;
+        this.quiet = quiet;
+    }
+    // CheckStyle:ParameterNumber ON
+
+    /**
+     * Attempt to build this entry.
+     *
+     * @param packagerXML packager XML input stream
+     * @throws IllegalStateException if this entry has already been built
+     */
+    public synchronized void build(InputStream packagerXML) throws IOException {
+
+        // Sanity check
+        if (this.built) {
+            throw new IllegalStateException("build in directory `"
+              + this.dir + "' already completed");
+        }
+
+        // Remove work directory if it exists (e.g. left over from last time)
+        if (this.dir.exists()) {
+            if (!cleanup()) {
+                throw new IOException("can't remove directory `" + this.dir + "'");
+            }
+        }
+
+        // Create work directory
+        if (!this.dir.mkdirs()) {
+            throw new IOException("can't create directory `" + this.dir + "'");
+        }
+
+        // Write out packager XML
+        saveFile("packager.xml", packagerXML);
+
+        // Write packager XSLT
+        saveFile("packager.xsl");
+
+        // Write packager XSD
+        saveFile("packager-1.0.xsd");
+
+        // Write master ant build file
+        saveFile("build.xml");
+
+        // Create new process argument list
+        ArrayList paramList = new ArrayList();
+        paramList.add("ant");
+        if (this.verbose) {
+            paramList.add("-verbose");
+        }
+        if (this.quiet) {
+            paramList.add("-quiet");
+        }
+        paramList.add("-Divy.packager.organisation=" + this.mr.getModuleId().getOrganisation());
+        paramList.add("-Divy.packager.module=" + this.mr.getModuleId().getName());
+        paramList.add("-Divy.packager.revision=" + this.mr.getRevision());
+        paramList.add("-Divy.packager.branch=" + this.mr.getBranch());
+        if (this.resourceCache != null) {
+            paramList.add("-Divy.packager.resourceCache=" + this.resourceCache.getCanonicalPath());
+        }
+        if (this.resourceURL != null) {
+            paramList.add("-Divy.packager.resourceURL=" + getResourceURL());
+        }
+        if (this.validate) {
+            paramList.add("-Divy.packager.validate=true");
+        }
+        String[] params = (String[]) paramList.toArray(new String[paramList.size()]);
+
+        // Run ant
+        SubProcess proc = new SubProcess(params, null, this.dir);
+        int result;
+        try {
+            result = proc.run();
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+        if (result != 0) {
+            throw new IOException("build in directory `" + this.dir + "' failed");
+        }
+        this.built = true;
+    }
+
+    /**
+     * Has this entry been successfully built?
+     */
+    public synchronized boolean isBuilt() {
+        return this.built;
+    }
+
+    /**
+     * Get a built artifact.
+     *
+     * @throws IllegalStateException if this entry's built has not
+     *  (yet) completed successfully
+     */
+    public ResolvedResource getBuiltArtifact(Artifact artifact) {
+        if (!this.built) {
+            throw new IllegalStateException("build in directory `" + this.dir
+              + "' has not yet successfully completed");
+        }
+        return new ResolvedResource(
+          new BuiltFileResource(this.dir, artifact), this.mr.getRevision());
+    }
+
+    public synchronized boolean cleanup() {
+        this.built = false;
+        return PackagerResolver.deleteRecursive(this.dir);
+    }
+
+    protected void saveFile(String name, InputStream input) throws IOException {
+        OutputStream out = new BufferedOutputStream(
+          new FileOutputStream(new File(this.dir, name)));
+        SubProcess.relayStream(input, out);
+        input.close();
+        out.close();
+    }
+
+    protected void saveFile(String name) throws IOException {
+        InputStream input = getClass().getResourceAsStream(name);
+        if (input == null) {
+            throw new IOException("can't find resource `" + name + "'");
+        }
+        saveFile(name, input);
+    }
+
+    // @Override
+    protected void finalize() throws Throwable {
+        try {
+            if (!this.preserve) {
+                cleanup();
+            }
+        } finally {
+            super.finalize();
+        }
+    }
+
+    private String getResourceURL() {
+        String baseURL = IvyPatternHelper.substitute(this.resourceURL, this.mr.getOrganisation(),
+          this.mr.getName(), this.mr.getRevision(), null, null, null, null,
+          this.mr.getAttributes());
+        int slash = baseURL.lastIndexOf('/');
+        if (slash != -1) {
+            baseURL = baseURL.substring(0, slash + 1);
+        }
+        return baseURL;
+    }
+
+    private static File getSubdir(File rootDir, ModuleRevisionId mr) {
+        return new File(rootDir,
+          mr.getOrganisation() + File.separatorChar
+          + mr.getName() + File.separatorChar
+          + mr.getRevision());
+    }
+}
+

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerCacheEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerCacheEntry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerResolver.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerResolver.java?rev=670997&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerResolver.java (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerResolver.java Mon Jun 23 19:44:04 2008
@@ -0,0 +1,222 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ivy.plugins.resolver.packager;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.ivy.core.module.descriptor.Artifact;
+import org.apache.ivy.core.module.descriptor.DefaultArtifact;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.plugins.resolver.URLResolver;
+import org.apache.ivy.plugins.resolver.util.ResolvedResource;
+import org.apache.ivy.util.Message;
+
+/**
+ * Resolver that performs a "build" operation to resolve artifacts.
+ *
+ * <p>
+ * The resolver is configured with a base URL, from which the "ivy.xml"
+ * and "packager.xml" files are resolved. The latter file contains
+ * instructions describing how to build the actual artifacts.
+ */
+public class PackagerResolver extends URLResolver {
+
+    private static final String PACKAGER_ARTIFACT_NAME = "packager";
+    private static final String PACKAGER_ARTIFACT_TYPE = "packager";
+    private static final String PACKAGER_ARTIFACT_EXT = "xml";
+
+    private final HashMap/*<ModuleRevisionId, PackagerCacheEntry>*/ packagerCache = new HashMap();
+
+    private File buildRoot;
+    private File resourceCache;
+    private String resourceURL;
+    private boolean validate = true;
+    private boolean preserve;
+    private boolean verbose;
+    private boolean quiet;
+
+    public PackagerResolver() {
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            public void run() {
+                clearCache();
+            }
+        });
+    }
+
+    protected synchronized void clearCache() {
+        if (this.preserve) {
+            return;
+        }
+        for (Iterator i = packagerCache.values().iterator(); i.hasNext();) {
+            PackagerCacheEntry entry = (PackagerCacheEntry) i.next();
+            entry.cleanup();
+        }
+        packagerCache.clear();
+        if (this.buildRoot != null) {
+            deleteRecursive(this.buildRoot);
+        }
+    }
+
+    /**
+     * Set root directory under which builds take place.
+     */
+    public void setBuildRoot(String buildRoot) {
+        this.buildRoot = new File(buildRoot);
+    }
+
+    /**
+     * Set resource cache directory.
+     */
+    public void setResourceCache(String resourceCache) {
+        this.resourceCache = resourceCache != null ? new File(resourceCache) : null;
+    }
+
+    /**
+     * Set base resource override URL pattern.
+     */
+    public void setResourceURL(String resourceURL) {
+        this.resourceURL = resourceURL;
+    }
+
+    /**
+     * Set pattern for locating "packager.xml" files.
+     */
+    public void setPackagerPattern(String pattern) {
+        ArrayList list = new ArrayList();
+        list.add(pattern);
+        setArtifactPatterns(list);
+    }
+
+    /**
+     * Set whether to preserve build directories. Default is false.
+     */
+    public void setPreserveBuildDirectories(boolean preserve) {
+        this.preserve = preserve;
+    }
+
+    /**
+     * Set whether to run ant with the -verbose flag. Default is false.
+     */
+    public void setVerbose(boolean verbose) {
+        this.verbose = verbose;
+    }
+
+    /**
+     * Set whether to run ant with the -quiet flag. Default is false.
+     */
+    public void setQuiet(boolean quiet) {
+        this.quiet = quiet;
+    }
+
+    /**
+     * Set whether to validate downloaded packager.xml files. Default is true.
+     */
+    public void setValidate(boolean validate) {
+        this.validate = validate;
+    }
+
+    public void setAllownomd(boolean b) {
+        Message.error("allownomd not supported by resolver " + this);
+    }
+    public void setDescriptor(String rule) {
+        if (DESCRIPTOR_OPTIONAL.equals(rule)) {
+            Message.error("descriptor=\"" + DESCRIPTOR_OPTIONAL
+              + "\" not supported by resolver " + this);
+            return;
+        }
+        super.setDescriptor(rule);
+    }
+
+    // @Override
+    public void validate() {
+        super.validate();
+        if (this.buildRoot == null) {
+            throw new IllegalStateException("no buildRoot specified");
+        }
+        if (getArtifactPatterns().size() == 0) {
+            throw new IllegalStateException("no packager pattern specified");
+        }
+    }
+
+    // @Override
+    protected synchronized ResolvedResource findArtifactRef(Artifact artifact, Date date) {
+
+        // For our special packager.xml file, defer to superclass
+        if (PACKAGER_ARTIFACT_NAME.equals(artifact.getName())
+          && PACKAGER_ARTIFACT_TYPE.equals(artifact.getType())
+          && PACKAGER_ARTIFACT_EXT.equals(artifact.getExt())) {
+            return super.findArtifactRef(artifact, date);
+        }
+
+        // Check the cache
+        ModuleRevisionId mr = artifact.getModuleRevisionId();
+        PackagerCacheEntry entry = (PackagerCacheEntry) packagerCache.get(mr);
+
+        // Ignore invalid entries
+        if (entry != null && !entry.isBuilt()) {
+            packagerCache.remove(mr);
+            entry.cleanup();
+            entry = null;
+        }
+
+        // Build the artifacts (if not done already)
+        if (entry == null) {
+            ResolvedResource packager = findArtifactRef(new DefaultArtifact(mr, null,
+              PACKAGER_ARTIFACT_NAME, PACKAGER_ARTIFACT_TYPE, PACKAGER_ARTIFACT_EXT), date);
+            if (packager == null) {
+                return null;
+            }
+            entry = new PackagerCacheEntry(mr, this.buildRoot, this.resourceCache,
+              this.resourceURL, this.validate, this.preserve, this.verbose, this.quiet);
+            try {
+                entry.build(packager.getResource().openStream());
+            } catch (IOException e) {
+                throw new RuntimeException("can't build artifact " + artifact, e);
+            }
+            packagerCache.put(mr, entry);
+        }
+
+        // Return reference to desired artifact
+        return entry.getBuiltArtifact(artifact);
+    }
+
+    public String getTypeName() {
+        return "packager";
+    }
+
+    public static boolean deleteRecursive(File file) {
+        if (!file.exists()) {
+            return true;
+        }
+        if (file.isDirectory()) {
+            File[] files = file.listFiles();
+            for (int i = 0; i < files.length; i++) {
+                if (!deleteRecursive(files[i])) {
+                    return false;
+                }
+            }
+        }
+        return file.delete();
+    }
+}
+

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/PackagerResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/SubProcess.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/SubProcess.java?rev=670997&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/SubProcess.java (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/SubProcess.java Mon Jun 23 19:44:04 2008
@@ -0,0 +1,106 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ivy.plugins.resolver.packager;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Simple utility class for executing subprocesses. Handles I/O streams
+ * by closing standard input and relaying standard output and error.
+ */
+public class SubProcess {
+
+    private static final int BUFSIZE = 1024;
+
+    private final String[] cmd;
+    private final String[] env;
+    private final File dir;
+
+    /**
+     * Constructor.
+     *
+     * @param cmd command parameters
+     * @param env command environment
+     * @param dir command working directory
+     * @see Runtime.exec(String[], String[], File)
+     */
+    public SubProcess(String[] cmd, String[] env, File dir) {
+        this.cmd = cmd;
+        this.env = env;
+        this.dir = dir;
+    }
+
+    /**
+     * Execute the process and wait for it to complete.
+     *
+     * @return exit value from process
+     */
+    public int run() throws IOException, InterruptedException {
+        Process proc = Runtime.getRuntime().exec(this.cmd, this.env, this.dir);
+        proc.getOutputStream().close();
+        Thread relay1 = startRelay(proc.getInputStream(), System.out);
+        Thread relay2 = startRelay(proc.getErrorStream(), System.err);
+        int result;
+        relay1.join();
+        relay2.join();
+        return proc.waitFor();
+    }
+
+    /**
+     * Create and start a separate thread that copies input to output and closes
+     * the input when done.
+     *
+     * @param in input stream to read from
+     * @param out output stream to copy to
+     * @return thread doing the work
+     */
+    public static Thread startRelay(final InputStream in, final OutputStream out) {
+        Thread thread = new Thread() {
+            public void run() {
+                try {
+                    relayStream(in, out);
+                    in.close();
+                } catch (IOException e) {
+                    return;
+                }
+            }
+        };
+        thread.setDaemon(true);
+        thread.start();
+        return thread;
+    }
+
+    /**
+     * Copy from input to output. Does not close either stream when finished.
+     *
+     * @param in input stream to read from
+     * @param out output stream to copy to
+     */
+    public static void relayStream(InputStream in, OutputStream out) throws IOException {
+        byte[] buf = new byte[BUFSIZE];
+        int r;
+        while ((r = in.read(buf)) != -1) {
+            out.write(buf, 0, r);
+        }
+        out.flush();
+    }
+}
+

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/SubProcess.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/SubProcess.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/build.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/build.xml?rev=670997&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/build.xml (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/build.xml Mon Jun 23 19:44:04 2008
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+    Licensed under the Apache License, Version 2.0 (the "License"); you may
+    not use this file except in compliance with the License. You may obtain
+    a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+    License for the specific language governing permissions and limitations
+    under the License.
+-->
+
+<!-- $Id$ -->
+<project name="packager" default="build">
+
+    <!-- Validate packager.xml -->
+    <target name="validate" if="ivy.packager.validate">
+        <xmlvalidate failonerror="true" warn="yes" lenient="no">
+            <attribute name="http://xml.org/sax/features/namespaces" value="true"/>
+            <attribute name="http://apache.org/xml/features/validation/schema" value="true"/>
+            <attribute name="http://apache.org/xml/features/validation/schema-full-checking" value="true"/>
+            <property name="http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation" value="packager-1.0.xsd"/>
+            <fileset dir=".">
+                <include name="packager.xml"/>
+            </fileset>
+        </xmlvalidate>
+    </target>
+
+    <!-- Set ${resourceURL} (case 1) -->
+    <target name="setResourceURL1" if="ivy.packager.resourceURL">
+        <property name="resourceURL" value="${ivy.packager.resourceURL}"/>
+    </target>
+
+    <!-- Set ${resourceURL} (case 2) -->
+    <target name="setResourceURL2" unless="ivy.packager.resourceURL">
+        <property name="resourceURL" value=""/>
+    </target>
+
+    <!-- Apply XSLT to generate ant build file -->
+    <target name="style">
+        <xslt style="packager.xsl" in="packager.xml" out="packager-output.xml">
+            <param name="resourceURL" expression="${resourceURL}"/>
+        </xslt>
+    </target>
+
+    <!-- Main build target: invoke generated build file -->
+    <target name="build" depends="validate, setResourceURL1, setResourceURL2, style">
+        <ant antfile="packager-output.xml"/>
+    </target>
+
+</project>

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/build.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/build.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager-1.0.xsd
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager-1.0.xsd?rev=670997&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager-1.0.xsd (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager-1.0.xsd Mon Jun 23 19:44:04 2008
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+    Licensed under the Apache License, Version 2.0 (the "License"); you may
+    not use this file except in compliance with the License. You may obtain
+    a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+    License for the specific language governing permissions and limitations
+    under the License.
+-->
+
+<!-- $Id$ -->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+    <xsd:element name="packager-module">
+        <xsd:complexType>
+            <xsd:sequence>
+                <xsd:choice maxOccurs="unbounded">
+                    <xsd:element name="property">
+                        <xsd:complexType>
+                            <xsd:attribute name="name" type="xsd:string" use="required"/>
+                            <xsd:attribute name="value" type="xsd:string" use="required"/>
+                        </xsd:complexType>
+                    </xsd:element>
+                    <xsd:element name="resource">
+                        <xsd:complexType>
+                            <xsd:sequence minOccurs="0" maxOccurs="unbounded">
+                                <xsd:any processContents="lax"/>    <!-- XXX refine me -->
+                            </xsd:sequence>
+                            <xsd:attribute name="url" type="xsd:anyURI" use="required"/>
+                            <xsd:attribute name="sha1" type="sha1Type" use="required"/>
+                            <xsd:attribute name="dest" type="xsd:string"/>
+                            <xsd:attribute name="tofile" type="xsd:string"/>
+                            <xsd:attribute name="type" type="archiveType"/>
+                            <xsd:attribute name="filename" type="xsd:string"/>
+                        </xsd:complexType>
+                    </xsd:element>
+                    <xsd:element name="m2resource">
+                        <xsd:complexType>
+                            <xsd:sequence minOccurs="0" maxOccurs="unbounded">
+                                <xsd:element name="artifact">
+                                    <xsd:complexType>
+                                        <xsd:attribute name="ext" type="xsd:string"/>
+                                        <xsd:attribute name="classifier" type="xsd:string"/>
+                                        <xsd:attribute name="sha1" type="sha1Type" use="required"/>
+                                        <xsd:attribute name="dest" type="xsd:string"/>
+                                        <xsd:attribute name="tofile" type="xsd:string"/>
+                                        <xsd:attribute name="type" type="archiveType"/>
+                                    </xsd:complexType>
+                                </xsd:element>
+                            </xsd:sequence>
+                            <xsd:attribute name="groupId" type="xsd:string"/>
+                            <xsd:attribute name="artifactId" type="xsd:string"/>
+                            <xsd:attribute name="version" type="xsd:string"/>
+                            <xsd:attribute name="repo" type="xsd:anyURI"/>
+                        </xsd:complexType>
+                    </xsd:element>
+                    <xsd:element name="build">
+                        <xsd:complexType>
+                            <xsd:sequence minOccurs="0" maxOccurs="unbounded">
+                                <xsd:any processContents="lax"/>    <!-- XXX refine me -->
+                            </xsd:sequence>
+                        </xsd:complexType>
+                    </xsd:element>
+                </xsd:choice>
+            </xsd:sequence>
+            <xsd:attribute name="version" type="versionType" use="required"/>
+        </xsd:complexType>
+    </xsd:element>
+
+    <xsd:simpleType name="sha1Type">
+        <xsd:restriction base="xsd:string">
+            <xsd:pattern value="[0-9a-f]{40}"/>
+        </xsd:restriction>
+    </xsd:simpleType>
+
+    <xsd:simpleType name="versionType">
+        <xsd:restriction base="xsd:string">
+            <xsd:enumeration value="1.0"/>
+        </xsd:restriction>
+    </xsd:simpleType>
+
+    <xsd:simpleType name="archiveType">
+        <xsd:restriction base="xsd:string">
+            <xsd:enumeration value="zip"/>
+            <xsd:enumeration value="war"/>
+            <xsd:enumeration value="jar"/>
+            <xsd:enumeration value="tar"/>
+            <xsd:enumeration value="tgz"/>
+            <xsd:enumeration value="tar.gz"/>
+            <xsd:enumeration value="tar.bz2"/>
+        </xsd:restriction>
+    </xsd:simpleType>
+
+</xsd:schema>

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager-1.0.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager-1.0.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager.xsl
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager.xsl?rev=670997&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager.xsl (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager.xsl Mon Jun 23 19:44:04 2008
@@ -0,0 +1,485 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+    Licensed under the Apache License, Version 2.0 (the "License"); you may
+    not use this file except in compliance with the License. You may obtain
+    a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+    License for the specific language governing permissions and limitations
+    under the License.
+-->
+
+<!-- $Id$ -->
+<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+
+    <xsl:output encoding="UTF-8" method="xml" indent="yes" media-type="text/xml"/>
+
+    <xsl:param name="resourceURL"/>
+
+    <xsl:variable name="maven2repo" select="'http://repo1.maven.org/maven2/'"/>
+
+    <xsl:template match="/packager-module">
+        <xsl:comment> GENERATED FILE - DO NOT EDIT </xsl:comment>
+        <xsl:comment> Generated by $Id$ </xsl:comment>
+        <project name="packager" default="build">
+            <xsl:apply-templates select="property"/>
+
+            <xsl:apply-templates select="resource | m2resource"/>
+
+            <!-- First, download and extract all resources -->
+            <target name="resources">
+                <xsl:attribute name="depends">
+                    <xsl:for-each select="resource | m2resource/artifact">
+                        <xsl:if test="position() &gt; 1">
+                            <xsl:value-of select="', '"/>
+                        </xsl:if>
+                        <xsl:value-of select="concat('resource.', generate-id())"/>
+                    </xsl:for-each>
+                </xsl:attribute>
+            </target>
+
+            <!-- Second, put all artifacts into place under artifacts/ -->
+            <target name="build" depends="resources">
+                <mkdir dir="artifacts/jars"/>
+                <mkdir dir="artifacts/sources"/>
+                <mkdir dir="artifacts/javadocs"/>
+                <!-- ...add some other common artifact types here... -->
+                <xsl:apply-templates select="build/*"/>
+            </target>
+        </project>
+    </xsl:template>
+
+    <!-- Properties -->
+    <xsl:template match="/packager-module/property">
+        <xsl:copy-of select="."/>
+    </xsl:template>
+
+    <!-- The allowed build actions -->
+    <xsl:template match="/packager-module/build/copy"><xsl:copy-of select="."/></xsl:template>
+    <xsl:template match="/packager-module/build/jar"><xsl:copy-of select="."/></xsl:template>
+    <xsl:template match="/packager-module/build/mkdir"><xsl:copy-of select="."/></xsl:template>
+    <xsl:template match="/packager-module/build/move"><xsl:copy-of select="."/></xsl:template>
+    <xsl:template match="/packager-module/build/tar"><xsl:copy-of select="."/></xsl:template>
+    <xsl:template match="/packager-module/build/unjar"><xsl:copy-of select="."/></xsl:template>
+    <xsl:template match="/packager-module/build/untar"><xsl:copy-of select="."/></xsl:template>
+    <xsl:template match="/packager-module/build/unwar"><xsl:copy-of select="."/></xsl:template>
+    <xsl:template match="/packager-module/build/unzip"><xsl:copy-of select="."/></xsl:template>
+    <xsl:template match="/packager-module/build/war"><xsl:copy-of select="."/></xsl:template>
+    <xsl:template match="/packager-module/build/zip"><xsl:copy-of select="."/></xsl:template>
+
+    <!-- Resource definitions -->
+    <xsl:template match="/packager-module/resource">
+
+        <!-- Convert URL into simple filename -->
+        <target name="setfilename.{generate-id()}">
+            <xsl:choose>
+                <xsl:when test="@filename">
+                    <property name="filename.{generate-id()}" value="{@filename}"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <basename property="filename.{generate-id()}" file="{@url}"/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </target>
+
+        <!-- Generate list of URLs to try -->
+        <xsl:variable name="urls">
+            <xsl:call-template name="concat">
+                <xsl:with-param name="nodes" select="@url | url/@href"/>
+            </xsl:call-template>
+        </xsl:variable>
+
+        <!-- Get resource -->
+        <xsl:call-template name="resource">
+            <xsl:with-param name="urls" select="$urls"/>
+            <xsl:with-param name="type" select="@type"/>
+            <xsl:with-param name="csum" select="@sha1"/>
+            <xsl:with-param name="dest" select="@dest"/>
+            <xsl:with-param name="tofile" select="@tofile"/>
+            <xsl:with-param name="filename" select="concat('${filename.', generate-id(), '}')"/>
+            <xsl:with-param name="depends" select="concat('setfilename.', generate-id())"/>
+        </xsl:call-template>
+    </xsl:template>
+
+    <!-- Maven2 resources -->
+    <xsl:template match="/packager-module/m2resource">
+
+        <!-- Convert groupId into URL directories, where dots become slashes -->
+        <xsl:variable name="groupdirs" select="concat('groupdirs.', generate-id())"/>
+        <target name="setgroupdirs.{generate-id()}">
+            <xsl:variable name="groupId">
+                <xsl:choose>
+                    <xsl:when test="@groupId">
+                        <xsl:value-of select="@groupId"/>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:value-of select="'${ivy.packager.organisation}'"/>
+                    </xsl:otherwise>
+                </xsl:choose>
+            </xsl:variable>
+            <pathconvert property="{$groupdirs}" dirsep="/">
+                <path location="{$groupId}"/>
+                <mapper type="unpackage" to="*">
+                    <xsl:attribute name="from">
+                        <xsl:value-of select="'${basedir}/*'"/>
+                    </xsl:attribute>
+                </mapper>
+            </pathconvert>
+        </target>
+
+        <!-- Get maven2 artifactId (or use default) -->
+        <xsl:variable name="artifactId">
+            <xsl:choose>
+                <xsl:when test="@artifactId">
+                    <xsl:value-of select="@artifactId"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:value-of select="'${ivy.packager.module}'"/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
+
+        <!-- Get maven2 version (or use default) -->
+        <xsl:variable name="version">
+            <xsl:choose>
+                <xsl:when test="@version">
+                    <xsl:value-of select="@version"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:value-of select="'${ivy.packager.revision}'"/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
+
+        <!-- Get maven2 repository URL (or use default) -->
+        <xsl:variable name="repourl">
+            <xsl:choose>
+                <xsl:when test="@repo and substring(@repo, string-length(@repo) - 1) = '/'">
+                    <xsl:value-of select="@repo"/>
+                </xsl:when>
+                <xsl:when test="@repo">
+                    <xsl:value-of select="concat(@repo, '/')"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:value-of select="$maven2repo"/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
+
+        <!-- Compose directory in the maven2 repository -->
+        <xsl:variable name="m2dir" select="concat($repourl, '${', $groupdirs, '}/', $artifactId, '/', $version, '/')"/>
+
+        <!-- Iterate over artifacts -->
+        <xsl:for-each select="artifact">
+
+            <!-- Get classifier (or use default) -->
+            <xsl:variable name="classifier">
+                <xsl:choose>
+                    <xsl:when test="@classifier">
+                        <xsl:value-of select="concat('-', @classifier)"/>
+                    </xsl:when>
+                    <xsl:otherwise/>
+                </xsl:choose>
+            </xsl:variable>
+
+            <!-- Get classifier (or use default) -->
+            <xsl:variable name="suffix">
+                <xsl:choose>
+                    <xsl:when test="@ext">
+                        <xsl:value-of select="concat('.', @ext)"/>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:value-of select="'.jar'"/>
+                    </xsl:otherwise>
+                </xsl:choose>
+            </xsl:variable>
+
+            <!-- Compose to get filename, then complete URL -->
+            <xsl:variable name="filename" select="concat($artifactId, '-', $version, $classifier, $suffix)"/>
+            <xsl:variable name="url" select="concat($m2dir, $filename)"/>
+
+            <!-- Get resource -->
+            <xsl:call-template name="resource">
+                <xsl:with-param name="urls" select="$url"/>
+                <xsl:with-param name="csum" select="@sha1"/>
+                <xsl:with-param name="dest" select="@dest"/>
+                <xsl:with-param name="tofile" select="@tofile"/>
+                <xsl:with-param name="type" select="@type"/>
+                <xsl:with-param name="filename" select="$filename"/>
+                <xsl:with-param name="depends" select="concat('setgroupdirs.', generate-id(..))"/>
+            </xsl:call-template>
+        </xsl:for-each>
+    </xsl:template>
+
+    <!-- Download and optionally unpack a resource -->
+    <xsl:template name="resource">
+        <xsl:param name="urls"/>
+        <xsl:param name="type"/>
+        <xsl:param name="csum"/>
+        <xsl:param name="dest"/>
+        <xsl:param name="tofile"/>
+        <xsl:param name="filename"/>
+        <xsl:param name="depends"/>
+
+        <!-- Figure out which directory to download into (at runtime) -->
+        <target name="genresdir.1.{generate-id()}" unless="ivy.packager.resourceCache">
+            <property name="resdir.{generate-id()}" value="tempdir.{generate-id()}"/>
+        </target>
+        <target name="genresdir.2.{generate-id()}" if="ivy.packager.resourceCache">
+            <property name="resdir.{generate-id()}">
+                <xsl:attribute name="value">${ivy.packager.resourceCache}</xsl:attribute>
+            </property>
+            <echo level="info">
+                <xsl:attribute name="message">using resource cache: ${ivy.packager.resourceCache}</xsl:attribute>
+            </echo>
+        </target>
+        <xsl:variable name="resdir" select="concat('${resdir.', generate-id(), '}')"/>
+        <xsl:variable name="downloadfile" select="concat($resdir, '${file.separator}', $filename)"/>
+
+        <!-- Create directory for the downloaded resource -->
+        <target name="checkdownload.0.{generate-id()}" depends="{$depends}, genresdir.1.{generate-id()}, genresdir.2.{generate-id()}">
+            <mkdir dir="{$resdir}"/>
+            <condition property="alreadydownloaded.{generate-id()}">
+                <and>
+                    <available file="{$downloadfile}"/>
+                    <checksum file="{$downloadfile}" algorithm="SHA" property="{$csum}"/>
+                </and>
+            </condition>
+        </target>
+
+        <!-- Prepend URL list with resourceURL if configured -->
+        <xsl:variable name="urls2">
+            <xsl:choose>
+                <xsl:when test="$resourceURL">
+                    <xsl:value-of select="concat($resourceURL, $filename, ' ', $urls)"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:value-of select="$urls"/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
+
+        <!-- Try to download each of the URLs in order -->
+        <xsl:call-template name="downloads">
+            <xsl:with-param name="urls" select="$urls2"/>
+            <xsl:with-param name="filename" select="$filename"/>
+            <xsl:with-param name="destfile" select="$downloadfile"/>
+            <xsl:with-param name="csum" select="$csum"/>
+        </xsl:call-template>
+
+        <!-- Unpack or just copy the file to its destination -->
+        <target name="resource.{generate-id()}" depends="download.{generate-id()}">
+            <xsl:choose>
+                <xsl:when test="$tofile">
+                    <copy file="{$downloadfile}" tofile="{$tofile}"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:variable name="realdest">
+                        <xsl:choose>
+                            <xsl:when test="$dest">
+                                <xsl:value-of select="$dest"/>
+                            </xsl:when>
+                            <xsl:otherwise>archive</xsl:otherwise>
+                        </xsl:choose>
+                    </xsl:variable>
+                    <xsl:choose>
+                        <xsl:when test="$type = 'none'">
+                            <copy file="{$downloadfile}" todir="{$realdest}"/>
+                        </xsl:when>
+                        <xsl:otherwise>
+                            <xsl:variable name="actualtype">
+                                <xsl:choose>
+                                    <xsl:when test="$type">
+                                        <xsl:value-of select="$type"/>
+                                    </xsl:when>
+                                    <xsl:when test="@filename">
+                                        <xsl:call-template name="archiveType">
+                                            <xsl:with-param name="file" select="@filename"/>
+                                        </xsl:call-template>
+                                    </xsl:when>
+                                    <xsl:otherwise>
+                                        <xsl:call-template name="archiveType">
+                                            <xsl:with-param name="file" select="$urls"/>
+                                        </xsl:call-template>
+                                    </xsl:otherwise>
+                                </xsl:choose>
+                            </xsl:variable>
+                            <xsl:call-template name="unpack">
+                                <xsl:with-param name="file" select="$downloadfile"/>
+                                <xsl:with-param name="dir" select="$realdest"/>
+                                <xsl:with-param name="type" select="$actualtype"/>
+                            </xsl:call-template>
+                        </xsl:otherwise>
+                    </xsl:choose>
+                </xsl:otherwise>
+            </xsl:choose>
+        </target>
+    </xsl:template>
+
+    <!-- Download resource, trying one or more URLs in order -->
+    <xsl:template name="downloads">
+        <xsl:param name="urls"/>
+        <xsl:param name="filename"/>
+        <xsl:param name="destfile"/>
+        <xsl:param name="csum"/>
+        <xsl:param name="index" select="1"/>
+
+        <!-- Parse out first URL from whitespace-separated list -->
+        <xsl:variable name="nurls" select="normalize-space($urls)"/>
+        <xsl:variable name="isFirstURL" select="$index = 1"/>
+        <xsl:variable name="isLastURL" select="not(contains($nurls, ' '))"/>
+        <xsl:variable name="url">
+            <xsl:choose>
+                <xsl:when test="not($isLastURL)">
+                    <xsl:value-of select="substring-before($nurls, ' ')"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:value-of select="$nurls"/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
+        <xsl:variable name="rurls" select="substring-after($nurls, ' ')"/>
+
+        <!-- Attempt download using this URL; allow download to fail if this is not the last URL -->
+        <target name="download.{$index}.{generate-id()}" depends="checkdownload.{$index - 1}.{generate-id()}"
+          unless="alreadydownloaded.{generate-id()}">
+            <get src="{$url}" dest="{$destfile}" verbose="true" ignoreerrors="{string(not($isLastURL))}"/>
+        </target>
+
+        <!-- Check whether download attempt was successful -->
+        <target name="checkdownload.{$index}.{generate-id()}" depends="download.{$index}.{generate-id()}"
+          unless="alreadydownloaded.{generate-id()}">
+            <condition property="alreadydownloaded.{generate-id()}">
+                <and>
+                    <available file="{$destfile}"/>
+                    <checksum file="{$destfile}" algorithm="SHA" property="{$csum}"/>
+                </and>
+            </condition>
+        </target>
+
+        <!-- Do final check after last attempt, or recurse -->
+        <xsl:choose>
+            <xsl:when test="$isLastURL">
+                <target name="download.{generate-id()}" depends="checkdownload.{$index}.{generate-id()}"
+                  unless="alreadydownloaded.{generate-id()}">
+                    <fail message="Unable to download {$filename} from any configured URL">
+                        <condition>
+                            <not>
+                                <available file="{$destfile}"/>
+                            </not>
+                        </condition>
+                    </fail>
+                    <fail message="SHA1 checksum verification for {$filename} failed!"/>
+                </target>
+            </xsl:when>
+            <xsl:otherwise>
+                <xsl:call-template name="downloads">
+                    <xsl:with-param name="urls" select="$rurls"/>
+                    <xsl:with-param name="filename" select="$filename"/>
+                    <xsl:with-param name="destfile" select="$destfile"/>
+                    <xsl:with-param name="csum" select="$csum"/>
+                    <xsl:with-param name="index" select="$index + 1"/>
+                </xsl:call-template>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <!-- Unpack an archive -->
+    <xsl:template name="unpack">
+        <xsl:param name="file"/>
+        <xsl:param name="dir"/>
+        <xsl:param name="type"/>
+
+        <!-- Get nested includes, excludes, etc. -->
+        <xsl:variable name="includes" select="*[name() != 'url']"/>
+
+        <!-- Unpack -->
+        <mkdir dir="{$dir}"/>
+        <xsl:choose>
+
+            <!-- ZIP type files -->
+            <xsl:when test="$type = 'zip' or $type = 'war' or $type = 'jar'">
+                <unzip src="{$file}" dest="{$dir}">
+                    <xsl:if test="$includes">
+                        <fileset dir=".">
+                            <xsl:copy-of select="$includes"/>
+                        </fileset>
+                    </xsl:if>
+                </unzip>
+            </xsl:when>
+
+            <!-- TAR files, optionally compressed -->
+            <xsl:when test="starts-with($type, 'tar')">
+                <untar src="{$file}" dest="{$dir}">
+                    <xsl:choose>
+                        <xsl:when test="$type = 'tar.gz'">
+                            <xsl:attribute name="compression">gzip</xsl:attribute>
+                        </xsl:when>
+                        <xsl:when test="$type = 'tar.bz2'">
+                            <xsl:attribute name="compression">bzip2</xsl:attribute>
+                        </xsl:when>
+                    </xsl:choose>
+                    <xsl:if test="$includes">
+                        <fileset dir=".">
+                            <xsl:copy-of select="$includes"/>
+                        </fileset>
+                    </xsl:if>
+                </untar>
+            </xsl:when>
+            <xsl:otherwise>
+                <xsl:message terminate="yes">
+                    <xsl:value-of select="concat('ERROR: unknown archive type &quot;', $type, '&quot;&#10;')"/>
+                    <xsl:value-of select="'Please set the &quot;type&quot; attribute to one of: zip, tar, tar.gz, or tar.bz2.&#10;'"/>
+                </xsl:message>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <!-- Determine type of archive automatically based on filename -->
+    <xsl:template name="archiveType">
+        <xsl:param name="file"/>
+        <xsl:choose>
+            <xsl:when test="substring($file, string-length($file) - 3) = '.jar'">jar</xsl:when>
+            <xsl:when test="substring($file, string-length($file) - 3) = '.war'">war</xsl:when>
+            <xsl:when test="substring($file, string-length($file) - 3) = '.zip'">zip</xsl:when>
+            <xsl:when test="substring($file, string-length($file) - 3) = '.tar'">tar</xsl:when>
+            <xsl:when test="substring($file, string-length($file) - 3) = '.tgz'">tar.gz</xsl:when>
+            <xsl:when test="substring($file, string-length($file) - 6) = '.tar.gz'">tar.gz</xsl:when>
+            <xsl:when test="substring($file, string-length($file) - 7) = '.tar.bz2'">tar.bz2</xsl:when>
+            <xsl:otherwise>
+                <xsl:message terminate="yes">
+                    <xsl:value-of select="concat('ERROR: cannot determine type of archive: ', $file, '&#10;')"/>
+                    <xsl:value-of select="'Please set the &quot;type&quot; attribute to one of: zip, tar, tar.gz, or tar.bz2.&#10;'"/>
+                </xsl:message>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <!-- Concatenate nodes separated by spaces -->
+    <xsl:template name="concat">
+        <xsl:param name="nodes"/>
+        <xsl:choose>
+            <xsl:when test="count($nodes) &lt;= 1">
+                <xsl:value-of select="string($nodes)"/>
+            </xsl:when>
+            <xsl:otherwise>
+                <xsl:value-of select="concat(string($nodes[1]), ' ')"/>
+                <xsl:call-template name="concat">
+                    <xsl:with-param name="nodes" select="$nodes[position() &gt; 1]"/>
+                </xsl:call-template>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <!-- Ignore anything unexpected -->
+    <xsl:template match="*">
+        <xsl:message terminate="no">ignoring unexpected XML node &lt;<xsl:value-of select="name()"/>&gt;</xsl:message>
+    </xsl:template>
+    <xsl:template match="@*|node()"/>
+
+</xsl:transform>

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager.xsl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/packager/packager.xsl
------------------------------------------------------------------------------
    svn:mime-type = text/plain