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.configuration.FileTypes;
23 import org.apache.archiva.repository.ManagedRepositoryContent;
24 import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
25 import org.apache.archiva.repository.ManagedRepository;
26 import org.apache.archiva.repository.BaseRepositoryContentLayout;
27 import org.apache.archiva.repository.RemoteRepository;
28 import org.apache.archiva.repository.RemoteRepositoryContent;
29 import org.apache.archiva.repository.Repository;
30 import org.apache.archiva.repository.RepositoryContent;
31 import org.apache.archiva.repository.RepositoryContentProvider;
32 import org.apache.archiva.repository.RepositoryException;
33 import org.apache.archiva.repository.RepositoryType;
34 import org.springframework.stereotype.Service;
36 import javax.inject.Inject;
37 import javax.inject.Named;
38 import java.util.HashSet;
39 import java.util.List;
43 * Maven implementation of the repository content provider. Only default layout and
44 * maven repository types are supported.
46 @Service("repositoryContentProvider#maven")
47 public class MavenContentProvider implements RepositoryContentProvider
52 private FileTypes filetypes;
55 private FileLockManager fileLockManager;
58 protected List<? extends ArtifactMappingProvider> artifactMappingProviders;
61 @Named("MavenContentHelper")
62 MavenContentHelper mavenContentHelper;
64 private static final Set<RepositoryType> REPOSITORY_TYPES = new HashSet<>( );
66 REPOSITORY_TYPES.add(RepositoryType.MAVEN);
70 public boolean supportsLayout( String layout )
72 return "default".equals( layout );
76 public Set<RepositoryType> getSupportedRepositoryTypes( )
78 return REPOSITORY_TYPES;
82 public boolean supports( RepositoryType type )
84 return type.equals( RepositoryType.MAVEN );
88 public RemoteRepositoryContent createRemoteContent( RemoteRepository repository ) throws RepositoryException
90 if (!supports( repository.getType() )) {
91 throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
93 if (!supportsLayout( repository.getLayout() )) {
94 throw new RepositoryException( "Repository layout "+repository.getLayout()+" is not supported by this implementation." );
96 RemoteDefaultRepositoryContent content = new RemoteDefaultRepositoryContent(artifactMappingProviders);
97 content.setRepository( repository );
102 public ManagedRepositoryContent createManagedContent( ManagedRepository repository ) throws RepositoryException
104 if (!supports( repository.getType() )) {
105 throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
107 if (!supportsLayout( repository.getLayout() )) {
108 throw new RepositoryException( "Repository layout "+repository.getLayout()+" is not supported by this implementation." );
110 ManagedDefaultRepositoryContent content = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, filetypes ,fileLockManager);
111 content.setMavenContentHelper( mavenContentHelper );
115 @SuppressWarnings( "unchecked" )
117 public <T extends RepositoryContent, V extends Repository> T createContent( Class<T> clazz, V repository ) throws RepositoryException
119 if (!supports( repository.getType() )) {
120 throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
122 if (repository instanceof ManagedRepository && BaseRepositoryContentLayout.class.isAssignableFrom( clazz ) ) {
123 return (T) this.createManagedContent( (ManagedRepository) repository );
124 } else if (repository instanceof RemoteRepository && RemoteRepository.class.isAssignableFrom( clazz )) {
125 return (T) this.createRemoteContent( (RemoteRepository) repository );
127 throw new RepositoryException( "Repository flavour is not supported: "+repository.getClass().getName() );