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.

BasicRemoteRepository.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package org.apache.archiva.repository.base.remote;
  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.EditableRemoteRepository;
  22. import org.apache.archiva.repository.ReleaseScheme;
  23. import org.apache.archiva.repository.RepositoryCapabilities;
  24. import org.apache.archiva.repository.RepositoryState;
  25. import org.apache.archiva.repository.RepositoryType;
  26. import org.apache.archiva.repository.StandardCapabilities;
  27. import org.apache.archiva.repository.features.IndexCreationFeature;
  28. import org.apache.archiva.repository.features.RemoteIndexFeature;
  29. import org.apache.archiva.repository.storage.RepositoryStorage;
  30. import org.apache.archiva.repository.storage.fs.FilesystemStorage;
  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 BasicRemoteRepository extends AbstractRemoteRepository implements EditableRemoteRepository
  43. {
  44. Logger log = LoggerFactory.getLogger(BasicRemoteRepository.class);
  45. RemoteIndexFeature remoteIndexFeature = new RemoteIndexFeature();
  46. IndexCreationFeature indexCreationFeature = new IndexCreationFeature(true);
  47. static final StandardCapabilities CAPABILITIES = new StandardCapabilities( new ReleaseScheme[] {
  48. ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT
  49. }, new String[] {"default"}, new String[0], new String[] {
  50. RemoteIndexFeature.class.toString(),
  51. IndexCreationFeature.class.toString()
  52. }, true, true, true, true, true );
  53. public BasicRemoteRepository( String id, String name, RepositoryStorage storage)
  54. {
  55. super( RepositoryType.MAVEN, id, name, storage);
  56. initFeatures();
  57. setLastState( RepositoryState.CREATED );
  58. }
  59. public BasicRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage storage )
  60. {
  61. super( primaryLocale, type, id, name, storage );
  62. initFeatures();
  63. setLastState( RepositoryState.CREATED );
  64. }
  65. private void initFeatures() {
  66. addFeature( remoteIndexFeature );
  67. addFeature( indexCreationFeature );
  68. }
  69. @Override
  70. public boolean hasIndex( )
  71. {
  72. return true;
  73. }
  74. @Override
  75. public RepositoryCapabilities getCapabilities( )
  76. {
  77. return CAPABILITIES;
  78. }
  79. public static BasicRemoteRepository newFilesystemInstance(String id, String name, Path basePath) throws IOException {
  80. FileLockManager lockManager = new DefaultFileLockManager();
  81. FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager);
  82. return new BasicRemoteRepository(id, name, storage);
  83. }
  84. }