This project has retired. For details please refer to its Attic page.
MavenContentProvider xref
View Javadoc
1   package org.apache.archiva.repository.content.maven2;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * Maven implementation of the repository content provider. Only default layout and
44   * maven repository types are supported.
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 }