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.

MavenRemoteRepository.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package org.apache.archiva.repository.maven;
  2. import org.apache.archiva.common.filelock.DefaultFileLockManager;
  3. import org.apache.archiva.common.filelock.FileLockManager;
  4. import org.apache.archiva.repository.ReleaseScheme;
  5. import org.apache.archiva.repository.RemoteRepository;
  6. import org.apache.archiva.repository.RepositoryCapabilities;
  7. import org.apache.archiva.repository.RepositoryType;
  8. import org.apache.archiva.repository.StandardCapabilities;
  9. import org.apache.archiva.repository.UnsupportedFeatureException;
  10. import org.apache.archiva.repository.base.remote.AbstractRemoteRepository;
  11. import org.apache.archiva.repository.features.IndexCreationFeature;
  12. import org.apache.archiva.repository.features.RemoteIndexFeature;
  13. import org.apache.archiva.repository.features.RepositoryFeature;
  14. import org.apache.archiva.repository.storage.fs.FilesystemStorage;
  15. import org.slf4j.Logger;
  16. import org.slf4j.LoggerFactory;
  17. import java.io.IOException;
  18. import java.nio.file.Path;
  19. import java.util.Locale;
  20. /*
  21. * Licensed to the Apache Software Foundation (ASF) under one
  22. * or more contributor license agreements. See the NOTICE file
  23. * distributed with this work for additional information
  24. * regarding copyright ownership. The ASF licenses this file
  25. * to you under the Apache License, Version 2.0 (the
  26. * "License"); you may not use this file except in compliance
  27. * with the License. You may obtain a copy of the License at
  28. *
  29. * http://www.apache.org/licenses/LICENSE-2.0
  30. *
  31. * Unless required by applicable law or agreed to in writing,
  32. * software distributed under the License is distributed on an
  33. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34. * KIND, either express or implied. See the License for the
  35. * specific language governing permissions and limitations
  36. * under the License.
  37. */
  38. /**
  39. * Maven2 remote repository implementation
  40. */
  41. public class MavenRemoteRepository extends AbstractRemoteRepository
  42. implements RemoteRepository
  43. {
  44. Logger log = LoggerFactory.getLogger(MavenRemoteRepository.class);
  45. final private RemoteIndexFeature remoteIndexFeature = new RemoteIndexFeature();
  46. final private IndexCreationFeature indexCreationFeature;
  47. private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
  48. new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT },
  49. new String[] { MavenManagedRepository.DEFAULT_LAYOUT, MavenManagedRepository.LEGACY_LAYOUT},
  50. new String[] {},
  51. new String[] {RemoteIndexFeature.class.getName(), IndexCreationFeature.class.getName()},
  52. true,
  53. true,
  54. true,
  55. true,
  56. false
  57. );
  58. public MavenRemoteRepository(String id, String name, FilesystemStorage storage)
  59. {
  60. super( RepositoryType.MAVEN, id, name, storage );
  61. this.indexCreationFeature = new IndexCreationFeature(this, this);
  62. }
  63. public MavenRemoteRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage )
  64. {
  65. super( primaryLocale, RepositoryType.MAVEN, id, name, storage );
  66. this.indexCreationFeature = new IndexCreationFeature(this, this);
  67. }
  68. @Override
  69. public boolean hasIndex( )
  70. {
  71. return remoteIndexFeature.hasIndex();
  72. }
  73. @Override
  74. public RepositoryCapabilities getCapabilities( )
  75. {
  76. return CAPABILITIES;
  77. }
  78. @SuppressWarnings( "unchecked" )
  79. @Override
  80. public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
  81. {
  82. if (RemoteIndexFeature.class.equals( clazz )) {
  83. return (RepositoryFeature<T>) remoteIndexFeature;
  84. } else if (IndexCreationFeature.class.equals(clazz)) {
  85. return (RepositoryFeature<T>) indexCreationFeature;
  86. } else {
  87. throw new UnsupportedFeatureException( );
  88. }
  89. }
  90. @Override
  91. public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
  92. {
  93. if ( RemoteIndexFeature.class.equals(clazz) || IndexCreationFeature.class.equals(clazz)) {
  94. return true;
  95. } else {
  96. return false;
  97. }
  98. }
  99. @Override
  100. public String toString() {
  101. return super.toString()+", remoteIndexFeature="+remoteIndexFeature.toString()+", indexCreationFeature="+indexCreationFeature.toString();
  102. }
  103. public static MavenRemoteRepository newLocalInstance(String id, String name, Path basePath) throws IOException {
  104. FileLockManager lockManager = new DefaultFileLockManager();
  105. FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager);
  106. return new MavenRemoteRepository(id, name, storage);
  107. }
  108. }