From ddfcb4adb6d0d0d903753d55560021b6e5c6c982 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Tue, 2 Jun 2020 14:50:21 +0200 Subject: [PATCH] Moving to new layout interface --- .../proxy/DefaultRepositoryProxyHandler.java | 14 +++++++-- .../BaseRepositoryContentLayout.java | 8 +++++ .../mock/ManagedRepositoryContentMock.java | 8 +++++ .../mock/ManagedRepositoryContentMock.java | 10 +++++++ .../archiva/proxy/MetadataTransferTest.java | 29 +++++++++++-------- .../mock/ManagedRepositoryContentMock.java | 7 +++++ .../ManagedDefaultRepositoryContent.java | 7 +++++ 7 files changed, 69 insertions(+), 14 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java index 8dd9a7b89..e5c0b4b0d 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java @@ -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? diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java index c71d757eb..6a0b0a86d 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java @@ -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 ********************** diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java index 435e889e0..ddf40519a 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java @@ -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 { diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java index 16a6adcf4..0bba6d5b2 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java @@ -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 { diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java index 1a19acfdd..71b66b9ec 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java @@ -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 ); diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java index 4c3d1bfc5..f2541b010 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java @@ -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 { diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java index 5906c5695..91657ce09 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java @@ -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 -- 2.39.5