]> source.dussan.org Git - archiva.git/commitdiff
Moving to new layout interface
authorMartin Stockhammer <martin_s@apache.org>
Tue, 2 Jun 2020 12:50:21 +0000 (14:50 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Tue, 2 Jun 2020 12:50:21 +0000 (14:50 +0200)
archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java
archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java
archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java
archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java

index 8dd9a7b893e2a05e1aec7aa1312b09b8095705c8..e5c0b4b0dfe495289e95df3a037c2ae7cecb63ce 100644 (file)
@@ -288,8 +288,14 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
     }
 
     @Override
-    public ProxyFetchResult fetchMetadataFromProxies( ManagedRepository repository, String logicalPath )
+    public ProxyFetchResult fetchMetadataFromProxies( ManagedRepository repository, String rawLogicalPath )
     {
+        String logicalPath;
+        if (rawLogicalPath.startsWith( "/" )){
+            logicalPath = rawLogicalPath.substring( 1 );
+        } else {
+            logicalPath = rawLogicalPath;
+        }
         StorageAsset localFile = repository.getAsset( logicalPath );
 
         Properties requestProperties = new Properties();
@@ -470,7 +476,11 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
         {
             url = url + "/";
         }
-        url = url + remotePath;
+        if (remotePath.startsWith( "/" )) {
+            url = url + remotePath.substring( 1 );
+        } else {
+            url = url + remotePath;
+        }
         requestProperties.setProperty( "url", url );
 
         // Is a whitelist defined?
index c71d757ebca77ae9017aade590c61af2cced879c..6a0b0a86d508e00153246f1c909be80ac256597c 100644 (file)
@@ -258,6 +258,14 @@ public interface BaseRepositoryContentLayout extends ManagedRepositoryContentLay
      */
     DataItem getMetadataItem( Version version );
 
+    /**
+     * Returns the metadata file for the given project
+     *
+     * @param project the project
+     * @return the metadata file
+     */
+    DataItem getMetadataItem( Project project );
+
 
     /// *****************   End of new generation interface **********************
 
index 435e889e064d67fe5187f83bbefe9b9077bdf2f6..ddf40519aa396af24413d857b1c692b6ffdf9bbf 100644 (file)
@@ -292,6 +292,14 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
             .withDataType( BaseDataItemTypes.METADATA ).build();
     }
 
+    @Override
+    public DataItem getMetadataItem( Project project )
+    {
+        return ArchivaDataItem.withAsset( project.getAsset( ).resolve( "maven-metadata.xml" ) ).withId( "maven-metadata.xml" )
+            .withDataType( BaseDataItemTypes.METADATA ).build( );
+    }
+
+
     @Override
     public ContentItem toItem( String path ) throws LayoutException
     {
index 16a6adcf43670df66809b8da25af38b775c531bb..0bba6d5b27df99c5d81d4bffd4ceb1c43003c3da 100644 (file)
@@ -29,6 +29,7 @@ import org.apache.archiva.model.ProjectReference;
 import org.apache.archiva.model.VersionedReference;
 import org.apache.archiva.repository.*;
 import org.apache.archiva.repository.content.Artifact;
+import org.apache.archiva.repository.content.BaseDataItemTypes;
 import org.apache.archiva.repository.content.ContentItem;
 import org.apache.archiva.repository.content.DataItem;
 import org.apache.archiva.repository.content.ItemNotFoundException;
@@ -36,6 +37,7 @@ import org.apache.archiva.repository.content.ItemSelector;
 import org.apache.archiva.repository.content.Namespace;
 import org.apache.archiva.repository.content.Project;
 import org.apache.archiva.repository.content.Version;
+import org.apache.archiva.repository.content.base.ArchivaDataItem;
 import org.apache.archiva.repository.content.base.ArchivaNamespace;
 import org.apache.archiva.repository.content.base.ArchivaProject;
 import org.apache.archiva.repository.content.base.ArchivaVersion;
@@ -286,6 +288,14 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
         return null;
     }
 
+    @Override
+    public DataItem getMetadataItem( Project project )
+    {
+        return ArchivaDataItem.withAsset( project.getAsset( ).resolve( "maven-metadata.xml" ) ).withId( "maven-metadata.xml" )
+            .withDataType( BaseDataItemTypes.METADATA ).build( );
+    }
+
+
     @Override
     public ContentItem toItem( String path ) throws LayoutException
     {
index 1a19acfddec6e7c2b29f01d1071a115f24353051..71b66b9ec45b31cb80e58b04a5d8bb7d572ff15f 100644 (file)
@@ -34,7 +34,9 @@ import org.apache.archiva.policies.SnapshotsPolicy;
 import org.apache.archiva.repository.BaseRepositoryContentLayout;
 import org.apache.archiva.repository.content.ContentItem;
 import org.apache.archiva.repository.content.DataItem;
+import org.apache.archiva.repository.content.Project;
 import org.apache.archiva.repository.content.Version;
+import org.apache.archiva.repository.content.base.ArchivaItemSelector;
 import org.apache.archiva.repository.metadata.base.MetadataTools;
 import org.apache.archiva.repository.metadata.RepositoryMetadataException;
 import org.apache.archiva.repository.metadata.base.RepositoryMetadataWriter;
@@ -129,13 +131,13 @@ public class MetadataTransferTest
         assertNoRepoMetadata( ID_PROXIED1, requestedResource );
 
         Path expectedFile = managedDefaultDir.resolve(requestedResource);
-
-        ProjectReference metadata = createProjectReference( requestedResource );
-
         BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
+        ContentItem metaItem = managedDefaultRepository.toItem( requestedResource );
+        Project project = layout.adaptItem( Project.class, managedDefaultRepository.getParent( metaItem ) );
+        assertNotNull( project );
+        String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem( project ) );
         StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
-                                                                     layout.toMetadataPath(
-                                                                         metadata ) ).getFile();
+                                                                     metaPath ).getFile();
 
         assertNull( "Should not have downloaded a file.", downloadedFile );
         assertNoTempFiles( expectedFile );
@@ -994,13 +996,14 @@ public class MetadataTransferTest
     {
         Path expectedFile = managedDefaultDir.resolve(requestedResource);
 
-        ProjectReference metadata = createProjectReference( requestedResource );
-
         BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
+        ContentItem metaItem = managedDefaultRepository.toItem( requestedResource );
+        Project project = layout.adaptItem( Project.class, managedDefaultRepository.getParent( metaItem ) );
+        assertNotNull( project );
+        String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem( project ) );
 
         StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
-                                                                     layout.toMetadataPath(
-                                                                         metadata ) ).getFile();
+                                                                     metaPath ).getFile();
 
         assertNotNull( "Should have downloaded a file.", downloadedFile );
         assertNoTempFiles( expectedFile );
@@ -1022,12 +1025,14 @@ public class MetadataTransferTest
         throws Exception
     {
         Path expectedFile = managedDefaultDir.resolve(requestedResource);
-        ProjectReference metadata = createProjectReference( requestedResource );
 
         BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
+        ContentItem metaItem = managedDefaultRepository.toItem( requestedResource );
+        Project project = layout.adaptItem( Project.class, managedDefaultRepository.getParent( metaItem ) );
+        assertNotNull( project );
+        String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem( project ) );
         StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
-                                                                     layout.toMetadataPath(
-                                                                         metadata ) ).getFile();
+                                                                     metaPath ).getFile();
 
         assertNull( downloadedFile );
         assertNoTempFiles( expectedFile );
index 4c3d1bfc5b49e3d9914ac793b9833fd194f32e33..f2541b010b9e1814331aa123a830bfd17254b79c 100644 (file)
@@ -293,6 +293,13 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
             .withDataType( BaseDataItemTypes.METADATA ).build();
     }
 
+    @Override
+    public DataItem getMetadataItem( Project project )
+    {
+        return ArchivaDataItem.withAsset( project.getAsset( ).resolve( "maven-metadata.xml" ) ).withId( "maven-metadata.xml" )
+            .withDataType( BaseDataItemTypes.METADATA ).build( );
+    }
+
     @Override
     public ContentItem toItem( String path ) throws LayoutException
     {
index 5906c5695451f67fec4d6a25e8e9e19cca73ca7e..91657ce09a86a5b74549f78bd911790e0498007b 100644 (file)
@@ -1336,6 +1336,13 @@ public class ManagedDefaultRepositoryContent
         return getDataItemFromPath( metaPath );
     }
 
+    @Override
+    public DataItem getMetadataItem( Project project )
+    {
+        StorageAsset metaPath = project.getAsset( ).resolve( MAVEN_METADATA );
+        return getDataItemFromPath( metaPath );
+    }
+
 
     @Override
     public void deleteVersion( VersionedReference ref ) throws ContentNotFoundException, ContentAccessException