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

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