dion 02/05/02 23:03:26
Modified: src/java/org/apache/maven ProjectVerifier.java
xdocs/ref properties.xml
src/java/org/apache/maven/util HttpUtils.java
Log:
Glenn McAllister's patch for multiple maven jar repositories.
Currently if you specify a dependancy on a jar, it is downloaded from only
one place - the URL pointed to by the maven.repo.remote property. This is
fine for maven itself, but what about organizations that want a "local"
remote repository of jars in addition to those provided by Maven?
This patch permits the maven.repo.remote property to be a comma separated
list of URLs, providing the ability to have multiple "remote" repositories
of pre-built jars.
Revision Changes Path
1.2 +84 -20
jakarta-turbine-maven/src/java/org/apache/maven/ProjectVerifier.java
Index: ProjectVerifier.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/ProjectVerifier.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProjectVerifier.java 22 Apr 2002 20:21:57 -0000 1.1
+++ ProjectVerifier.java 3 May 2002 06:03:26 -0000 1.2
@@ -59,12 +59,15 @@
import java.io.FileReader;
import java.net.URL;
+import java.net.MalformedURLException;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.ArrayList;
import java.util.Map;
+import java.util.StringTokenizer;
import org.apache.commons.lang.Strings;
@@ -78,7 +81,7 @@
* and make sure they are all here before trying to compile.
*
* @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: ProjectVerifier.java,v 1.1 2002/04/22 20:21:57 jvanzyl Exp $
+ * @version $Id: ProjectVerifier.java,v 1.2 2002/05/03 06:03:26 dion Exp $
* @task Create a list of all things that could go wrong and then protect
* against them.
* @task Merge the XML POM validation mechanism in here.
@@ -92,9 +95,9 @@
private String mavenLocalRepo;
/**
- * Maven remote repo
+ * Maven remote repo locations
*/
- private String mavenRemoteRepo;
+ private List mavenRemoteRepos = new ArrayList();
/**
* Verbosity during downloading of missing resources.
@@ -148,7 +151,7 @@
}
/**
- * Sets the mavenLocalRepo attribute of the Get object
+ * Sets the mavenLocalRepo attribute.
*/
public void setMavenLocalRepo(String mavenLocalRepo)
{
@@ -164,19 +167,24 @@
}
/**
- * Sets the mavenRemoteRepo attribute of the Get object
+ * Sets the mavenRemoteRepo attribute. This can be a comma separated list
+ * of URLs.
*/
public void setMavenRemoteRepo(String mavenRemoteRepo)
{
- this.mavenRemoteRepo = mavenRemoteRepo;
+ StringTokenizer st = new StringTokenizer( mavenRemoteRepo, "," );
+ while (st.hasMoreTokens())
+ {
+ mavenRemoteRepos.add( st.nextToken() );
+ }
}
/**
- * Get the maven remote repo.
+ * Get the maven remote repository list of URLs.
*/
- public String getMavenRemoteRepo()
+ public List getMavenRemoteRepo()
{
- return mavenRemoteRepo;
+ return mavenRemoteRepos;
}
/**
@@ -217,19 +225,34 @@
// them for the user.
if (failedDependencies.size() > 0)
{
- File f = new File(getMavenLocalRepo(), NON_DIST_JAR_LIST);
-
- HttpUtils.getFile(new URL(getMavenRemoteRepo() + NON_DIST_JAR_LIST),
- f, NON_DIST_JAR_LIST,verbose,
- ignoreErrors,useTimestamp,"","");
+ File f = new File(getMavenLocalRepo(), NON_DIST_JAR_LIST);
- Map nonDistMap = getNonDistMap(f);
+ Map nonDistMap;
+ if (!getNonDistFile( f ))
+ {
+ StringBuffer msg = new StringBuffer( 128 );
+ msg.append("-----------------------------------------------\n")
+ .append("W A R N I N G\n")
+ .append("-----------------------------------------------\n")
+ .append("Failed to download list of non-distributable\n")
+ .append("jars ")
+ .append(NON_DIST_JAR_LIST)
+ .append("\n")
+ .append("Will continue with attempted downloads of ")
+ .append("dependent jars.\n\n" );
+
+ log( msg.toString() );
+
+ nonDistMap = new HashMap(0);
+ }
+ else
+ {
+ nonDistMap = getNonDistMap(f);
+ }
for (Iterator i = failedDependencies.iterator(); i.hasNext();)
{
String dependency = (String) i.next();
- log("Retrieving missing dependency: " + dependency);
- URL url = new URL(mavenRemoteRepo + dependency);
File destinationFile = new File(getMavenLocalRepo(),dependency);
if (nonDistMap.containsKey(dependency))
@@ -254,9 +277,16 @@
}
continue;
}
-
- HttpUtils.getFile(url, destinationFile, dependency, verbose,
- ignoreErrors, useTimestamp,"","");
+
+ if (!getRemoteFile( dependency, destinationFile ))
+ {
+
warnings.append("-------------------------------------------------\n")
+ .append("W A R N I N G\n")
+
.append("------------------------------------------------\n")
+ .append("Failed to download dependent file ")
+ .append(dependency)
+ .append("\n\n");
+ }
}
}
@@ -269,6 +299,40 @@
// continue.
getProject().setProperty("verificationFailed","true");
}
+ }
+
+ /**
+ * Download the list of non-distributable jars.
+ */
+ private boolean getNonDistFile(File f)
+ {
+ return getRemoteFile( f.getName(), f );
+ }
+
+ private boolean getRemoteFile( String remoteFile, File localFile )
+ {
+ boolean gotFile = false;
+ Iterator remoteIter = getMavenRemoteRepo().iterator();
+
+ while (!gotFile && remoteIter.hasNext())
+ {
+ String remoteRepo = (String)remoteIter.next();
+ try
+ {
+ gotFile = HttpUtils.getFile( new URL(remoteRepo + remoteFile),
+ localFile, remoteFile, verbose,
+ ignoreErrors, useTimestamp,
+ "", "" );
+ }
+ catch (MalformedURLException mue)
+ {
+ mue.printStackTrace();
+ log("Cannot retrieve " + remoteFile + " from " + remoteRepo +
+ "; malformed URL" );
+ }
+ }
+
+ return gotFile;
}
/**
1.3 +7 -5 jakarta-turbine-maven/xdocs/ref/properties.xml
Index: properties.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/xdocs/ref/properties.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- properties.xml 2 May 2002 16:03:06 -0000 1.2
+++ properties.xml 3 May 2002 06:03:26 -0000 1.3
@@ -104,11 +104,13 @@
<td>maven.repo.remote</td>
<td>Yes</td>
<td>
- Specifies the URL to a central JAR repository that is used
- when the <a
href="build-file.html#maven:verify-project">maven:verify-project</a>
- target is invoked (this target is not normally invoked
- directly by users as its invoked automatically by Maven upon
- every invocation). The default value of this property is <a
+ Specifies a comma separated list of URLs to one or more
+ central JAR repositories used
+ when the <a href="build-file.html#maven:verify-project">
+ maven:verify-project</a> target is invoked (this target is not
+ normally invoked directly by users as its invoked automatically
+ by Maven upon every invocation) to retrieve required dependencies.
+ The default value of this property is <a
href="http://jakarta.apache.org/turbine/jars/">http://jakarta.apache.org/turbine/jars</a>.
</td>
</tr>
1.2 +20 -19
jakarta-turbine-maven/src/java/org/apache/maven/util/HttpUtils.java
Index: HttpUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/util/HttpUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HttpUtils.java 11 Apr 2002 11:57:40 -0000 1.1
+++ HttpUtils.java 3 May 2002 06:03:26 -0000 1.2
@@ -54,23 +54,24 @@
* <http://www.apache.org/>.
*/
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.FileReader;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
-import java.util.Date;
+import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
-import java.io.BufferedReader;
-import java.io.FileReader;
/**
* Http utils for retrieving files.
@@ -81,10 +82,15 @@
*/
public class HttpUtils
{
- public static void getFile(URL source, File destinationFile, String file,
+ /**
+ * Retrieve a remote file. Returns true if the file was successfully
+ * retrieved or if it is up to date (when the useTimestamp flag is set).
+ */
+ public static boolean getFile(URL source, File destinationFile, String file,
boolean verbose, boolean ignoreErrors, boolean
useTimestamp,
String uname, String pword)
{
+ boolean retrievedFile = false;
try
{
logx("Getting: " + source);
@@ -147,13 +153,13 @@
//and trace out something so the user doesn't think that the
//download happened when it didnt
logx("Not modified - so not downloaded");
- return;
+ return true;
}
// test for 401 result (HTTP only)
if (httpConnection.getResponseCode() ==
HttpURLConnection.HTTP_UNAUTHORIZED)
{
logx("Not authorized - check " + destinationFile + " for
details");
- return;
+ return false;
}
}
@@ -182,7 +188,7 @@
logx("Can't get " + file + " to " + destinationFile);
if (ignoreErrors)
{
- return;
+ return false;
}
throw new Exception(
"Can't get " + file + " to " + destinationFile);
@@ -217,25 +223,20 @@
touchFile(destinationFile, remoteTimestamp);
}
}
+
+ retrievedFile = true;
}
- catch (IOException ioe)
+ catch (FileNotFoundException fnfe)
{
- ioe.printStackTrace();
-
- logx("Error getting " + file + " to " + destinationFile);
- if (ignoreErrors)
- {
- return;
- }
-
- // We don't ever really want to throw an exception
- // just want to truck along.
- //throw new Exception(ioe.getMessage());
+ logx( "Error getting " + source + " ; it does not exist." );
}
catch (Exception e)
{
e.printStackTrace();
+ logx("Error getting " + file + " to " + destinationFile);
}
+
+ return retrievedFile;
}