diff --git a/docs/manual/CoreTasks/libraries.html b/docs/manual/CoreTasks/libraries.html
index e884ee074..2f2f669d9 100644
--- a/docs/manual/CoreTasks/libraries.html
+++ b/docs/manual/CoreTasks/libraries.html
@@ -42,7 +42,7 @@
destDir |
Destination directory for all downloads
|
- Yes |
+ No - default is ${user.home}/.maven/repository |
offline |
@@ -68,10 +68,15 @@
repositoryRef |
Reference to a predefined repository
|
- Only if no repository is defined inline |
+ No |
+
+The default destination is that used by Maven,
+${user.home}/.maven/repository . It can be overridden by setting the
+property ant.maven.repository.dir
to a new location.
+
Nested Elements
@@ -127,9 +132,12 @@ This is the core of the system; a library to (potentially) download.
Repository
-
+
A repository is Ant datatype that extends the Repository
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.
+
@@ -143,12 +151,6 @@ Ant only ships with one: the mavenrepository;
No |
-
- |
-
- |
- No |
-
Example:
@@ -158,6 +160,15 @@ Ant only ships with one: the mavenrepository;
mavenrepository
+
+This connects to the Maven repository at ibiblio.org, or another
+chosen. Private repositories should copy the existing layout.
+
+
+If no url
is set, the default URL is
+http://ibiblio.org/maven
, unless the property
+ant.maven.repository.url
is set to something else.
+
Attribute |
diff --git a/docs/manual/running.html b/docs/manual/running.html
index 877bacb79..83058184f 100644
--- a/docs/manual/running.html
+++ b/docs/manual/running.html
@@ -276,6 +276,18 @@ org.apache.tools.ant.Executor implementation specified here.
AnsiColorLogger.
+
+ ant.maven.repository.dir |
+ directory e.g. ${user.home}/.maven/repository |
+ Override the default download location for libraries.
+ |
+
+
+ ant.maven.repository.url |
+ URL e.g. http://ibiblio.org/maven |
+ Override the default source location for libraries.
+ |
+
ant.netrexxc.* |
several formats |
diff --git a/src/etc/testcases/taskdefs/libraries.xml b/src/etc/testcases/taskdefs/libraries.xml
index 7db66e892..a3ee66e04 100644
--- a/src/etc/testcases/taskdefs/libraries.xml
+++ b/src/etc/testcases/taskdefs/libraries.xml
@@ -2,10 +2,28 @@
+
+
-
+
+
+
+
+
+
+
+
+
+
+ proxy: ${proxy.host}:${proxy.port} [${proxy.user}/${proxy.pass}]
+
+
+
+
+
@@ -15,6 +33,9 @@
+
+
@@ -28,6 +49,21 @@
+
+
+
+
+ Not found: "@{repository}/@{library}"
+
+
+
+
+
+
+
+
+
+
+
-
-
-
- Found: ${@{library}.path}
+
+ Unexpectedly found: "@{repository}/@{library}"
+
+
+
-
+
@@ -77,6 +114,7 @@
+
@@ -85,7 +123,6 @@
-
@@ -202,12 +239,10 @@
-
-
@@ -215,7 +250,6 @@
-
@@ -223,7 +257,6 @@
-
diff --git a/src/main/org/apache/tools/ant/taskdefs/repository/Libraries.java b/src/main/org/apache/tools/ant/taskdefs/repository/Libraries.java
index 7454e5398..9ccc7d0ea 100644
--- a/src/main/org/apache/tools/ant/taskdefs/repository/Libraries.java
+++ b/src/main/org/apache/tools/ant/taskdefs/repository/Libraries.java
@@ -85,7 +85,7 @@ public final class Libraries extends Task {
private boolean flatten = false;
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_LIBRARIES = "No libraries declared";
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";
+ /**
+ * 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
*
@@ -107,6 +123,23 @@ public final class Libraries extends Task {
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
*
@@ -325,13 +358,12 @@ public final class Libraries extends Task {
* @throws BuildException
*/
public void validate() {
- if (destDir == null
- // || !destDir.isDirectory()
- ) {
- throw new BuildException(ERROR_NO_DEST_DIR);
+ if (destDir == null) {
+ destDir=locateDefaultDestDirectory();
}
if (repository == null) {
- throw new BuildException(ERROR_NO_REPOSITORY);
+ MavenRepository maven=(MavenRepository)getProject().createDataType(MavenRepository.TYPE_NAME);
+ repository=maven;
}
Iterator it = libraries.iterator();
while (it.hasNext()) {
@@ -365,9 +397,12 @@ public final class Libraries extends Task {
*/
private void doExecute() throws BuildException {
destDir.mkdirs();
+ //get the ultimate repository
Repository repo = repository.resolve();
+ //validate it
repo.validate();
if (libraries.size() == 0) {
+ //bail out on an empty library
throw new BuildException(ERROR_NO_LIBRARIES);
}
log("Getting libraries from " + repo.toString(), Project.MSG_VERBOSE);
diff --git a/src/main/org/apache/tools/ant/taskdefs/repository/MavenRepository.java b/src/main/org/apache/tools/ant/taskdefs/repository/MavenRepository.java
index 643c56335..611efc099 100644
--- a/src/main/org/apache/tools/ant/taskdefs/repository/MavenRepository.java
+++ b/src/main/org/apache/tools/ant/taskdefs/repository/MavenRepository.java
@@ -18,6 +18,7 @@
package org.apache.tools.ant.taskdefs.repository;
import org.apache.tools.ant.util.FileUtils;
+import org.apache.tools.ant.BuildException;
import java.io.File;
import java.io.FileInputStream;
@@ -48,12 +49,12 @@ public class MavenRepository extends HttpRepository {
* this is what we think the MD5 type is
*/
protected static final String MAVEN_MD5_FILE_TYPE = "US-ASCII";
+ public static final String TYPE_NAME = "mavenrepository";
/**
* bind to the main maven repository
*/
public MavenRepository() {
- setUrl(MAVEN_URL);
}
@@ -65,6 +66,29 @@ public class MavenRepository extends HttpRepository {
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
*
diff --git a/src/main/org/apache/tools/ant/taskdefs/repository/Repository.java b/src/main/org/apache/tools/ant/taskdefs/repository/Repository.java
index e1b035b3d..18dab297e 100644
--- a/src/main/org/apache/tools/ant/taskdefs/repository/Repository.java
+++ b/src/main/org/apache/tools/ant/taskdefs/repository/Repository.java
@@ -27,9 +27,9 @@ import java.io.IOException;
* 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.
*
- * 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
- * GetLibraries#setRepositoryRef(org.apache.tools.ant.types.Reference)}
+ * Libraries#setRepositoryRef(org.apache.tools.ant.types.Reference)}
*
* @since Ant1.7
*/
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/LibrariesTest.java b/src/testcases/org/apache/tools/ant/taskdefs/LibrariesTest.java
index 3bc9b71da..6d77d3c58 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/LibrariesTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/LibrariesTest.java
@@ -47,11 +47,11 @@ public class LibrariesTest extends BuildFileTest {
}
public void testEmpty() {
- expectBuildException("testEmpty",Libraries.ERROR_NO_DEST_DIR);
+ expectBuildException("testEmpty", Libraries.ERROR_NO_LIBRARIES);
}
public void testEmpty2() {
- expectBuildException("testEmpty2", Libraries.ERROR_NO_REPOSITORY);
+ expectBuildException("testEmpty2", Libraries.ERROR_NO_LIBRARIES);
}
public void testEmpty3() {
@@ -59,7 +59,7 @@ public class LibrariesTest extends BuildFileTest {
}
public void testNoRepo() {
- expectBuildException("testNoRepo", Libraries.ERROR_NO_REPOSITORY);
+ execIfOnline("testNoRepo");
}
public void testUnknownReference() {