1 package org.apache.archiva.repository.maven.content;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.common.filelock.FileLockManager;
22 import org.apache.archiva.common.utils.FileUtils;
23 import org.apache.archiva.configuration.FileTypes;
24 import org.apache.archiva.metadata.maven.MavenMetadataReader;
25 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
26 import org.apache.archiva.model.ArtifactReference;
27 import org.apache.archiva.model.VersionedReference;
28 import org.apache.archiva.repository.ContentAccessException;
29 import org.apache.archiva.repository.ContentNotFoundException;
30 import org.apache.archiva.repository.EditableManagedRepository;
31 import org.apache.archiva.repository.ManagedRepositoryContent;
32 import org.apache.archiva.repository.ItemDeleteStatus;
33 import org.apache.archiva.repository.LayoutException;
34 import org.apache.archiva.repository.ManagedRepository;
35 import org.apache.archiva.repository.BaseRepositoryContentLayout;
36 import org.apache.archiva.repository.ManagedRepositoryContentLayout;
37 import org.apache.archiva.repository.content.Artifact;
38 import org.apache.archiva.repository.content.ArtifactType;
39 import org.apache.archiva.repository.content.BaseArtifactTypes;
40 import org.apache.archiva.repository.content.ContentItem;
41 import org.apache.archiva.repository.content.DataItem;
42 import org.apache.archiva.repository.content.ItemNotFoundException;
43 import org.apache.archiva.repository.content.ItemSelector;
44 import org.apache.archiva.repository.content.Namespace;
45 import org.apache.archiva.repository.content.Project;
46 import org.apache.archiva.repository.content.Version;
47 import org.apache.archiva.repository.content.base.ArchivaContentItem;
48 import org.apache.archiva.repository.content.base.ArchivaItemSelector;
49 import org.apache.archiva.repository.content.base.ArchivaNamespace;
50 import org.apache.archiva.repository.content.base.ArchivaProject;
51 import org.apache.archiva.repository.content.base.ArchivaVersion;
52 import org.apache.archiva.repository.content.base.builder.ArtifactOptBuilder;
53 import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
54 import org.apache.archiva.repository.maven.metadata.storage.DefaultArtifactMappingProvider;
55 import org.apache.archiva.repository.storage.RepositoryStorage;
56 import org.apache.archiva.repository.storage.StorageAsset;
57 import org.apache.archiva.repository.storage.util.StorageUtil;
58 import org.apache.commons.collections4.map.ReferenceMap;
59 import org.apache.commons.lang3.StringUtils;
61 import javax.inject.Inject;
62 import javax.inject.Named;
63 import java.io.IOException;
65 import java.nio.file.Files;
66 import java.nio.file.Path;
67 import java.nio.file.Paths;
68 import java.util.Arrays;
69 import java.util.Collections;
70 import java.util.List;
71 import java.util.function.Consumer;
72 import java.util.function.Predicate;
73 import java.util.regex.Matcher;
74 import java.util.regex.Pattern;
75 import java.util.stream.Collectors;
76 import java.util.stream.Stream;
79 * ManagedDefaultRepositoryContent
81 public class ManagedDefaultRepositoryContent
82 extends AbstractDefaultRepositoryContent
83 implements ManagedRepositoryContent, BaseRepositoryContentLayout
86 // attribute flag that marks version objects that point to a snapshot artifact version
87 public static final String SNAPSHOT_ARTIFACT_VERSION = "maven.snav";
89 private FileTypes filetypes;
91 public void setFileTypes( FileTypes fileTypes )
93 this.filetypes = fileTypes;
96 private ManagedRepository repository;
98 private FileLockManager lockManager;
101 @Named( "repositoryPathTranslator#maven2" )
102 private RepositoryPathTranslator pathTranslator;
105 @Named( "metadataReader#maven" )
106 MavenMetadataReader metadataReader;
109 @Named( "MavenContentHelper" )
110 MavenContentHelper mavenContentHelper;
112 public static final String SNAPSHOT = "SNAPSHOT";
114 public static final Pattern UNIQUE_SNAPSHOT_PATTERN = Pattern.compile( "^(SNAPSHOT|[0-9]{8}\\.[0-9]{6}-[0-9]+)(.*)" );
115 public static final Pattern CLASSIFIER_PATTERN = Pattern.compile( "^-([^.]+)(\\..*)" );
116 public static final Pattern COMMON_EXTENSIONS = Pattern.compile( "^(jar|war|ear|dar|tar|zip|pom|xml)$" );
118 public static final Pattern TIMESTAMP_PATTERN = Pattern.compile( "^([0-9]{8})\\.([0-9]{6})$" );
120 public static final Pattern GENERIC_SNAPSHOT_PATTERN = Pattern.compile( "^(.*)-" + SNAPSHOT );
123 * We are caching content items in a weak reference map. To avoid always recreating the
124 * the hierarchical structure.
125 * TODO: Better use a object cache? E.g. our spring cache implementation?
127 private ReferenceMap<StorageAsset, ContentItem> itemMap = new ReferenceMap<>( );
128 private ReferenceMap<StorageAsset, DataItem> dataItemMap = new ReferenceMap<>( );
130 public ManagedDefaultRepositoryContent( )
132 super( Collections.singletonList( new DefaultArtifactMappingProvider( ) ) );
135 public ManagedDefaultRepositoryContent( ManagedRepository repository, FileTypes fileTypes, FileLockManager lockManager )
137 super( Collections.singletonList( new DefaultArtifactMappingProvider( ) ) );
138 setFileTypes( fileTypes );
139 this.lockManager = lockManager;
140 setRepository( repository );
143 public ManagedDefaultRepositoryContent( ManagedRepository repository, List<? extends ArtifactMappingProvider> artifactMappingProviders, FileTypes fileTypes, FileLockManager lockManager )
145 super( artifactMappingProviders == null ? Collections.singletonList( new DefaultArtifactMappingProvider( ) ) : artifactMappingProviders );
146 setFileTypes( fileTypes );
147 this.lockManager = lockManager;
148 setRepository( repository );
152 private StorageAsset getAssetByPath( String assetPath )
154 return getStorage( ).getAsset( assetPath );
157 private StorageAsset getAsset( String namespace )
159 String namespacePath = formatAsDirectory( namespace.trim( ) );
160 if ( StringUtils.isEmpty( namespacePath ) )
164 return getAssetByPath( namespacePath );
167 private StorageAsset getAsset( String namespace, String project )
169 return getAsset( namespace ).resolve( project );
172 private StorageAsset getAsset( String namespace, String project, String version )
174 return getAsset( namespace, project ).resolve( version );
177 private StorageAsset getAsset( String namespace, String project, String version, String fileName )
179 return getAsset( namespace, project, version ).resolve( fileName );
183 /// ************* Start of new generation interface ******************
187 public <T extends ContentItem> T adaptItem( Class<T> clazz, ContentItem item ) throws LayoutException
189 if (clazz.isAssignableFrom( Version.class ))
191 if ( !item.hasCharacteristic( Version.class ) )
193 item.setCharacteristic( Version.class, createVersionFromPath( item.getAsset() ) );
195 return (T) item.adapt( Version.class );
196 } else if ( clazz.isAssignableFrom( Project.class )) {
197 if ( !item.hasCharacteristic( Project.class ) )
199 item.setCharacteristic( Project.class, createProjectFromPath( item.getAsset() ) );
201 return (T) item.adapt( Project.class );
202 } else if ( clazz.isAssignableFrom( Namespace.class )) {
203 if ( !item.hasCharacteristic( Namespace.class ) )
205 item.setCharacteristic( Namespace.class, createNamespaceFromPath( item.getAsset() ) );
207 return (T) item.adapt( Namespace.class );
208 } else if ( clazz.isAssignableFrom( Artifact.class )) {
209 if (!item.hasCharacteristic( Artifact.class )) {
210 item.setCharacteristic( Artifact.class, createArtifactFromPath( item.getAsset( ) ) );
212 return (T) item.adapt( Artifact.class );
214 throw new LayoutException( "Could not convert item to class " + clazz);
219 public void deleteAllItems( ItemSelector selector, Consumer<ItemDeleteStatus> consumer ) throws ContentAccessException, IllegalArgumentException
221 try ( Stream<? extends ContentItem> stream = newItemStream( selector, false ) )
223 stream.forEach( item -> {
227 consumer.accept( new ItemDeleteStatus( item ) );
229 catch ( ItemNotFoundException e )
231 consumer.accept( new ItemDeleteStatus( item, ItemDeleteStatus.ITEM_NOT_FOUND, e ) );
233 catch ( Exception e )
235 consumer.accept( new ItemDeleteStatus( item, ItemDeleteStatus.DELETION_FAILED, e ) );
237 catch ( Throwable e )
239 consumer.accept( new ItemDeleteStatus( item, ItemDeleteStatus.UNKNOWN, e ) );
246 * Removes the item from the filesystem. For namespaces, projects and versions it deletes
248 * For namespaces you have to be careful, because maven repositories may have sub namespaces
249 * parallel to projects. Which means deleting a namespaces also deletes the sub namespaces and
250 * not only the projects of the given namespace. Better run the delete for each project of
253 * Artifacts are deleted as provided. No related artifacts will be deleted.
255 * @param item the item that should be removed
256 * @throws ItemNotFoundException if the item does not exist
257 * @throws ContentAccessException if some error occurred while accessing the filesystem
260 public void deleteItem( ContentItem item ) throws ItemNotFoundException, ContentAccessException
262 final Path baseDirectory = getRepoDir( );
263 final Path itemPath = item.getAsset( ).getFilePath( );
264 if ( !Files.exists( itemPath ) )
266 throw new ItemNotFoundException( "The item " + item.toString( ) + "does not exist in the repository " + getId( ) );
268 if ( !itemPath.toAbsolutePath( ).startsWith( baseDirectory.toAbsolutePath( ) ) )
270 log.error( "The namespace {} to delete from repository {} is not a subdirectory of the repository base.", item, getId( ) );
271 log.error( "Namespace directory: {}", itemPath );
272 log.error( "Repository directory: {}", baseDirectory );
273 throw new ContentAccessException( "Inconsistent directories found. Could not delete namespace." );
277 if ( Files.isDirectory( itemPath ) )
279 FileUtils.deleteDirectory( itemPath );
283 Files.deleteIfExists( itemPath );
286 catch ( IOException e )
288 log.error( "Could not delete item from path {}: {}", itemPath, e.getMessage( ), e );
289 throw new ContentAccessException( "Error occured while deleting item " + item + ": " + e.getMessage( ), e );
294 public ContentItem getItem( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
296 if ( selector.hasVersion( ) && selector.hasArtifactId( ) )
298 return getArtifact( selector );
300 else if ( selector.hasProjectId( ) && selector.hasVersion( ) )
302 return getVersion( selector );
304 else if ( selector.hasProjectId( ) )
306 return getProject( selector );
310 return getNamespace( selector );
315 public Namespace getNamespace( final ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException
317 StorageAsset nsPath = getAsset( namespaceSelector.getNamespace() );
318 return getNamespaceFromPath( nsPath );
323 public Project getProject( final ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
325 if ( !selector.hasProjectId( ) )
327 throw new IllegalArgumentException( "Project id must be set" );
329 final StorageAsset path = getAsset( selector.getNamespace( ), selector.getProjectId( ) );
330 return getProjectFromPath( path );
335 public Version getVersion( final ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
337 if ( !selector.hasProjectId( ) )
339 throw new IllegalArgumentException( "Project id must be set" );
341 if ( !selector.hasVersion( ) )
343 throw new IllegalArgumentException( "Version must be set" );
345 final StorageAsset path = getAsset( selector.getNamespace( ), selector.getProjectId( ), selector.getVersion( ) );
346 return getVersionFromPath( path );
350 public Artifact createArtifact( final StorageAsset artifactPath, final ItemSelector selector,
351 final String classifier, final String extension )
353 Version version = getVersion( selector );
354 ArtifactOptBuilder builder = org.apache.archiva.repository.content.base.ArchivaArtifact.withAsset( artifactPath )
355 .withVersion( version )
356 .withId( selector.getArtifactId( ) )
357 .withArtifactVersion( mavenContentHelper.getArtifactVersion( artifactPath, selector ) )
358 .withClassifier( classifier );
359 if ( selector.hasType( ) )
361 builder.withType( selector.getType( ) );
363 return builder.build( );
366 public Namespace getNamespaceFromArtifactPath( final StorageAsset artifactPath )
368 final StorageAsset namespacePath = artifactPath.getParent( ).getParent( ).getParent( );
369 return getNamespaceFromPath( namespacePath );
372 public Namespace getNamespaceFromPath( final StorageAsset nsPath )
374 ContentItem item = itemMap.computeIfAbsent( nsPath,
375 path -> createNamespaceFromPath( nsPath ) );
376 if (!item.hasCharacteristic( Namespace.class )) {
377 item.setCharacteristic( Namespace.class, createNamespaceFromPath( nsPath ) );
379 return item.adapt( Namespace.class );
382 public Namespace createNamespaceFromPath( final StorageAsset namespacePath) {
383 final String namespace = MavenContentHelper.getNamespaceFromNamespacePath( namespacePath );
384 return ArchivaNamespace.withRepository( this )
385 .withAsset( namespacePath )
386 .withNamespace( namespace )
390 private Project getProjectFromPath( final StorageAsset path )
392 ContentItem item = itemMap.computeIfAbsent( path, projectPath ->
393 createProjectFromPath( projectPath )
395 if (!item.hasCharacteristic( Project.class )) {
396 item.setCharacteristic( Project.class, createProjectFromPath( path ) );
398 return item.adapt( Project.class );
401 private Project createProjectFromPath( final StorageAsset projectPath ) {
402 Namespace namespace = getNamespaceFromPath( projectPath.getParent( ) );
403 return ArchivaProject.withRepository( this ).withAsset( projectPath )
404 .withNamespace( namespace )
405 .withId( projectPath.getName( ) ).build( );
408 private Project getProjectFromArtifactPath( final StorageAsset artifactPath )
410 final StorageAsset projectPath = artifactPath.getParent( ).getParent( );
411 return getProjectFromPath( projectPath );
414 private Version getVersionFromArtifactPath( final StorageAsset artifactPath )
416 final StorageAsset versionPath = artifactPath.getParent( );
417 return getVersionFromPath( versionPath );
420 private Version getVersionFromPath( StorageAsset path )
422 ContentItem item = itemMap.computeIfAbsent( path, versionPath ->
423 createVersionFromPath( versionPath )
425 if (!item.hasCharacteristic( Version.class )) {
426 item.setCharacteristic( Version.class, createVersionFromPath( path ) );
428 return item.adapt( Version.class );
431 private Version createVersionFromPath(StorageAsset path) {
432 Project proj = getProjectFromPath( path.getParent( ) );
433 return ArchivaVersion.withRepository( this ).withAsset( path )
434 .withProject( proj ).withVersion(path.getName()).build();
437 private Artifact getArtifactFromPath( final StorageAsset artifactPath )
439 DataItem item = dataItemMap.computeIfAbsent( artifactPath, myArtifactPath ->
440 createArtifactFromPath( myArtifactPath )
442 if (!item.hasCharacteristic( Artifact.class )) {
443 item.setCharacteristic( Artifact.class, createArtifactFromPath( artifactPath ) );
445 return item.adapt( Artifact.class );
448 private Artifact createArtifactFromPath( final StorageAsset artifactPath ) {
449 final Version version = getVersionFromArtifactPath( artifactPath );
450 final ArtifactInfo info = getArtifactInfoFromPath( version.getVersion( ), artifactPath );
451 return org.apache.archiva.repository.content.base.ArchivaArtifact.withAsset( artifactPath )
452 .withVersion( version )
454 .withClassifier( info.classifier )
455 .withRemainder( info.remainder )
456 .withType( info.type )
457 .withArtifactVersion( info.version )
458 .withContentType( info.contentType )
459 .withArtifactType( info.artifactType )
463 private String getContentType(StorageAsset artifactPath) {
466 return Files.probeContentType( artifactPath.getFilePath( ) );
469 catch ( IOException e )
475 private DataItem getDataItemFromPath( final StorageAsset artifactPath )
477 final String extension = StringUtils.substringAfterLast( artifactPath.getName( ), "." );
478 final String contentType = getContentType( artifactPath );
479 return dataItemMap.computeIfAbsent( artifactPath, myArtifactPath ->
480 org.apache.archiva.repository.content.base.ArchivaDataItem.withAsset( artifactPath )
481 .withId( artifactPath.getName( ) )
482 .withContentType( contentType )
488 private ContentItem getItemFromPath( final StorageAsset itemPath )
490 if ( itemPath.isLeaf( ) )
492 if (dataItemMap.containsKey( itemPath )) {
493 return dataItemMap.get( itemPath );
495 return getDataItemFromPath( itemPath );
499 if (itemMap.containsKey( itemPath )) {
500 return itemMap.get( itemPath );
502 return ArchivaContentItem.withRepository( this ).withAsset( itemPath ).build();
508 public ManagedRepositoryContent getGenericContent( )
513 // Simple object to hold artifact information
514 private class ArtifactInfo
517 private String version;
518 private String extension;
519 private String remainder;
521 private String classifier;
522 private String contentType;
523 private StorageAsset asset;
524 private ArtifactType artifactType = BaseArtifactTypes.MAIN;
527 private ArtifactInfo getArtifactInfoFromPath( String genericVersion, StorageAsset path )
529 final ArtifactInfo info = new ArtifactInfo( );
531 info.id = path.getParent( ).getParent( ).getName( );
532 final String fileName = path.getName( );
533 if ( genericVersion.endsWith( "-" + SNAPSHOT ) )
535 String baseVersion = StringUtils.substringBeforeLast( genericVersion, "-" + SNAPSHOT );
536 String prefix = info.id + "-" + baseVersion + "-";
537 if ( fileName.startsWith( prefix ) )
539 String versionPostfix = StringUtils.removeStart( fileName, prefix );
540 Matcher matcher = UNIQUE_SNAPSHOT_PATTERN.matcher( versionPostfix );
541 if ( matcher.matches( ) )
543 info.version = baseVersion + "-" + matcher.group( 1 );
544 String newPrefix = info.id + "-" + info.version;
545 if ( fileName.startsWith( newPrefix ) )
547 String classPostfix = StringUtils.removeStart( fileName, newPrefix );
548 Matcher cMatch = CLASSIFIER_PATTERN.matcher( classPostfix );
549 if ( cMatch.matches( ) )
551 info.classifier = cMatch.group( 1 );
552 info.remainder = cMatch.group( 2 );
556 info.classifier = "";
557 info.remainder = classPostfix;
562 log.debug( "Artifact does not match the maven name pattern {}", path );
563 info.artifactType = BaseArtifactTypes.UNKNOWN;
564 info.classifier = "";
565 info.remainder = StringUtils.substringAfter( fileName, prefix );
570 log.debug( "Artifact does not match the snapshot version pattern {}", path );
572 info.artifactType = BaseArtifactTypes.UNKNOWN;
573 // This is just a guess. No guarantee to the get a usable version.
574 info.version = StringUtils.removeStart( fileName, info.id + '-' );
575 String postfix = StringUtils.substringAfterLast( info.version, "." ).toLowerCase( );
576 while ( COMMON_EXTENSIONS.matcher( postfix ).matches( ) )
578 info.version = StringUtils.substringBeforeLast( info.version, "." );
579 postfix = StringUtils.substringAfterLast( info.version, "." ).toLowerCase( );
581 info.classifier = "";
582 info.remainder = StringUtils.substringAfter( fileName, prefix );
587 log.debug( "Artifact does not match the maven name pattern: {}", path );
588 if ( fileName.contains( "-" + baseVersion ) )
590 info.id = StringUtils.substringBefore( fileName, "-" + baseVersion );
596 info.artifactType = BaseArtifactTypes.UNKNOWN;
598 info.classifier = "";
599 info.remainder = StringUtils.substringAfterLast( fileName, "." );
604 String prefix = info.id + "-" + genericVersion;
605 if ( fileName.startsWith( prefix ) )
607 info.version = genericVersion;
608 String classPostfix = StringUtils.removeStart( fileName, prefix );
609 Matcher cMatch = CLASSIFIER_PATTERN.matcher( classPostfix );
610 if ( cMatch.matches( ) )
612 info.classifier = cMatch.group( 1 );
613 info.remainder = cMatch.group( 2 );
617 info.classifier = "";
618 info.remainder = classPostfix;
623 if ( fileName.contains( "-" + genericVersion ) )
625 info.id = StringUtils.substringBefore( fileName, "-" + genericVersion );
631 log.debug( "Artifact does not match the version pattern {}", path );
632 info.artifactType = BaseArtifactTypes.UNKNOWN;
634 info.classifier = "";
635 info.remainder = StringUtils.substringAfterLast( fileName, "." );
638 info.extension = StringUtils.substringAfterLast( fileName, "." );
639 info.type = MavenContentHelper.getTypeFromClassifierAndExtension( info.classifier, info.extension );
642 info.contentType = Files.probeContentType( path.getFilePath( ) );
644 catch ( IOException e )
646 info.contentType = "";
649 if ( MavenContentHelper.METADATA_FILENAME.equalsIgnoreCase( fileName ) )
651 info.artifactType = BaseArtifactTypes.METADATA;
653 else if ( MavenContentHelper.METADATA_REPOSITORY_FILENAME.equalsIgnoreCase( fileName ) )
655 info.artifactType = MavenTypes.REPOSITORY_METADATA;
657 else if ( StringUtils.isNotEmpty( info.remainder ) && StringUtils.countMatches( info.remainder, "." ) >= 2 )
659 String mainFile = StringUtils.substringBeforeLast( fileName, "." );
660 if ( path.getParent( ).resolve( mainFile ).exists( ) )
662 info.artifactType = BaseArtifactTypes.RELATED;
670 public Artifact getArtifact( final ItemSelector selector ) throws ContentAccessException
672 if ( !selector.hasProjectId( ) )
674 throw new IllegalArgumentException( "Project id must be set" );
676 if ( !selector.hasVersion( ) )
678 throw new IllegalArgumentException( "Version must be set" );
680 if ( !selector.hasArtifactId( ) )
682 throw new IllegalArgumentException( "Artifact id must be set" );
684 final StorageAsset artifactDir = getAsset( selector.getNamespace( ), selector.getProjectId( ),
685 selector.getVersion( ) );
686 final String artifactVersion = mavenContentHelper.getArtifactVersion( artifactDir, selector );
687 final String classifier = MavenContentHelper.getClassifier( selector );
688 final String extension = MavenContentHelper.getArtifactExtension( selector );
689 final String artifactId = StringUtils.isEmpty( selector.getArtifactId( ) ) ? selector.getProjectId( ) : selector.getArtifactId( );
690 final String fileName = MavenContentHelper.getArtifactFileName( artifactId, artifactVersion, classifier, extension );
691 final StorageAsset path = getAsset( selector.getNamespace( ), selector.getProjectId( ),
692 selector.getVersion( ), fileName );
693 return getArtifactFromPath( path );
697 * Returns all the subdirectories of the given namespace directory as project.
700 public List<? extends Project> getProjects( Namespace namespace )
702 return namespace.getAsset( ).list( ).stream( )
703 .filter( a -> a.isContainer( ) )
704 .map( a -> getProjectFromPath( a ) )
705 .collect( Collectors.toList( ) );
709 public List<? extends Project> getProjects( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
711 return getProjects( getNamespace( selector ) );
715 * Returns a version object for each directory that is a direct child of the project directory.
717 * @param project the project for which the versions should be returned
718 * @return the list of versions or a empty list, if not version was found
721 public List<? extends Version> getVersions( final Project project )
723 StorageAsset asset = getAsset( project.getNamespace( ).getNamespace( ), project.getId( ) );
724 return asset.list( ).stream( ).filter( a -> a.isContainer( ) )
725 .map( a -> ArchivaVersion.withAsset( a )
726 .withProject( project )
727 .withVersion( a.getName( ) ).build( ) )
728 .collect( Collectors.toList( ) );
732 * Returns the versions that can be found for the given selector.
734 * @param selector the item selector. At least namespace and projectId must be set.
735 * @return the list of version objects or a empty list, if the selector does not match a version
736 * @throws ContentAccessException if the access to the underlying backend failed
737 * @throws IllegalArgumentException if the selector has no projectId specified
740 public List<? extends Version> getVersions( final ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
742 if ( !selector.hasProjectId( ) )
744 log.error( "Bad item selector for version list: {}", selector );
745 throw new IllegalArgumentException( "Project id not set, while retrieving versions." );
747 final Project project = getProject( selector );
748 if ( selector.hasVersion( ) )
750 final StorageAsset asset = getAsset( selector.getNamespace( ), selector.getProjectId( ), selector.getVersion( ) );
751 return asset.list( ).stream( ).map( a -> getArtifactInfoFromPath( selector.getVersion( ), a ) )
752 .filter( ai -> StringUtils.isNotEmpty( ai.version ) )
753 .map( v -> getVersionFromArtifactPath( v.asset ) )
755 .collect( Collectors.toList( ) );
759 return getVersions( project );
763 public List<String> getArtifactVersions( final ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
765 if ( !selector.hasProjectId( ) )
767 log.error( "Bad item selector for version list: {}", selector );
768 throw new IllegalArgumentException( "Project id not set, while retrieving versions." );
770 final Project project = getProject( selector );
771 if ( selector.hasVersion( ) )
773 final StorageAsset asset = getAsset( selector.getNamespace( ), selector.getProjectId( ), selector.getVersion( ) );
774 return asset.list( ).stream( ).map( a -> getArtifactInfoFromPath( selector.getVersion( ), a ) )
775 .filter( ai -> StringUtils.isNotEmpty( ai.version ) )
776 .map( v -> v.version )
778 .collect( Collectors.toList( ) );
782 return project.getAsset( ).list( ).stream( ).map( a -> getVersionFromPath( a ) )
783 .flatMap( v -> v.getAsset( ).list( ).stream( ).map( a -> getArtifactInfoFromPath( v.getVersion( ), a ) ) )
784 .filter( ai -> StringUtils.isNotEmpty( ai.version ) )
785 .map( v -> v.version )
787 .collect( Collectors.toList( ) );
793 * See {@link #newArtifactStream(ItemSelector)}. This method collects the stream into a list.
795 * @param selector the selector for the artifacts
796 * @return the list of artifacts
797 * @throws ContentAccessException if the access to the underlying filesystem failed
800 public List<? extends Artifact> getArtifacts( ItemSelector selector ) throws ContentAccessException
802 try ( Stream<? extends Artifact> stream = newArtifactStream( selector ) )
804 return stream.collect( Collectors.toList( ) );
810 * File filter to select certain artifacts using the selector data.
812 private Predicate<StorageAsset> getArtifactFileFilterFromSelector( final ItemSelector selector )
814 Predicate<StorageAsset> p = a -> a.isLeaf( );
815 StringBuilder fileNamePattern = new StringBuilder( "^" );
816 if ( selector.hasArtifactId( ) )
818 fileNamePattern.append( Pattern.quote( selector.getArtifactId( ) ) ).append( "-" );
822 fileNamePattern.append( "[A-Za-z0-9_\\-.]+-" );
824 if ( selector.hasArtifactVersion( ) )
826 if ( selector.getArtifactVersion( ).contains( "*" ) )
828 String[] tokens = StringUtils.splitByWholeSeparator( selector.getArtifactVersion( ), "*" );
829 for ( String currentToken : tokens )
831 if ( !currentToken.equals( "" ) )
833 fileNamePattern.append( Pattern.quote( currentToken ) );
835 fileNamePattern.append( "[A-Za-z0-9_\\-.]*" );
840 fileNamePattern.append( Pattern.quote( selector.getArtifactVersion( ) ) );
845 fileNamePattern.append( "[A-Za-z0-9_\\-.]+" );
847 String classifier = selector.hasClassifier( ) ? selector.getClassifier( ) :
848 ( selector.hasType( ) ? MavenContentHelper.getClassifierFromType( selector.getType( ) ) : null );
849 if ( classifier != null )
851 if ( "*".equals( classifier ) )
853 fileNamePattern.append( "(-[A-Za-z0-9]+)?\\." );
857 fileNamePattern.append( "-" ).append( Pattern.quote( classifier ) ).append( "\\." );
862 fileNamePattern.append( "\\." );
864 String extension = selector.hasExtension( ) ? selector.getExtension( ) :
865 ( selector.hasType( ) ? MavenContentHelper.getArtifactExtension( selector ) : null );
866 if ( extension != null )
868 if ( selector.includeRelatedArtifacts( ) )
870 fileNamePattern.append( Pattern.quote( extension ) ).append( "(\\.[A-Za-z0-9]+)?" );
874 fileNamePattern.append( Pattern.quote( extension ) );
879 fileNamePattern.append( "[A-Za-z0-9.]+" );
881 final Pattern pattern = Pattern.compile( fileNamePattern.toString( ) );
882 return p.and( a -> pattern.matcher( a.getName( ) ).matches( ) );
887 * Returns the artifacts. The number of artifacts returned depend on the selector.
888 * If the selector sets the flag {@link ItemSelector#includeRelatedArtifacts()} to <code>true</code>,
889 * additional to the matching artifacts, related artifacts like hash values or signatures are included in the artifact
891 * If the selector sets the flag {@link ItemSelector#recurse()} to <code>true</code>, artifacts of the given
892 * namespace and from all sub namespaces that start with the given namespace are returned.
894 * <li>If only a namespace is given, all artifacts with the given namespace or starting with the given
895 * namespace (see {@link ItemSelector#recurse()} are returned.</li>
896 * <li>If a namespace and a project id, or artifact id is given, the artifacts of all versions of the given
897 * namespace and project are returned.</li>
898 * <li>If a namespace and a project id or artifact id and a version is given, the artifacts of the given
899 * version are returned</li>
900 * <li>If no artifact version or artifact id is given, it will return all "artifacts" found in the directory.
901 * To select only artifacts that match the layout you should add the artifact id and artifact version
902 * (can contain a '*' pattern).</li>
905 * The '*' pattern can be used in classifiers and artifact versions and match zero or more characters.
907 * There is no determinate order of the elements in the stream.
909 * Returned streams are auto closable and should be used in a try-with-resources statement.
911 * @param selector the item selector
912 * @throws ContentAccessException if the access to the underlying filesystem failed
915 public Stream<? extends Artifact> newArtifactStream( ItemSelector selector ) throws ContentAccessException
917 String projectId = selector.hasProjectId( ) ? selector.getProjectId( ) : ( selector.hasArtifactId( ) ? selector.getArtifactId( )
919 final Predicate<StorageAsset> filter = getArtifactFileFilterFromSelector( selector );
920 if ( projectId != null && selector.hasVersion( ) )
922 return getAsset( selector.getNamespace( ), projectId, selector.getVersion( ) )
923 .list( ).stream( ).filter( filter )
924 .map( this::getArtifactFromPath );
926 else if ( projectId != null )
928 final StorageAsset projDir = getAsset( selector.getNamespace( ), projectId );
929 return projDir.list( ).stream( )
930 .map( a -> a.isContainer( ) ? a.list( ) : Arrays.asList( a ) )
931 .flatMap( List::stream )
933 .map( this::getArtifactFromPath );
937 StorageAsset namespaceDir = getAsset( selector.getNamespace( ) );
938 if ( selector.recurse( ) )
940 return StorageUtil.newAssetStream( namespaceDir, true )
942 .map( this::getArtifactFromPath );
947 // We descend into 2 subdirectories (project and version)
948 return namespaceDir.list( ).stream( )
949 .map( a -> a.isContainer( ) ? a.list( ) : Arrays.asList( a ) )
950 .flatMap( List::stream )
951 .map( a -> a.isContainer( ) ? a.list( ) : Arrays.asList( a ) )
952 .flatMap( List::stream )
954 .map( this::getArtifactFromPath );
960 * Same as {@link #newArtifactStream(ContentItem)} but returns the collected stream as list.
962 * @param item the item the parent item
963 * @return the list of artifacts or a empty list of no artifacts where found
966 public List<? extends Artifact> getArtifacts( ContentItem item )
968 try ( Stream<? extends Artifact> stream = newArtifactStream( item ) )
970 return stream.collect( Collectors.toList( ) );
975 * Returns all artifacts
979 * @throws ContentAccessException
981 public Stream<? extends Artifact> newArtifactStream( Namespace item ) throws ContentAccessException
983 return newArtifactStream( ArchivaItemSelector.builder( ).withNamespace( item.getNamespace( ) ).build( ) );
986 public Stream<? extends Artifact> newArtifactStream( Project item ) throws ContentAccessException
988 return newArtifactStream( ArchivaItemSelector.builder( ).withNamespace( item.getNamespace( ).getNamespace( ) )
989 .withProjectId( item.getId( ) ).build( ) );
992 public Stream<? extends Artifact> newArtifactStream( Version item ) throws ContentAccessException
994 return newArtifactStream( ArchivaItemSelector.builder( ).withNamespace( item.getProject( ).getNamespace( ).getNamespace( ) )
995 .withProjectId( item.getProject( ).getId( ) )
996 .withVersion( item.getVersion( ) ).build( ) );
1000 * Returns all related artifacts that match the given artifact. That means all artifacts that have
1001 * the same filename plus an additional extension, e.g. ${fileName}.sha2
1003 * @param item the artifact
1004 * @return the stream of artifacts
1005 * @throws ContentAccessException
1007 public Stream<? extends Artifact> newArtifactStream( Artifact item ) throws ContentAccessException
1009 final Version v = item.getVersion( );
1010 final String fileName = item.getFileName( );
1011 final Predicate<StorageAsset> filter = ( StorageAsset a ) ->
1012 a.getName( ).startsWith( fileName + "." );
1013 return v.getAsset( ).list( ).stream( ).filter( filter )
1014 .map( a -> getArtifactFromPath( a ) );
1018 * Returns the stream of artifacts that are children of the given item.
1020 * @param item the item from where the artifacts should be returned
1022 * @throws ContentAccessException
1025 public Stream<? extends Artifact> newArtifactStream( ContentItem item ) throws ContentAccessException
1027 if ( item instanceof Namespace )
1029 return newArtifactStream( ( (Namespace) item ) );
1031 else if ( item instanceof Project )
1033 return newArtifactStream( (Project) item );
1035 else if ( item instanceof Version )
1037 return newArtifactStream( (Version) item );
1039 else if ( item instanceof Artifact )
1041 return newArtifactStream( (Artifact) item );
1045 log.warn( "newArtifactStream for unsupported item requested: {}", item.getClass( ).getName( ) );
1046 return Stream.empty( );
1050 private void appendPatternRegex( StringBuilder builder, String name )
1052 String[] patternArray = name.split( "[*]" );
1053 for ( int i = 0; i < patternArray.length - 1; i++ )
1055 builder.append( Pattern.quote( patternArray[i] ) )
1056 .append( "[A-Za-z0-9_\\-]*" );
1058 builder.append( Pattern.quote( patternArray[patternArray.length - 1] ) );
1061 Predicate<StorageAsset> getItemFileFilterFromSelector( ItemSelector selector )
1063 if ( !selector.hasNamespace( ) && !selector.hasProjectId( ) )
1065 throw new IllegalArgumentException( "Selector must have at least namespace and projectid" );
1067 StringBuilder pathMatcher = new StringBuilder( "^" );
1068 if ( selector.hasNamespace( ) )
1070 String path = "/" + String.join( "/", selector.getNamespace( ).split( "\\." ) );
1071 if ( path.contains( "*" ) )
1073 appendPatternRegex( pathMatcher, path );
1077 pathMatcher.append( Pattern.quote( path ) );
1081 if ( selector.hasProjectId( ) )
1083 pathMatcher.append( "/" );
1084 if ( selector.getProjectId( ).contains( "*" ) )
1086 appendPatternRegex( pathMatcher, selector.getProjectId( ) );
1090 pathMatcher.append( Pattern.quote( selector.getProjectId( ) ) );
1093 if ( selector.hasVersion( ) )
1095 pathMatcher.append( "/" );
1096 if ( selector.getVersion( ).contains( "*" ) )
1098 appendPatternRegex( pathMatcher, selector.getVersion( ) );
1102 pathMatcher.append( Pattern.quote( selector.getVersion( ) ) );
1105 pathMatcher.append( ".*" );
1106 final Pattern pathPattern = Pattern.compile( pathMatcher.toString( ) );
1107 final Predicate<StorageAsset> pathPredicate = ( StorageAsset asset ) -> pathPattern.matcher( asset.getPath( ) ).matches( );
1108 if ( selector.hasArtifactId( ) || selector.hasArtifactVersion( ) || selector.hasClassifier( )
1109 || selector.hasType( ) || selector.hasExtension( ) )
1111 return getArtifactFileFilterFromSelector( selector ).and( pathPredicate );
1115 return pathPredicate;
1120 * Returns a concatenation of the asset and its children as stream, if they exist.
1121 * It descends <code>level+1</code> levels down.
1123 * @param a the asset to start from
1124 * @param level the number of child levels to descend. 0 means only the children of the given asset, 1 means the children of childrens of the given asset, ...
1125 * @return the stream of storage assets
1127 private Stream<StorageAsset> getChildrenDF( StorageAsset a, int level )
1129 if ( a.isContainer( ) )
1132 return Stream.concat( a.list().stream( ).flatMap( ch -> getChildrenDF( ch, level - 1 ) ), Stream.of( a ) );
1135 return Stream.concat( a.list( ).stream( ), Stream.of( a ) );
1140 return Stream.of( a );
1145 public Stream<? extends ContentItem> newItemStream( ItemSelector selector, boolean parallel ) throws ContentAccessException, IllegalArgumentException
1147 final Predicate<StorageAsset> filter = getItemFileFilterFromSelector( selector );
1148 StorageAsset startDir;
1149 if (selector.getNamespace().contains("*")) {
1150 startDir = getAsset( "" );
1151 } else if ( selector.hasProjectId( ) && selector.getProjectId().contains("*") )
1153 startDir = getAsset( selector.getNamespace( ) );
1154 } else if ( selector.hasProjectId() && selector.hasVersion() && selector.getVersion().contains("*")) {
1155 startDir = getAsset( selector.getNamespace( ), selector.getProjectId( ) );
1157 else if ( selector.hasProjectId( ) && selector.hasVersion( ) )
1159 startDir = getAsset( selector.getNamespace( ), selector.getProjectId( ), selector.getVersion() );
1161 else if ( selector.hasProjectId( ) )
1163 startDir = getAsset( selector.getNamespace( ), selector.getProjectId( ) );
1167 startDir = getAsset( selector.getNamespace( ) );
1168 if ( !selector.recurse( ) )
1170 // We descend into 2 subdirectories (project and version)
1171 return startDir.list( ).stream( )
1172 .flatMap( a -> getChildrenDF( a, 1 ) )
1173 .map( this::getItemFromPath );
1177 return StorageUtil.newAssetStream( startDir, parallel )
1179 .map( this::getItemFromPath );
1184 * Checks, if the asset/file queried by the given selector exists.
1187 public boolean hasContent( ItemSelector selector )
1189 return getItem( selector ).getAsset( ).exists( );
1193 public ContentItem getParent( ContentItem item )
1195 return getItemFromPath( item.getAsset( ).getParent( ) );
1199 public List<? extends ContentItem> getChildren( ContentItem item )
1201 if (item.getAsset().isLeaf()) {
1202 return Collections.emptyList( );
1204 return item.getAsset( ).list( ).stream( ).map( a -> getItemFromPath( a ) ).collect( Collectors.toList( ) );
1209 public <T extends ContentItem> T applyCharacteristic( Class<T> clazz, ContentItem item ) throws LayoutException
1211 if (item.getAsset().isLeaf()) {
1212 if (clazz.isAssignableFrom( Artifact.class )) {
1213 Artifact artifact = getArtifactFromPath( item.getAsset( ) );
1214 item.setCharacteristic( Artifact.class, artifact );
1215 return (T) artifact;
1217 throw new LayoutException( "Could not adapt file to clazz " + clazz );
1220 if (clazz.isAssignableFrom( Version.class )) {
1221 Version version = getVersionFromPath( item.getAsset( ) );
1222 item.setCharacteristic( Version.class, version );
1224 } else if (clazz.isAssignableFrom( Project.class )) {
1225 Project project = getProjectFromPath( item.getAsset( ) );
1226 item.setCharacteristic( Project.class, project );
1228 } else if (clazz.isAssignableFrom( Namespace.class )) {
1229 Namespace ns = getNamespaceFromPath( item.getAsset( ) );
1230 item.setCharacteristic( Namespace.class, ns );
1233 throw new LayoutException( "Cannot adapt directory to clazz " + clazz );
1239 public <T extends ManagedRepositoryContentLayout> T getLayout( Class<T> clazz ) throws LayoutException
1241 if (clazz.isAssignableFrom( this.getClass() )) {
1244 throw new LayoutException( "Cannot convert to layout " + clazz );
1249 public <T extends ManagedRepositoryContentLayout> boolean supportsLayout( Class<T> clazz )
1251 return clazz.isAssignableFrom( this.getClass( ) );
1255 * Moves the file to the artifact destination
1258 public void addArtifact( Path sourceFile, Artifact destination ) throws IllegalArgumentException, ContentAccessException
1262 StorageAsset asset = destination.getAsset( );
1263 if ( !asset.exists( ) )
1267 asset.replaceDataFromFile( sourceFile );
1269 catch ( IOException e )
1271 log.error( "Could not push data to asset source={} destination={}. {}", sourceFile, destination.getAsset( ).getFilePath( ), e.getMessage( ) );
1272 throw new ContentAccessException( e.getMessage( ), e );
1277 public ContentItem toItem( String path ) throws LayoutException
1279 StorageAsset asset = getRepository( ).getAsset( path );
1280 if ( asset.isLeaf( ) )
1282 ItemSelector selector = getPathParser( ).toItemSelector( path );
1283 return getItem( selector );
1287 return getItemFromPath( asset );
1292 public ContentItem toItem( StorageAsset assetPath ) throws LayoutException
1294 return toItem( assetPath.getPath( ) );
1297 /// ************* End of new generation interface ******************
1300 public String toPath( ContentItem item ) {
1301 return item.getAsset( ).getPath( );
1305 public DataItem getMetadataItem( Version version ) {
1306 StorageAsset metaPath = version.getAsset( ).resolve( MAVEN_METADATA );
1307 return getDataItemFromPath( metaPath );
1311 public DataItem getMetadataItem( Project project )
1313 StorageAsset metaPath = project.getAsset( ).resolve( MAVEN_METADATA );
1314 return getDataItemFromPath( metaPath );
1319 public String getId( )
1321 return repository.getId( );
1325 * Create the filter for various combinations of classifier and type
1327 private Predicate<ArtifactReference> getChecker( ArtifactReference referenceObject, String extension )
1329 // TODO: Check, if extension is the correct parameter here
1330 // We compare type with extension which works for artifacts like .jar.md5 but may
1331 // be not the best way.
1333 if ( referenceObject.getClassifier( ) != null && referenceObject.getType( ) != null )
1335 return ( ( ArtifactReference a ) ->
1336 referenceObject.getGroupId( ).equals( a.getGroupId( ) )
1337 && referenceObject.getArtifactId( ).equals( a.getArtifactId( ) )
1338 && referenceObject.getVersion( ).equals( a.getVersion( ) )
1339 && ( ( a.getType( ) == null )
1340 || referenceObject.getType( ).equals( a.getType( ) )
1341 || a.getType( ).startsWith( extension ) )
1342 && referenceObject.getClassifier( ).equals( a.getClassifier( ) )
1345 else if ( referenceObject.getClassifier( ) != null && referenceObject.getType( ) == null )
1347 return ( ( ArtifactReference a ) ->
1348 referenceObject.getGroupId( ).equals( a.getGroupId( ) )
1349 && referenceObject.getArtifactId( ).equals( a.getArtifactId( ) )
1350 && referenceObject.getVersion( ).equals( a.getVersion( ) )
1351 && referenceObject.getClassifier( ).equals( a.getClassifier( ) )
1354 else if ( referenceObject.getClassifier( ) == null && referenceObject.getType( ) != null )
1356 return ( ( ArtifactReference a ) ->
1357 referenceObject.getGroupId( ).equals( a.getGroupId( ) )
1358 && referenceObject.getArtifactId( ).equals( a.getArtifactId( ) )
1359 && referenceObject.getVersion( ).equals( a.getVersion( ) )
1360 && ( ( a.getType( ) == null )
1361 || referenceObject.getType( ).equals( a.getType( ) )
1362 || a.getType( ).startsWith( extension ) )
1367 return ( ( ArtifactReference a ) ->
1368 referenceObject.getGroupId( ).equals( a.getGroupId( ) )
1369 && referenceObject.getArtifactId( ).equals( a.getArtifactId( ) )
1370 && referenceObject.getVersion( ).equals( a.getVersion( ) )
1378 public String getRepoRoot( )
1380 return convertUriToPath( repository.getLocation( ) );
1383 private String convertUriToPath( URI uri )
1385 if ( uri.getScheme( ) == null )
1387 return Paths.get( uri.getPath( ) ).toString( );
1389 else if ( "file".equals( uri.getScheme( ) ) )
1391 return Paths.get( uri ).toString( );
1395 return uri.toString( );
1400 public ManagedRepository getRepository( )
1406 public void setRepository( final ManagedRepository repo )
1408 this.repository = repo;
1411 if ( repository instanceof EditableManagedRepository )
1413 ( (EditableManagedRepository) repository ).setContent( this );
1418 private Path getRepoDir( )
1420 return repository.getAsset( "" ).getFilePath( );
1423 private RepositoryStorage getStorage( )
1425 return repository.getAsset( "" ).getStorage( );
1429 * Convert a path to an artifact reference.
1431 * @param path the path to convert. (relative or full location path)
1432 * @throws LayoutException if the path cannot be converted to an artifact reference.
1435 public ArtifactReference toArtifactReference( String path )
1436 throws LayoutException
1438 String repoPath = convertUriToPath( repository.getLocation( ) );
1439 if ( ( path != null ) && path.startsWith( repoPath ) && repoPath.length( ) > 0 )
1441 return super.toArtifactReference( path.substring( repoPath.length( ) + 1 ) );
1446 if ( repoPath != null )
1448 while ( repoPath.startsWith( "/" ) )
1450 repoPath = repoPath.substring( 1 );
1453 return super.toArtifactReference( repoPath );
1458 // The variant with runtime exception for stream usage
1459 private ArtifactReference toArtifactRef( String path )
1463 return toArtifactReference( path );
1465 catch ( LayoutException e )
1467 throw new RuntimeException( e );
1473 * Get the first Artifact found in the provided VersionedReference location.
1475 * @param reference the reference to the versioned reference to search within
1476 * @return the ArtifactReference to the first artifact located within the versioned reference. or null if
1477 * no artifact was found within the versioned reference.
1478 * @throws java.io.IOException if the versioned reference is invalid (example: doesn't exist, or isn't a directory)
1479 * @throws LayoutException
1481 private ArtifactReference getFirstArtifact( VersionedReference reference )
1482 throws ContentNotFoundException, LayoutException, IOException
1484 try ( Stream<ArtifactReference> stream = newArtifactStream( reference ) )
1486 return stream.findFirst( ).orElse( null );
1488 catch ( RuntimeException e )
1490 throw new ContentNotFoundException( e.getMessage( ), e.getCause( ) );
1494 private Stream<ArtifactReference> newArtifactStream( VersionedReference reference ) throws ContentNotFoundException, LayoutException, IOException
1496 final Path repoBase = getRepoDir( );
1497 String path = toMetadataPath( reference );
1498 Path versionDir = repoBase.resolve( path ).getParent( );
1499 if ( !Files.exists( versionDir ) )
1501 throw new ContentNotFoundException( "Unable to gather the list of artifacts on a non-existant directory: "
1502 + versionDir.toAbsolutePath( ) );
1505 if ( !Files.isDirectory( versionDir ) )
1507 throw new ContentNotFoundException(
1508 "Unable to gather the list of snapshot versions on a non-directory: " + versionDir.toAbsolutePath( ) );
1510 return Files.list( versionDir ).filter( Files::isRegularFile )
1511 .map( p -> repoBase.relativize( p ).toString( ) )
1512 .filter( p -> !filetypes.matchesDefaultExclusions( p ) )
1513 .filter( filetypes::matchesArtifactPattern )
1514 .map( this::toArtifactRef );
1517 private boolean hasArtifact( VersionedReference reference )
1520 try ( Stream<ArtifactReference> stream = newArtifactStream( reference ) )
1522 return stream.anyMatch( e -> true );
1524 catch ( ContentNotFoundException e )
1528 catch ( LayoutException | IOException e )
1530 // We throw the runtime exception for better stream handling
1531 throw new RuntimeException( e );
1535 public void setFiletypes( FileTypes filetypes )
1537 this.filetypes = filetypes;
1540 public void setMavenContentHelper( MavenContentHelper contentHelper )
1542 this.mavenContentHelper = contentHelper;
1546 public MavenMetadataReader getMetadataReader( )
1548 return metadataReader;
1551 public void setMetadataReader( MavenMetadataReader metadataReader )
1553 this.metadataReader = metadataReader;