This project has retired. For details please refer to its
        
        Attic page.
      
1   package org.apache.archiva.repository.content.maven2;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  import org.apache.archiva.common.filelock.FileLockManager;
23  import org.apache.archiva.configuration.FileTypes;
24  import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
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.springframework.stereotype.Service;
35  
36  import javax.inject.Inject;
37  import javax.inject.Named;
38  import java.util.HashSet;
39  import java.util.List;
40  import java.util.Set;
41  
42  
43  
44  
45  
46  @Service("repositoryContentProvider#maven")
47  public class MavenContentProvider implements RepositoryContentProvider
48  {
49  
50      @Inject
51      @Named( "fileTypes" )
52      private FileTypes filetypes;
53  
54      @Inject
55      private FileLockManager fileLockManager;
56  
57      @Inject
58      protected List<? extends ArtifactMappingProvider> artifactMappingProviders;
59  
60  
61      private static final Set<RepositoryType> REPOSITORY_TYPES = new HashSet<>(  );
62      static {
63          REPOSITORY_TYPES.add(RepositoryType.MAVEN);
64      }
65  
66      @Override
67      public boolean supportsLayout( String layout )
68      {
69          return "default".equals( layout );
70      }
71  
72      @Override
73      public Set<RepositoryType> getSupportedRepositoryTypes( )
74      {
75          return REPOSITORY_TYPES;
76      }
77  
78      @Override
79      public boolean supports( RepositoryType type )
80      {
81          return type.equals( RepositoryType.MAVEN );
82      }
83  
84      @Override
85      public RemoteRepositoryContent createRemoteContent( RemoteRepository repository ) throws RepositoryException
86      {
87          if (!supports( repository.getType() )) {
88              throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
89          }
90          if (!supportsLayout( repository.getLayout() )) {
91              throw new RepositoryException( "Repository layout "+repository.getLayout()+" is not supported by this implementation." );
92          }
93          RemoteDefaultRepositoryContentmoteDefaultRepositoryContent.html#RemoteDefaultRepositoryContent">RemoteDefaultRepositoryContent content = new RemoteDefaultRepositoryContent(artifactMappingProviders);
94          content.setRepository( repository );
95          return content;
96      }
97  
98      @Override
99      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         ManagedDefaultRepositoryContentagedDefaultRepositoryContent.html#ManagedDefaultRepositoryContent">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 }