1 package org.apache.archiva.maven.repository.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.maven.repository.metadata.storage.ArtifactMappingProvider;
24 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
25 import org.apache.archiva.repository.ManagedRepository;
26 import org.apache.archiva.repository.ManagedRepositoryContent;
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.apache.archiva.repository.content.BaseRepositoryContentLayout;
35 import org.springframework.stereotype.Service;
37 import javax.inject.Inject;
38 import javax.inject.Named;
39 import java.util.HashSet;
40 import java.util.List;
44 * Maven implementation of the repository content provider. Only default layout and
45 * maven repository types are supported.
47 @Service("repositoryContentProvider#maven")
48 public class MavenContentProvider implements RepositoryContentProvider
53 private FileTypes filetypes;
56 private FileLockManager fileLockManager;
59 protected List<? extends ArtifactMappingProvider> artifactMappingProviders;
62 @Named("MavenContentHelper")
63 MavenContentHelper mavenContentHelper;
66 @Named("repositoryPathTranslator#maven2")
67 RepositoryPathTranslator pathTranslator;
69 private static final Set<RepositoryType> REPOSITORY_TYPES = new HashSet<>( );
71 REPOSITORY_TYPES.add(RepositoryType.MAVEN);
75 public boolean supportsLayout( String layout )
77 return "default".equals( layout );
81 public Set<RepositoryType> getSupportedRepositoryTypes( )
83 return REPOSITORY_TYPES;
87 public boolean supports( RepositoryType type )
89 return type.equals( RepositoryType.MAVEN );
93 public RemoteRepositoryContent createRemoteContent( RemoteRepository repository ) throws RepositoryException
95 if (!supports( repository.getType() )) {
96 throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
98 if (!supportsLayout( repository.getLayout() )) {
99 throw new RepositoryException( "Repository layout "+repository.getLayout()+" is not supported by this implementation." );
101 RemoteDefaultRepositoryContent content = new RemoteDefaultRepositoryContent();
102 content.setRepository( repository );
103 content.setPathTranslator( pathTranslator );
104 content.setArtifactMappingProviders( artifactMappingProviders );
109 public ManagedRepositoryContent createManagedContent( ManagedRepository repository ) throws RepositoryException
111 if (!supports( repository.getType() )) {
112 throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
114 if (!supportsLayout( repository.getLayout() )) {
115 throw new RepositoryException( "Repository layout "+repository.getLayout()+" is not supported by this implementation." );
117 ManagedDefaultRepositoryContent content = new ManagedDefaultRepositoryContent(repository, filetypes ,fileLockManager);
118 content.setMavenContentHelper( mavenContentHelper );
119 content.setPathTranslator( pathTranslator );
120 content.setArtifactMappingProviders( artifactMappingProviders );
124 @SuppressWarnings( "unchecked" )
126 public <T extends RepositoryContent, V extends Repository> T createContent( Class<T> clazz, V repository ) throws RepositoryException
128 if (!supports( repository.getType() )) {
129 throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
131 if (repository instanceof ManagedRepository && BaseRepositoryContentLayout.class.isAssignableFrom( clazz ) ) {
132 return (T) this.createManagedContent( (ManagedRepository) repository );
133 } else if (repository instanceof RemoteRepository && RemoteRepository.class.isAssignableFrom( clazz )) {
134 return (T) this.createRemoteContent( (RemoteRepository) repository );
136 throw new RepositoryException( "Repository flavour is not supported: "+repository.getClass().getName() );