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

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