-default dest, repository -override properties -changes to tests to keep working -enhancements to tests so they work behind a firewall if ~/.ant/proxy.properties contains the settings git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277397 13f79535-47bb-0310-9956-ffa450edef68master
@@ -42,7 +42,7 @@ | |||||
<td valign="top">destDir</td> | <td valign="top">destDir</td> | ||||
<td valign="top">Destination directory for all downloads | <td valign="top">Destination directory for all downloads | ||||
</td> | </td> | ||||
<td valign="top" align="center">Yes</td> | |||||
<td valign="top" align="center">No - default is ${user.home}/.maven/repository</td> | |||||
</tr> | </tr> | ||||
<tr> | <tr> | ||||
<td valign="top">offline</td> | <td valign="top">offline</td> | ||||
@@ -68,10 +68,15 @@ | |||||
<td valign="top">repositoryRef</td> | <td valign="top">repositoryRef</td> | ||||
<td valign="top">Reference to a predefined repository | <td valign="top">Reference to a predefined repository | ||||
</td> | </td> | ||||
<td valign="top" align="center">Only if no repository is defined inline</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | </tr> | ||||
</table> | </table> | ||||
<p> | |||||
The default destination is that used by Maven, | |||||
${user.home}/.maven/repository . It can be overridden by setting the | |||||
property <code>ant.maven.repository.dir</code> to a new location. | |||||
</p> | |||||
</table> | </table> | ||||
<h3>Nested Elements</h3> | <h3>Nested Elements</h3> | ||||
@@ -127,9 +132,12 @@ This is the core of the system; a library to (potentially) download. | |||||
</table> | </table> | ||||
<h4>Repository</h4> | <h4>Repository</h4> | ||||
<p> | |||||
A repository is Ant datatype that extends the <code>Repository</code> type. | A repository is Ant datatype that extends the <code>Repository</code> type. | ||||
Ant only ships with one: the mavenrepository; | |||||
Ant only ships with one: the mavenrepository. If no repository is | |||||
declared inline, and no repositoryref attribute set, the task | |||||
will default to the maven repository. | |||||
</p> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | <table border="1" cellpadding="2" cellspacing="0"> | ||||
<tr> | <tr> | ||||
@@ -143,12 +151,6 @@ Ant only ships with one: the mavenrepository; | |||||
</td> | </td> | ||||
<td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
</tr> | </tr> | ||||
<tr> | |||||
<td valign="top"></td> | |||||
<td valign="top"> | |||||
</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
</table> | </table> | ||||
<p>Example:</p> | <p>Example:</p> | ||||
@@ -158,6 +160,15 @@ Ant only ships with one: the mavenrepository; | |||||
<h4>mavenrepository</h4> | <h4>mavenrepository</h4> | ||||
<p> | |||||
This connects to the Maven repository at ibiblio.org, or another | |||||
chosen. Private repositories should copy the existing layout. | |||||
</p> | |||||
<p> | |||||
If no <code>url</code> is set, the default URL is | |||||
<code>http://ibiblio.org/maven</code>, unless the property | |||||
<code>ant.maven.repository.url</code> is set to something else. | |||||
<table border="1" cellpadding="2" cellspacing="0"> | <table border="1" cellpadding="2" cellspacing="0"> | ||||
<tr> | <tr> | ||||
<td valign="top"><b>Attribute</b></td> | <td valign="top"><b>Attribute</b></td> | ||||
@@ -276,6 +276,18 @@ org.apache.tools.ant.Executor implementation specified here. | |||||
<a href="listeners.html#AnsiColorLogger">AnsiColorLogger</a>. | <a href="listeners.html#AnsiColorLogger">AnsiColorLogger</a>. | ||||
</td> | </td> | ||||
</tr> | </tr> | ||||
<tr> | |||||
<td><code>ant.maven.repository.dir</code></td> | |||||
<td>directory e.g. ${user.home}/.maven/repository </td> | |||||
<td>Override the default download location for <a href="CoreTasks/libraries.html">libraries</a>. | |||||
</td> | |||||
</tr> | |||||
<tr> | |||||
<td><code>ant.maven.repository.url</code></td> | |||||
<td>URL e.g. <code>http://ibiblio.org/maven</code> </td> | |||||
<td>Override the default source location for <a href="CoreTasks/libraries.html">libraries</a>. | |||||
</td> | |||||
</tr> | |||||
<tr> | <tr> | ||||
<td><code>ant.netrexxc.*</code></td> | <td><code>ant.netrexxc.*</code></td> | ||||
<td>several formats</td> | <td>several formats</td> | ||||
@@ -2,10 +2,28 @@ | |||||
<project name="getlibraries" basedir="." default="init"> | <project name="getlibraries" basedir="." default="init"> | ||||
<!-- use the normal one at ibiblio--> | <!-- use the normal one at ibiblio--> | ||||
<mavenrepository id="maven"/> | <mavenrepository id="maven"/> | ||||
<target name="init"> | |||||
<!-- configure an HTTP proxy --> | |||||
<target name="setproxy" unless="setproxy.disabled" > | |||||
<!-- put your proxy settings here --> | |||||
<property file="${user.home}/.ant/proxy.properties" /> | |||||
<property name="proxy.host" value="" /> | |||||
<property name="proxy.port" value="80" /> | |||||
<property name="proxy.user" value="" /> | |||||
<property name="proxy.pass" value="" /> | |||||
<echo level="verbose"> | |||||
proxy: ${proxy.host}:${proxy.port} [${proxy.user}/${proxy.pass}] | |||||
</echo> | |||||
<setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}" | |||||
proxyuser="${proxy.user}" proxypassword="${proxy.pass}" /> | |||||
</target> | |||||
<target name="init" depends="setproxy"> | |||||
<property name="lib.dir" value="getlib"/> | <property name="lib.dir" value="getlib"/> | ||||
<property name="commons.logging.project" value="commons-logging"/> | <property name="commons.logging.project" value="commons-logging"/> | ||||
@@ -15,6 +33,9 @@ | |||||
<property name="commons.logging" | <property name="commons.logging" | ||||
value="${commons.logging.project}/jars/${commons.logging.filename}"/> | value="${commons.logging.project}/jars/${commons.logging.filename}"/> | ||||
<property name="maven.repository.dir" | |||||
location="${user.home}/.maven/repository" /> | |||||
<presetdef name="gl1"> | <presetdef name="gl1"> | ||||
<libraries destDir="${lib.dir}"> | <libraries destDir="${lib.dir}"> | ||||
</libraries> | </libraries> | ||||
@@ -28,6 +49,21 @@ | |||||
</presetdef> | </presetdef> | ||||
<macrodef name="assert-downloaded"> | <macrodef name="assert-downloaded"> | ||||
<attribute name="library" default="${commons.logging}"/> | |||||
<attribute name="repository" default="${lib.dir}"/> | |||||
<sequential> | |||||
<fail > | |||||
Not found: "@{repository}/@{library}" | |||||
<condition> | |||||
<not> | |||||
<available file="@{repository}/@{library}"/> | |||||
</not> | |||||
</condition> | |||||
</fail> | |||||
</sequential> | |||||
</macrodef> | |||||
<!-- <macrodef name="assert-downloaded"> | |||||
<attribute name="library" default="${commons.logging}"/> | <attribute name="library" default="${commons.logging}"/> | ||||
<sequential> | <sequential> | ||||
<property name="@{library}.path" location="${lib.dir}/@{library}" /> | <property name="@{library}.path" location="${lib.dir}/@{library}" /> | ||||
@@ -37,20 +73,21 @@ | |||||
Not found: ${@{library}.path} | Not found: ${@{library}.path} | ||||
</fail> | </fail> | ||||
</sequential> | </sequential> | ||||
</macrodef> | |||||
</macrodef> --> | |||||
<macrodef name="assert-not-downloaded"> | <macrodef name="assert-not-downloaded"> | ||||
<attribute name="library" default="${commons.logging}"/> | <attribute name="library" default="${commons.logging}"/> | ||||
<attribute name="repository" default="${lib.dir}"/> | |||||
<sequential> | <sequential> | ||||
<property name="@{library}.path" location="${lib.dir}/@{library}" /> | |||||
<available property="@{library}.exists" | |||||
file="${@{library}.path}"/> | |||||
<fail if="@{library}.exists"> | |||||
Found: ${@{library}.path} | |||||
<fail> | |||||
Unexpectedly found: "@{repository}/@{library}" | |||||
<condition> | |||||
<available file="@{repository}/@{library}"/> | |||||
</condition> | |||||
</fail> | </fail> | ||||
</sequential> | </sequential> | ||||
</macrodef> | </macrodef> | ||||
</target> | </target> | ||||
<target name="cleanup" depends="init"> | <target name="cleanup" depends="init"> | ||||
@@ -77,6 +114,7 @@ | |||||
<target name="testNoRepo" depends="init"> | <target name="testNoRepo" depends="init"> | ||||
<getlib/> | <getlib/> | ||||
<assert-downloaded/> | |||||
</target> | </target> | ||||
<target name="testUnknownReference" depends="init"> | <target name="testUnknownReference" depends="init"> | ||||
@@ -85,7 +123,6 @@ | |||||
</getlib> | </getlib> | ||||
</target> | </target> | ||||
<target name="testFunctionalInline" depends="init"> | <target name="testFunctionalInline" depends="init"> | ||||
<getlib repositoryref="maven"> | <getlib repositoryref="maven"> | ||||
</getlib> | </getlib> | ||||
@@ -202,12 +239,10 @@ | |||||
<target name="testForceDisabled" depends="init"> | <target name="testForceDisabled" depends="init"> | ||||
<getlib> | <getlib> | ||||
<mavenrepository/> | |||||
<force enabled="true" /> | <force enabled="true" /> | ||||
<assertdownloaded count="1" /> | <assertdownloaded count="1" /> | ||||
</getlib> | </getlib> | ||||
<getlib > | <getlib > | ||||
<mavenrepository/> | |||||
<force enabled="false" /> | <force enabled="false" /> | ||||
<assertdownloaded count="0" /> | <assertdownloaded count="0" /> | ||||
</getlib> | </getlib> | ||||
@@ -215,7 +250,6 @@ | |||||
<target name="testAbsentFiles" depends="init"> | <target name="testAbsentFiles" depends="init"> | ||||
<getlib > | <getlib > | ||||
<mavenrepository/> | |||||
<absentfiles enabled="true" /> | <absentfiles enabled="true" /> | ||||
<assertdownloaded count="1" /> | <assertdownloaded count="1" /> | ||||
</getlib> | </getlib> | ||||
@@ -223,7 +257,6 @@ | |||||
<target name="testAbsentFilesTwice" depends="testAbsentFiles"> | <target name="testAbsentFilesTwice" depends="testAbsentFiles"> | ||||
<getlib > | <getlib > | ||||
<mavenrepository/> | |||||
<absentfiles enabled="true" /> | <absentfiles enabled="true" /> | ||||
<assertdownloaded count="0" /> | <assertdownloaded count="0" /> | ||||
</getlib> | </getlib> | ||||
@@ -85,7 +85,7 @@ public final class Libraries extends Task { | |||||
private boolean flatten = false; | private boolean flatten = false; | ||||
public static final String ERROR_ONE_REPOSITORY_ONLY = "Only one repository is allowed"; | public static final String ERROR_ONE_REPOSITORY_ONLY = "Only one repository is allowed"; | ||||
public static final String ERROR_NO_DEST_DIR = "No destination directory"; | |||||
//public static final String ERROR_NO_DEST_DIR = "No destination directory"; | |||||
public static final String ERROR_NO_REPOSITORY = "No repository defined"; | public static final String ERROR_NO_REPOSITORY = "No repository defined"; | ||||
public static final String ERROR_NO_LIBRARIES = "No libraries declared"; | public static final String ERROR_NO_LIBRARIES = "No libraries declared"; | ||||
public static final String ERROR_REPO_PROBE_FAILED = "Repository probe failed with "; | public static final String ERROR_REPO_PROBE_FAILED = "Repository probe failed with "; | ||||
@@ -95,6 +95,22 @@ public final class Libraries extends Task { | |||||
public static final String MSG_NO_LIBRARIES_TO_FETCH = "No libraries marked for retrieval"; | public static final String MSG_NO_LIBRARIES_TO_FETCH = "No libraries marked for retrieval"; | ||||
/** | |||||
* where maven stores stuff, and where we save stuff too, unless | |||||
* declared otherwise. | |||||
*/ | |||||
public static final String MAVEN_LOCATION=".maven/repository"; | |||||
/** | |||||
* name of the property which can provide an override of the repository dir | |||||
* from {@link #MAVEN_LOCATION} | |||||
*/ | |||||
public static final String REPOSITORY_DIR_PROPERTY="ant.maven.repository.dir"; | |||||
/** | |||||
* name of the property which can provide an override of the repository URL | |||||
*/ | |||||
public static final String REPOSITORY_URL_PROPERTY = "ant.maven.repository.url"; | |||||
/** | /** | ||||
* Init the task | * Init the task | ||||
* | * | ||||
@@ -107,6 +123,23 @@ public final class Libraries extends Task { | |||||
add(new AbsentFilesPolicy()); | add(new AbsentFilesPolicy()); | ||||
} | } | ||||
/** | |||||
* locate the default directory, by looking for the property | |||||
* {@link #REPOSITORY_DIR_PROPERTY}, and if not defined, | |||||
* ${user.home}/.maven/repository | |||||
* @return file for the default dest dir; may not exist yet. | |||||
*/ | |||||
private File locateDefaultDestDirectory() { | |||||
//set the dest dir up to the default. | |||||
File mavenDir | |||||
= new File(System.getProperty("user.home"), MAVEN_LOCATION); | |||||
String propertyDir = getProject().getProperty(REPOSITORY_DIR_PROPERTY); | |||||
if(propertyDir!=null) { | |||||
mavenDir=getProject().resolveFile(propertyDir); | |||||
} | |||||
return mavenDir; | |||||
} | |||||
/** | /** | ||||
* add a repository. Only one is (currently) supported | * add a repository. Only one is (currently) supported | ||||
* | * | ||||
@@ -325,13 +358,12 @@ public final class Libraries extends Task { | |||||
* @throws BuildException | * @throws BuildException | ||||
*/ | */ | ||||
public void validate() { | public void validate() { | ||||
if (destDir == null | |||||
// || !destDir.isDirectory() | |||||
) { | |||||
throw new BuildException(ERROR_NO_DEST_DIR); | |||||
if (destDir == null) { | |||||
destDir=locateDefaultDestDirectory(); | |||||
} | } | ||||
if (repository == null) { | if (repository == null) { | ||||
throw new BuildException(ERROR_NO_REPOSITORY); | |||||
MavenRepository maven=(MavenRepository)getProject().createDataType(MavenRepository.TYPE_NAME); | |||||
repository=maven; | |||||
} | } | ||||
Iterator it = libraries.iterator(); | Iterator it = libraries.iterator(); | ||||
while (it.hasNext()) { | while (it.hasNext()) { | ||||
@@ -365,9 +397,12 @@ public final class Libraries extends Task { | |||||
*/ | */ | ||||
private void doExecute() throws BuildException { | private void doExecute() throws BuildException { | ||||
destDir.mkdirs(); | destDir.mkdirs(); | ||||
//get the ultimate repository | |||||
Repository repo = repository.resolve(); | Repository repo = repository.resolve(); | ||||
//validate it | |||||
repo.validate(); | repo.validate(); | ||||
if (libraries.size() == 0) { | if (libraries.size() == 0) { | ||||
//bail out on an empty library | |||||
throw new BuildException(ERROR_NO_LIBRARIES); | throw new BuildException(ERROR_NO_LIBRARIES); | ||||
} | } | ||||
log("Getting libraries from " + repo.toString(), Project.MSG_VERBOSE); | log("Getting libraries from " + repo.toString(), Project.MSG_VERBOSE); | ||||
@@ -18,6 +18,7 @@ | |||||
package org.apache.tools.ant.taskdefs.repository; | package org.apache.tools.ant.taskdefs.repository; | ||||
import org.apache.tools.ant.util.FileUtils; | import org.apache.tools.ant.util.FileUtils; | ||||
import org.apache.tools.ant.BuildException; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileInputStream; | import java.io.FileInputStream; | ||||
@@ -48,12 +49,12 @@ public class MavenRepository extends HttpRepository { | |||||
* this is what we think the MD5 type is | * this is what we think the MD5 type is | ||||
*/ | */ | ||||
protected static final String MAVEN_MD5_FILE_TYPE = "US-ASCII"; | protected static final String MAVEN_MD5_FILE_TYPE = "US-ASCII"; | ||||
public static final String TYPE_NAME = "mavenrepository"; | |||||
/** | /** | ||||
* bind to the main maven repository | * bind to the main maven repository | ||||
*/ | */ | ||||
public MavenRepository() { | public MavenRepository() { | ||||
setUrl(MAVEN_URL); | |||||
} | } | ||||
@@ -65,6 +66,29 @@ public class MavenRepository extends HttpRepository { | |||||
this.checkMD5 = checkMD5; | this.checkMD5 = checkMD5; | ||||
} | } | ||||
/** | |||||
* Validation time is where the final fixup of repositories exist; this | |||||
* is the last chance to examine properties to see if there is an override. | |||||
* | |||||
* @throws BuildException if unhappy | |||||
*/ | |||||
public void validate() { | |||||
if(getUrl()==null) { | |||||
//we have no URL yet; so use the maven one | |||||
if(getProject()!=null) { | |||||
String urlProperty=getProject() | |||||
.getProperty(Libraries.REPOSITORY_URL_PROPERTY); | |||||
if(urlProperty!=null) { | |||||
setUrl(urlProperty); | |||||
} else { | |||||
setUrl(MAVEN_URL); | |||||
} | |||||
} | |||||
} | |||||
super.validate(); | |||||
} | |||||
/** | /** | ||||
* Get the path to a remote library. This is the full URL | * Get the path to a remote library. This is the full URL | ||||
* | * | ||||
@@ -27,9 +27,9 @@ import java.io.IOException; | |||||
* retrieval. To use this type, you must use a non-abstract class, either one | * retrieval. To use this type, you must use a non-abstract class, either one | ||||
* that ships with Ant, or one you implement and declare yourself. | * that ships with Ant, or one you implement and declare yourself. | ||||
* <p/> | * <p/> | ||||
* The <getlibraries> task lets you supply a repository by reference | |||||
* The <libraries> task lets you supply a repository by reference | |||||
* inline {@link Libraries#add(Repository)} or on the command line {@link | * inline {@link Libraries#add(Repository)} or on the command line {@link | ||||
* GetLibraries#setRepositoryRef(org.apache.tools.ant.types.Reference)} | |||||
* Libraries#setRepositoryRef(org.apache.tools.ant.types.Reference)} | |||||
* | * | ||||
* @since Ant1.7 | * @since Ant1.7 | ||||
*/ | */ | ||||
@@ -47,11 +47,11 @@ public class LibrariesTest extends BuildFileTest { | |||||
} | } | ||||
public void testEmpty() { | public void testEmpty() { | ||||
expectBuildException("testEmpty",Libraries.ERROR_NO_DEST_DIR); | |||||
expectBuildException("testEmpty", Libraries.ERROR_NO_LIBRARIES); | |||||
} | } | ||||
public void testEmpty2() { | public void testEmpty2() { | ||||
expectBuildException("testEmpty2", Libraries.ERROR_NO_REPOSITORY); | |||||
expectBuildException("testEmpty2", Libraries.ERROR_NO_LIBRARIES); | |||||
} | } | ||||
public void testEmpty3() { | public void testEmpty3() { | ||||
@@ -59,7 +59,7 @@ public class LibrariesTest extends BuildFileTest { | |||||
} | } | ||||
public void testNoRepo() { | public void testNoRepo() { | ||||
expectBuildException("testNoRepo", Libraries.ERROR_NO_REPOSITORY); | |||||
execIfOnline("testNoRepo"); | |||||
} | } | ||||
public void testUnknownReference() { | public void testUnknownReference() { | ||||