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.maven.metadata.storage.ArtifactMappingProvider;
24 import org.apache.archiva.repository.ManagedRepository;
25 import org.apache.archiva.repository.BaseRepositoryContentLayout;
26 import org.apache.archiva.repository.RemoteRepository;
27 import org.apache.archiva.repository.RemoteRepositoryContent;
28 import org.apache.archiva.repository.Repository;
29 import org.apache.archiva.repository.RepositoryContent;
30 import org.apache.archiva.repository.RepositoryContentProvider;
31 import org.apache.archiva.repository.RepositoryException;
32 import org.apache.archiva.repository.RepositoryType;
33 import org.springframework.stereotype.Service;
35 import javax.inject.Inject;
36 import javax.inject.Named;
37 import java.util.HashSet;
38 import java.util.List;
42 * Maven implementation of the repository content provider. Only default layout and
43 * maven repository types are supported.
45 @Service("repositoryContentProvider#maven")
46 public class MavenContentProvider implements RepositoryContentProvider
51 private FileTypes filetypes;
54 private FileLockManager fileLockManager;
57 protected List<? extends ArtifactMappingProvider> artifactMappingProviders;
60 @Named("MavenContentHelper")
61 MavenContentHelper mavenContentHelper;
63 private static final Set<RepositoryType> REPOSITORY_TYPES = new HashSet<>( );
65 REPOSITORY_TYPES.add(RepositoryType.MAVEN);
69 public boolean supportsLayout( String layout )
71 return "default".equals( layout );
75 public Set<RepositoryType> getSupportedRepositoryTypes( )
77 return REPOSITORY_TYPES;
81 public boolean supports( RepositoryType type )
83 return type.equals( RepositoryType.MAVEN );
87 public RemoteRepositoryContent createRemoteContent( RemoteRepository repository ) throws RepositoryException
89 if (!supports( repository.getType() )) {
90 throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
92 if (!supportsLayout( repository.getLayout() )) {
93 throw new RepositoryException( "Repository layout "+repository.getLayout()+" is not supported by this implementation." );
95 RemoteDefaultRepositoryContent content = new RemoteDefaultRepositoryContent(artifactMappingProviders);
96 content.setRepository( repository );
101 public BaseRepositoryContentLayout createManagedContent( ManagedRepository repository ) throws RepositoryException
103 if (!supports( repository.getType() )) {
104 throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
106 if (!supportsLayout( repository.getLayout() )) {
107 throw new RepositoryException( "Repository layout "+repository.getLayout()+" is not supported by this implementation." );
109 ManagedDefaultRepositoryContent content = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, filetypes ,fileLockManager);
110 content.setMavenContentHelper( mavenContentHelper );
114 @SuppressWarnings( "unchecked" )
116 public <T extends RepositoryContent, V extends Repository> T createContent( Class<T> clazz, V repository ) throws RepositoryException
118 if (!supports( repository.getType() )) {
119 throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
121 if (repository instanceof ManagedRepository && BaseRepositoryContentLayout.class.isAssignableFrom( clazz ) ) {
122 return (T) this.createManagedContent( (ManagedRepository) repository );
123 } else if (repository instanceof RemoteRepository && RemoteRepository.class.isAssignableFrom( clazz )) {
124 return (T) this.createRemoteContent( (RemoteRepository) repository );
126 throw new RepositoryException( "Repository flavour is not supported: "+repository.getClass().getName() );