Author: hibou
Date: Wed Nov 3 18:12:20 2010
New Revision: 1030584
URL: http://svn.apache.org/viewvc?rev=1030584&view=rev
Log:
IVY-334:
- refactor the work done on ivy:resources so it becomes and post resolve task,
then it can be used like ivy:cachepath
- nice side effect: ivy:resolve and every post resolve tasks support now
"inlined ivy.xml dependencies"
Added:
ant/ivy/core/trunk/test/repositories/1/usecacheonly/mod3/
ant/ivy/core/trunk/test/repositories/1/usecacheonly/mod3/ivys/
ant/ivy/core/trunk/test/repositories/1/usecacheonly/mod3/ivys/ivy-1.0.xml
ant/ivy/core/trunk/test/repositories/1/usecacheonly/mod3/jars/
ant/ivy/core/trunk/test/repositories/1/usecacheonly/mod3/jars/mod3-1.0.jar
Modified:
ant/ivy/core/trunk/CHANGES.txt
ant/ivy/core/trunk/META-INF/MANIFEST.MF
ant/ivy/core/trunk/doc/use/postresolvetask.html
ant/ivy/core/trunk/doc/use/resolve.html
ant/ivy/core/trunk/doc/use/resources.html
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPostResolveTask.java
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyResolve.java
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyResources.java
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyResolveTest.java
ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
Modified: ant/ivy/core/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=1030584&r1=1030583&r2=1030584&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Wed Nov 3 18:12:20 2010
@@ -113,6 +113,9 @@ for detailed view of each issue, please
trunk
=====================================
+- NEW: New Ant datatype ivy:resources, an Ant resource collection like
ivy:cachepath or ivy:cachefileset (IVY-334)
+- NEW: ivy:resolve and post resole task can now have inlined dependencies
declaration.
+
- FIX: Can not use a v[revision] in an artifact pattern of a filesystem
resolver (IVY-1238)
- FIX: Cached ivy.xml is invalid if the description contains the ampersand
entity (&) (IVY-1237)
- FIX: Couldn't authenticate against sites having the same address as the
proxy server (IVY-1234)
Modified: ant/ivy/core/trunk/META-INF/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/META-INF/MANIFEST.MF?rev=1030584&r1=1030583&r2=1030584&view=diff
==============================================================================
--- ant/ivy/core/trunk/META-INF/MANIFEST.MF (original)
+++ ant/ivy/core/trunk/META-INF/MANIFEST.MF Wed Nov 3 18:12:20 2010
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
Main-Class: org.apache.ivy.Main
-Bundle-Version: 0.0.0
+Bundle-Version: 2.3.0
Bundle-Name: Ivy
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.apache.ivy
Modified: ant/ivy/core/trunk/doc/use/postresolvetask.html
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/use/postresolvetask.html?rev=1030584&r1=1030583&r2=1030584&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/use/postresolvetask.html (original)
+++ ant/ivy/core/trunk/doc/use/postresolvetask.html Wed Nov 3 18:12:20 2010
@@ -82,6 +82,29 @@ Available options are:
</ul></td><td>No, defaults to 'default'.</td></tr>
</tbody>
</table>
+
+<h1>Child elements</h1>
+
+<b><i>(Since 2.3)</i></b>
+
+These child elements are defining an inlined ivy.xml's <a
href="../ivyfile/dependencies.html">dependencies</a> elements. Thus these child
elements cannot be used together with the <i>inline</i> or <i>file</i>
attributes.
+There is one important difference with the ivy.xml's <a
href="../ivyfile/dependencies.html">dependencies</a>: there is no master
configuration to handle here. There is actually only one, the one on which the
resolve will run. So every attribute in <a
href="../ivyfile/dependency.html">dependency</a>, <a
href="../ivyfile/exclude.html">exclude</a>, <a
href="../ivyfile/override.html">override</a> or <a
href="../ivyfile/conflict.html">conflict</a> which is about a master
configuration is not supported. And every attribute about a mapping of a master
configuration on a dependency configuration is now expecting only the
dependency configuration.
+
+<table class="ant">
+<thead>
+ <tr><th class="ant-att">Element</th><th
class="ant-desc">Description</th><th class="ant-req">Cardinality</th></tr>
+</thead>
+<tbody>
+ <tr><td><a
href="../ivyfile/dependency.html">dependency</a></td><td>declares a dependency
to resolve</td>
+ <td>0..n</td></tr>
+ <tr><td><a href="../ivyfile/exclude.html">exclude</a></td><td>excludes
artifacts, modules or whole organizations from the set of dependencies to
resolve</td>
+ <td>0..n</td></tr>
+ <tr><td><a href="../ivyfile/override.html">override</a></td><td>specify an
override mediation rule, overriding the revision and/or branch requested for a
transitive dependency <span class="since">since 2.0</span></td>
+ <td>0..n</td></tr>
+ <tr><td><a href="../ivyfile/conflict.html">conflict</a></td><td>specify a
a conflict manager for one or several dependencies <span class="since">since
2.0</span></td>
+</tbody>
+</table>
+
<h1>Examples</h1>
<code type="xml">
<ivy:cachepath organisation="emma" module="emma" revision="2.0.4217"
inline="true" conf="ant" pathid="emma.classpath"/>
Modified: ant/ivy/core/trunk/doc/use/resolve.html
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/use/resolve.html?rev=1030584&r1=1030583&r2=1030584&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/use/resolve.html (original)
+++ ant/ivy/core/trunk/doc/use/resolve.html Wed Nov 3 18:12:20 2010
@@ -163,6 +163,29 @@ Available options are:
</tbody>
</table>
+
+<h1>Child elements</h1>
+
+<b><i>(Since 2.3)</i></b>
+
+These child elements are defining an inlined ivy.xml's <a
href="../ivyfile/dependencies.html">dependencies</a> elements. Thus these child
elements cannot be used together with the <i>inline</i> or <i>file</i>
attributes.
+There is one important difference with the ivy.xml's <a
href="../ivyfile/dependencies.html">dependencies</a>: there is no master
configuration to handle here. There is actually only one, the one on which the
resolve will run. So every attribute in <a
href="../ivyfile/dependency.html">dependency</a>, <a
href="../ivyfile/exclude.html">exclude</a>, <a
href="../ivyfile/override.html">override</a> or <a
href="../ivyfile/conflict.html">conflict</a> which is about a master
configuration is not supported. And every attribute about a mapping of a master
configuration on a dependency configuration is now expecting only the
dependency configuration.
+
+<table class="ant">
+<thead>
+ <tr><th class="ant-att">Element</th><th
class="ant-desc">Description</th><th class="ant-req">Cardinality</th></tr>
+</thead>
+<tbody>
+ <tr><td><a
href="../ivyfile/dependency.html">dependency</a></td><td>declares a dependency
to resolve</td>
+ <td>0..n</td></tr>
+ <tr><td><a href="../ivyfile/exclude.html">exclude</a></td><td>excludes
artifacts, modules or whole organizations from the set of dependencies to
resolve</td>
+ <td>0..n</td></tr>
+ <tr><td><a href="../ivyfile/override.html">override</a></td><td>specify an
override mediation rule, overriding the revision and/or branch requested for a
transitive dependency <span class="since">since 2.0</span></td>
+ <td>0..n</td></tr>
+ <tr><td><a href="../ivyfile/conflict.html">conflict</a></td><td>specify a
a conflict manager for one or several dependencies <span class="since">since
2.0</span></td>
+</tbody>
+</table>
+
<h1>Examples</h1>
<code type="xml">
<ivy:resolve file="path/to/ivy.xml"/>
@@ -196,6 +219,24 @@ Resolve all dependencies declared in pat
</code>
Resolve the commons-lang module revision 2+ from the repository, with its
dependencies.
+<hr/>
+<code type="xml">
+<ivy:resolve>
+ <dependency org="apache" module="commons-lang" rev="2+" />
+ <dependency org="apache" module="commons-logging" rev="1.1" />
+ <exclude org="apache" module="log4j" />
+</ivy:resolve>
+</code>
+Resolve of both commons lang and commons logging, with their dependencies but
not log4j.
+
+<hr/>
+<code type="xml">
+<ivy:resolve>
+ <dependency org="org.slf4j" module="slf4j" rev="1.6" conf="api,log4j" />
+</ivy:resolve>
+</code>
+Resolve the configurations "api" and "log4j" of "slf4j".
+
</textarea>
<script type="text/javascript">xooki.postProcess();</script>
</body>
Modified: ant/ivy/core/trunk/doc/use/resources.html
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/use/resources.html?rev=1030584&r1=1030583&r2=1030584&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/use/resources.html (original)
+++ ant/ivy/core/trunk/doc/use/resources.html Wed Nov 3 18:12:20 2010
@@ -24,84 +24,62 @@
</head>
<body>
<textarea id="xooki-source">
-<span class="since">(since 2.3)</span>
-<span class="since">(Ant 1.7 required)</span>
+<b><i>(since 2.3) (Ant 1.7 required)</i></b>
<tt>ivy:resources</tt> is an Ant <a
href="http://ant.apache.org/manual/Types/resources.html#collection">resource
collection</a>, which files are based on an Ivy resolve, and then can be used
with any task which is working with resources like <tt>copy</tt> or
<tt>import</tt>.
-This datatype is a sort of clone and merge of both the Ivy <a
hef="resolve.html">resolve task</a> and the <a
href="../ivyfile/dependencies.html">dependencies</a> element of an ivy.xml
file. So most of the attributes and xml elements are the same and have the same
semantic.
+This datatype share the same attributes, child elements and behaviour of a
[[ant:postresolvetask post resolve task]]. It is not expected to be used as an
Ant task though, only as a resource collection.
-There is one important difference: there is no master configuration to handle
here. There is actually only one, the one on which the resolve will run.
+<h1>Examples</h1>
+<code type="xml">
+<ivy:resources file="path/to/ivy.xml"/>
+</code>
+Build a resource collection of every artifacts of all dependencies declared in
path/to/ivy.xml file.
-<h1>Attributes</h1>
-<table class="ant">
-<thead>
- <tr><th class="ant-att">Attribute</th><th
class="ant-desc">Description</th><th class="ant-req">Required</th></tr>
-</thead>
-<tbody>
- <tr><td>refresh</td><td>true to force Ivy to resolve dynamic revision in
this resolve process, false to use cached resolved revision</td><td>No.
defaults to false</td></tr>
-
- <tr><td>resolveMode</td><td>the resolve mode to use for this dependency
resolution process</td><td>No. defaults to using the resolve mode set in the
[[settings settings]]</td></tr>
-
- <tr><td>changing</td><td>indicates that the module may change when
resolving in inline mode. See <a href="../concept.html#change">cache and change
management</a> for details. Ignored when resolving in standard
mode.</td><td>No. Defaults to false.</td></tr>
-
- <tr><td>type</td><td>comma separated list of accepted artifact
types</td><td>No. defaults to ${ivy.resolve.default.type.filter}</td></tr>
-
- <tr><td>transitive</td><td>true to resolve dependencies transitively,
false otherwise</td><td>No. Defaults to true</td></tr>
-
- <tr><td>showprogress</td><td>true to show dots while downloading, false
otherwise</td><td>No. Defaults to true</td></tr>
-
- <tr><td>validate</td><td>true to force ivy files validation against
ivy.xsd, false to force no validation</td><td>No. Defaults to default ivy value
(as configured in configuration file)</td></tr>
-
- <tr><td>settingsRef</td><td>A reference to the ivy settings that must be
used by this task</td><td>No, 'ivy.instance' is taken by default.</td></tr>
-
- <tr><td>resolveId</td><td>An id which can be used later to refer to the
results of this resolve</td><td>No, defaults to '[org]-[module]'.</td></tr>
-
- <tr><td>log</td><td>the log setting to use during the resolve process.<br/>
-Available options are:
-<ul><li>default</li> the default log settings, where all usual messages are
output to the console
-<li>download-only</li> disable all usual messages but download ones. A resolve
with everything in cache won't output any message.
-<li>quiet</li> disable all usual messages, making the whole resolve process
quiet unless errors occur
-</ul></td><td>No, defaults to 'default'.</td></tr>
-
- <tr><td>checkIfChanged</td><td>When set to true, the resolve will compare
the result with the last resolution done on this module, with those
configurations in order to define the property ivy.deps.changed. Put it to
false may provides slightly better performance.</td><td>No, default to
'true'</td></tr>
-</tbody>
-</table>
-
-<h1>Child elements</h1>
-<table class="ant">
-<thead>
- <tr><th class="ant-att">Element</th><th class="ant-desc">Element</th><th
class="ant-req">Element</th></tr>
-</thead>
-<tbody>
- <tr><td><a
href="../ivyfile/dependency.html">dependency</a></td><td>declares a dependency
to resolve</td>
- <td>0..n</td></tr>
- <tr><td><a href="../ivyfile/exclude.html">exclude</a></td><td>excludes
artifacts, modules or whole organizations from the set of dependencies to
resolve</td>
- <td>0..n</td></tr>
- <tr><td><a href="../ivyfile/override.html">override</a></td><td>specify an
override mediation rule, overriding the revision and/or branch requested for a
transitive dependency <span class="since">since 2.0</span></td>
- <td>0..n</td></tr>
- <tr><td><a href="../ivyfile/conflict.html">conflict</a></td><td>specify a
a conflict manager for one or several dependencies <span class="since">since
2.0</span></td>
-</tbody>
-</table>
+<hr/>
-<h1>Examples</h1>
-<h2>Simplest resolved resources</h2>
-<code><ivy:resources>
- <dependency org="org.apache.ivy" name="ivy" rev="2.2.0" />
-</ivy:resources>
+<code type="xml">
+<ivy:resources file="path/to/ivy.xml" transitive="false" />
</code>
-<h2>Specific resolved configuration</h2>
-<code><ivy:resources>
- <dependency org="org.apache.ant" name="ant" rev="1.8.0"
conf="core,launcher" />
- <dependency org="org.apache.ivy" name="ivy" rev="2.2.0" conf="runtime" />
+Same as above, but with transitive dependencies disabled.
+
+<hr/>
+
+<code type="xml">
+<ivy:resources file="path/to/ivy.xml" conf="default, test"/>
+</code>
+Build a resource collection of every artifacts of the dependencies declared in
the configuration default and test of the path/to/ivy.xml file.
+
+<hr/>
+
+<code type="xml">
+<ivy:resources file="path/to/ivy.xml" type="jar"/>
+</code>
+Build a resource collection of every jar artifact of all dependencies declared
in path/to/ivy.xml file.
+
+<hr/>
+<code type="xml">
+<ivy:resources organisation="apache" module="commons-lang" revision="2+"
inline="true" />
+</code>
+Build a resource collection of every artifacts of commons-lang module revision
2+ from the repository, with its dependencies.
+
+<hr/>
+<code type="xml">
+<ivy:resources>
+ <dependency org="apache" module="commons-lang" rev="2+" />
+ <dependency org="apache" module="commons-logging" rev="1.1" />
+ <exclude org="apache" module="log4j" />
</ivy:resources>
</code>
-<h2>Filtering to jars only and excluding a dependency</h2>
-<code><ivy:resources type="jar">
- <dependency org="org.apache.ant" name="ant" rev="1.8.0"
conf="core,launcher" />
- <dependency org="org.apache.ivy" name="ivy" rev="2.2.0" conf="runtime" />
- <exclude org="org.apache.commons" module="commons-loging" />
+Build a resource collection of every artifacts of both commons lang and
commons logging, with their dependencies but not log4j.
+
+<hr/>
+<code type="xml">
+<ivy:resources>
+ <dependency org="org.slf4j" module="slf4j" rev="1.6" conf="api,log4j" />
</ivy:resources>
</code>
+Build a resource collection of every artifacts of the configurations "api" and
"log4j" of "slf4j".
+
</textarea>
<script type="text/javascript">xooki.postProcess();</script>
</body>
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPostResolveTask.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPostResolveTask.java?rev=1030584&r1=1030583&r2=1030584&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPostResolveTask.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPostResolveTask.java Wed
Nov 3 18:12:20 2010
@@ -18,9 +18,11 @@
package org.apache.ivy.ant;
import java.io.File;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import org.apache.ivy.Ivy;
import org.apache.ivy.core.cache.ResolutionCacheManager;
@@ -76,6 +78,8 @@ public abstract class IvyPostResolveTask
private boolean changing = false;
+ private IvyResolve resolve = new IvyResolve();
+
public boolean isUseOrigin() {
return useOrigin;
}
@@ -92,6 +96,18 @@ public abstract class IvyPostResolveTask
this.log = log;
}
+ public IvyDependency createDependency() {
+ return resolve.createDependency();
+ }
+
+ public IvyExclude createExclude() {
+ return resolve.createExclude();
+ }
+
+ public IvyConflict createConflict() {
+ return resolve.createConflict();
+ }
+
protected void prepareAndCheck() {
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
@@ -134,7 +150,7 @@ public abstract class IvyPostResolveTask
Message.verbose("using inline mode to resolve " +
getOrganisation() + " "
+ getModule() + " " + getRevision() + " ("
+ StringUtils.join(toResolve, ", ") + ")");
- IvyResolve resolve = createResolve(isHaltonfailure(),
isUseOrigin());
+ IvyResolve resolve = setupResolve(isHaltonfailure(),
isUseOrigin());
resolve.setOrganisation(getOrganisation());
resolve.setModule(getModule());
resolve.setBranch(getBranch());
@@ -209,7 +225,7 @@ public abstract class IvyPostResolveTask
}
if (confs.length > 0) {
- IvyResolve resolve = createResolve(isHaltonfailure(),
isUseOrigin());
+ IvyResolve resolve = setupResolve(isHaltonfailure(),
isUseOrigin());
resolve.setFile(getFile());
resolve.setTransitive(isTransitive());
resolve.setConf(StringUtils.join(confs, ", "));
@@ -289,9 +305,8 @@ public abstract class IvyPostResolveTask
}
- protected IvyResolve createResolve(boolean haltOnFailure, boolean
useOrigin) {
+ protected IvyResolve setupResolve(boolean haltOnFailure, boolean
useOrigin) {
Message.verbose("no resolved descriptor found: launching default
resolve");
- IvyResolve resolve = new IvyResolve();
resolve.setTaskName(getTaskName());
resolve.setProject(getProject());
resolve.setHaltonfailure(haltOnFailure);
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyResolve.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyResolve.java?rev=1030584&r1=1030583&r2=1030584&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyResolve.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyResolve.java Wed Nov 3
18:12:20 2010
@@ -18,13 +18,20 @@
package org.apache.ivy.ant;
import java.io.File;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.text.ParseException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
import org.apache.ivy.Ivy;
import org.apache.ivy.core.LogOptions;
+import org.apache.ivy.core.module.descriptor.DefaultExcludeRule;
+import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor;
+import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
import org.apache.ivy.core.module.id.ModuleRevisionId;
import org.apache.ivy.core.report.ResolveReport;
@@ -82,6 +89,12 @@ public class IvyResolve extends IvyTask
private boolean checkIfChanged = true; //for backward compatibility
+ private List/* <IvyDependency> */dependencies = new ArrayList();
+
+ private List/* <IvyExclude> */excludes = new ArrayList();
+
+ private List/* <IvyConflict> */conflicts = new ArrayList();
+
public boolean isUseOrigin() {
return useOrigin;
}
@@ -195,6 +208,24 @@ public class IvyResolve extends IvyTask
return failureProperty;
}
+ public IvyDependency createDependency() {
+ IvyDependency dep = new IvyDependency();
+ dependencies.add(dep);
+ return dep;
+ }
+
+ public IvyExclude createExclude() {
+ IvyExclude ex = new IvyExclude();
+ excludes.add(ex);
+ return ex;
+ }
+
+ public IvyConflict createConflict() {
+ IvyConflict c = new IvyConflict();
+ conflicts.add(c);
+ return c;
+ }
+
public void doExecute() throws BuildException {
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
@@ -203,8 +234,53 @@ public class IvyResolve extends IvyTask
type = getProperty(type, settings,
"ivy.resolve.default.type.filter");
String[] confs = splitConfs(conf);
+ boolean childs = !dependencies.isEmpty() || !excludes.isEmpty() ||
!conflicts.isEmpty();
+
ResolveReport report;
- if (isInline()) {
+ if (childs) {
+ if (isInline()) {
+ throw new BuildException("the inline mode is incompatible
with child elements");
+ }
+ if (organisation != null) {
+ throw new BuildException("'organisation' is not allowed
with child elements");
+ }
+ if (module != null) {
+ throw new BuildException("'module' is not allowed with
child elements");
+ }
+ if (file != null) {
+ throw new BuildException("'file' not allowed with child
elements");
+ }
+ if (!getAllowedLogOptions().contains(log)) {
+ throw new BuildException("invalid option for 'log': " +
log
+ + ". Available options are " + getAllowedLogOptions());
+ }
+
+ ModuleRevisionId mrid = ModuleRevisionId.newInstance("", "",
Ivy.getWorkingRevision());
+ DefaultModuleDescriptor md =
DefaultModuleDescriptor.newBasicInstance(mrid, null);
+
+ Iterator itDeps = dependencies.iterator();
+ while (itDeps.hasNext()) {
+ IvyDependency dep = (IvyDependency) itDeps.next();
+ DependencyDescriptor dd = dep.asDependencyDescriptor(md,
"default", settings);
+ md.addDependency(dd);
+ }
+
+ Iterator itExcludes = excludes.iterator();
+ while (itExcludes.hasNext()) {
+ IvyExclude exclude = (IvyExclude) itExcludes.next();
+ DefaultExcludeRule rule = exclude.asRule(settings);
+ rule.addConfiguration("default");
+ md.addExcludeRule(rule);
+ }
+
+ Iterator itConflicts = conflicts.iterator();
+ while (itConflicts.hasNext()) {
+ IvyConflict conflict = (IvyConflict) itConflicts.next();
+ conflict.addConflict(md, settings);
+ }
+
+ report = ivy.resolve(md, getResolveOptions(ivy, new String[]
{"default"}, settings));
+ } else if (isInline()) {
if (organisation == null) {
throw new BuildException("'organisation' is required when
using inline mode");
}
@@ -229,7 +305,7 @@ public class IvyResolve extends IvyTask
report = ivy.resolve(ModuleRevisionId
.newInstance(organisation, module, branch, revision),
getResolveOptions(ivy, confs, settings), changing);
-
+
} else {
if (organisation != null) {
throw new BuildException(
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyResources.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyResources.java?rev=1030584&r1=1030583&r2=1030584&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyResources.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyResources.java Wed Nov 3
18:12:20 2010
@@ -17,219 +17,102 @@
*/
package org.apache.ivy.ant;
-import java.io.IOException;
-import java.text.ParseException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
-import org.apache.ivy.Ivy;
-import org.apache.ivy.core.LogOptions;
-import org.apache.ivy.core.module.descriptor.DefaultExcludeRule;
-import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor;
-import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
-import org.apache.ivy.core.module.id.ModuleRevisionId;
import org.apache.ivy.core.report.ArtifactDownloadReport;
-import org.apache.ivy.core.report.ConfigurationResolveReport;
-import org.apache.ivy.core.report.ResolveReport;
-import org.apache.ivy.core.resolve.ResolveOptions;
-import org.apache.ivy.util.filter.Filter;
-import org.apache.ivy.util.filter.FilterHelper;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Location;
+import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.resources.BaseResourceCollectionWrapper;
import org.apache.tools.ant.types.resources.FileResource;
-public class IvyResources extends BaseResourceCollectionWrapper {
+public class IvyResources extends IvyCacheTask implements ResourceCollection {
- private List/* <IvyDependency> */dependencies = new ArrayList();
+ /**
+ * Delegate for the implementation of the resource collection
+ */
+ private class IvyBaseResourceCollectionWrapper extends
BaseResourceCollectionWrapper {
- private List/* <IvyExclude> */excludes = new ArrayList();
-
- private List/* <IvyConflict> */conflicts = new ArrayList();
-
- private String type = null;
-
- private String pubdate = null;
-
- private boolean useCacheOnly = false;
-
- private boolean transitive = true;
-
- private boolean refresh = false;
-
- private String resolveMode = null;
-
- private String resolveId = null;
-
- private String log = ResolveOptions.LOG_DEFAULT;
-
- private Reference antIvyEngineRef;
-
- public IvyDependency createDependency() {
- IvyDependency dep = new IvyDependency();
- dependencies.add(dep);
- return dep;
- }
-
- public IvyExclude createExclude() {
- IvyExclude ex = new IvyExclude();
- excludes.add(ex);
- return ex;
- }
+ protected Collection getCollection() {
+ return resolveResources(null);
+ }
- public IvyConflict createConflict() {
- IvyConflict c = new IvyConflict();
- conflicts.add(c);
- return c;
}
- public void setType(String type) {
- this.type = type;
- }
+ private IvyBaseResourceCollectionWrapper wrapper = new
IvyBaseResourceCollectionWrapper();
- public void setDate(String pubdate) {
- this.pubdate = pubdate;
- }
+ // delegate the ProjectComponent API on the wrapper
- public void setPubdate(String pubdate) {
- this.pubdate = pubdate;
+ public void setLocation(Location location) {
+ super.setLocation(location);
+ wrapper.setLocation(location);
}
- public void setUseCacheOnly(boolean useCacheOnly) {
- this.useCacheOnly = useCacheOnly;
+ public void setProject(Project project) {
+ super.setProject(project);
+ wrapper.setProject(project);
}
- public void setTransitive(boolean transitive) {
- this.transitive = transitive;
+ public void setDescription(String desc) {
+ super.setDescription(desc);
+ wrapper.setDescription(desc);
}
- public void setRefresh(boolean refresh) {
- this.refresh = refresh;
- }
+ // delegate the DataType API on the wrapper
- public void setResolveMode(String resolveMode) {
- this.resolveMode = resolveMode;
+ public void setRefid(Reference ref) {
+ wrapper.setRefid(ref);
}
- public void setResolveId(String resolveId) {
- this.resolveId = resolveId;
- }
+ // delegate the AbstractResourceCollectionWrapper API on the wrapper
- public void setLog(String log) {
- this.log = log;
+ public void setCache(boolean b) {
+ wrapper.setCache(b);
}
- public void setSettingsRef(Reference ref) {
- antIvyEngineRef = ref;
- }
+ // implementation of the Resource Collection API
public boolean isFilesystemOnly() {
return true;
}
- protected Collection/* <String> */getAllowedLogOptions() {
- return Arrays.asList(new String[] {LogOptions.LOG_DEFAULT,
LogOptions.LOG_DOWNLOAD_ONLY,
- LogOptions.LOG_QUIET});
+ public Iterator iterator() {
+ return wrapper.iterator();
}
- protected Ivy getIvyInstance() {
- Object antIvyEngine;
- if (antIvyEngineRef != null) {
- antIvyEngine = antIvyEngineRef.getReferencedObject(getProject());
- if
(!antIvyEngine.getClass().getName().equals(IvyAntSettings.class.getName())) {
- throw new BuildException(antIvyEngineRef.getRefId()
- + " doesn't reference an ivy:settings", getLocation());
- }
- if (!(antIvyEngine instanceof IvyAntSettings)) {
- throw new BuildException(antIvyEngineRef.getRefId()
- + " has been defined in a different classloader. "
- + "Please use the same loader when defining your task,
or "
- + "redeclare your ivy:settings in this classloader",
getLocation());
- }
- } else {
- antIvyEngine = IvyAntSettings.getDefaultInstance(this);
- }
- Ivy ivy = ((IvyAntSettings)
antIvyEngine).getConfiguredIvyInstance(this);
- AntMessageLogger.register(this, ivy);
- return ivy;
+ public int size() {
+ return wrapper.size();
}
- protected Collection getCollection() {
- if (!getAllowedLogOptions().contains(log)) {
- throw new BuildException("invalid option for 'log': " + log
- + ". Available options are " + getAllowedLogOptions());
- }
-
- Ivy ivy = getIvyInstance();
-
- ModuleRevisionId mrid = ModuleRevisionId.newInstance("", "", "");
- DefaultModuleDescriptor md =
DefaultModuleDescriptor.newBasicInstance(mrid, null);
-
- Iterator itDeps = dependencies.iterator();
- while (itDeps.hasNext()) {
- IvyDependency dep = (IvyDependency) itDeps.next();
- DependencyDescriptor dd = dep.asDependencyDescriptor(md,
"default", ivy.getSettings());
- md.addDependency(dd);
- }
-
- Iterator itExcludes = excludes.iterator();
- while (itExcludes.hasNext()) {
- IvyExclude exclude = (IvyExclude) itExcludes.next();
- DefaultExcludeRule rule = exclude.asRule(ivy.getSettings());
- rule.addConfiguration("default");
- md.addExcludeRule(rule);
- }
+ // convert the ivy reports into an Ant Resource collection
- Iterator itConflicts = conflicts.iterator();
- while (itConflicts.hasNext()) {
- IvyConflict conflict = (IvyConflict) itConflicts.next();
- conflict.addConflict(md, ivy.getSettings());
- }
-
- ResolveOptions options = new ResolveOptions();
- options.setConfs(new String[] {"default"});
- options.setDate(IvyTask.getPubDate(pubdate, null));
- options.setUseCacheOnly(useCacheOnly);
- options.setRefresh(refresh);
- options.setTransitive(transitive);
- options.setResolveMode(resolveMode);
- options.setResolveId(resolveId);
-
- ResolveReport report;
+ private Collection resolveResources(String id) throws BuildException {
+ prepareAndCheck();
try {
- report = ivy.resolve(md, options);
- } catch (ParseException e) {
- throw new BuildException(e);
- } catch (IOException e) {
- throw new BuildException(e);
- }
-
- List/* <FileResource> */resources = new ArrayList();
-
- if (report.hasError()) {
- throw new BuildException("resolve failed - see output for
details");
- } else {
- Filter artifactTypeFilter =
FilterHelper.getArtifactTypeFilter(type);
-
- ConfigurationResolveReport configurationReport = report
- .getConfigurationReport("default");
- Set revisions = configurationReport.getModuleRevisionIds();
- for (Iterator it = revisions.iterator(); it.hasNext();) {
- ModuleRevisionId revId = (ModuleRevisionId) it.next();
- ArtifactDownloadReport[] aReports =
configurationReport.getDownloadReports(revId);
- for (int i = 0; i < aReports.length; i++) {
- if (artifactTypeFilter.accept(aReports[i].getArtifact())) {
- resources.add(new
FileResource(aReports[i].getLocalFile()));
- }
- }
+ List/* <FileResource> */resources = new ArrayList();
+ if (id != null) {
+ getProject().addReference(id, this);
+ }
+ for (Iterator iter = getArtifactReports().iterator();
iter.hasNext();) {
+ ArtifactDownloadReport a = (ArtifactDownloadReport)
iter.next();
+ resources.add(new FileResource(a.getLocalFile()));
}
+ return resources;
+ } catch (Exception ex) {
+ throw new BuildException("impossible to build ivy resources: " +
ex, ex);
}
+ }
+
+ // implementation of the IvyPostResolveTask API
- return resources;
+ public void doExecute() throws BuildException {
+ // TODO : maybe there is a way to implement it ?
+ throw new BuildException("ivy:resources should not be used as a Ant
Task");
}
}
Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyResolveTest.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyResolveTest.java?rev=1030584&r1=1030583&r2=1030584&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyResolveTest.java
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyResolveTest.java Wed Nov
3 18:12:20 2010
@@ -18,6 +18,7 @@
package org.apache.ivy.ant;
import java.io.File;
+import java.util.List;
import junit.framework.TestCase;
@@ -437,4 +438,153 @@ public class IvyResolveTest extends Test
return resolve.getIvyInstance();
}
+ public void testChildsSimple() throws Exception {
+ IvyDependency dependency = resolve.createDependency();
+ dependency.setOrg("org1");
+ dependency.setName("mod1.2");
+ dependency.setRev("2.0");
+
+ resolve.execute();
+
+ assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2",
"jar", "jar").exists());
+ }
+
+ public void testChildsMultiple() throws Exception {
+ IvyDependency dependency = resolve.createDependency();
+ dependency.setOrg("org1");
+ dependency.setName("mod1.2");
+ dependency.setRev("2.0");
+
+ dependency = resolve.createDependency();
+ dependency.setOrg("org2");
+ dependency.setName("mod2.3");
+ dependency.setRev("0.7");
+
+ resolve.execute();
+
+ assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org2", "mod2.3", "0.7", "mod2.3",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1",
"jar", "jar").exists());
+ }
+
+ public void testChildsMultipleWithConf() throws Exception {
+ IvyDependency dependency = resolve.createDependency();
+ dependency.setOrg("org1");
+ dependency.setName("mod1.2");
+ dependency.setRev("2.0");
+
+ dependency = resolve.createDependency();
+ dependency.setOrg("org2");
+ dependency.setName("mod2.2");
+ dependency.setRev("0.10");
+ dependency.setConf("A");
+
+ resolve.execute();
+
+ assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org2", "mod2.2", "0.10", "mod2.2",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.7", "mod2.1",
"jar", "jar").exists());
+ }
+
+ public void testChildsMultipleWithConf2() throws Exception {
+ IvyDependency dependency = resolve.createDependency();
+ dependency.setOrg("org1");
+ dependency.setName("mod1.2");
+ dependency.setRev("2.0");
+
+ dependency = resolve.createDependency();
+ dependency.setOrg("org2");
+ dependency.setName("mod2.2");
+ dependency.setRev("0.10");
+ dependency.setConf("B");
+
+ resolve.execute();
+
+ assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org2", "mod2.2", "0.10", "mod2.2",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.7", "mod2.1",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1",
"jar", "jar").exists());
+ }
+
+ public void testChildsExclude() throws Exception {
+ IvyDependency dependency = resolve.createDependency();
+ dependency.setOrg("org1");
+ dependency.setName("mod1.2");
+ dependency.setRev("2.0");
+
+ dependency = resolve.createDependency();
+ dependency.setOrg("org2");
+ dependency.setName("mod2.2");
+ dependency.setRev("0.10");
+ dependency.setConf("B");
+
+ IvyExclude exclude = resolve.createExclude();
+ exclude.setOrg("org1");
+ exclude.setModule("mod1.1");
+
+ resolve.execute();
+
+ assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org2", "mod2.2", "0.10", "mod2.2",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.7", "mod2.1",
"jar", "jar").exists());
+ }
+
+ public void testChildsDependencyExclude() throws Exception {
+ IvyDependency dependency = resolve.createDependency();
+ dependency.setOrg("org1");
+ dependency.setName("mod1.2");
+ dependency.setRev("2.0");
+
+ dependency = resolve.createDependency();
+ dependency.setOrg("org2");
+ dependency.setName("mod2.2");
+ dependency.setRev("0.10");
+ dependency.setConf("B");
+
+ IvyDependencyExclude exclude = dependency.createExclude();
+ exclude.setOrg("org1");
+
+ resolve.execute();
+
+ assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org2", "mod2.2", "0.10", "mod2.2",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.7", "mod2.1",
"jar", "jar").exists());
+ }
+
+ public void testChildsDependencyInclude() throws Exception {
+ IvyDependency dependency = resolve.createDependency();
+ dependency.setOrg("org1");
+ dependency.setName("mod1.2");
+ dependency.setRev("2.0");
+
+ dependency = resolve.createDependency();
+ dependency.setOrg("org2");
+ dependency.setName("mod2.2");
+ dependency.setRev("0.9");
+
+ IvyDependencyInclude include = dependency.createInclude();
+ include.setName("art22-1");
+
+ resolve.execute();
+
+ assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2",
"jar", "jar").exists());
+ assertTrue(getArchiveFileInCache("org2", "mod2.2", "0.9", "art22-1",
"jar", "jar").exists());
+ }
+
+ public void testChildsFail() throws Exception {
+ IvyDependency dependency = resolve.createDependency();
+ dependency.setOrg("org1");
+ dependency.setName("noexisting");
+ dependency.setRev("2.0");
+
+ try {
+ resolve.execute();
+ fail("A fail resolved should have raised a build exception");
+ } catch (BuildException e) {
+ // ok
+ }
+ }
+
}
Modified:
ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java?rev=1030584&r1=1030583&r2=1030584&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
Wed Nov 3 18:12:20 2010
@@ -5272,4 +5272,25 @@ public class ResolveTest extends TestCas
report = ivy.resolve(url, option);
assertFalse(report.hasError());
}
+
+ public void testUseCacheOnlyWithRange() throws Exception {
+ ResolveOptions option = getResolveOptions(new String[] {"*"});
+ option.setValidate(false);
+
+ ivy.getSettings().setDefaultUseOrigin(true);
+ ivy.getSettings().setDefaultResolveMode("dynamic");
+
+ URL url = new
File("test/repositories/1/usecacheonly/mod3/ivys/ivy-1.0.xml").toURI()
+ .toURL();
+
+ // normal resolve, the file goes in the cache
+ ResolveReport report = ivy.resolve(url, option);
+ assertFalse(report.hasError());
+
+ option.setUseCacheOnly(true);
+
+ // use cache only, hit the cache
+ report = ivy.resolve(url, option);
+ assertFalse(report.hasError());
+ }
}
Added: ant/ivy/core/trunk/test/repositories/1/usecacheonly/mod3/ivys/ivy-1.0.xml
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/repositories/1/usecacheonly/mod3/ivys/ivy-1.0.xml?rev=1030584&view=auto
==============================================================================
--- ant/ivy/core/trunk/test/repositories/1/usecacheonly/mod3/ivys/ivy-1.0.xml
(added)
+++ ant/ivy/core/trunk/test/repositories/1/usecacheonly/mod3/ivys/ivy-1.0.xml
Wed Nov 3 18:12:20 2010
@@ -0,0 +1,27 @@
+<!--
+ 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.
+-->
+<ivy-module version="1.0">
+ <info organisation="usecacheonly" module="mod3" revision="1.0" />
+ <configurations>
+ <conf name="default" />
+ </configurations>
+ <dependencies>
+ <dependency org="usecacheonly" name="mod2" rev="[1.0,2.0)" />
+ </dependencies>
+</ivy-module>
Added:
ant/ivy/core/trunk/test/repositories/1/usecacheonly/mod3/jars/mod3-1.0.jar
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/repositories/1/usecacheonly/mod3/jars/mod3-1.0.jar?rev=1030584&view=auto
==============================================================================
--- ant/ivy/core/trunk/test/repositories/1/usecacheonly/mod3/jars/mod3-1.0.jar
(added)
+++ ant/ivy/core/trunk/test/repositories/1/usecacheonly/mod3/jars/mod3-1.0.jar
Wed Nov 3 18:12:20 2010
@@ -0,0 +1 @@
+.
\ No newline at end of file