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

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