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 2010/07/03 15:17:55 UTC
svn commit: r960217 - in /gump/mvnrepo/trunk: build.xml
src/java/org/apache/gump/mvnrepoproxy/HostResolver.java
src/java/org/apache/gump/mvnrepoproxy/Main.java
src/java/org/apache/gump/mvnrepoproxy/hostresolver.properties
Author: bodewig
Date: Sat Jul 3 13:17:55 2010
New Revision: 960217
URL: http://svn.apache.org/viewvc?rev=960217&view=rev
Log:
read map of URL prefix to real repository from optional properties file
Added:
gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/hostresolver.properties (with props)
Modified:
gump/mvnrepo/trunk/build.xml
gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/HostResolver.java
gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/Main.java
Modified: gump/mvnrepo/trunk/build.xml
URL: http://svn.apache.org/viewvc/gump/mvnrepo/trunk/build.xml?rev=960217&r1=960216&r2=960217&view=diff
==============================================================================
--- gump/mvnrepo/trunk/build.xml (original)
+++ gump/mvnrepo/trunk/build.xml Sat Jul 3 13:17:55 2010
@@ -9,7 +9,8 @@
</target>
<target name="clean">
- <delete dir="${classes.dir}"/>
+ <delete dir="${build.dir}"/>
+ <delete file="${target.jar}"/>
</target>
<target name="compile" depends="init">
@@ -35,6 +36,7 @@
<attribute name="Class-Path" value="${manifest.classpath}"/>
</manifest>
<fileset dir="${classes.dir}"/>
+ <fileset dir="src/java" includes="**/*.properties"/>
</jar>
</target>
Modified: gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/HostResolver.java
URL: http://svn.apache.org/viewvc/gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/HostResolver.java?rev=960217&r1=960216&r2=960217&view=diff
==============================================================================
--- gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/HostResolver.java (original)
+++ gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/HostResolver.java Sat Jul 3 13:17:55 2010
@@ -19,8 +19,11 @@
package org.apache.gump.mvnrepoproxy;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Properties;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.logging.Logger;
/**
* Support for proxying more than one repository by guessing the
@@ -31,6 +34,9 @@ import java.util.Map;
*/
public class HostResolver {
+ private static final Logger LOG =
+ Logger.getLogger(HostResolver.class.getName());
+
/**
* Real central Maven repository in the format http://hostname with no
* trailing slash.
@@ -41,15 +47,15 @@ public class HostResolver {
private static final Map<String, String> PREFIX_2_HOST =
new LinkedHashMap<String, String>();
- static {
- PREFIX_2_HOST.put("/maven2", CENTRAL_MVN_REPO_HOST);
- PREFIX_2_HOST.put("/repo/m2-snapshot-repository",
- "http://people.apache.org");
- PREFIX_2_HOST.put("/maven/2",
- "http://download.java.net");
- // old and doesn't work if proxied
- PREFIX_2_HOST.put("/nonav/repository",
- "https://maven2-repository.dev.java.net");
+ static void initialize(Properties props) {
+ for (Object key : Collections.list(props.propertyNames())) {
+ if (key instanceof String) {
+ @SuppressWarnings("Unchecked") String prefix = (String) key;
+ LOG.info("Mapping " + prefix + " to "
+ + props.getProperty(prefix));
+ PREFIX_2_HOST.put(prefix, props.getProperty(prefix));
+ }
+ }
}
/**
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=960217&r1=960216&r2=960217&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 Sat Jul 3 13:17:55 2010
@@ -18,7 +18,10 @@
package org.apache.gump.mvnrepoproxy;
+import java.io.FileInputStream;
+import java.io.InputStream;
import java.util.Map;
+import java.util.Properties;
import org.apache.gump.mvnrepoproxy.resources.ArtifactsForm;
import org.apache.gump.mvnrepoproxy.resources.Jar;
@@ -68,13 +71,43 @@ public class Main {
* Starts Jetty with the application
*/
public static void main(String[] args) throws Exception {
- if (args.length > 1) {
- System.err.println("org.apache.gump.mvnrepoproxyproxy.Main [port]");
+ if (args.length > 2) {
+ System.err.println("org.apache.gump.mvnrepoproxyproxy.Main [port]"
+ + " [prefixmap]");
System.exit(0);
}
int exitCode = 0;
try {
- int port = args.length > 0 ? Integer.valueOf(args[0]) : 8192;
+ int port = 8192;
+ int consumed = 0;
+ if (args.length > 0) {
+ try {
+ port = Integer.valueOf(args[0]);
+ consumed++;
+ } catch (NumberFormatException ex) {
+ // first arg is properties file
+ }
+ }
+
+ Properties props = new Properties();
+ InputStream is = null;
+ try {
+ if (args.length > consumed) {
+ System.err.println("Loading prefix map from "
+ + args[consumed]);
+ is = new FileInputStream(args[consumed++]);
+ } else {
+ is = Main.class
+ .getResourceAsStream("hostresolver.properties");
+ }
+ props.load(is);
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ }
+ HostResolver.initialize(props);
+
Component c = getRepositoryComponent();
c.getServers().add(Protocol.HTTP, port);
c.getClients().add(Protocol.HTTP);
Added: gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/hostresolver.properties
URL: http://svn.apache.org/viewvc/gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/hostresolver.properties?rev=960217&view=auto
==============================================================================
--- gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/hostresolver.properties (added)
+++ gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/hostresolver.properties Sat Jul 3 13:17:55 2010
@@ -0,0 +1,2 @@
+/maven2=http\://repo1.maven.org
+/repo/m2-snapshot-repository=http\://people.apache.org
Propchange: gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepoproxy/hostresolver.properties
------------------------------------------------------------------------------
svn:eol-style = native