Index: test/java/org/apache/ivy/ant/IvyInstallTest.java =================================================================== --- test/java/org/apache/ivy/ant/IvyInstallTest.java (revision 0) +++ test/java/org/apache/ivy/ant/IvyInstallTest.java (revision 0) @@ -0,0 +1,105 @@ +/* + * 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.ant; + +import java.io.File; +import java.io.IOException; + +import junit.framework.TestCase; + +import org.apache.ivy.TestHelper; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + + +public class IvyInstallTest extends TestCase { + private static final String IVY_RETRIEVE_PATTERN = "build/test/lib/[organisation]/[module]/ivy-[revision].xml"; + private static final String RETRIEVE_PATTERN = "build/test/lib/[conf]/[artifact]-[revision].[type]"; + private File _cache; + private IvyInstall _install; + private Project _project; + + protected void setUp() throws Exception { + createCache(); + cleanTestLib(); + _project = new Project(); + _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + _install = new IvyInstall(); + _install.setProject(_project); + _install.setCache(_cache); + } + + private void createCache() { + _cache = new File("build/cache"); + _cache.mkdirs(); + } + + protected void tearDown() throws Exception { + cleanCache(); + cleanTestLib(); + } + + private void cleanCache() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(_cache); + del.execute(); + } + + private void cleanTestLib() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(new File("build/test/lib")); + del.execute(); + } + + public void testDependencyNotFoundFailure() { + _install.setOrganisation("xxx"); + _install.setModule("yyy"); + _install.setRevision("zzz"); + _install.setFrom("test"); + _install.setTo("1"); + + try { + _install.execute(); + fail("unknown dependency, failure expected (haltunresolved=true)"); + } catch (BuildException be) { + // success + be.printStackTrace(); + } + } + + public void testDependencyNotFoundSuccess() { + _install.setOrganisation("xxx"); + _install.setModule("yyy"); + _install.setRevision("zzz"); + _install.setFrom("test"); + _install.setTo("1"); + _install.setHaltonunresolved(false); + + try { + _install.execute(); + } catch (BuildException be) { + be.printStackTrace(); + fail("unknown dependency, failure unexepected (haltunresolved=false)"); + } + } +} Index: src/java/org/apache/ivy/ant/IvyInstall.java =================================================================== --- src/java/org/apache/ivy/ant/IvyInstall.java (revision 531541) +++ src/java/org/apache/ivy/ant/IvyInstall.java (working copy) @@ -25,12 +25,13 @@ import org.apache.ivy.plugins.matcher.PatternMatcher; import org.apache.ivy.util.filter.FilterHelper; import org.apache.tools.ant.BuildException; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.tools.ant.BuildException; - /** * Allow to install a module or a set of module from repository to another one. - * - * + * + * * @author Xavier Hanin * */ @@ -38,13 +39,14 @@ private String _organisation; private String _module; private String _revision; - private File _cache; + private File _cache; private boolean _overwrite = false; private String _from; private String _to; private boolean _transitive; private String _type; private String _matcher = PatternMatcher.EXACT; + private boolean _haltOnUnresolved = true; public void execute() throws BuildException { Ivy ivy = getIvyInstance(); @@ -58,12 +60,12 @@ if (_module == null && PatternMatcher.EXACT.equals(_matcher)) { throw new BuildException("no module name provided for ivy publish task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to "); } else if (_module == null && !PatternMatcher.EXACT.equals(_matcher)) { - _module = PatternMatcher.ANY_EXPRESSION; + _module = PatternMatcher.ANY_EXPRESSION; } if (_revision == null && PatternMatcher.EXACT.equals(_matcher)) { throw new BuildException("no module revision provided for ivy publish task: It can either be set explicitely via the attribute 'revision' or via 'ivy.revision' property or a prior call to "); } else if (_revision == null && !PatternMatcher.EXACT.equals(_matcher)) { - _revision = PatternMatcher.ANY_EXPRESSION; + _revision = PatternMatcher.ANY_EXPRESSION; } if (_from == null) { throw new BuildException("no from resolver name: please provide it through parameter 'from'"); @@ -72,13 +74,25 @@ throw new BuildException("no to resolver name: please provide it through parameter 'to'"); } ModuleRevisionId mrid = ModuleRevisionId.newInstance(_organisation, _module, _revision); + ResolveReport report; try { - ivy.install(mrid, _from, _to, _transitive, doValidate(settings), _overwrite, FilterHelper.getArtifactTypeFilter(_type), _cache, _matcher); + report = ivy.install(mrid, _from, _to, _transitive, doValidate(settings), _overwrite, FilterHelper.getArtifactTypeFilter(_type), _cache, _matcher); } catch (Exception e) { throw new BuildException("impossible to install "+ mrid +": "+e, e); } + + if (report.getUnresolvedDependencies().length > 0 && isHaltonunresolved()) { + throw new BuildException("could not resolve dependencies - see output for details"); + } } - + + public boolean isHaltonunresolved() { + return _haltOnUnresolved; + } + public void setHaltonunresolved(boolean haltOnUnresolved) { + _haltOnUnresolved = haltOnUnresolved; + } + public File getCache() { return _cache; } @@ -134,11 +148,11 @@ public void setType(String type) { _type = type; } - + public String getMatcher() { return _matcher; } - + public void setMatcher(String matcher) { _matcher = matcher; } Index: doc/doc/use/install.html =================================================================== --- doc/doc/use/install.html (revision 531541) +++ doc/doc/use/install.html (working copy) @@ -56,6 +56,8 @@ No, defaults to false matcherthe name of the matcher to use to find the modules to install No, defaults to exact + haltonunresolvedtrue to fail build on unresolved dependencies + No, defaults to true

Examples