You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by br...@apache.org on 2007/08/03 08:54:06 UTC
svn commit: r562356 - in /maven/archiva/trunk:
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/
archiva-web/a...
Author: brett
Date: Thu Aug 2 23:54:05 2007
New Revision: 562356
URL: http://svn.apache.org/viewvc?view=rev&rev=562356
Log:
[MRM-412] support legacy layout requests
Submitted by: nicolas de loof
Modified:
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayout.java
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactory.java
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactoryTest.java
maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java
Modified: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayout.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayout.java?view=diff&rev=562356&r1=562355&r2=562356
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayout.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayout.java Thu Aug 2 23:54:05 2007
@@ -26,7 +26,7 @@
/**
* BidirectionalRepositoryLayout - Similar in scope to ArtifactRepositoryLayout, but does
- * the both the Path to Artifact, and Artifact to Path conversions.
+ * the both the Path to Artifact, and Artifact to Path conversions.
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
@@ -35,80 +35,90 @@
{
/**
* Get the identifier for this layout.
- *
+ *
* @return the identifier for this layout.
*/
public String getId();
-
+
+ /**
+ * Given a repository relative path, return <code>true</code> if the path is valid
+ * according to the repository layout.
+ */
+ public boolean isValidPath( String path );
+
/**
* Given an ArchivaArtifact, return the relative path to the artifact.
- *
+ *
* @param artifact the artifact to use.
- * @return the relative path to the artifact.
+ * @return the relative path to the artifact.
*/
public String toPath( ArchivaArtifact artifact );
-
+
/**
* Given an ArtifactReference, return the relative path to the artifact.
- *
+ *
* @param reference the artifact reference to use.
- * @return the relative path to the artifact.
+ * @return the relative path to the artifact.
*/
public String toPath( ArtifactReference reference );
-
+
/**
* Given an {@link VersionedReference}, return the relative path to that reference.
- *
+ *
* @param reference the versioned project reference to use.
- * @return the relative path to the project reference.
+ * @return the relative path to the project reference.
*/
public String toPath( VersionedReference reference );
-
+
/**
* Given an ProjectReference, return the relative path to that reference.
- *
+ *
* @param reference the project reference to use.
- * @return the relative path to the project reference.
+ * @return the relative path to the project reference.
*/
public String toPath( ProjectReference reference );
/**
* Given a repository relative path to a filename, return the {@link ArchivaArtifact} object suitable for the path.
- *
+ *
* @param path the path relative to the repository base dir for the artifact.
- * @return the {@link ArchivaArtifact} representing the path. (or null if path cannot be converted to
+ * @return the {@link ArchivaArtifact} representing the path. (or null if path cannot be converted to
* an {@link ArchivaArtifact})
* @throws LayoutException if there was a problem converting the path to an artifact.
*/
- public ArchivaArtifact toArtifact( String path ) throws LayoutException;
-
+ public ArchivaArtifact toArtifact( String path )
+ throws LayoutException;
+
/**
* Given a repository relative path to a filename, return the {@link ProjectReference} object suitable for the path.
- *
+ *
* @param path the path relative to the repository base dir for the artifact.
- * @return the {@link ProjectReference} representing the path. (or null if path cannot be converted to
+ * @return the {@link ProjectReference} representing the path. (or null if path cannot be converted to
* a {@link ProjectReference})
* @throws LayoutException if there was a problem converting the path to an artifact.
*/
- public ProjectReference toProjectReference( String path ) throws LayoutException;
-
+ public ProjectReference toProjectReference( String path )
+ throws LayoutException;
+
/**
* Given a repository relative path to a filename, return the {@link VersionedReference} object suitable for the path.
- *
+ *
* @param path the path relative to the repository base dir for the artifact.
- * @return the {@link VersionedReference} representing the path. (or null if path cannot be converted to
+ * @return the {@link VersionedReference} representing the path. (or null if path cannot be converted to
* a {@link VersionedReference})
* @throws LayoutException if there was a problem converting the path to an artifact.
*/
- public VersionedReference toVersionedReference( String path ) throws LayoutException;
-
+ public VersionedReference toVersionedReference( String path )
+ throws LayoutException;
+
/**
* Given a repository relative path to a filename, return the {@link VersionedReference} object suitable for the path.
- *
+ *
* @param path the path relative to the repository base dir for the artifact.
- * @return the {@link ArtifactReference} representing the path. (or null if path cannot be converted to
+ * @return the {@link ArtifactReference} representing the path. (or null if path cannot be converted to
* a {@link ArtifactReference})
* @throws LayoutException if there was a problem converting the path to an artifact.
*/
- public ArtifactReference toArtifactReference( String path ) throws LayoutException;
+ public ArtifactReference toArtifactReference( String path )
+ throws LayoutException;
}
Modified: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactory.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactory.java?view=diff&rev=562356&r1=562355&r2=562356
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactory.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactory.java Thu Aug 2 23:54:05 2007
@@ -31,14 +31,14 @@
import org.codehaus.plexus.registry.RegistryListener;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
/**
- * BidirectionalRepositoryLayoutFactory
+ * BidirectionalRepositoryLayoutFactory
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
- *
* @plexus.component role="org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory"
*/
public class BidirectionalRepositoryLayoutFactory
@@ -49,12 +49,12 @@
* @plexus.requirement role="org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout"
*/
private Map layouts;
-
+
/**
* @plexus.requirement
*/
private ArchivaConfiguration configuration;
-
+
private Map repositoryMap = new HashMap();
public BidirectionalRepositoryLayout getLayout( String type )
@@ -62,13 +62,28 @@
{
if ( !layouts.containsKey( type ) )
{
- throw new LayoutException( "Layout type [" + type + "] does not exist. " + "Available types ["
- + layouts.keySet() + "]" );
+ throw new LayoutException(
+ "Layout type [" + type + "] does not exist. " + "Available types [" + layouts.keySet() + "]" );
}
return (BidirectionalRepositoryLayout) layouts.get( type );
}
+ public BidirectionalRepositoryLayout getLayoutForPath( String path )
+ throws LayoutException
+ {
+ for ( Iterator iter = layouts.values().iterator(); iter.hasNext(); )
+ {
+ BidirectionalRepositoryLayout layout = (BidirectionalRepositoryLayout) iter.next();
+ if ( layout.isValidPath( path ) )
+ {
+ return layout;
+ }
+ }
+ throw new LayoutException( "No valid layout was found for path [" + path + "]" );
+ }
+
+
public BidirectionalRepositoryLayout getLayout( ArchivaArtifact artifact )
throws LayoutException
{
@@ -76,13 +91,13 @@
{
throw new LayoutException( "Cannot determine layout using a null artifact." );
}
-
+
String repoId = artifact.getModel().getRepositoryId();
if ( StringUtils.isBlank( repoId ) )
{
throw new LayoutException( "Cannot determine layout using artifact with no repository id: " + artifact );
}
-
+
RepositoryConfiguration repo = (RepositoryConfiguration) this.repositoryMap.get( repoId );
return getLayout( repo.getLayout() );
}
@@ -99,7 +114,7 @@
{
/* do nothing */
}
-
+
private void initRepositoryMap()
{
synchronized ( this.repositoryMap )
Modified: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java?view=diff&rev=562356&r1=562355&r2=562356
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java Thu Aug 2 23:54:05 2007
@@ -32,7 +32,6 @@
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
- *
* @plexus.component role-hint="default"
*/
public class DefaultBidirectionalRepositoryLayout
@@ -134,7 +133,8 @@
path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR );
path.append( reference.getArtifactId() ).append( PATH_SEPARATOR );
- if( reference.getVersion() != null ) {
+ if ( reference.getVersion() != null )
+ {
// add the version only if it is present
path.append( VersionUtil.getBaseVersion( reference.getVersion() ) ).append( PATH_SEPARATOR );
}
@@ -148,8 +148,8 @@
{
if ( !path.endsWith( "/maven-metadata.xml" ) )
{
- throw new LayoutException( "Only paths ending in '/maven-metadata.xml' can be "
- + "converted to a ProjectReference." );
+ throw new LayoutException(
+ "Only paths ending in '/maven-metadata.xml' can be " + "converted to a ProjectReference." );
}
PathReferences pathrefs = toPathReferences( path, false );
@@ -165,8 +165,8 @@
{
if ( !path.endsWith( "/maven-metadata.xml" ) )
{
- throw new LayoutException( "Only paths ending in '/maven-metadata.xml' can be "
- + "converted to a VersionedReference." );
+ throw new LayoutException(
+ "Only paths ending in '/maven-metadata.xml' can be " + "converted to a VersionedReference." );
}
PathReferences pathrefs = toPathReferences( path, false );
@@ -211,6 +211,19 @@
return path.toString();
}
+ public boolean isValidPath( String path )
+ {
+ try
+ {
+ toPathReferences( path, false );
+ return true;
+ }
+ catch ( LayoutException e )
+ {
+ return false;
+ }
+ }
+
private PathReferences toPathReferences( String path, boolean parseFilename )
throws LayoutException
{
@@ -232,8 +245,8 @@
if ( pathParts.length < 4 )
{
// Illegal Path Parts Length.
- throw new LayoutException( "Not enough parts to the path [" + path
- + "] to construct an ArchivaArtifact from. (Requires at least 4 parts)" );
+ throw new LayoutException( "Not enough parts to the path [" + path +
+ "] to construct an ArchivaArtifact from. (Requires at least 4 parts)" );
}
// Maven 2.x path.
@@ -246,9 +259,9 @@
// Second to last is the baseVersion (the directory version)
prefs.baseVersion = pathParts[baseVersionPos];
- if ( "maven-metadata.xml".equals( pathParts[filenamePos] ) )
+ if ( "maven-metadata.xml".equals( pathParts[filenamePos] ) )
{
- if( !VersionUtil.isVersion( prefs.baseVersion ) )
+ if ( !VersionUtil.isVersion( prefs.baseVersion ) )
{
// We have a simple path without a version identifier.
prefs.baseVersion = null;
Modified: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java?view=diff&rev=562356&r1=562355&r2=562356
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java Thu Aug 2 23:54:05 2007
@@ -34,7 +34,6 @@
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
- *
* @plexus.component role-hint="legacy"
*/
public class LegacyBidirectionalRepositoryLayout
@@ -63,8 +62,8 @@
public String toPath( ArchivaArtifact artifact )
{
- return toPath( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
- artifact.getClassifier(), artifact.getType() );
+ return toPath( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier(),
+ artifact.getType() );
}
public String toPath( ProjectReference reference )
@@ -177,8 +176,8 @@
if ( pathParts.length != 3 )
{
// Illegal Path Parts Length.
- throw new LayoutException( "Invalid number of parts to the path [" + path
- + "] to construct an ArchivaArtifact from. (Required to be 3 parts)" );
+ throw new LayoutException( "Invalid number of parts to the path [" + path +
+ "] to construct an ArchivaArtifact from. (Required to be 3 parts)" );
}
// The Group ID.
@@ -204,9 +203,9 @@
if ( !prefs.type.equals( prefs.fileParts.extension ) )
{
- throw new LayoutException( "Invalid artifact, mismatch on extension <" + prefs.fileParts.extension
- + "> and expected layout specified type <" + prefs.pathType + "> (mapped type: <" + prefs.type
- + ">) on path <" + path + ">" );
+ throw new LayoutException( "Invalid artifact, mismatch on extension <" + prefs.fileParts.extension +
+ "> and expected layout specified type <" + prefs.pathType + "> (mapped type: <" + prefs.type +
+ ">) on path <" + path + ">" );
}
}
@@ -217,6 +216,19 @@
throws LayoutException
{
throw new LayoutException( "Cannot parse legacy paths to a Project Reference." );
+ }
+
+ public boolean isValidPath( String path )
+ {
+ try
+ {
+ toPathReferences( path, false );
+ return true;
+ }
+ catch ( LayoutException e )
+ {
+ return false;
+ }
}
public ArchivaArtifact toArtifact( String path )
Modified: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactoryTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactoryTest.java?view=diff&rev=562356&r1=562355&r2=562356
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactoryTest.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactoryTest.java Thu Aug 2 23:54:05 2007
@@ -22,7 +22,7 @@
import org.apache.maven.archiva.model.ArchivaArtifact;
/**
- * BidirectionalRepositoryLayoutFactoryTest
+ * BidirectionalRepositoryLayoutFactoryTest
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
@@ -73,5 +73,16 @@
{
/* expected path */
}
+ }
+
+ public void testFindLayoutForPath()
+ throws LayoutException
+ {
+ BidirectionalRepositoryLayout layout =
+ factory.getLayoutForPath( "javax/servlet/servlet-api/2.3/servlet-api-2.3.jar" );
+ assertEquals( "default", layout.getId() );
+
+ layout = factory.getLayoutForPath( "javax.servlet/jars/servlet-api-2.3.jar" );
+ assertEquals( "legacy", layout.getId() );
}
}
Modified: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java?view=diff&rev=562356&r1=562355&r2=562356
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java (original)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java Thu Aug 2 23:54:05 2007
@@ -38,12 +38,11 @@
import org.codehaus.plexus.webdav.servlet.DavServerRequest;
import org.codehaus.plexus.webdav.util.WebdavMethodUtil;
-import java.io.File;
-import java.io.IOException;
-
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
/**
* ProxiedDavServer
@@ -51,8 +50,8 @@
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
* @version $Id$
* @plexus.component role="org.codehaus.plexus.webdav.DavServerComponent"
- * role-hint="proxied"
- * instantiation-strategy="per-lookup"
+ * role-hint="proxied"
+ * instantiation-strategy="per-lookup"
*/
public class ProxiedDavServer
extends AbstractDavServerComponent
@@ -154,13 +153,25 @@
ProjectReference project;
VersionedReference versioned;
ArtifactReference artifact;
+ BidirectionalRepositoryLayout resourceLayout;
+
+ try
+ {
+ resourceLayout = layoutFactory.getLayoutForPath( resource );
+ }
+ catch ( LayoutException e )
+ {
+ /* invalid request - eat it */
+ return;
+ }
try
{
- artifact = layout.toArtifactReference( resource );
+ artifact = resourceLayout.toArtifactReference( resource );
if ( artifact != null )
{
connectors.fetchFromProxies( managedRepository, artifact );
+ request.getRequest().setPathInfo( layout.toPath( artifact ) );
return;
}
}
@@ -171,10 +182,11 @@
try
{
- versioned = layout.toVersionedReference( resource );
+ versioned = resourceLayout.toVersionedReference( resource );
if ( versioned != null )
{
connectors.fetchFromProxies( managedRepository, versioned );
+ request.getRequest().setPathInfo( layout.toPath( versioned ) );
return;
}
}
@@ -185,10 +197,11 @@
try
{
- project = layout.toProjectReference( resource );
+ project = resourceLayout.toProjectReference( resource );
if ( project != null )
{
connectors.fetchFromProxies( managedRepository, project );
+ request.getRequest().setPathInfo( layout.toPath( project ) );
return;
}
}