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.5KB

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