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.

BasicManagedRepository.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package org.apache.archiva.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. *
  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.repository.storage.FilesystemStorage;
  23. import org.apache.archiva.repository.storage.RepositoryStorage;
  24. import org.apache.archiva.repository.features.ArtifactCleanupFeature;
  25. import org.apache.archiva.repository.features.IndexCreationFeature;
  26. import org.apache.archiva.repository.features.StagingRepositoryFeature;
  27. import org.slf4j.Logger;
  28. import org.slf4j.LoggerFactory;
  29. import java.io.IOException;
  30. import java.nio.file.Path;
  31. import java.util.Locale;
  32. /**
  33. *
  34. * Just a helper class, mainly used for unit tests.
  35. *
  36. *
  37. */
  38. public class BasicManagedRepository extends AbstractManagedRepository
  39. {
  40. Logger log = LoggerFactory.getLogger(BasicManagedRepository.class);
  41. ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( );
  42. StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( );
  43. static final StandardCapabilities CAPABILITIES = new StandardCapabilities( new ReleaseScheme[] {
  44. ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT
  45. }, new String[] {"default"}, new String[0], new String[] {
  46. ArtifactCleanupFeature.class.toString(), IndexCreationFeature.class.toString(),
  47. StagingRepositoryFeature.class.toString()
  48. }, true, true, true, true, true );
  49. public BasicManagedRepository( String id, String name, RepositoryStorage repositoryStorage )
  50. {
  51. super( RepositoryType.MAVEN, id, name, repositoryStorage );
  52. initFeatures();
  53. }
  54. public BasicManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage repositoryStorage )
  55. {
  56. super( primaryLocale, type, id, name, repositoryStorage);
  57. initFeatures();
  58. }
  59. private void initFeatures() {
  60. IndexCreationFeature indexCreationFeature = new IndexCreationFeature(this, this);
  61. addFeature( artifactCleanupFeature );
  62. addFeature( indexCreationFeature );
  63. addFeature( stagingRepositoryFeature );
  64. }
  65. @Override
  66. public boolean hasIndex( )
  67. {
  68. return true;
  69. }
  70. @Override
  71. public RepositoryCapabilities getCapabilities( )
  72. {
  73. return CAPABILITIES;
  74. }
  75. @Override
  76. public RepositoryRequestInfo getRequestInfo() {
  77. return null;
  78. }
  79. /**
  80. * Creates a filesystem based repository instance. The path is built by basePath/repository-id
  81. *
  82. * @param id The repository id
  83. * @param name The name of the repository
  84. * @param repositoryPath The path to the repository
  85. * @return The repository instance
  86. * @throws IOException
  87. */
  88. public static BasicManagedRepository newFilesystemInstance(String id, String name, Path repositoryPath) throws IOException {
  89. FileLockManager lockManager = new DefaultFileLockManager();
  90. FilesystemStorage storage = new FilesystemStorage(repositoryPath, lockManager);
  91. return new BasicManagedRepository(id, name, storage);
  92. }
  93. }