You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MavenContentProvider.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package org.apache.archiva.repository.content.maven2;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  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
  18. * under the License.
  19. */
  20. import org.apache.archiva.configuration.FileTypes;
  21. import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
  22. import org.apache.archiva.repository.ManagedRepository;
  23. import org.apache.archiva.repository.ManagedRepositoryContent;
  24. import org.apache.archiva.repository.RemoteRepository;
  25. import org.apache.archiva.repository.RemoteRepositoryContent;
  26. import org.apache.archiva.repository.Repository;
  27. import org.apache.archiva.repository.RepositoryContent;
  28. import org.apache.archiva.repository.RepositoryContentProvider;
  29. import org.apache.archiva.repository.RepositoryException;
  30. import org.apache.archiva.repository.RepositoryType;
  31. import org.springframework.stereotype.Service;
  32. import javax.inject.Inject;
  33. import javax.inject.Named;
  34. import java.util.HashSet;
  35. import java.util.List;
  36. import java.util.Set;
  37. /**
  38. * Maven implementation of the repository content provider. Only default layout and
  39. * maven repository types are supported.
  40. */
  41. @Service("repositoryContentProvider#maven")
  42. public class MavenContentProvider implements RepositoryContentProvider
  43. {
  44. @Inject
  45. @Named( "fileTypes" )
  46. private FileTypes filetypes;
  47. @Inject
  48. protected List<? extends ArtifactMappingProvider> artifactMappingProviders;
  49. private static final Set<RepositoryType> REPOSITORY_TYPES = new HashSet<>( );
  50. static {
  51. REPOSITORY_TYPES.add(RepositoryType.MAVEN);
  52. }
  53. @Override
  54. public boolean supportsLayout( String layout )
  55. {
  56. return "default".equals( layout );
  57. }
  58. @Override
  59. public Set<RepositoryType> getSupportedRepositoryTypes( )
  60. {
  61. return REPOSITORY_TYPES;
  62. }
  63. @Override
  64. public boolean supports( RepositoryType type )
  65. {
  66. return type.equals( RepositoryType.MAVEN );
  67. }
  68. @Override
  69. public RemoteRepositoryContent createRemoteContent( RemoteRepository repository ) throws RepositoryException
  70. {
  71. if (!supports( repository.getType() )) {
  72. throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
  73. }
  74. if (!supportsLayout( repository.getLayout() )) {
  75. throw new RepositoryException( "Repository layout "+repository.getLayout()+" is not supported by this implementation." );
  76. }
  77. RemoteDefaultRepositoryContent content = new RemoteDefaultRepositoryContent(artifactMappingProviders);
  78. content.setRepository( repository );
  79. return content;
  80. }
  81. @Override
  82. public ManagedRepositoryContent createManagedContent( ManagedRepository repository ) throws RepositoryException
  83. {
  84. if (!supports( repository.getType() )) {
  85. throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
  86. }
  87. if (!supportsLayout( repository.getLayout() )) {
  88. throw new RepositoryException( "Repository layout "+repository.getLayout()+" is not supported by this implementation." );
  89. }
  90. ManagedDefaultRepositoryContent content = new ManagedDefaultRepositoryContent(artifactMappingProviders, filetypes);
  91. content.setRepository( repository );
  92. return content;
  93. }
  94. @SuppressWarnings( "unchecked" )
  95. @Override
  96. public <T extends RepositoryContent, V extends Repository> T createContent( Class<T> clazz, V repository ) throws RepositoryException
  97. {
  98. if (!supports( repository.getType() )) {
  99. throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." );
  100. }
  101. if (repository instanceof ManagedRepository && ManagedRepositoryContent.class.isAssignableFrom( clazz ) ) {
  102. return (T) this.createManagedContent( (ManagedRepository) repository );
  103. } else if (repository instanceof RemoteRepository && RemoteRepository.class.isAssignableFrom( clazz )) {
  104. return (T) this.createRemoteContent( (RemoteRepository) repository );
  105. } else {
  106. throw new RepositoryException( "Repository flavour is not supported: "+repository.getClass().getName() );
  107. }
  108. }
  109. }