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.

AbstractRemoteRepository.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.repository.storage.RepositoryStorage;
  21. import org.apache.archiva.repository.storage.StorageAsset;
  22. import java.net.URI;
  23. import java.nio.file.Path;
  24. import java.time.Duration;
  25. import java.util.Collections;
  26. import java.util.HashMap;
  27. import java.util.Locale;
  28. import java.util.Map;
  29. /**
  30. * Abstract implementation of a remote repository. Abstract classes must implement the
  31. * features and capabilities by themselves.
  32. */
  33. public abstract class AbstractRemoteRepository extends AbstractRepository implements EditableRemoteRepository
  34. {
  35. private RepositoryCredentials credentials;
  36. private String checkPath;
  37. private Map<String,String> extraParameters = new HashMap<>( );
  38. private Map<String,String> uExtraParameters = Collections.unmodifiableMap( extraParameters );
  39. private Map<String,String> extraHeaders = new HashMap<>( );
  40. private Map<String,String> uExtraHeaders = Collections.unmodifiableMap( extraHeaders );
  41. private Duration timeout = Duration.ofSeconds( 60 );
  42. private String proxyId;
  43. private RemoteRepositoryContent content;
  44. public AbstractRemoteRepository(RepositoryType type, String id, String name , RepositoryStorage storage)
  45. {
  46. super( type, id, name, storage );
  47. }
  48. public AbstractRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage storage )
  49. {
  50. super( primaryLocale, type, id, name, storage );
  51. }
  52. @Override
  53. public void setCredentials( RepositoryCredentials credentials )
  54. {
  55. this.credentials = credentials;
  56. }
  57. @Override
  58. public void setCheckPath( String path )
  59. {
  60. this.checkPath = path;
  61. }
  62. @Override
  63. public void setExtraParameters( Map<String, String> params )
  64. {
  65. this.extraParameters.clear();
  66. this.extraParameters.putAll(params);
  67. }
  68. @Override
  69. public void addExtraParameter( String key, String value )
  70. {
  71. this.extraParameters.put(key, value);
  72. }
  73. @Override
  74. public void setExtraHeaders( Map<String, String> headers )
  75. {
  76. this.extraHeaders.clear();
  77. this.extraHeaders.putAll(headers);
  78. }
  79. @Override
  80. public void addExtraHeader( String header, String value )
  81. {
  82. this.extraHeaders.put(header, value);
  83. }
  84. @Override
  85. public void setTimeout( Duration duration )
  86. {
  87. this.timeout = duration;
  88. }
  89. @Override
  90. public RemoteRepositoryContent getContent( )
  91. {
  92. return content;
  93. }
  94. @Override
  95. public void setContent(RemoteRepositoryContent content) {
  96. this.content = content;
  97. }
  98. @Override
  99. public RepositoryCredentials getLoginCredentials( )
  100. {
  101. return credentials;
  102. }
  103. @Override
  104. public String getCheckPath( )
  105. {
  106. return checkPath;
  107. }
  108. @Override
  109. public Map<String, String> getExtraParameters( )
  110. {
  111. return uExtraParameters;
  112. }
  113. @Override
  114. public Map<String, String> getExtraHeaders( )
  115. {
  116. return uExtraHeaders;
  117. }
  118. @Override
  119. public Duration getTimeout( )
  120. {
  121. return timeout;
  122. }
  123. /**
  124. * Remote repositories resolve always relative to the base directory.
  125. * @return
  126. */
  127. @Override
  128. public StorageAsset getLocalPath() {
  129. return getStorage().getAsset("");
  130. }
  131. @Override
  132. public String toString() {
  133. StringBuilder str = new StringBuilder();
  134. return str.append("checkPath=").append(checkPath)
  135. .append(",creds:").append(credentials).toString();
  136. }
  137. @Override
  138. public void setLocation(URI location) {
  139. // Location of remote repositories is not for the local filestore
  140. super.location = location;
  141. }
  142. }