]> source.dussan.org Git - archiva.git/commitdiff
Changing maven implementation to new RequestInfo interface
authorMartin Stockhammer <martin_s@apache.org>
Thu, 9 May 2019 20:58:14 +0000 (22:58 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Thu, 9 May 2019 20:58:14 +0000 (22:58 +0200)
archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepository.java
archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java
archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicManagedRepository.java
archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfo.java [new file with mode: 0644]
archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java [deleted file]
archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java
archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfoTest.java [new file with mode: 0644]
archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java [deleted file]
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java

index 1dea02bb1006bf82c80e173af20de0d4622c6cb6..3acd1619860ca245268bab9045b4797deffd0aba 100644 (file)
@@ -47,4 +47,11 @@ public interface ManagedRepository extends Repository {
      */
     Set<ReleaseScheme> getActiveReleaseSchemes();
 
+
+    /**
+     * Returns the request info object, which you can use for gathering information from the web request path.
+     * @return Instance of a request info object that corresponds to this repository
+     */
+    RepositoryRequestInfo getRequestInfo();
+
 }
index 043c09cce254379c05d2a8fb0fefda1bf7b77f30..ecc97b8446737dee81c59f3ccb9b74a5a03ebbb6 100644 (file)
@@ -118,7 +118,7 @@ public interface RepositoryRequestInfo
      * @return the adjusted (to native) path.
      * @throws LayoutException if the path cannot be parsed.
      */
-    void toNativePath( String requestPath);
+    String toNativePath( String requestPath)  throws LayoutException;
 
     /**
      * Extension method that allows to provide different features that are not supported by all
index d424862a9245802f617434974d6391b7bf170a57..d45daead60f525f70fe7f2a0d3dda2df5ee737fc 100644 (file)
@@ -80,4 +80,9 @@ public class BasicManagedRepository extends AbstractManagedRepository
         return CAPABILITIES;
     }
 
+
+    @Override
+    public RepositoryRequestInfo getRequestInfo() {
+        return null;
+    }
 }
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfo.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfo.java
new file mode 100644 (file)
index 0000000..9e70ede
--- /dev/null
@@ -0,0 +1,297 @@
+package org.apache.archiva.repository.content.maven2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.repository.*;
+import org.apache.archiva.repository.content.PathParser;
+import org.apache.archiva.repository.features.RepositoryFeature;
+import org.apache.archiva.repository.metadata.MetadataTools;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * RepositoryRequest is used to determine the type of request that is incoming, and convert it to an appropriate
+ * ArtifactReference.
+ */
+public class MavenRepositoryRequestInfo implements RepositoryRequestInfo
+{
+    private PathParser defaultPathParser = new DefaultPathParser();
+
+    ManagedRepository repository;
+
+    public MavenRepositoryRequestInfo(ManagedRepository repository)
+    {
+        this.repository = repository;
+    }
+
+    /**
+     * Takes an incoming requested path (in "/" format) and gleans the layout
+     * and ArtifactReference appropriate for that content.
+     *
+     * @param requestedPath the relative path to the content.
+     * @return the ArtifactReference for the requestedPath.
+     * @throws LayoutException if the request path is not layout valid.
+     */
+    public ArtifactReference toArtifactReference( String requestedPath )
+        throws LayoutException
+    {
+        if ( StringUtils.isBlank( requestedPath ) )
+        {
+            throw new LayoutException( "Blank request path is not a valid." );
+        }
+
+        String path = requestedPath;
+        while ( path.startsWith( "/" ) )
+        {
+            path = path.substring( 1 );
+
+            // Only slash? that's bad, mmm-kay?
+            if ( "/".equals( path ) )
+            {
+                throw new LayoutException( "Invalid request path: Slash only." );
+            }
+        }
+
+        if ( isDefault( path ) )
+        {
+            return defaultPathParser.toArtifactReference( path );
+        }
+        else if ( isLegacy( path ) )
+        {
+            throw new LayoutException( "Legacy Maven1 repository not supported anymore." );
+        }
+        else
+        {
+            throw new LayoutException( "Not a valid request path layout, too short." );
+        }
+    }
+
+    /**
+     * <p>
+     * Tests the path to see if it conforms to the expectations of a metadata request.
+     * </p>
+     * <p>
+     * NOTE: This does a cursory check on the path's last element.  A result of true
+     * from this method is not a guarantee that the metadata is in a valid format, or
+     * that it even contains data.
+     * </p>
+     *
+     * @param requestedPath the path to test.
+     * @return true if the requestedPath is likely a metadata request.
+     */
+    public boolean isMetadata( String requestedPath )
+    {
+        return requestedPath.endsWith( "/" + MetadataTools.MAVEN_METADATA );
+    }
+
+    /**
+     * @param requestedPath
+     * @return true if the requestedPath is likely an archetype catalog request.
+     */
+    public boolean isArchetypeCatalog( String requestedPath )
+    {
+        return requestedPath.endsWith( "/" + MetadataTools.MAVEN_ARCHETYPE_CATALOG );
+    }
+
+    /**
+     * <p>
+     * Tests the path to see if it conforms to the expectations of a support file request.
+     * </p>
+     * <p>
+     * Tests for <code>.sha1</code>, <code>.md5</code>, <code>.asc</code>, and <code>.php</code>.
+     * </p>
+     * <p>
+     * NOTE: This does a cursory check on the path's extension only.  A result of true
+     * from this method is not a guarantee that the support resource is in a valid format, or
+     * that it even contains data.
+     * </p>
+     *
+     * @param requestedPath the path to test.
+     * @return true if the requestedPath is likely that of a support file request.
+     */
+    public boolean isSupportFile( String requestedPath )
+    {
+        int idx = requestedPath.lastIndexOf( '.' );
+        if ( idx <= 0 )
+        {
+            return false;
+        }
+
+        String ext = requestedPath.substring( idx );
+        return ( ".sha1".equals( ext ) || ".md5".equals( ext ) || ".asc".equals( ext ) || ".pgp".equals( ext ) );
+    }
+
+    public boolean isMetadataSupportFile( String requestedPath )
+    {
+        if ( isSupportFile( requestedPath ) )
+        {
+            String basefilePath = StringUtils.substring( requestedPath, 0, requestedPath.lastIndexOf( '.' ) );
+            if ( isMetadata( basefilePath ) )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    @Override
+    public String getLayout(String requestPath) {
+        if (isDefault(requestPath)) {
+            return "default";
+        } else if (isLegacy(requestPath)) {
+            return "legacy";
+        } else {
+            return "unknown";
+        }
+    }
+
+    /**
+     * <p>
+     * Tests the path to see if it conforms to the expectations of a default layout request.
+     * </p>
+     * <p>
+     * NOTE: This does a cursory check on the count of path elements only.  A result of
+     * true from this method is not a guarantee that the path sections are valid and
+     * can be resolved to an artifact reference.  use {@link #toArtifactReference(String)}
+     * if you want a more complete analysis of the validity of the path.
+     * </p>
+     *
+     * @param requestedPath the path to test.
+     * @return true if the requestedPath is likely that of a default layout request.
+     */
+    private boolean isDefault( String requestedPath )
+    {
+        if ( StringUtils.isBlank( requestedPath ) )
+        {
+            return false;
+        }
+
+        String pathParts[] = StringUtils.splitPreserveAllTokens( requestedPath, '/' );
+        if ( pathParts.length > 3 )
+        {
+            return true;
+        }
+        else if ( pathParts.length == 3 )
+        {
+            // check if artifact-level metadata (ex. eclipse/jdtcore/maven-metadata.xml)
+            if ( isMetadata( requestedPath ) )
+            {
+                return true;
+            }
+            else
+            {
+                // check if checksum of artifact-level metadata (ex. eclipse/jdtcore/maven-metadata.xml.sha1)
+                int idx = requestedPath.lastIndexOf( '.' );
+                if ( idx > 0 )
+                {
+                    String base = requestedPath.substring( 0, idx );
+                    if ( isMetadata( base ) && isSupportFile( requestedPath ) )
+                    {
+                        return true;
+                    }
+                }
+
+                return false;
+            }
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    /**
+     * <p>
+     * Tests the path to see if it conforms to the expectations of a legacy layout request.
+     * </p>
+     * <p>
+     * NOTE: This does a cursory check on the count of path elements only.  A result of
+     * true from this method is not a guarantee that the path sections are valid and
+     * can be resolved to an artifact reference.  use {@link #toArtifactReference(String)}
+     * if you want a more complete analysis of the validity of the path.
+     * </p>
+     *
+     * @param requestedPath the path to test.
+     * @return true if the requestedPath is likely that of a legacy layout request.
+     */
+    private boolean isLegacy( String requestedPath )
+    {
+        if ( StringUtils.isBlank( requestedPath ) )
+        {
+            return false;
+        }
+
+        String pathParts[] = StringUtils.splitPreserveAllTokens( requestedPath, '/' );
+        return pathParts.length == 3;
+    }
+
+    /**
+     * Adjust the requestedPath to conform to the native layout of the provided {@link org.apache.archiva.repository.ManagedRepositoryContent}.
+     *
+     * @param requestedPath the incoming requested path.
+     * @return the adjusted (to native) path.
+     * @throws LayoutException if the path cannot be parsed.
+     */
+    public String toNativePath( String requestedPath)
+        throws LayoutException
+    {
+        if ( StringUtils.isBlank( requestedPath ) )
+        {
+            throw new LayoutException( "Request Path is blank." );
+        }
+
+        String referencedResource = requestedPath;
+        // No checksum by default.
+        String supportfile = "";
+
+        // Figure out support file, and actual referencedResource.
+        if ( isSupportFile( requestedPath ) )
+        {
+            int idx = requestedPath.lastIndexOf( '.' );
+            referencedResource = requestedPath.substring( 0, idx );
+            supportfile = requestedPath.substring( idx );
+        }
+
+        if ( isMetadata( referencedResource ) )
+        {
+            /* Nothing to translate.
+             * Default layout is the only layout that can contain maven-metadata.xml files, and
+             * if the managedRepository is layout legacy, this request would never occur.
+             */
+            return requestedPath;
+        }
+
+        // Treat as an artifact reference.
+        ArtifactReference ref = toArtifactReference( referencedResource );
+        String adjustedPath = repository.getContent().toPath( ref );
+        return adjustedPath + supportfile;
+    }
+
+    @Override
+    public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature(Class<T> clazz) throws UnsupportedFeatureException {
+        return null;
+    }
+
+    @Override
+    public <T extends RepositoryFeature<T>> boolean supportsFeature(Class<T> clazz) {
+        return false;
+    }
+}
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java
deleted file mode 100644 (file)
index fa7ec89..0000000
+++ /dev/null
@@ -1,275 +0,0 @@
-package org.apache.archiva.repository.content.maven2;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.archiva.model.ArtifactReference;
-import org.apache.archiva.repository.LayoutException;
-import org.apache.archiva.repository.ManagedRepositoryContent;
-import org.apache.archiva.repository.content.PathParser;
-import org.apache.archiva.repository.metadata.MetadataTools;
-import org.apache.commons.lang.StringUtils;
-
-/**
- * RepositoryRequest is used to determine the type of request that is incoming, and convert it to an appropriate
- * ArtifactReference.
- */
-public class RepositoryRequest
-{
-    private PathParser defaultPathParser = new DefaultPathParser();
-
-    public RepositoryRequest()
-    {
-        // no op
-    }
-
-    /**
-     * Takes an incoming requested path (in "/" format) and gleans the layout
-     * and ArtifactReference appropriate for that content.
-     *
-     * @param requestedPath the relative path to the content.
-     * @return the ArtifactReference for the requestedPath.
-     * @throws LayoutException if the request path is not layout valid.
-     */
-    public ArtifactReference toArtifactReference( String requestedPath )
-        throws LayoutException
-    {
-        if ( StringUtils.isBlank( requestedPath ) )
-        {
-            throw new LayoutException( "Blank request path is not a valid." );
-        }
-
-        String path = requestedPath;
-        while ( path.startsWith( "/" ) )
-        {
-            path = path.substring( 1 );
-
-            // Only slash? that's bad, mmm-kay?
-            if ( "/".equals( path ) )
-            {
-                throw new LayoutException( "Invalid request path: Slash only." );
-            }
-        }
-
-        if ( isDefault( path ) )
-        {
-            return defaultPathParser.toArtifactReference( path );
-        }
-        else if ( isLegacy( path ) )
-        {
-            throw new LayoutException( "Legacy Maven1 repository not supported anymore." );
-        }
-        else
-        {
-            throw new LayoutException( "Not a valid request path layout, too short." );
-        }
-    }
-
-    /**
-     * <p>
-     * Tests the path to see if it conforms to the expectations of a metadata request.
-     * </p>
-     * <p>
-     * NOTE: This does a cursory check on the path's last element.  A result of true
-     * from this method is not a guarantee that the metadata is in a valid format, or
-     * that it even contains data.
-     * </p>
-     *
-     * @param requestedPath the path to test.
-     * @return true if the requestedPath is likely a metadata request.
-     */
-    public boolean isMetadata( String requestedPath )
-    {
-        return requestedPath.endsWith( "/" + MetadataTools.MAVEN_METADATA );
-    }
-
-    /**
-     * @param requestedPath
-     * @return true if the requestedPath is likely an archetype catalog request.
-     */
-    public boolean isArchetypeCatalog( String requestedPath )
-    {
-        return requestedPath.endsWith( "/" + MetadataTools.MAVEN_ARCHETYPE_CATALOG );
-    }
-
-    /**
-     * <p>
-     * Tests the path to see if it conforms to the expectations of a support file request.
-     * </p>
-     * <p>
-     * Tests for <code>.sha1</code>, <code>.md5</code>, <code>.asc</code>, and <code>.php</code>.
-     * </p>
-     * <p>
-     * NOTE: This does a cursory check on the path's extension only.  A result of true
-     * from this method is not a guarantee that the support resource is in a valid format, or
-     * that it even contains data.
-     * </p>
-     *
-     * @param requestedPath the path to test.
-     * @return true if the requestedPath is likely that of a support file request.
-     */
-    public boolean isSupportFile( String requestedPath )
-    {
-        int idx = requestedPath.lastIndexOf( '.' );
-        if ( idx <= 0 )
-        {
-            return false;
-        }
-
-        String ext = requestedPath.substring( idx );
-        return ( ".sha1".equals( ext ) || ".md5".equals( ext ) || ".asc".equals( ext ) || ".pgp".equals( ext ) );
-    }
-
-    public boolean isMetadataSupportFile( String requestedPath )
-    {
-        if ( isSupportFile( requestedPath ) )
-        {
-            String basefilePath = StringUtils.substring( requestedPath, 0, requestedPath.lastIndexOf( '.' ) );
-            if ( isMetadata( basefilePath ) )
-            {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * <p>
-     * Tests the path to see if it conforms to the expectations of a default layout request.
-     * </p>
-     * <p>
-     * NOTE: This does a cursory check on the count of path elements only.  A result of
-     * true from this method is not a guarantee that the path sections are valid and
-     * can be resolved to an artifact reference.  use {@link #toArtifactReference(String)}
-     * if you want a more complete analysis of the validity of the path.
-     * </p>
-     *
-     * @param requestedPath the path to test.
-     * @return true if the requestedPath is likely that of a default layout request.
-     */
-    public boolean isDefault( String requestedPath )
-    {
-        if ( StringUtils.isBlank( requestedPath ) )
-        {
-            return false;
-        }
-
-        String pathParts[] = StringUtils.splitPreserveAllTokens( requestedPath, '/' );
-        if ( pathParts.length > 3 )
-        {
-            return true;
-        }
-        else if ( pathParts.length == 3 )
-        {
-            // check if artifact-level metadata (ex. eclipse/jdtcore/maven-metadata.xml)
-            if ( isMetadata( requestedPath ) )
-            {
-                return true;
-            }
-            else
-            {
-                // check if checksum of artifact-level metadata (ex. eclipse/jdtcore/maven-metadata.xml.sha1)
-                int idx = requestedPath.lastIndexOf( '.' );
-                if ( idx > 0 )
-                {
-                    String base = requestedPath.substring( 0, idx );
-                    if ( isMetadata( base ) && isSupportFile( requestedPath ) )
-                    {
-                        return true;
-                    }
-                }
-
-                return false;
-            }
-        }
-        else
-        {
-            return false;
-        }
-    }
-
-    /**
-     * <p>
-     * Tests the path to see if it conforms to the expectations of a legacy layout request.
-     * </p>
-     * <p>
-     * NOTE: This does a cursory check on the count of path elements only.  A result of
-     * true from this method is not a guarantee that the path sections are valid and
-     * can be resolved to an artifact reference.  use {@link #toArtifactReference(String)}
-     * if you want a more complete analysis of the validity of the path.
-     * </p>
-     *
-     * @param requestedPath the path to test.
-     * @return true if the requestedPath is likely that of a legacy layout request.
-     */
-    public boolean isLegacy( String requestedPath )
-    {
-        if ( StringUtils.isBlank( requestedPath ) )
-        {
-            return false;
-        }
-
-        String pathParts[] = StringUtils.splitPreserveAllTokens( requestedPath, '/' );
-        return pathParts.length == 3;
-    }
-
-    /**
-     * Adjust the requestedPath to conform to the native layout of the provided {@link org.apache.archiva.repository.ManagedRepositoryContent}.
-     *
-     * @param requestedPath the incoming requested path.
-     * @param repository    the repository to adjust to.
-     * @return the adjusted (to native) path.
-     * @throws LayoutException if the path cannot be parsed.
-     */
-    public String toNativePath( String requestedPath, ManagedRepositoryContent repository )
-        throws LayoutException
-    {
-        if ( StringUtils.isBlank( requestedPath ) )
-        {
-            throw new LayoutException( "Request Path is blank." );
-        }
-
-        String referencedResource = requestedPath;
-        // No checksum by default.
-        String supportfile = "";
-
-        // Figure out support file, and actual referencedResource.
-        if ( isSupportFile( requestedPath ) )
-        {
-            int idx = requestedPath.lastIndexOf( '.' );
-            referencedResource = requestedPath.substring( 0, idx );
-            supportfile = requestedPath.substring( idx );
-        }
-
-        if ( isMetadata( referencedResource ) )
-        {
-            /* Nothing to translate.
-             * Default layout is the only layout that can contain maven-metadata.xml files, and
-             * if the managedRepository is layout legacy, this request would never occur.
-             */
-            return requestedPath;
-        }
-
-        // Treat as an artifact reference.
-        ArtifactReference ref = toArtifactReference( referencedResource );
-        String adjustedPath = repository.toPath( ref );
-        return adjustedPath + supportfile;
-    }
-}
index ea55b7c5e63526e28dd9e96a9120b3d7c20d04ac..c002854b5aa36af2de352392e6f1e0e034c9a309 100644 (file)
@@ -20,12 +20,8 @@ package org.apache.archiva.repository.maven2;
  */
 
 import org.apache.archiva.common.utils.PathUtil;
-import org.apache.archiva.repository.AbstractManagedRepository;
-import org.apache.archiva.repository.ReleaseScheme;
-import org.apache.archiva.repository.RepositoryCapabilities;
-import org.apache.archiva.repository.RepositoryType;
-import org.apache.archiva.repository.StandardCapabilities;
-import org.apache.archiva.repository.UnsupportedFeatureException;
+import org.apache.archiva.repository.*;
+import org.apache.archiva.repository.content.maven2.MavenRepositoryRequestInfo;
 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
 import org.apache.archiva.repository.features.IndexCreationFeature;
 import org.apache.archiva.repository.features.RepositoryFeature;
@@ -137,4 +133,8 @@ public class MavenManagedRepository extends AbstractManagedRepository
         }
     }
 
+    @Override
+    public RepositoryRequestInfo getRequestInfo() {
+        return new MavenRepositoryRequestInfo(this);
+    }
 }
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfoTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfoTest.java
new file mode 100644 (file)
index 0000000..95bbf0f
--- /dev/null
@@ -0,0 +1,561 @@
+package org.apache.archiva.repository.content.maven2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.common.utils.FileUtils;
+import org.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.configuration.FileType;
+import org.apache.archiva.configuration.FileTypes;
+import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.repository.LayoutException;
+import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.RepositoryContentProvider;
+import org.apache.archiva.repository.maven2.MavenManagedRepository;
+import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
+import org.apache.commons.lang.StringUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+/**
+ * RepositoryRequestTest
+ */
+@RunWith( ArchivaSpringJUnit4ClassRunner.class )
+@ContextConfiguration( { "classpath*:/META-INF/spring-context.xml",
+    "classpath:/spring-context-repo-request-test.xml" } )
+public class MavenRepositoryRequestInfoTest
+{
+
+    @Inject
+    protected ApplicationContext applicationContext;
+
+    @Inject
+    FileTypes fileTypes;
+
+    @Inject
+    @Named( "archivaConfiguration#repo-request-test" )
+    private ArchivaConfiguration archivaConfiguration;
+
+    @Inject
+    List<? extends ArtifactMappingProvider> artifactMappingProviders;
+
+    private MavenRepositoryRequestInfo repoRequest;
+
+
+    protected MavenManagedRepository createRepository( String id, String name, Path location )
+    {
+        MavenManagedRepository repo = new MavenManagedRepository( id, name, location.getParent().toAbsolutePath());
+        repo.setLocation( location.toAbsolutePath().toUri() );
+        return repo;
+    }
+
+
+    @Before
+    public void setUp()
+        throws Exception
+    {
+
+        Path repoDir = Paths.get( "src/test/repositories/default-repository" );
+        MavenManagedRepository repository = createRepository( "testRepo", "Unit Test Repo", repoDir );
+
+        FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
+        fileType.addPattern( "**/*.xml" );
+        assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
+
+        fileTypes.afterConfigurationChange( null, "fileType", null );
+
+        ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent(artifactMappingProviders, fileTypes);
+        //repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" );
+        repoContent.setRepository( repository );
+        repository.setContent(repoContent);
+        repoRequest = new MavenRepositoryRequestInfo(repository);
+    }
+
+    @Test
+    public void testInvalidRequestEmptyPath()
+    {
+        assertInvalidRequest( "" );
+    }
+
+    @Test
+    public void testInvalidRequestSlashOnly()
+    {
+        assertInvalidRequest( "//" );
+    }
+
+    @Test
+    public void testInvalidRequestNoArtifactId()
+    {
+        assertInvalidRequest( "groupId/jars/-1.0.jar" );
+    }
+
+
+    @Test
+    public void testInvalidRequestTooShort()
+    {
+        assertInvalidRequest( "org.apache.maven.test/artifactId-2.0.jar" );
+    }
+
+    @Test
+    public void testInvalidDefaultRequestBadLocation()
+    {
+        assertInvalidRequest( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
+    }
+
+    @Test( expected = LayoutException.class )
+    public void testValidLegacyGanymed()
+        throws Exception
+    {
+        assertValid( "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar", "ch.ethz.ganymed", "ganymed-ssh2", "build210",
+                     null, "jar" );
+    }
+
+    @Test
+    public void testValidDefaultGanymed()
+        throws Exception
+    {
+        assertValid( "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar", "ch.ethz.ganymed",
+                     "ganymed-ssh2", "build210", null, "jar" );
+    }
+
+    @Test( expected = LayoutException.class )
+    public void testValidLegacyJavaxComm()
+        throws Exception
+    {
+        assertValid( "javax/jars/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
+    }
+
+    @Test
+    public void testValidDefaultJavaxComm()
+        throws Exception
+    {
+        assertValid( "javax/comm/3.0-u1/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
+    }
+
+    @Test( expected = LayoutException.class )
+    public void testValidLegacyJavaxPersistence()
+        throws Exception
+    {
+        assertValid( "javax.persistence/jars/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
+                     "3.0-public_review", null, "jar" );
+    }
+
+    @Test
+    public void testValidDefaultJavaxPersistence()
+        throws Exception
+    {
+        assertValid( "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
+                     "3.0-public_review", null, "jar" );
+    }
+
+    @Test( expected = LayoutException.class )
+    public void testValidLegacyMavenTestPlugin()
+        throws Exception
+    {
+        assertValid( "maven/jars/maven-test-plugin-1.8.2.jar", "maven", "maven-test-plugin", "1.8.2", null, "jar" );
+    }
+
+    @Test
+    public void testValidDefaultMavenTestPlugin()
+        throws Exception
+    {
+        assertValid( "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom", "maven", "maven-test-plugin", "1.8.2",
+                     null, "pom" );
+    }
+
+    @Test( expected = LayoutException.class )
+    public void testValidLegacyCommonsLangJavadoc()
+        throws Exception
+    {
+        assertValid( "commons-lang/javadoc.jars/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", "2.1",
+                     "javadoc", "javadoc" );
+    }
+
+    @Test
+    public void testValidDefaultCommonsLangJavadoc()
+        throws Exception
+    {
+        assertValid( "commons-lang/commons-lang/2.1/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang",
+                     "2.1", "javadoc", "javadoc" );
+    }
+
+    @Test( expected = LayoutException.class )
+    public void testValidLegacyDerbyPom()
+        throws Exception
+    {
+        assertValid( "org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" );
+        // Starting slash should not prevent detection.
+        assertValid( "/org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null,
+                     "pom" );
+    }
+
+    @Test
+    public void testValidDefaultDerbyPom()
+        throws Exception
+    {
+        assertValid( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0",
+                     null, "pom" );
+    }
+
+    @Test( expected = LayoutException.class )
+    public void testValidLegacyGeronimoEjbSpec()
+        throws Exception
+    {
+        assertValid( "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar", "org.apache.geronimo.specs",
+                     "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
+    }
+
+    @Test
+    public void testValidDefaultGeronimoEjbSpec()
+        throws Exception
+    {
+        assertValid( "org/apache/geronimo/specs/geronimo-ejb_2.1_spec/1.0.1/geronimo-ejb_2.1_spec-1.0.1.jar",
+                     "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
+    }
+
+    @Test( expected = LayoutException.class )
+    public void testValidLegacyLdapSnapshot()
+        throws Exception
+    {
+        assertValid( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom", "directory-clients", "ldap-clients",
+                     "0.9.1-SNAPSHOT", null, "pom" );
+    }
+
+    @Test
+    public void testValidDefaultLdapSnapshot()
+        throws Exception
+    {
+        assertValid( "directory-clients/ldap-clients/0.9.1-SNAPSHOT/ldap-clients-0.9.1-SNAPSHOT.pom",
+                     "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", null, "pom" );
+    }
+
+    @Test( expected = LayoutException.class )
+    public void testValidLegacyTestArchSnapshot()
+        throws Exception
+    {
+        assertValid( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch", "test-arch",
+                     "2.0.3-SNAPSHOT", null, "pom" );
+    }
+
+    @Test
+    public void testValidDefaultTestArchSnapshot()
+        throws Exception
+    {
+        assertValid( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch",
+                     "test-arch", "2.0.3-SNAPSHOT", null, "pom" );
+    }
+
+    @Test( expected = LayoutException.class )
+    public void testValidLegacyOddDottedArtifactId()
+        throws Exception
+    {
+        assertValid( "com.company.department/poms/com.company.department.project-0.2.pom", "com.company.department",
+                     "com.company.department.project", "0.2", null, "pom" );
+    }
+
+    @Test
+    public void testValidDefaultOddDottedArtifactId()
+        throws Exception
+    {
+        assertValid( "com/company/department/com.company.department.project/0.2/com.company.department.project-0.2.pom",
+                     "com.company.department", "com.company.department.project", "0.2", null, "pom" );
+    }
+
+    @Test( expected = LayoutException.class )
+    public void testValidLegacyTimestampedSnapshot()
+        throws Exception
+    {
+        assertValid( "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar",
+                     "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" );
+    }
+
+    @Test
+    public void testValidDefaultTimestampedSnapshot()
+        throws Exception
+    {
+        assertValid(
+            "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar",
+            "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" );
+    }
+
+    @Test
+    public void testIsSupportFile()
+    {
+        assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) );
+        assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ) );
+        assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.asc" ) );
+        assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
+        assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
+        assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) );
+
+        assertFalse( repoRequest.isSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
+        assertFalse(
+            repoRequest.isSupportFile( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
+        assertFalse( repoRequest.isSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
+        assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
+        assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
+        assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/maven-metadata.xml" ) );
+    }
+
+    @Test
+    public void testIsMetadata()
+    {
+        assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
+        assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/maven-metadata.xml" ) );
+
+        assertFalse( repoRequest.isMetadata( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
+        assertFalse(
+            repoRequest.isMetadata( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
+        assertFalse( repoRequest.isMetadata( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
+        assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
+        assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
+        assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
+    }
+
+    @Test
+    public void testIsMetadataSupportFile()
+    {
+        assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
+        assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml" ) );
+        assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.sha1" ) );
+        assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.md5" ) );
+
+        assertFalse( repoRequest.isMetadataSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
+        assertFalse( repoRequest.isMetadataSupportFile(
+            "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
+        assertFalse(
+            repoRequest.isMetadataSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
+        assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
+        assertFalse(
+            repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
+        assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
+        assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) );
+    }
+
+    @Test
+    public void testIsDefault()
+    {
+        assertNotEquals( "default", repoRequest.getLayout( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
+        assertNotEquals("default", repoRequest.getLayout( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
+        assertNotEquals("default", repoRequest.getLayout( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
+
+        assertEquals("default", repoRequest.getLayout( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
+        assertEquals("default", repoRequest.getLayout( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
+        assertEquals("default", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
+        assertEquals("default", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
+        assertEquals("default", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
+        assertEquals("default", repoRequest.getLayout( "eclipse/jdtcore/maven-metadata.xml" ) );
+        assertEquals("default", repoRequest.getLayout( "eclipse/jdtcore/maven-metadata.xml.sha1" ) );
+        assertEquals("default", repoRequest.getLayout( "eclipse/jdtcore/maven-metadata.xml.md5" ) );
+
+        assertNotEquals("default", repoRequest.getLayout( null ) );
+        assertNotEquals("default", repoRequest.getLayout( "" ) );
+        assertNotEquals("default", repoRequest.getLayout( "foo" ) );
+        assertNotEquals("default", repoRequest.getLayout( "some.short/path" ) );
+    }
+
+    @Test
+    public void testIsLegacy()
+    {
+        assertEquals("legacy", repoRequest.getLayout( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
+        assertEquals("legacy", repoRequest.getLayout( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
+        assertEquals("legacy", repoRequest.getLayout( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
+
+        assertNotEquals("legacy", repoRequest.getLayout( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
+        assertNotEquals("legacy", repoRequest.getLayout( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
+        assertNotEquals("legacy", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
+        assertNotEquals("legacy", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
+        assertNotEquals("legacy", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
+
+        assertNotEquals("legacy", repoRequest.getLayout( null ) );
+        assertNotEquals("legacy", repoRequest.getLayout( "" ) );
+        assertNotEquals("legacy", repoRequest.getLayout( "some.short/path" ) );
+    }
+
+    private ManagedRepositoryContent createManagedRepo( String layout )
+        throws Exception
+    {
+        Path repoRoot = Paths.get( FileUtils.getBasedir() + "/target/test-repo" );
+        return createManagedRepositoryContent( "test-internal", "Internal Test Repo", repoRoot, layout );
+    }
+
+    /**
+     * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
+     */
+    @Test
+    public void testToNativePathArtifactDefaultToDefaultDualExtension()
+        throws Exception
+    {
+        ManagedRepositoryContent repository = createManagedRepo( "default" );
+
+        // Test (artifact) default to default - dual extension
+        assertEquals( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip",
+                      repoRequest.toNativePath( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip") );
+    }
+
+
+    @Test
+    public void testToNativePathMetadataDefaultToDefault()
+        throws Exception
+    {
+        ManagedRepositoryContent repository = createManagedRepo( "default" );
+
+        // Test (metadata) default to default
+        assertEquals( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1",
+                      repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1") );
+    }
+
+
+    @Test
+    public void testNativePathBadRequestTooShort()
+        throws Exception
+    {
+        ManagedRepositoryContent repository = createManagedRepo( "default" );
+
+        // Test bad request path (too short)
+        try
+        {
+            repoRequest.toNativePath( "org.apache.derby/license.txt");
+            fail( "Should have thrown an exception about a too short path." );
+        }
+        catch ( LayoutException e )
+        {
+            // expected path.
+        }
+    }
+
+    @Test
+    public void testNativePathBadRequestBlank()
+        throws Exception
+    {
+        ManagedRepositoryContent repository = createManagedRepo( "default" );
+
+        // Test bad request path (too short)
+        try
+        {
+            repoRequest.toNativePath( "");
+            fail( "Should have thrown an exception about an blank request." );
+        }
+        catch ( LayoutException e )
+        {
+            // expected path.
+        }
+    }
+
+    @Test
+    public void testNativePathBadRequestNull()
+        throws Exception
+    {
+        ManagedRepositoryContent repository = createManagedRepo( "default" );
+
+        // Test bad request path (too short)
+        try
+        {
+            repoRequest.toNativePath( null);
+            fail( "Should have thrown an exception about an null request." );
+        }
+        catch ( LayoutException e )
+        {
+            // expected path.
+        }
+    }
+
+    @Test
+    public void testNativePathBadRequestUnknownType()
+        throws Exception
+    {
+        ManagedRepositoryContent repository = createManagedRepo( "default" );
+
+        // Test bad request path (too short)
+        try
+        {
+            repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/license.txt");
+            fail( "Should have thrown an exception about an invalid type." );
+        }
+        catch ( LayoutException e )
+        {
+            // expected path.
+        }
+    }
+
+
+    private void assertValid( String path, String groupId, String artifactId, String version, String classifier,
+                              String type )
+        throws Exception
+    {
+        String expectedId =
+            "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + ( classifier != null ?
+                classifier + ":" : "" ) + type;
+
+        ArtifactReference reference = repoRequest.toArtifactReference( path );
+
+        assertNotNull( expectedId + " - Should not be null.", reference );
+
+        assertEquals( expectedId + " - Group ID", groupId, reference.getGroupId() );
+        assertEquals( expectedId + " - Artifact ID", artifactId, reference.getArtifactId() );
+        if ( StringUtils.isNotBlank( classifier ) )
+        {
+            assertEquals( expectedId + " - Classifier", classifier, reference.getClassifier() );
+        }
+        assertEquals( expectedId + " - Version ID", version, reference.getVersion() );
+        assertEquals( expectedId + " - Type", type, reference.getType() );
+    }
+
+    private void assertInvalidRequest( String path )
+    {
+        try
+        {
+            repoRequest.toArtifactReference( path );
+            fail( "Expected a LayoutException on an invalid path [" + path + "]" );
+        }
+        catch ( LayoutException e )
+        {
+            /* expected path */
+        }
+    }
+
+    protected ManagedRepositoryContent createManagedRepositoryContent( String id, String name, Path location,
+                                                                       String layout )
+        throws Exception
+    {
+        MavenManagedRepository repo = new MavenManagedRepository( id, name, archivaConfiguration.getRepositoryBaseDir());
+        repo.setLocation( location.toAbsolutePath().toUri() );
+        repo.setLayout( layout );
+
+        RepositoryContentProvider provider = applicationContext.getBean( "repositoryContentProvider#maven", RepositoryContentProvider.class );
+
+        ManagedRepositoryContent repoContent =
+            provider.createManagedContent( repo );
+
+        return repoContent;
+    }
+
+}
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java
deleted file mode 100644 (file)
index db32108..0000000
+++ /dev/null
@@ -1,530 +0,0 @@
-package org.apache.archiva.repository.content.maven2;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.archiva.common.utils.FileUtils;
-import org.apache.archiva.configuration.ArchivaConfiguration;
-import org.apache.archiva.model.ArtifactReference;
-import org.apache.archiva.repository.LayoutException;
-import org.apache.archiva.repository.ManagedRepositoryContent;
-import org.apache.archiva.repository.RepositoryContentProvider;
-import org.apache.archiva.repository.maven2.MavenManagedRepository;
-import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
-import org.apache.commons.lang.StringUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.context.ApplicationContext;
-import org.springframework.test.context.ContextConfiguration;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-import static org.junit.Assert.*;
-
-/**
- * RepositoryRequestTest
- */
-@RunWith( ArchivaSpringJUnit4ClassRunner.class )
-@ContextConfiguration( { "classpath*:/META-INF/spring-context.xml",
-    "classpath:/spring-context-repo-request-test.xml" } )
-public class RepositoryRequestTest
-{
-
-    @Inject
-    protected ApplicationContext applicationContext;
-
-    @Inject
-    @Named( "archivaConfiguration#repo-request-test" )
-    private ArchivaConfiguration archivaConfiguration;
-
-    private RepositoryRequest repoRequest;
-
-    @Before
-    public void setUp()
-        throws Exception
-    {
-        repoRequest = new RepositoryRequest();
-    }
-
-    @Test
-    public void testInvalidRequestEmptyPath()
-    {
-        assertInvalidRequest( "" );
-    }
-
-    @Test
-    public void testInvalidRequestSlashOnly()
-    {
-        assertInvalidRequest( "//" );
-    }
-
-    @Test
-    public void testInvalidRequestNoArtifactId()
-    {
-        assertInvalidRequest( "groupId/jars/-1.0.jar" );
-    }
-
-
-    @Test
-    public void testInvalidRequestTooShort()
-    {
-        assertInvalidRequest( "org.apache.maven.test/artifactId-2.0.jar" );
-    }
-
-    @Test
-    public void testInvalidDefaultRequestBadLocation()
-    {
-        assertInvalidRequest( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
-    }
-
-    @Test( expected = LayoutException.class )
-    public void testValidLegacyGanymed()
-        throws Exception
-    {
-        assertValid( "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar", "ch.ethz.ganymed", "ganymed-ssh2", "build210",
-                     null, "jar" );
-    }
-
-    @Test
-    public void testValidDefaultGanymed()
-        throws Exception
-    {
-        assertValid( "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar", "ch.ethz.ganymed",
-                     "ganymed-ssh2", "build210", null, "jar" );
-    }
-
-    @Test( expected = LayoutException.class )
-    public void testValidLegacyJavaxComm()
-        throws Exception
-    {
-        assertValid( "javax/jars/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
-    }
-
-    @Test
-    public void testValidDefaultJavaxComm()
-        throws Exception
-    {
-        assertValid( "javax/comm/3.0-u1/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
-    }
-
-    @Test( expected = LayoutException.class )
-    public void testValidLegacyJavaxPersistence()
-        throws Exception
-    {
-        assertValid( "javax.persistence/jars/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
-                     "3.0-public_review", null, "jar" );
-    }
-
-    @Test
-    public void testValidDefaultJavaxPersistence()
-        throws Exception
-    {
-        assertValid( "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
-                     "3.0-public_review", null, "jar" );
-    }
-
-    @Test( expected = LayoutException.class )
-    public void testValidLegacyMavenTestPlugin()
-        throws Exception
-    {
-        assertValid( "maven/jars/maven-test-plugin-1.8.2.jar", "maven", "maven-test-plugin", "1.8.2", null, "jar" );
-    }
-
-    @Test
-    public void testValidDefaultMavenTestPlugin()
-        throws Exception
-    {
-        assertValid( "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom", "maven", "maven-test-plugin", "1.8.2",
-                     null, "pom" );
-    }
-
-    @Test( expected = LayoutException.class )
-    public void testValidLegacyCommonsLangJavadoc()
-        throws Exception
-    {
-        assertValid( "commons-lang/javadoc.jars/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", "2.1",
-                     "javadoc", "javadoc" );
-    }
-
-    @Test
-    public void testValidDefaultCommonsLangJavadoc()
-        throws Exception
-    {
-        assertValid( "commons-lang/commons-lang/2.1/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang",
-                     "2.1", "javadoc", "javadoc" );
-    }
-
-    @Test( expected = LayoutException.class )
-    public void testValidLegacyDerbyPom()
-        throws Exception
-    {
-        assertValid( "org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" );
-        // Starting slash should not prevent detection.
-        assertValid( "/org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null,
-                     "pom" );
-    }
-
-    @Test
-    public void testValidDefaultDerbyPom()
-        throws Exception
-    {
-        assertValid( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0",
-                     null, "pom" );
-    }
-
-    @Test( expected = LayoutException.class )
-    public void testValidLegacyGeronimoEjbSpec()
-        throws Exception
-    {
-        assertValid( "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar", "org.apache.geronimo.specs",
-                     "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
-    }
-
-    @Test
-    public void testValidDefaultGeronimoEjbSpec()
-        throws Exception
-    {
-        assertValid( "org/apache/geronimo/specs/geronimo-ejb_2.1_spec/1.0.1/geronimo-ejb_2.1_spec-1.0.1.jar",
-                     "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
-    }
-
-    @Test( expected = LayoutException.class )
-    public void testValidLegacyLdapSnapshot()
-        throws Exception
-    {
-        assertValid( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom", "directory-clients", "ldap-clients",
-                     "0.9.1-SNAPSHOT", null, "pom" );
-    }
-
-    @Test
-    public void testValidDefaultLdapSnapshot()
-        throws Exception
-    {
-        assertValid( "directory-clients/ldap-clients/0.9.1-SNAPSHOT/ldap-clients-0.9.1-SNAPSHOT.pom",
-                     "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", null, "pom" );
-    }
-
-    @Test( expected = LayoutException.class )
-    public void testValidLegacyTestArchSnapshot()
-        throws Exception
-    {
-        assertValid( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch", "test-arch",
-                     "2.0.3-SNAPSHOT", null, "pom" );
-    }
-
-    @Test
-    public void testValidDefaultTestArchSnapshot()
-        throws Exception
-    {
-        assertValid( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch",
-                     "test-arch", "2.0.3-SNAPSHOT", null, "pom" );
-    }
-
-    @Test( expected = LayoutException.class )
-    public void testValidLegacyOddDottedArtifactId()
-        throws Exception
-    {
-        assertValid( "com.company.department/poms/com.company.department.project-0.2.pom", "com.company.department",
-                     "com.company.department.project", "0.2", null, "pom" );
-    }
-
-    @Test
-    public void testValidDefaultOddDottedArtifactId()
-        throws Exception
-    {
-        assertValid( "com/company/department/com.company.department.project/0.2/com.company.department.project-0.2.pom",
-                     "com.company.department", "com.company.department.project", "0.2", null, "pom" );
-    }
-
-    @Test( expected = LayoutException.class )
-    public void testValidLegacyTimestampedSnapshot()
-        throws Exception
-    {
-        assertValid( "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar",
-                     "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" );
-    }
-
-    @Test
-    public void testValidDefaultTimestampedSnapshot()
-        throws Exception
-    {
-        assertValid(
-            "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar",
-            "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" );
-    }
-
-    @Test
-    public void testIsSupportFile()
-    {
-        assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) );
-        assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ) );
-        assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.asc" ) );
-        assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
-        assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
-        assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) );
-
-        assertFalse( repoRequest.isSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
-        assertFalse(
-            repoRequest.isSupportFile( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
-        assertFalse( repoRequest.isSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
-        assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
-        assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
-        assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/maven-metadata.xml" ) );
-    }
-
-    @Test
-    public void testIsMetadata()
-    {
-        assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
-        assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/maven-metadata.xml" ) );
-
-        assertFalse( repoRequest.isMetadata( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
-        assertFalse(
-            repoRequest.isMetadata( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
-        assertFalse( repoRequest.isMetadata( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
-        assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
-        assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
-        assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
-    }
-
-    @Test
-    public void testIsMetadataSupportFile()
-    {
-        assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
-        assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml" ) );
-        assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.sha1" ) );
-        assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.md5" ) );
-
-        assertFalse( repoRequest.isMetadataSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
-        assertFalse( repoRequest.isMetadataSupportFile(
-            "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
-        assertFalse(
-            repoRequest.isMetadataSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
-        assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
-        assertFalse(
-            repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
-        assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
-        assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) );
-    }
-
-    @Test
-    public void testIsDefault()
-    {
-        assertFalse( repoRequest.isDefault( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
-        assertFalse( repoRequest.isDefault( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
-        assertFalse( repoRequest.isDefault( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
-
-        assertTrue( repoRequest.isDefault( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
-        assertTrue( repoRequest.isDefault( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
-        assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
-        assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
-        assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
-        assertTrue( repoRequest.isDefault( "eclipse/jdtcore/maven-metadata.xml" ) );
-        assertTrue( repoRequest.isDefault( "eclipse/jdtcore/maven-metadata.xml.sha1" ) );
-        assertTrue( repoRequest.isDefault( "eclipse/jdtcore/maven-metadata.xml.md5" ) );
-
-        assertFalse( repoRequest.isDefault( null ) );
-        assertFalse( repoRequest.isDefault( "" ) );
-        assertFalse( repoRequest.isDefault( "foo" ) );
-        assertFalse( repoRequest.isDefault( "some.short/path" ) );
-    }
-
-    @Test
-    public void testIsLegacy()
-    {
-        assertTrue( repoRequest.isLegacy( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
-        assertTrue( repoRequest.isLegacy( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
-        assertTrue( repoRequest.isLegacy( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
-
-        assertFalse( repoRequest.isLegacy( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
-        assertFalse( repoRequest.isLegacy( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
-        assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
-        assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
-        assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
-
-        assertFalse( repoRequest.isLegacy( null ) );
-        assertFalse( repoRequest.isLegacy( "" ) );
-        assertFalse( repoRequest.isLegacy( "some.short/path" ) );
-    }
-
-    private ManagedRepositoryContent createManagedRepo( String layout )
-        throws Exception
-    {
-        Path repoRoot = Paths.get( FileUtils.getBasedir() + "/target/test-repo" );
-        return createManagedRepositoryContent( "test-internal", "Internal Test Repo", repoRoot, layout );
-    }
-
-    /**
-     * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
-     */
-    @Test
-    public void testToNativePathArtifactDefaultToDefaultDualExtension()
-        throws Exception
-    {
-        ManagedRepositoryContent repository = createManagedRepo( "default" );
-
-        // Test (artifact) default to default - dual extension
-        assertEquals( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip",
-                      repoRequest.toNativePath( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip",
-                                                repository ) );
-    }
-
-
-    @Test
-    public void testToNativePathMetadataDefaultToDefault()
-        throws Exception
-    {
-        ManagedRepositoryContent repository = createManagedRepo( "default" );
-
-        // Test (metadata) default to default
-        assertEquals( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1",
-                      repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1",
-                                                repository ) );
-    }
-
-
-    @Test
-    public void testNativePathBadRequestTooShort()
-        throws Exception
-    {
-        ManagedRepositoryContent repository = createManagedRepo( "default" );
-
-        // Test bad request path (too short)
-        try
-        {
-            repoRequest.toNativePath( "org.apache.derby/license.txt", repository );
-            fail( "Should have thrown an exception about a too short path." );
-        }
-        catch ( LayoutException e )
-        {
-            // expected path.
-        }
-    }
-
-    @Test
-    public void testNativePathBadRequestBlank()
-        throws Exception
-    {
-        ManagedRepositoryContent repository = createManagedRepo( "default" );
-
-        // Test bad request path (too short)
-        try
-        {
-            repoRequest.toNativePath( "", repository );
-            fail( "Should have thrown an exception about an blank request." );
-        }
-        catch ( LayoutException e )
-        {
-            // expected path.
-        }
-    }
-
-    @Test
-    public void testNativePathBadRequestNull()
-        throws Exception
-    {
-        ManagedRepositoryContent repository = createManagedRepo( "default" );
-
-        // Test bad request path (too short)
-        try
-        {
-            repoRequest.toNativePath( null, repository );
-            fail( "Should have thrown an exception about an null request." );
-        }
-        catch ( LayoutException e )
-        {
-            // expected path.
-        }
-    }
-
-    @Test
-    public void testNativePathBadRequestUnknownType()
-        throws Exception
-    {
-        ManagedRepositoryContent repository = createManagedRepo( "default" );
-
-        // Test bad request path (too short)
-        try
-        {
-            repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/license.txt", repository );
-            fail( "Should have thrown an exception about an invalid type." );
-        }
-        catch ( LayoutException e )
-        {
-            // expected path.
-        }
-    }
-
-
-    private void assertValid( String path, String groupId, String artifactId, String version, String classifier,
-                              String type )
-        throws Exception
-    {
-        String expectedId =
-            "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + ( classifier != null ?
-                classifier + ":" : "" ) + type;
-
-        ArtifactReference reference = repoRequest.toArtifactReference( path );
-
-        assertNotNull( expectedId + " - Should not be null.", reference );
-
-        assertEquals( expectedId + " - Group ID", groupId, reference.getGroupId() );
-        assertEquals( expectedId + " - Artifact ID", artifactId, reference.getArtifactId() );
-        if ( StringUtils.isNotBlank( classifier ) )
-        {
-            assertEquals( expectedId + " - Classifier", classifier, reference.getClassifier() );
-        }
-        assertEquals( expectedId + " - Version ID", version, reference.getVersion() );
-        assertEquals( expectedId + " - Type", type, reference.getType() );
-    }
-
-    private void assertInvalidRequest( String path )
-    {
-        try
-        {
-            repoRequest.toArtifactReference( path );
-            fail( "Expected a LayoutException on an invalid path [" + path + "]" );
-        }
-        catch ( LayoutException e )
-        {
-            /* expected path */
-        }
-    }
-
-    protected ManagedRepositoryContent createManagedRepositoryContent( String id, String name, Path location,
-                                                                       String layout )
-        throws Exception
-    {
-        MavenManagedRepository repo = new MavenManagedRepository( id, name, archivaConfiguration.getRepositoryBaseDir());
-        repo.setLocation( location.toAbsolutePath().toUri() );
-        repo.setLayout( layout );
-
-        RepositoryContentProvider provider = applicationContext.getBean( "repositoryContentProvider#maven", RepositoryContentProvider.class );
-
-        ManagedRepositoryContent repoContent =
-            provider.createManagedContent( repo );
-
-        return repoContent;
-    }
-
-}
index b229ec9815652ef4196f9e0964290af2cc0588d0..3cdf4c67f9e2eaa39d1ad5e904ad471804beffa9 100644 (file)
@@ -58,13 +58,8 @@ import org.apache.archiva.redback.policy.MustChangePasswordException;
 import org.apache.archiva.redback.system.SecuritySession;
 import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.users.UserManager;
-import org.apache.archiva.repository.LayoutException;
-import org.apache.archiva.repository.ManagedRepository;
-import org.apache.archiva.repository.ManagedRepositoryContent;
-import org.apache.archiva.repository.ReleaseScheme;
-import org.apache.archiva.repository.RepositoryContentFactory;
-import org.apache.archiva.repository.RepositoryRegistry;
-import org.apache.archiva.repository.content.maven2.RepositoryRequest;
+import org.apache.archiva.repository.*;
+import org.apache.archiva.repository.content.maven2.MavenRepositoryRequestInfo;
 import org.apache.archiva.repository.events.AuditListener;
 import org.apache.archiva.repository.features.IndexCreationFeature;
 import org.apache.archiva.repository.metadata.MetadataTools;
@@ -132,11 +127,6 @@ public class ArchivaDavResourceFactory
     @Inject
     private List<AuditListener> auditListeners = new ArrayList<>();
 
-    @Inject
-    private RepositoryContentFactory repositoryFactory;
-
-    private RepositoryRequest repositoryRequest;
-
     @Inject
     private ProxyRegistry proxyRegistry;
 
@@ -203,8 +193,6 @@ public class ArchivaDavResourceFactory
         this.digestMd5 = plexusSisuBridge.lookup( Digester.class, "md5" );
         this.digestSha1 = plexusSisuBridge.lookup( Digester.class, "sha1" );
 
-        // TODO remove this hard dependency on maven !!
-        repositoryRequest = new RepositoryRequest( );
     }
 
     @PostConstruct
@@ -228,6 +216,7 @@ public class ArchivaDavResourceFactory
         List<String> resourcesInAbsolutePath = new ArrayList<>();
 
         boolean readMethod = WebdavMethodUtil.isReadMethod( request.getMethod() );
+        RepositoryRequestInfo repositoryRequestInfo = null;
         DavResource resource;
         if ( repoGroupConfig != null )
         {
@@ -259,6 +248,13 @@ public class ArchivaDavResourceFactory
                 List<String> repositories = new ArrayList<>( repoGroupConfig.getRepositories() );
                 resource = processRepositoryGroup( request, archivaLocator, repositories, activePrincipal,
                                                    resourcesInAbsolutePath, repoGroupConfig );
+                for (String repoId: repositories ) {
+                    ManagedRepository repo = repositoryRegistry.getManagedRepository(repoId);
+                    if (repo!=null) {
+                        repositoryRequestInfo = repo.getRequestInfo();
+                        break;
+                    }
+                }
             }
         }
         else
@@ -315,7 +311,7 @@ public class ArchivaDavResourceFactory
 
             resource = processRepository( request, archivaLocator, activePrincipal, managedRepositoryContent,
                                           repo);
-
+            repositoryRequestInfo = repo.getRequestInfo();
             String logicalResource = getLogicalResource( archivaLocator, null, false );
             resourcesInAbsolutePath.add(
                 Paths.get( managedRepositoryContent.getRepoRoot(), logicalResource ).toAbsolutePath().toString() );
@@ -326,7 +322,7 @@ public class ArchivaDavResourceFactory
 
         // MRM-872 : merge all available metadata
         // merge metadata only when requested via the repo group
-        if ( ( repositoryRequest.isMetadata( requestedResource ) || repositoryRequest.isMetadataSupportFile(
+        if ( ( repositoryRequestInfo.isMetadata( requestedResource ) || repositoryRequestInfo.isMetadataSupportFile(
             requestedResource ) ) && repoGroupConfig != null )
         {
             // this should only be at the project level not version level!
@@ -340,7 +336,7 @@ public class ArchivaDavResourceFactory
                 filePath = filePath + "/maven-metadata-" + repoGroupConfig.getId() + ".xml";
 
                 // for MRM-872 handle checksums of the merged metadata files
-                if ( repositoryRequest.isSupportFile( requestedResource ) )
+                if ( repositoryRequestInfo.isSupportFile( requestedResource ) )
                 {
                     Path metadataChecksum =
                         Paths.get( filePath + "." + StringUtils.substringAfterLast( requestedResource, "." ) );
@@ -609,8 +605,7 @@ public class ArchivaDavResourceFactory
                         {
                             // Perform an adjustment of the resource to the managed
                             // repository expected path.
-                            String localResourcePath =
-                                repositoryRequest.toNativePath( logicalResource.getPath(), managedRepositoryContent );
+                            String localResourcePath = managedRepository.getRequestInfo().toNativePath( logicalResource.getPath() );
                             resourceFile = Paths.get( managedRepositoryContent.getRepoRoot(), localResourcePath );
                             resource =
                                 new ArchivaDavResource( resourceFile.toAbsolutePath().toString(), logicalResource.getPath(),
@@ -650,11 +645,11 @@ public class ArchivaDavResourceFactory
             if ( request.getMethod().equals( HTTP_PUT_METHOD ) )
             {
                 String resourcePath = logicalResource.getPath();
-
+                RepositoryRequestInfo repositoryRequestInfo = managedRepository.getRequestInfo();
                 // check if target repo is enabled for releases
                 // we suppose that release-artifacts can be deployed only to repos enabled for releases
-                if ( managedRepositoryContent.getRepository().getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE ) && !repositoryRequest.isMetadata(
-                    resourcePath ) && !repositoryRequest.isSupportFile( resourcePath ) )
+                if ( managedRepositoryContent.getRepository().getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE ) && !repositoryRequestInfo.isMetadata(
+                    resourcePath ) && !repositoryRequestInfo.isSupportFile( resourcePath ) )
                 {
                     ArtifactReference artifact = null;
                     try
@@ -756,8 +751,9 @@ public class ArchivaDavResourceFactory
         if (!proxyRegistry.hasHandler(managedRepository.getRepository().getType())) {
             throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No proxy handler found for repository type "+managedRepository.getRepository().getType());
         }
+        RepositoryRequestInfo repositoryRequestInfo = managedRepository.getRepository().getRequestInfo();
         RepositoryProxyHandler proxyHandler = proxyRegistry.getHandler(managedRepository.getRepository().getType()).get(0);
-        if ( repositoryRequest.isSupportFile( path ) )
+        if ( repositoryRequestInfo.isSupportFile( path ) )
         {
             Path proxiedFile = proxyHandler.fetchFromProxies( managedRepository, path );
 
@@ -765,13 +761,13 @@ public class ArchivaDavResourceFactory
         }
 
         // Is it a Metadata resource?
-        if ( repositoryRequest.isDefault( path ) && repositoryRequest.isMetadata( path ) )
+        if ( "default".equals(repositoryRequestInfo.getLayout( path )) && repositoryRequestInfo.isMetadata( path ) )
         {
             return proxyHandler.fetchMetadataFromProxies( managedRepository, path ).isModified();
         }
 
         // Is it an Archetype Catalog?
-        if ( repositoryRequest.isArchetypeCatalog( path ) )
+        if ( repositoryRequestInfo.isArchetypeCatalog( path ) )
         {
             // FIXME we must implement a merge of remote archetype catalog from remote servers.
             Path proxiedFile = proxyHandler.fetchFromProxies( managedRepository, path );
@@ -783,7 +779,7 @@ public class ArchivaDavResourceFactory
         try
         {
             // Get the artifact reference in a layout neutral way.
-            ArtifactReference artifact = repositoryRequest.toArtifactReference( path );
+            ArtifactReference artifact = repositoryRequestInfo.toArtifactReference( path );
 
             if ( artifact != null )
             {
@@ -1418,16 +1414,6 @@ public class ArchivaDavResourceFactory
         this.archivaConfiguration = archivaConfiguration;
     }
 
-    public void setRepositoryFactory( RepositoryContentFactory repositoryFactory )
-    {
-        this.repositoryFactory = repositoryFactory;
-    }
-
-    public void setRepositoryRequest( RepositoryRequest repositoryRequest )
-    {
-        this.repositoryRequest = repositoryRequest;
-    }
-
     public RemoteRepositoryAdmin getRemoteRepositoryAdmin()
     {
         return remoteRepositoryAdmin;
index 22a99f3b038de444a60a4b596a7d3ec0f5712e86..6932a31c41e11d61e42a1246fd021cd5bb2c1416 100644 (file)
@@ -47,7 +47,7 @@ import org.apache.archiva.repository.RepositoryException;
 import org.apache.archiva.repository.RepositoryRegistry;
 import org.apache.archiva.repository.RepositoryType;
 import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
-import org.apache.archiva.repository.content.maven2.RepositoryRequest;
+import org.apache.archiva.repository.content.maven2.MavenRepositoryRequestInfo;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.apache.commons.lang.StringUtils;
 import org.apache.jackrabbit.webdav.DavException;
@@ -105,7 +105,7 @@ public class ArchivaDavResourceFactoryTest
 
     private IMocksControl repoRequestControl;
 
-    private RepositoryRequest repoRequest;
+    private MavenRepositoryRequestInfo repoRequest;
 
     private IMocksControl responseControl;
 
@@ -222,13 +222,11 @@ public class ArchivaDavResourceFactoryTest
         repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class );
 
         repoRequestControl = createControl();
-        repoRequest = repoRequestControl.createMock( RepositoryRequest.class );
+        repoRequest = repoRequestControl.createMock( MavenRepositoryRequestInfo.class );
 
         resourceFactory =
             new OverridingArchivaDavResourceFactory( applicationContext, plexusSisuBridge, archivaConfiguration );
         resourceFactory.setArchivaConfiguration( archivaConfiguration );
-        resourceFactory.setRepositoryFactory( repoFactory );
-        resourceFactory.setRepositoryRequest( repoRequest );
         proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).clear();
         proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).add(new OverridingRepositoryProxyHandler(this));
         resourceFactory.setProxyRegistry(proxyRegistry);
@@ -353,14 +351,14 @@ public class ArchivaDavResourceFactoryTest
             expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
 
             expect(
-                repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
-                false );
+                repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
+                "legacy" );
 
             expect( repoRequest.toArtifactReference(
                 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
 
-            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
-                                              internalRepo ) ).andReturn(
+            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
+            ) ).andReturn(
                 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
                           "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
 
@@ -433,14 +431,14 @@ public class ArchivaDavResourceFactoryTest
             expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
 
             expect(
-                repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
-                false );
+                repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
+                "legacy" );
 
             expect( repoRequest.toArtifactReference(
                 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
 
-            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
-                                              internalRepo ) ).andReturn(
+            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
+            ) ).andReturn(
                 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
                           "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
 
@@ -515,19 +513,19 @@ public class ArchivaDavResourceFactoryTest
             expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
 
             expect(
-                repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
-                false ).times( 2 );
+                repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
+                "legacy" ).times( 2 );
 
             expect( repoRequest.toArtifactReference(
                 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 );
 
-            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
-                                              internalRepo ) ).andReturn(
+            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
+            ) ).andReturn(
                 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
                           "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString() );
 
-            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
-                                              localMirrorRepo ) )
+            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
+            ) )
                 .andReturn( Paths.get( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
                                       "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
 
@@ -565,8 +563,7 @@ public class ArchivaDavResourceFactoryTest
         ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
 
         // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
-        RepositoryRequest repoRequest = new RepositoryRequest( );
-        resourceFactory.setRepositoryRequest( repoRequest );
+        MavenRepositoryRequestInfo repoRequest = new MavenRepositoryRequestInfo(internalRepo.getRepository() );
 
         try
         {
@@ -624,10 +621,6 @@ public class ArchivaDavResourceFactoryTest
 
         ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
 
-        // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
-        RepositoryRequest repoRequest = new RepositoryRequest( );
-        resourceFactory.setRepositoryRequest( repoRequest );
-
         try
         {
             archivaConfigurationControl.reset();
@@ -680,10 +673,6 @@ public class ArchivaDavResourceFactoryTest
                                            LEGACY_REPO, new ArchivaDavLocatorFactory() );
 
 
-        // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
-        RepositoryRequest repoRequest = new RepositoryRequest( );
-        resourceFactory.setRepositoryRequest( repoRequest );
-
         try
         {
             archivaConfigurationControl.reset();