You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gump.apache.org by bo...@apache.org on 2009/03/31 07:36:32 UTC
svn commit: r760341 - in
/gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy: Constants.java
Main.java resources/GumpArtifact.java
Author: bodewig
Date: Tue Mar 31 05:36:31 2009
New Revision: 760341
URL: http://svn.apache.org/viewvc?rev=760341&view=rev
Log:
experiment with proxying more than one repo - doesn't work yet
Modified:
gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/Constants.java
gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/Main.java
gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/resources/GumpArtifact.java
Modified: gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/Constants.java
URL: http://svn.apache.org/viewvc/gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/Constants.java?rev=760341&r1=760340&r2=760341&view=diff
==============================================================================
--- gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/Constants.java (original)
+++ gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/Constants.java Tue Mar 31 05:36:31 2009
@@ -34,14 +34,16 @@
* parameter representing the artifact id
*/
String ARTIFACT_ID = "artifactId";
+ /**
+ * URL-Prefix
+ */
+ String PREFIX = "prefix";
/**
* URL template that matches requests for jars by mvn
*/
String JAR_ARTIFACT_TEMPLATE
- = "/maven2/{" + GROUP_ID + "}/{" + ARTIFACT_ID
- + "}/{version}/{jarname}.jar";
-
+ = "/{" + GROUP_ID + "}/{" + ARTIFACT_ID + "}/{version}/{jarname}.jar";
/**
* parameter representing the checksum algorithm
@@ -70,9 +72,25 @@
Variant CHECKSUM_VARIANT = new Variant(MediaType.TEXT_PLAIN);
/**
- * Real Maven repository in the format http://hostname with no
+ * URL prefix used by the central repository.
+ */
+ String CENTRAL_PREFIX = "maven2";
+
+ /**
+ * URL prefix used by the Apache Snapshot repository.
+ */
+ String APACHE_SNAPSHOT_PREFIX = "repo/m2-snapshot-repository";
+
+ /**
+ * Real central Maven repository in the format http://hostname with no
+ * trailing slash.
+ */
+ String CENTRAL_MVN_REPO_HOST = "http://repo1.maven.org";
+
+ /**
+ * Real Apache snapshots repository in the format http://hostname with no
* trailing slash.
*/
- String MVN_REPO_HOST = "http://repo1.maven.org";
+ String APACHE_SNAPSHOT_MVN_REPO_HOST = "http://people.apache.org";
}
\ No newline at end of file
Modified: gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/Main.java
URL: http://svn.apache.org/viewvc/gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/Main.java?rev=760341&r1=760340&r2=760341&view=diff
==============================================================================
--- gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/Main.java (original)
+++ gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/Main.java Tue Mar 31 05:36:31 2009
@@ -18,6 +18,8 @@
package org.apache.gump.mvnrepoproxy;
+import java.util.Map;
+
import org.apache.gump.mvnrepoproxy.resources.ArtifactsForm;
import org.apache.gump.mvnrepoproxy.resources.Checksum;
import org.apache.gump.mvnrepoproxy.resources.Jar;
@@ -96,16 +98,8 @@
.createChildContext());
// known artifacts or proxy requests for jars
- Route r = router.attach(Constants.JAR_ARTIFACT_TEMPLATE,
- Jar.class);
- r.getTemplate().getVariables()
- .put(Constants.GROUP_ID,
- new Variable(Variable.TYPE_URI_PATH));
- r = router.attach(Constants.CHECKSUM_ARTIFACT_TEMPLATE,
- Checksum.class);
- r.getTemplate().getVariables()
- .put(Constants.GROUP_ID,
- new Variable(Variable.TYPE_URI_PATH));
+ attachResources(router, Constants.APACHE_SNAPSHOT_PREFIX);
+ attachResources(router, Constants.CENTRAL_PREFIX);
// other resources
router.attach("/proxyLog.html", LogFile.class);
@@ -113,9 +107,9 @@
router.attach("/addartifact.html", ArtifactsForm.class);
// Restlet that registers artifacts
- r = router.attach("/addartifact",
- new ArtifactAdder(getContext()
- .createChildContext()));
+ Route r = router.attach("/addartifact",
+ new ArtifactAdder(getContext()
+ .createChildContext()));
r.extractEntity(Constants.GROUP_ID,
Constants.GROUP_ID, true);
r.extractEntity(Constants.ARTIFACT_ID,
@@ -128,10 +122,19 @@
.createChildContext(),
component));
+ // Proxy for Apache Snapshot Repo
+ router.attach("/" + Constants.APACHE_SNAPSHOT_PREFIX + "/",
+ new Proxy(getContext()
+ .createChildContext(),
+ Constants.APACHE_SNAPSHOT_MVN_REPO_HOST
+ + "/"
+ + Constants.APACHE_SNAPSHOT_PREFIX
+ + "/{rr}"));
+
// catch all - proxy to real repository
router.attach("/", new Proxy(getContext()
.createChildContext(),
- Constants.MVN_REPO_HOST
+ Constants.CENTRAL_MVN_REPO_HOST
+ "/{rr}"));
return router;
@@ -141,4 +144,23 @@
component.getDefaultHost().attach(repoApp);
return component;
}
+
+ private static void attachResources(Router router, String prefix) {
+ attachResource(router, prefix, Constants.JAR_ARTIFACT_TEMPLATE,
+ Jar.class);
+ attachResource(router, prefix, Constants.CHECKSUM_ARTIFACT_TEMPLATE,
+ Checksum.class);
+ }
+
+ private static void attachResource(Router router, String prefix,
+ String uriTemplate, Class clazz) {
+ Route r = router.attach("/" + prefix + uriTemplate, clazz);
+ prepareVariables(r, prefix);
+ }
+
+ private static void prepareVariables(Route r, String prefix) {
+ Map<String, Variable> vars = r.getTemplate().getVariables();
+ vars.put(Constants.GROUP_ID,
+ new Variable(Variable.TYPE_URI_PATH));
+ }
}
Modified: gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/resources/GumpArtifact.java
URL: http://svn.apache.org/viewvc/gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/resources/GumpArtifact.java?rev=760341&r1=760340&r2=760341&view=diff
==============================================================================
--- gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/resources/GumpArtifact.java (original)
+++ gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/resources/GumpArtifact.java Tue Mar 31 05:36:31 2009
@@ -66,9 +66,14 @@
log("serving " + fileName + " as");
return getRepresentation(fileName);
} else {
- log("proxying");
- return new Proxy(getContext(),
- Constants.MVN_REPO_HOST + getURITemplate())
+ String uriTemplate = getURITemplate();
+ log("template is " + uriTemplate);
+ String host =
+ uriTemplate.startsWith("/" + Constants.APACHE_SNAPSHOT_PREFIX)
+ ? Constants.APACHE_SNAPSHOT_MVN_REPO_HOST
+ : Constants.CENTRAL_MVN_REPO_HOST;
+ log("proxying for " + host + ":");
+ return new Proxy(getContext(), host + uriTemplate)
.serve(getRequest(), getResponse());
}
}