diff --git a/mrm-maven-plugin/src/it/hostedrepo/src/it/local-maven-repo-proxy/invoker.properties b/mrm-maven-plugin/src/it/hostedrepo/src/it/local-maven-repo-proxy/invoker.properties
new file mode 100644
index 00000000..ece61424
--- /dev/null
+++ b/mrm-maven-plugin/src/it/hostedrepo/src/it/local-maven-repo-proxy/invoker.properties
@@ -0,0 +1 @@
+invoker.goals = deploy
diff --git a/mrm-maven-plugin/src/it/hostedrepo/src/it/local-maven-repo-proxy/pom.xml b/mrm-maven-plugin/src/it/hostedrepo/src/it/local-maven-repo-proxy/pom.xml
new file mode 100644
index 00000000..1e4ab3ff
--- /dev/null
+++ b/mrm-maven-plugin/src/it/hostedrepo/src/it/local-maven-repo-proxy/pom.xml
@@ -0,0 +1,18 @@
+
+
+
+ 4.0.0
+
+
+
+ mrm
+ @mrm.distribution.url@
+
+
+
+ org.mojohaus.mrm.hostedrepo.its
+ deploy
+ 1.0.0
+ pom
+
+
diff --git a/mrm-maven-plugin/src/it/hostedrepo/src/it/local-maven-repo-proxy/verify.groovy b/mrm-maven-plugin/src/it/hostedrepo/src/it/local-maven-repo-proxy/verify.groovy
new file mode 100644
index 00000000..9035b087
--- /dev/null
+++ b/mrm-maven-plugin/src/it/hostedrepo/src/it/local-maven-repo-proxy/verify.groovy
@@ -0,0 +1,4 @@
+assert new File( basedir, '../../hosted-repo/org/mojohaus/mrm/hostedrepo/its/deploy/maven-metadata.xml').exists()
+assert new File( basedir, '../../hosted-repo/org/mojohaus/mrm/hostedrepo/its/deploy/1.0.0/deploy-1.0.0.pom').exists()
+assert new File( basedir, '../../hosted-repo/org/mojohaus/mrm/hostedrepo/its/deploy/1.0.0/deploy-1.0.0.pom.md5').exists()
+assert new File( basedir, '../../hosted-repo/org/mojohaus/mrm/hostedrepo/its/deploy/1.0.0/deploy-1.0.0.pom.sha1').exists()
diff --git a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/AbstractStartMojo.java b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/AbstractStartMojo.java
index 6759fdd3..9cfd4b12 100644
--- a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/AbstractStartMojo.java
+++ b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/AbstractStartMojo.java
@@ -41,6 +41,18 @@ public abstract class AbstractStartMojo
@Parameter( property = "mrm.port" )
private int port;
+ /**
+ * The base path under which the repository will be served.
+ *
+ * By default, {@code org.acme:my-artifact:pom:1.2.3} will be served under
+ * {@code http://localhost:/org/acme/my-artifact/1.2.3/my-artifact-1.2.3.pom}.
+ *
+ * If {@code basePath} is set to e.g. {@code foo/bar} then {@code org.acme:my-artifact:pom:1.2.3} will be served
+ * under {@code http://localhost:/foo/bar/org/acme/my-artifact/1.2.3/my-artifact-1.2.3.pom}.
+ */
+ @Parameter( property = "mrm.basePath", defaultValue = "/" )
+ private String basePath;
+
/**
* The repositories to serve. When more than one repository is specified, a merged repository view
* of those will be used. If none specified then a proxy of the invoking Maven's repositories will
@@ -59,13 +71,14 @@ protected FileSystemServer createFileSystemServer( ArtifactStore artifactStore )
{
return new FileSystemServer( ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ),
Math.max( 0, Math.min( port, 65535 ) ),
- new AutoDigestFileSystem( new ArtifactStoreFileSystem( artifactStore ) ),
+ basePath,
+ new AutoDigestFileSystem( new ArtifactStoreFileSystem( artifactStore ) ),
getSettingsServletPath() );
}
/**
- * When set, this points to the to the location from where the settings file can be downloaded.
- *
+ * When set, this points to the to the location from where the settings file can be downloaded.
+ *
* @return the servlet path to the settings file of {@code null}
*/
protected String getSettingsServletPath()
diff --git a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/FileSystemServer.java b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/FileSystemServer.java
index e9493ef8..8d99b5f7 100644
--- a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/FileSystemServer.java
+++ b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/FileSystemServer.java
@@ -95,7 +95,12 @@ public class FileSystemServer
* The port to try and serve on.
*/
private final int requestedPort;
-
+
+ /**
+ * The context path where to bind the {@code fileSystem}.
+ */
+ private final String contextPath;
+
/**
* The path to settingsFile containing the configuration to connect to this repository manager.
*/
@@ -108,14 +113,37 @@ public class FileSystemServer
* @param port The port to server on or 0
to pick a random, but available, port.
* @param fileSystem the file system to serve.
*/
- public FileSystemServer( String name, int port, FileSystem fileSystem, String settingsServletPath )
+ public FileSystemServer( String name, int port, String contextPath, FileSystem fileSystem, String settingsServletPath )
{
this.name = name;
this.fileSystem = fileSystem;
this.requestedPort = port;
+ this.contextPath = sanitizeContextPath(contextPath);
this.settingsServletPath = settingsServletPath;
}
+ /**
+ * Sanitize the given {@code contextPath} by prepending slash if necessary and/or removing the trailing slash if necessary
+ * @param contextPath the contextPath to sanitize
+ * @return sanitized {@code contextPath}
+ */
+ static String sanitizeContextPath(String contextPath)
+ {
+ if ( contextPath == null || contextPath.isEmpty() || contextPath.equals("/") )
+ {
+ return "/";
+ }
+ if ( !contextPath.startsWith("/") )
+ {
+ return "/" + contextPath;
+ }
+ if ( contextPath.endsWith("/") )
+ {
+ return contextPath.substring( 0, contextPath.length() - 1 );
+ }
+ return contextPath;
+ }
+
/**
* Ensures that the file system server is started (if already starting, will block until started, otherwise starts
* the file system server and blocks until started)
@@ -235,20 +263,21 @@ public int getPort()
*/
public String getUrl()
{
- return "http://localhost:" + getPort();
+ return "http://localhost:" + getPort() + (contextPath.equals("/") ? "" : contextPath);
}
/**
* Same as {@link #getUrl()}, but now for remote users
- *
- * @return the scheme + raw IP address + port
- * @throws UnknownHostException if the local host name could not be resolved into an address.
+ *
+ * @return the scheme + raw IP address + port + contextPath
+ * @throws UnknownHostException if the local host name could not be resolved into an address.
*/
public String getRemoteUrl() throws UnknownHostException
{
- return "http://" + InetAddress.getLocalHost().getHostAddress() + ":" + getPort();
+ return "http://" + InetAddress.getLocalHost().getHostAddress() + ":" + getPort()
+ + (contextPath.equals("/") ? "" : contextPath);
}
-
+
/**
* The work to monitor and control the Jetty instance that hosts the file system.
*/
@@ -264,7 +293,7 @@ public void run()
Server server = new Server(requestedPort);
try {
ServletContextHandler context = new ServletContextHandler();
- context.setContextPath("/");
+ context.setContextPath(contextPath);
context.addServlet(new ServletHolder(new FileSystemServlet(fileSystem, settingsServletPath)), "/*");
server.setHandler(context);
server.start();