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 4.9KB

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