/**
* 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$
{
/**
* 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;
}
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
* @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 )
{
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
{
{
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() );
}
{
/* do nothing */
}
-
+
private void initRepositoryMap()
{
synchronized ( this.repositoryMap )
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
- *
* @plexus.component role-hint="default"
*/
public class DefaultBidirectionalRepositoryLayout
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 );
}
{
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 );
{
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 );
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
{
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.
// 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;
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
- *
* @plexus.component role-hint="legacy"
*/
public class LegacyBidirectionalRepositoryLayout
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 )
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.
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 + ">" );
}
}
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 )
throws LayoutException
{
import org.apache.maven.archiva.model.ArchivaArtifact;
/**
- * BidirectionalRepositoryLayoutFactoryTest
+ * BidirectionalRepositoryLayoutFactoryTest
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
/* 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() );
+ }
}
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
* @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
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;
}
}
try
{
- versioned = layout.toVersionedReference( resource );
+ versioned = resourceLayout.toVersionedReference( resource );
if ( versioned != null )
{
connectors.fetchFromProxies( managedRepository, versioned );
+ request.getRequest().setPathInfo( layout.toPath( versioned ) );
return;
}
}
try
{
- project = layout.toProjectReference( resource );
+ project = resourceLayout.toProjectReference( resource );
if ( project != null )
{
connectors.fetchFromProxies( managedRepository, project );
+ request.getRequest().setPathInfo( layout.toPath( project ) );
return;
}
}