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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package org.apache.archiva.repository.base.managed;
  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. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import org.apache.archiva.common.filelock.DefaultFileLockManager;
  20. import org.apache.archiva.common.filelock.FileLockManager;
  21. import org.apache.archiva.repository.ReleaseScheme;
  22. import org.apache.archiva.repository.RepositoryCapabilities;
  23. import org.apache.archiva.repository.RepositoryRequestInfo;
  24. import org.apache.archiva.repository.RepositoryType;
  25. import org.apache.archiva.repository.StandardCapabilities;
  26. import org.apache.archiva.repository.storage.fs.FilesystemStorage;
  27. import org.apache.archiva.repository.storage.RepositoryStorage;
  28. import org.apache.archiva.repository.features.ArtifactCleanupFeature;
  29. import org.apache.archiva.repository.features.IndexCreationFeature;
  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. *
  38. * Just a helper class, mainly used for unit tests.
  39. *
  40. *
  41. */
  42. public class BasicManagedRepository extends AbstractManagedRepository
  43. {
  44. Logger log = LoggerFactory.getLogger(BasicManagedRepository.class);
  45. ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( );
  46. StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( );
  47. static final StandardCapabilities CAPABILITIES = new StandardCapabilities( new ReleaseScheme[] {
  48. ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT
  49. }, new String[] {"default"}, new String[0], new String[] {
  50. ArtifactCleanupFeature.class.toString(), IndexCreationFeature.class.toString(),
  51. StagingRepositoryFeature.class.toString()
  52. }, true, true, true, true, true );
  53. public BasicManagedRepository( String id, String name, RepositoryStorage repositoryStorage )
  54. {
  55. super( RepositoryType.MAVEN, id, name, repositoryStorage );
  56. initFeatures();
  57. }
  58. public BasicManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage repositoryStorage )
  59. {
  60. super( primaryLocale, type, id, name, repositoryStorage);
  61. initFeatures();
  62. }
  63. private void initFeatures() {
  64. IndexCreationFeature indexCreationFeature = new IndexCreationFeature(this, this);
  65. addFeature( artifactCleanupFeature );
  66. addFeature( indexCreationFeature );
  67. addFeature( stagingRepositoryFeature );
  68. }
  69. @Override
  70. public boolean hasIndex( )
  71. {
  72. return true;
  73. }
  74. @Override
  75. public RepositoryCapabilities getCapabilities( )
  76. {
  77. return CAPABILITIES;
  78. }
  79. @Override
  80. public RepositoryRequestInfo getRequestInfo() {
  81. return null;
  82. }
  83. /**
  84. * Creates a filesystem based repository instance. The path is built by basePath/repository-id
  85. *
  86. * @param id The repository id
  87. * @param name The name of the repository
  88. * @param repositoryPath The path to the repository
  89. * @return The repository instance
  90. * @throws IOException
  91. */
  92. public static BasicManagedRepository newFilesystemInstance(String id, String name, Path repositoryPath) throws IOException {
  93. FileLockManager lockManager = new DefaultFileLockManager();
  94. FilesystemStorage storage = new FilesystemStorage(repositoryPath, lockManager);
  95. return new BasicManagedRepository(id, name, storage);
  96. }
  97. }