This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.repository.content.maven2;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.archiva.common.filelock.FileLockManager;
023import org.apache.archiva.configuration.FileTypes;
024import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
025import org.apache.archiva.repository.ManagedRepository;
026import org.apache.archiva.repository.ManagedRepositoryContent;
027import org.apache.archiva.repository.RemoteRepository;
028import org.apache.archiva.repository.RemoteRepositoryContent;
029import org.apache.archiva.repository.Repository;
030import org.apache.archiva.repository.RepositoryContent;
031import org.apache.archiva.repository.RepositoryContentProvider;
032import org.apache.archiva.repository.RepositoryException;
033import org.apache.archiva.repository.RepositoryType;
034import org.springframework.stereotype.Service;
035
036import javax.inject.Inject;
037import javax.inject.Named;
038import java.util.HashSet;
039import java.util.List;
040import java.util.Set;
041
042/**
043 * Maven implementation of the repository content provider. Only default layout and
044 * maven repository types are supported.
045 */
046@Service("repositoryContentProvider#maven")
047public class MavenContentProvider implements RepositoryContentProvider
048{
049
050    @Inject
051    @Named( "fileTypes" )
052    private FileTypes filetypes;
053
054    @Inject
055    private FileLockManager fileLockManager;
056
057    @Inject
058    protected List<? extends ArtifactMappingProvider> artifactMappingProviders;
059
060
061    private static final Set<RepositoryType> REPOSITORY_TYPES = new HashSet<>(  );
062    static {
063        REPOSITORY_TYPES.add(RepositoryType.MAVEN);
064    }
065
066    @Override
067    public boolean supportsLayout( String layout )
068    {
069        return "default".equals( layout );
070    }
071
072    @Override
073    public Set<RepositoryType> getSupportedRepositoryTypes( )
074    {
075        return REPOSITORY_TYPES;
076    }
077
078    @Override
079    public boolean supports( RepositoryType type )
080    {
081        return type.equals( RepositoryType.MAVEN );
082    }
083
084    @Override
085    public RemoteRepositoryContent createRemoteContent( RemoteRepository repository ) throws RepositoryException
086    {
087        if (!supports( repository.getType() )) {
088            throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
089        }
090        if (!supportsLayout( repository.getLayout() )) {
091            throw new RepositoryException( "Repository layout "+repository.getLayout()+" is not supported by this implementation." );
092        }
093        RemoteDefaultRepositoryContent content = new RemoteDefaultRepositoryContent(artifactMappingProviders);
094        content.setRepository( repository );
095        return content;
096    }
097
098    @Override
099    public ManagedRepositoryContent createManagedContent( ManagedRepository repository ) throws RepositoryException
100    {
101        if (!supports( repository.getType() )) {
102            throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
103        }
104        if (!supportsLayout( repository.getLayout() )) {
105            throw new RepositoryException( "Repository layout "+repository.getLayout()+" is not supported by this implementation." );
106        }
107        ManagedDefaultRepositoryContent content = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, filetypes ,fileLockManager);
108        return content;
109    }
110
111    @SuppressWarnings( "unchecked" )
112    @Override
113    public <T extends RepositoryContent, V extends Repository> T createContent( Class<T> clazz, V repository ) throws RepositoryException
114    {
115        if (!supports( repository.getType() )) {
116            throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
117        }
118        if (repository instanceof ManagedRepository && ManagedRepositoryContent.class.isAssignableFrom( clazz ) ) {
119            return (T) this.createManagedContent( (ManagedRepository) repository );
120        } else if (repository instanceof RemoteRepository && RemoteRepository.class.isAssignableFrom( clazz )) {
121            return (T) this.createRemoteContent( (RemoteRepository) repository );
122        } else {
123            throw new RepositoryException( "Repository flavour is not supported: "+repository.getClass().getName() );
124        }
125    }
126
127}