@Test public void testToItemFromPath() throws LayoutException { String path = "/org/apache/maven/shared"; ContentItem item = repoContent.toItem( path ); assertNotNull( item ); assertTrue( item instanceof ArchivaContentItem ); path = "/org/apache/maven/shared/maven-downloader"; item = repoContent.toItem( path ); assertNotNull( item ); assertTrue( item instanceof ArchivaContentItem ); path = "/org/apache/maven/shared/maven-downloader/1.1"; item = repoContent.toItem( path ); assertNotNull( item ); assertTrue( item instanceof ArchivaContentItem ); path = "/org/apache/maven/shared/maven-downloader/1.1/maven-downloader-1.1.jar"; item = repoContent.toItem( path ); assertNotNull( item ); assertTrue( item instanceof DataItem ); }
@Override public ContentItem toItem( String path ) throws LayoutException { StorageAsset asset = getRepository( ).getAsset( path ); ContentItem item = getItemFromPath( asset ); if (item instanceof DataItem) { Artifact artifact = adaptItem( Artifact.class, item ); if (asset.getParent()==null) { throw new LayoutException( "Path too short for maven artifact "+path ); } String version = asset.getParent( ).getName( ); if (asset.getParent().getParent()==null) { throw new LayoutException( "Path too short for maven artifact " + path ); } String project = item.getAsset( ).getParent( ).getParent( ).getName( ); DataItem dataItem = (DataItem) item; if (StringUtils.isEmpty( dataItem.getExtension())) { throw new LayoutException( "Missing type on maven artifact" ); } if (!project.equals(artifact.getId())) { throw new LayoutException( "The maven artifact id "+artifact.getId() +" does not match the project id: " + project); } boolean versionIsGenericSnapshot = VersionUtil.isGenericSnapshot( version ); boolean artifactVersionIsSnapshot = VersionUtil.isSnapshot( artifact.getArtifactVersion() ); if ( versionIsGenericSnapshot && !artifactVersionIsSnapshot ) { throw new LayoutException( "The maven artifact has no snapshot version in snapshot directory " + dataItem ); } if ( !versionIsGenericSnapshot && artifactVersionIsSnapshot) { throw new LayoutException( "The maven artifact version " + artifact.getArtifactVersion() + " is a snapshot version but inside a non snapshot directory " + version ); } if ( !versionIsGenericSnapshot && !version.equals( artifact.getArtifactVersion() ) ) { throw new LayoutException( "The maven artifact version " + artifact.getArtifactVersion() + " does not match the version directory " + version ); } } return item; }
ManagedDefaultRepositoryContent extends AbstractDefaultRepositoryContent implements ManagedRepositoryContent, BaseRepositoryContentLayout { @Override public ContentItem toItem( String path ) throws LayoutException { StorageAsset asset = getRepository( ).getAsset( path ); ContentItem item = getItemFromPath( asset ); if (item instanceof DataItem) { Artifact artifact = adaptItem( Artifact.class, item ); if (asset.getParent()==null) { throw new LayoutException( "Path too short for maven artifact "+path ); } String version = asset.getParent( ).getName( ); if (asset.getParent().getParent()==null) { throw new LayoutException( "Path too short for maven artifact " + path ); } String project = item.getAsset( ).getParent( ).getParent( ).getName( ); DataItem dataItem = (DataItem) item; if (StringUtils.isEmpty( dataItem.getExtension())) { throw new LayoutException( "Missing type on maven artifact" ); } if (!project.equals(artifact.getId())) { throw new LayoutException( "The maven artifact id "+artifact.getId() +" does not match the project id: " + project); } boolean versionIsGenericSnapshot = VersionUtil.isGenericSnapshot( version ); boolean artifactVersionIsSnapshot = VersionUtil.isSnapshot( artifact.getArtifactVersion() ); if ( versionIsGenericSnapshot && !artifactVersionIsSnapshot ) { throw new LayoutException( "The maven artifact has no snapshot version in snapshot directory " + dataItem ); } if ( !versionIsGenericSnapshot && artifactVersionIsSnapshot) { throw new LayoutException( "The maven artifact version " + artifact.getArtifactVersion() + " is a snapshot version but inside a non snapshot directory " + version ); } if ( !versionIsGenericSnapshot && !version.equals( artifact.getArtifactVersion() ) ) { throw new LayoutException( "The maven artifact version " + artifact.getArtifactVersion() + " does not match the version directory " + version ); } } return item; } }
ManagedDefaultRepositoryContent extends AbstractDefaultRepositoryContent implements ManagedRepositoryContent, BaseRepositoryContentLayout { @Override public ContentItem toItem( String path ) throws LayoutException { StorageAsset asset = getRepository( ).getAsset( path ); ContentItem item = getItemFromPath( asset ); if (item instanceof DataItem) { Artifact artifact = adaptItem( Artifact.class, item ); if (asset.getParent()==null) { throw new LayoutException( "Path too short for maven artifact "+path ); } String version = asset.getParent( ).getName( ); if (asset.getParent().getParent()==null) { throw new LayoutException( "Path too short for maven artifact " + path ); } String project = item.getAsset( ).getParent( ).getParent( ).getName( ); DataItem dataItem = (DataItem) item; if (StringUtils.isEmpty( dataItem.getExtension())) { throw new LayoutException( "Missing type on maven artifact" ); } if (!project.equals(artifact.getId())) { throw new LayoutException( "The maven artifact id "+artifact.getId() +" does not match the project id: " + project); } boolean versionIsGenericSnapshot = VersionUtil.isGenericSnapshot( version ); boolean artifactVersionIsSnapshot = VersionUtil.isSnapshot( artifact.getArtifactVersion() ); if ( versionIsGenericSnapshot && !artifactVersionIsSnapshot ) { throw new LayoutException( "The maven artifact has no snapshot version in snapshot directory " + dataItem ); } if ( !versionIsGenericSnapshot && artifactVersionIsSnapshot) { throw new LayoutException( "The maven artifact version " + artifact.getArtifactVersion() + " is a snapshot version but inside a non snapshot directory " + version ); } if ( !versionIsGenericSnapshot && !version.equals( artifact.getArtifactVersion() ) ) { throw new LayoutException( "The maven artifact version " + artifact.getArtifactVersion() + " does not match the version directory " + version ); } } return item; } ManagedDefaultRepositoryContent( );  ManagedDefaultRepositoryContent( ManagedRepository repository, FileTypes fileTypes, FileLockManager lockManager ); }
ManagedDefaultRepositoryContent extends AbstractDefaultRepositoryContent implements ManagedRepositoryContent, BaseRepositoryContentLayout { @Override public ContentItem toItem( String path ) throws LayoutException { StorageAsset asset = getRepository( ).getAsset( path ); ContentItem item = getItemFromPath( asset ); if (item instanceof DataItem) { Artifact artifact = adaptItem( Artifact.class, item ); if (asset.getParent()==null) { throw new LayoutException( "Path too short for maven artifact "+path ); } String version = asset.getParent( ).getName( ); if (asset.getParent().getParent()==null) { throw new LayoutException( "Path too short for maven artifact " + path ); } String project = item.getAsset( ).getParent( ).getParent( ).getName( ); DataItem dataItem = (DataItem) item; if (StringUtils.isEmpty( dataItem.getExtension())) { throw new LayoutException( "Missing type on maven artifact" ); } if (!project.equals(artifact.getId())) { throw new LayoutException( "The maven artifact id "+artifact.getId() +" does not match the project id: " + project); } boolean versionIsGenericSnapshot = VersionUtil.isGenericSnapshot( version ); boolean artifactVersionIsSnapshot = VersionUtil.isSnapshot( artifact.getArtifactVersion() ); if ( versionIsGenericSnapshot && !artifactVersionIsSnapshot ) { throw new LayoutException( "The maven artifact has no snapshot version in snapshot directory " + dataItem ); } if ( !versionIsGenericSnapshot && artifactVersionIsSnapshot) { throw new LayoutException( "The maven artifact version " + artifact.getArtifactVersion() + " is a snapshot version but inside a non snapshot directory " + version ); } if ( !versionIsGenericSnapshot && !version.equals( artifact.getArtifactVersion() ) ) { throw new LayoutException( "The maven artifact version " + artifact.getArtifactVersion() + " does not match the version directory " + version ); } } return item; } ManagedDefaultRepositoryContent( );  ManagedDefaultRepositoryContent( ManagedRepository repository, FileTypes fileTypes, FileLockManager lockManager ); void setFileTypes( FileTypes fileTypes ); @Override T adaptItem( Class<T> clazz, ContentItem item ); @Override void deleteAllItems( ItemSelector selector, Consumer<ItemDeleteStatus> consumer ); @Override void deleteItem( ContentItem item ); @Override ContentItem getItem( ItemSelector selector ); @Override Namespace getNamespace( final ItemSelector namespaceSelector ); @Override Project getProject( final ItemSelector selector ); @Override Version getVersion( final ItemSelector selector ); Artifact createArtifact( final StorageAsset artifactPath, final ItemSelector selector,
                                    final String classifier ); Namespace getNamespaceFromArtifactPath( final StorageAsset artifactPath ); Namespace getNamespaceFromPath( final StorageAsset nsPath ); Namespace createNamespaceFromPath( final StorageAsset namespacePath); @Override ManagedRepositoryContent getGenericContent( ); @Override Artifact getArtifact( final ItemSelector selectorArg ); @Override Artifact getArtifact( String path ); @Override List<? extends Project> getProjects( Namespace namespace ); @Override List<? extends Project> getProjects( ItemSelector selector ); @Override List<? extends Version> getVersions( final Project project ); @Override List<? extends Version> getVersions( final ItemSelector selector ); List<String> getArtifactVersions( final ItemSelector selector ); @Override List<? extends Artifact> getArtifacts( ItemSelector selector ); @Override Stream<? extends Artifact> newArtifactStream( ItemSelector selector ); @Override List<? extends Artifact> getArtifacts( ContentItem item ); Stream<? extends Artifact> newArtifactStream( Namespace item ); Stream<? extends Artifact> newArtifactStream( Project item ); Stream<? extends Artifact> newArtifactStream( Version item ); Stream<? extends Artifact> newArtifactStream( Artifact item ); @Override Stream<? extends Artifact> newArtifactStream( ContentItem item ); @Override Stream<? extends ContentItem> newItemStream( ItemSelector selector, boolean parallel ); @Override boolean hasContent( ItemSelector selector ); @Override ContentItem getParent( ContentItem item ); @Override List<? extends ContentItem> getChildren( ContentItem item ); @Override T applyCharacteristic( Class<T> clazz, ContentItem item ); @Override T getLayout( Class<T> clazz ); @Override boolean supportsLayout( Class<T> clazz ); @Override List<Class<? extends ManagedRepositoryContentLayout>> getSupportedLayouts( ); @Override void addArtifact( Path sourceFile, Artifact destination ); @Override ContentItem toItem( String path ); @Override ContentItem toItem( StorageAsset assetPath ); @Override String toPath( ContentItem item ); @Override DataItem getMetadataItem( Version version ); @Override DataItem getMetadataItem( Project project ); @Override String getId( ); @Override ManagedRepository getRepository( ); @Override void setRepository( final ManagedRepository repo ); void setFiletypes( FileTypes filetypes ); void setMavenContentHelper( MavenContentHelper contentHelper ); MavenMetadataReader getMetadataReader( ); void setMetadataReader( MavenMetadataReader metadataReader ); }
ManagedDefaultRepositoryContent extends AbstractDefaultRepositoryContent implements ManagedRepositoryContent, BaseRepositoryContentLayout { @Override public ContentItem toItem( String path ) throws LayoutException { StorageAsset asset = getRepository( ).getAsset( path ); ContentItem item = getItemFromPath( asset ); if (item instanceof DataItem) { Artifact artifact = adaptItem( Artifact.class, item ); if (asset.getParent()==null) { throw new LayoutException( "Path too short for maven artifact "+path ); } String version = asset.getParent( ).getName( ); if (asset.getParent().getParent()==null) { throw new LayoutException( "Path too short for maven artifact " + path ); } String project = item.getAsset( ).getParent( ).getParent( ).getName( ); DataItem dataItem = (DataItem) item; if (StringUtils.isEmpty( dataItem.getExtension())) { throw new LayoutException( "Missing type on maven artifact" ); } if (!project.equals(artifact.getId())) { throw new LayoutException( "The maven artifact id "+artifact.getId() +" does not match the project id: " + project); } boolean versionIsGenericSnapshot = VersionUtil.isGenericSnapshot( version ); boolean artifactVersionIsSnapshot = VersionUtil.isSnapshot( artifact.getArtifactVersion() ); if ( versionIsGenericSnapshot && !artifactVersionIsSnapshot ) { throw new LayoutException( "The maven artifact has no snapshot version in snapshot directory " + dataItem ); } if ( !versionIsGenericSnapshot && artifactVersionIsSnapshot) { throw new LayoutException( "The maven artifact version " + artifact.getArtifactVersion() + " is a snapshot version but inside a non snapshot directory " + version ); } if ( !versionIsGenericSnapshot && !version.equals( artifact.getArtifactVersion() ) ) { throw new LayoutException( "The maven artifact version " + artifact.getArtifactVersion() + " does not match the version directory " + version ); } } return item; } ManagedDefaultRepositoryContent( );  ManagedDefaultRepositoryContent( ManagedRepository repository, FileTypes fileTypes, FileLockManager lockManager ); void setFileTypes( FileTypes fileTypes ); @Override T adaptItem( Class<T> clazz, ContentItem item ); @Override void deleteAllItems( ItemSelector selector, Consumer<ItemDeleteStatus> consumer ); @Override void deleteItem( ContentItem item ); @Override ContentItem getItem( ItemSelector selector ); @Override Namespace getNamespace( final ItemSelector namespaceSelector ); @Override Project getProject( final ItemSelector selector ); @Override Version getVersion( final ItemSelector selector ); Artifact createArtifact( final StorageAsset artifactPath, final ItemSelector selector,
                                    final String classifier ); Namespace getNamespaceFromArtifactPath( final StorageAsset artifactPath ); Namespace getNamespaceFromPath( final StorageAsset nsPath ); Namespace createNamespaceFromPath( final StorageAsset namespacePath); @Override ManagedRepositoryContent getGenericContent( ); @Override Artifact getArtifact( final ItemSelector selectorArg ); @Override Artifact getArtifact( String path ); @Override List<? extends Project> getProjects( Namespace namespace ); @Override List<? extends Project> getProjects( ItemSelector selector ); @Override List<? extends Version> getVersions( final Project project ); @Override List<? extends Version> getVersions( final ItemSelector selector ); List<String> getArtifactVersions( final ItemSelector selector ); @Override List<? extends Artifact> getArtifacts( ItemSelector selector ); @Override Stream<? extends Artifact> newArtifactStream( ItemSelector selector ); @Override List<? extends Artifact> getArtifacts( ContentItem item ); Stream<? extends Artifact> newArtifactStream( Namespace item ); Stream<? extends Artifact> newArtifactStream( Project item ); Stream<? extends Artifact> newArtifactStream( Version item ); Stream<? extends Artifact> newArtifactStream( Artifact item ); @Override Stream<? extends Artifact> newArtifactStream( ContentItem item ); @Override Stream<? extends ContentItem> newItemStream( ItemSelector selector, boolean parallel ); @Override boolean hasContent( ItemSelector selector ); @Override ContentItem getParent( ContentItem item ); @Override List<? extends ContentItem> getChildren( ContentItem item ); @Override T applyCharacteristic( Class<T> clazz, ContentItem item ); @Override T getLayout( Class<T> clazz ); @Override boolean supportsLayout( Class<T> clazz ); @Override List<Class<? extends ManagedRepositoryContentLayout>> getSupportedLayouts( ); @Override void addArtifact( Path sourceFile, Artifact destination ); @Override ContentItem toItem( String path ); @Override ContentItem toItem( StorageAsset assetPath ); @Override String toPath( ContentItem item ); @Override DataItem getMetadataItem( Version version ); @Override DataItem getMetadataItem( Project project ); @Override String getId( ); @Override ManagedRepository getRepository( ); @Override void setRepository( final ManagedRepository repo ); void setFiletypes( FileTypes filetypes ); void setMavenContentHelper( MavenContentHelper contentHelper ); MavenMetadataReader getMetadataReader( ); void setMetadataReader( MavenMetadataReader metadataReader ); static final String SNAPSHOT_ARTIFACT_VERSION; static final String SNAPSHOT; static final Pattern UNIQUE_SNAPSHOT_PATTERN; static final Pattern CLASSIFIER_PATTERN; static final Pattern COMMON_EXTENSIONS; static final Pattern TIMESTAMP_PATTERN; static final Pattern GENERIC_SNAPSHOT_PATTERN; }