diff options
author | Martin Stockhammer <martin_s@apache.org> | 2020-06-01 14:03:03 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2020-06-01 14:03:03 +0200 |
commit | 2257aae023b20646e0b34369be24f5fc1718750f (patch) | |
tree | 7118f423730ab645510567f83e6aa4bf72348ef4 /archiva-modules/archiva-maven/archiva-maven-proxy | |
parent | 6d7a510dea283ff8c4b1e6ae54a395dbe386e4a5 (diff) | |
download | archiva-2257aae023b20646e0b34369be24f5fc1718750f.tar.gz archiva-2257aae023b20646e0b34369be24f5fc1718750f.zip |
Repository content refactoring
Diffstat (limited to 'archiva-modules/archiva-maven/archiva-maven-proxy')
2 files changed, 101 insertions, 35 deletions
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 654e4980d..1a19acfdd 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 @@ -32,6 +32,9 @@ import org.apache.archiva.policies.ChecksumPolicy; import org.apache.archiva.policies.ReleasesPolicy; 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.Version; import org.apache.archiva.repository.metadata.base.MetadataTools; import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.repository.metadata.base.RepositoryMetadataWriter; @@ -1041,12 +1044,19 @@ public class MetadataTransferTest { Path expectedFile = managedDefaultDir.resolve(requestedResource); - VersionedReference metadata = createVersionedReference( requestedResource ); - + ContentItem item = managedDefaultRepository.toItem( requestedResource ); + if (item instanceof DataItem) { + item = managedDefaultRepository.getParent( item ); + } + assertNotNull( item ); BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class ); + Version version = layout.adaptItem( Version.class, item ); + assertNotNull( version ); + String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem( + version ) ); + StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(), - layout.toMetadataPath( - metadata ) ).getFile(); + metaPath).getFile(); assertNotNull( "Should have downloaded a file.", downloadedFile ); assertNoTempFiles( expectedFile ); @@ -1068,12 +1078,16 @@ public class MetadataTransferTest throws Exception { Path expectedFile = managedDefaultDir.resolve(requestedResource); - VersionedReference metadata = createVersionedReference( requestedResource ); - + ContentItem item = managedDefaultRepository.toItem( requestedResource ); + assertNotNull( item ); BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class ); + Version version = layout.adaptItem( Version.class, item ); + assertNotNull( version ); + String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem( + version ) ); + assertNotNull( metaPath ); 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 ae862aea9..4c3d1bfc5 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 @@ -29,12 +29,19 @@ 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; 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.ArchivaContentItem; +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; import org.apache.archiva.repository.storage.fs.FilesystemStorage; import org.apache.archiva.repository.storage.RepositoryStorage; import org.apache.archiva.repository.storage.StorageAsset; @@ -84,6 +91,51 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout } @Override + public <T extends ContentItem> T adaptItem( Class<T> clazz, ContentItem item ) throws LayoutException + { + if (clazz.isAssignableFrom( Version.class )) + { + if ( !item.hasCharacteristic( Version.class ) ) + { + item.setCharacteristic( Version.class, createVersionFromPath( item.getAsset() ) ); + } + return (T) item.adapt( Version.class ); + } else if ( clazz.isAssignableFrom( Project.class )) { + if ( !item.hasCharacteristic( Project.class ) ) + { + item.setCharacteristic( Project.class, createProjectFromPath( item.getAsset() ) ); + } + return (T) item.adapt( Project.class ); + } else if ( clazz.isAssignableFrom( Namespace.class )) { + if ( !item.hasCharacteristic( Namespace.class ) ) + { + item.setCharacteristic( Namespace.class, createNamespaceFromPath( item.getAsset() ) ); + } + return (T) item.adapt( Namespace.class ); + } + throw new LayoutException( "Could not convert item to class " + clazz); + } + + private Version createVersionFromPath( StorageAsset asset ) + { + Project proj = createProjectFromPath( asset.getParent( ) ); + return ArchivaVersion.withRepository( this ).withAsset( asset ) + .withProject( proj ).withVersion( asset.getName( ) ).build(); + } + + private Project createProjectFromPath( StorageAsset asset) { + Namespace ns = createNamespaceFromPath( asset ); + return ArchivaProject.withRepository( this ).withAsset( asset ) + .withNamespace( ns ).withId( asset.getName( ) ).build( ); + } + + private Namespace createNamespaceFromPath( StorageAsset asset) { + String namespace = asset.getPath( ).replace( "/", "." ); + return ArchivaNamespace.withRepository( this ) + .withAsset( asset ).withNamespace( namespace ).build(); + } + + @Override public void deleteAllItems( ItemSelector selector, Consumer<ItemDeleteStatus> consumer ) throws ContentAccessException, IllegalArgumentException { @@ -194,7 +246,14 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout @Override public ContentItem getParent( ContentItem item ) { - return null; + try + { + return toItem( item.getAsset( ).getParent( ) ); + } + catch ( LayoutException e ) + { + throw new RuntimeException( "Bad layout conversion " + e.getMessage( ) ); + } } @Override @@ -228,15 +287,30 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout } @Override + public DataItem getMetadataItem( Version version ) + { + return ArchivaDataItem.withAsset( version.getAsset( ).resolve( "maven-metadata.xml" ) ).withId( "maven-metadata.xml" ) + .withDataType( BaseDataItemTypes.METADATA ).build(); + } + + @Override public ContentItem toItem( String path ) throws LayoutException { - return null; + StorageAsset asset = repository.getAsset( "" ).resolve( path ); + return toItem( asset ); } @Override - public ContentItem toItem( StorageAsset assetPath ) throws LayoutException + public ContentItem toItem( StorageAsset asset ) throws LayoutException { - return null; + if (asset.isLeaf()) { + return ArchivaDataItem.withAsset( asset ).withId( asset.getName( ) ).build(); + } else + { + return ArchivaContentItem.withRepository( this ) + .withAsset( asset ) + .build( ); + } } @Override @@ -272,7 +346,7 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout @Override public String toPath( ContentItem item ) { - return null; + return item.getAsset( ).getPath( ); } @Override @@ -557,22 +631,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout return path.toString(); } - public String toMetadataPath( VersionedReference reference ) - { - StringBuilder path = new StringBuilder(); - - path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR ); - path.append( reference.getArtifactId() ).append( PATH_SEPARATOR ); - if ( reference.getVersion() != null ) - { - // add the version only if it is present - path.append( VersionUtil.getBaseVersion( reference.getVersion() ) ).append( PATH_SEPARATOR ); - } - path.append( MAVEN_METADATA ); - - return path.toString(); - } - @Override public String toPath( ArtifactReference reference ) { @@ -592,12 +650,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout } @Override - public String toPath( ArchivaArtifact reference ) - { - return null; - } - - @Override public ManagedRepositoryContent getGenericContent( ) { return null; |