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

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