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.

MavenManagedRepository.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package org.apache.archiva.repository.maven;
  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.common.filelock.DefaultFileLockManager;
  21. import org.apache.archiva.common.filelock.FileLockManager;
  22. import org.apache.archiva.indexer.ArchivaIndexingContext;
  23. import org.apache.archiva.repository.ReleaseScheme;
  24. import org.apache.archiva.repository.RepositoryCapabilities;
  25. import org.apache.archiva.repository.RepositoryRequestInfo;
  26. import org.apache.archiva.repository.RepositoryType;
  27. import org.apache.archiva.repository.StandardCapabilities;
  28. import org.apache.archiva.repository.UnsupportedFeatureException;
  29. import org.apache.archiva.repository.base.managed.AbstractManagedRepository;
  30. import org.apache.archiva.repository.features.ArtifactCleanupFeature;
  31. import org.apache.archiva.repository.features.IndexCreationFeature;
  32. import org.apache.archiva.repository.features.RepositoryFeature;
  33. import org.apache.archiva.repository.features.StagingRepositoryFeature;
  34. import org.apache.archiva.repository.maven.content.MavenRepositoryRequestInfo;
  35. import org.apache.archiva.repository.storage.fs.FilesystemStorage;
  36. import org.slf4j.Logger;
  37. import org.slf4j.LoggerFactory;
  38. import java.io.IOException;
  39. import java.nio.file.Path;
  40. import java.util.Locale;
  41. /**
  42. * Maven2 managed repository implementation.
  43. */
  44. public class MavenManagedRepository extends AbstractManagedRepository
  45. {
  46. private static final Logger log = LoggerFactory.getLogger( MavenManagedRepository.class );
  47. public static final String DEFAULT_LAYOUT = "default";
  48. public static final String LEGACY_LAYOUT = "legacy";
  49. private ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( );
  50. private IndexCreationFeature indexCreationFeature;
  51. private StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( );
  52. private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
  53. new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT },
  54. new String[] { DEFAULT_LAYOUT, LEGACY_LAYOUT},
  55. new String[] {},
  56. new String[] {ArtifactCleanupFeature.class.getName(), IndexCreationFeature.class.getName(),
  57. StagingRepositoryFeature.class.getName()},
  58. true,
  59. true,
  60. true,
  61. true,
  62. false
  63. );
  64. public MavenManagedRepository(String id, String name, FilesystemStorage storage)
  65. {
  66. super( RepositoryType.MAVEN, id, name, storage);
  67. this.indexCreationFeature = new IndexCreationFeature(this, this);
  68. setLocation(storage.getRoot().getFilePath().toUri());
  69. }
  70. public MavenManagedRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage )
  71. {
  72. super( primaryLocale, RepositoryType.MAVEN, id, name, storage );
  73. setLocation(storage.getRoot().getFilePath().toUri());
  74. }
  75. @Override
  76. public RepositoryCapabilities getCapabilities( )
  77. {
  78. return CAPABILITIES;
  79. }
  80. @SuppressWarnings( "unchecked" )
  81. @Override
  82. public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
  83. {
  84. if (ArtifactCleanupFeature.class.equals( clazz ))
  85. {
  86. return (RepositoryFeature<T>) artifactCleanupFeature;
  87. } else if (IndexCreationFeature.class.equals(clazz)) {
  88. return (RepositoryFeature<T>) indexCreationFeature;
  89. } else if (StagingRepositoryFeature.class.equals(clazz)) {
  90. return (RepositoryFeature<T>) stagingRepositoryFeature;
  91. } else {
  92. throw new UnsupportedFeatureException( );
  93. }
  94. }
  95. @Override
  96. public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
  97. {
  98. if (ArtifactCleanupFeature.class.equals(clazz) ||
  99. IndexCreationFeature.class.equals(clazz) ||
  100. StagingRepositoryFeature.class.equals(clazz)) {
  101. return true;
  102. }
  103. return false;
  104. }
  105. @Override
  106. public boolean hasIndex( )
  107. {
  108. return indexCreationFeature.hasIndex();
  109. }
  110. @Override
  111. public RepositoryRequestInfo getRequestInfo() {
  112. return new MavenRepositoryRequestInfo(this);
  113. }
  114. public static MavenManagedRepository newLocalInstance(String id, String name, Path basePath) throws IOException {
  115. FileLockManager lockManager = new DefaultFileLockManager();
  116. FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager);
  117. return new MavenManagedRepository(id, name, storage);
  118. }
  119. @Override
  120. public void setIndexingContext(ArchivaIndexingContext context) {
  121. super.setIndexingContext(context);
  122. }
  123. }