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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package org.apache.archiva.maven.repository;
  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. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import org.apache.archiva.common.filelock.DefaultFileLockManager;
  20. import org.apache.archiva.common.filelock.FileLockManager;
  21. import org.apache.archiva.indexer.ArchivaIndexingContext;
  22. import org.apache.archiva.maven.repository.content.MavenRepositoryRequestInfo;
  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.RepositoryState;
  27. import org.apache.archiva.repository.RepositoryType;
  28. import org.apache.archiva.repository.StandardCapabilities;
  29. import org.apache.archiva.repository.UnsupportedFeatureException;
  30. import org.apache.archiva.repository.base.managed.AbstractManagedRepository;
  31. import org.apache.archiva.repository.features.ArtifactCleanupFeature;
  32. import org.apache.archiva.repository.features.IndexCreationFeature;
  33. import org.apache.archiva.repository.features.RepositoryFeature;
  34. import org.apache.archiva.repository.features.StagingRepositoryFeature;
  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. setLastState( RepositoryState.CREATED );
  70. }
  71. public MavenManagedRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage )
  72. {
  73. super( primaryLocale, RepositoryType.MAVEN, id, name, storage );
  74. setLocation(storage.getRoot().getFilePath().toUri());
  75. setLastState( RepositoryState.CREATED );
  76. }
  77. @Override
  78. public RepositoryCapabilities getCapabilities( )
  79. {
  80. return CAPABILITIES;
  81. }
  82. @SuppressWarnings( "unchecked" )
  83. @Override
  84. public <T extends RepositoryFeature<T>> T getFeature( Class<T> clazz ) throws UnsupportedFeatureException
  85. {
  86. if (ArtifactCleanupFeature.class.equals( clazz ))
  87. {
  88. return (T) artifactCleanupFeature;
  89. } else if (IndexCreationFeature.class.equals(clazz)) {
  90. return (T) indexCreationFeature;
  91. } else if (StagingRepositoryFeature.class.equals(clazz)) {
  92. return (T) stagingRepositoryFeature;
  93. } else {
  94. throw new UnsupportedFeatureException( );
  95. }
  96. }
  97. @Override
  98. public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
  99. {
  100. if (ArtifactCleanupFeature.class.equals(clazz) ||
  101. IndexCreationFeature.class.equals(clazz) ||
  102. StagingRepositoryFeature.class.equals(clazz)) {
  103. return true;
  104. }
  105. return false;
  106. }
  107. @Override
  108. public boolean hasIndex( )
  109. {
  110. return indexCreationFeature.hasIndex();
  111. }
  112. @Override
  113. public RepositoryRequestInfo getRequestInfo() {
  114. return new MavenRepositoryRequestInfo(this);
  115. }
  116. public static MavenManagedRepository newLocalInstance(String id, String name, Path basePath) throws IOException {
  117. FileLockManager lockManager = new DefaultFileLockManager();
  118. FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager);
  119. return new MavenManagedRepository(id, name, storage);
  120. }
  121. @Override
  122. public void setIndexingContext(ArchivaIndexingContext context) {
  123. super.setIndexingContext(context);
  124. }
  125. }