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.

RemoteIndexFeature.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package org.apache.archiva.repository.features;
  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.commons.lang3.StringUtils;
  21. import java.net.URI;
  22. import java.net.URISyntaxException;
  23. import java.time.Duration;
  24. /**
  25. * Feature for remote index download.
  26. */
  27. public class RemoteIndexFeature implements RepositoryFeature<RemoteIndexFeature> {
  28. private boolean downloadRemoteIndex = false;
  29. private URI indexUri;
  30. {
  31. try {
  32. indexUri = new URI(".index");
  33. } catch (URISyntaxException e) {
  34. // Ignore
  35. }
  36. }
  37. private boolean downloadRemoteIndexOnStartup = false;
  38. private Duration downloadTimeout = Duration.ofSeconds( 600 );
  39. private String proxyId = "";
  40. /**
  41. * True, if the remote index should be downloaded.
  42. * @return True if download, otherwise false.
  43. */
  44. public boolean isDownloadRemoteIndex() {
  45. return downloadRemoteIndex;
  46. }
  47. public void setDownloadRemoteIndex(boolean downloadRemoteIndex) {
  48. this.downloadRemoteIndex = downloadRemoteIndex;
  49. }
  50. /**
  51. * The URI to access the remote index. May be a relative URI that is relative to the
  52. * repository URI.
  53. *
  54. * @return
  55. */
  56. public URI getIndexUri() {
  57. return indexUri;
  58. }
  59. /**
  60. * Sets the URI to access the remote index. May be a relative URI that is relative to the
  61. * repository URI. The allowed URI schemes are dependent on the repository type.
  62. *
  63. * @param indexUri The URI of the index
  64. */
  65. public void setIndexUri(URI indexUri) {
  66. this.indexUri = indexUri;
  67. }
  68. /**
  69. * Returns true, if the remote index should be downloaded on startup of the repository.
  70. * @return true, if the index should be downloaded during startup, otherwise false.
  71. */
  72. public boolean isDownloadRemoteIndexOnStartup() {
  73. return downloadRemoteIndexOnStartup;
  74. }
  75. /**
  76. * Sets the flag for download of the remote repository index.
  77. *
  78. * @param downloadRemoteIndexOnStartup
  79. */
  80. public void setDownloadRemoteIndexOnStartup(boolean downloadRemoteIndexOnStartup) {
  81. this.downloadRemoteIndexOnStartup = downloadRemoteIndexOnStartup;
  82. }
  83. /**
  84. * Returns the timeout after that the remote index download is aborted.
  85. * @return the time duration after that, the download is aborted.
  86. */
  87. public Duration getDownloadTimeout() {
  88. return this.downloadTimeout;
  89. }
  90. /**
  91. * Sets the timeout after that a remote index download will be aborted.
  92. * @param timeout The duration
  93. */
  94. public void setDownloadTimeout(Duration timeout) {
  95. this.downloadTimeout = timeout;
  96. }
  97. /**
  98. * Returns the id of the proxy, that should be used to download the remote index.
  99. * @return The proxy id
  100. */
  101. public String getProxyId( )
  102. {
  103. return proxyId;
  104. }
  105. /**
  106. * Sets the id of the proxy that should be used to download the remote index.
  107. * @param proxyId
  108. */
  109. public void setProxyId( String proxyId )
  110. {
  111. this.proxyId = proxyId;
  112. }
  113. /**
  114. * Returns true, if there is a index available.
  115. *
  116. * @return
  117. */
  118. public boolean hasIndex() {
  119. return this.indexUri!=null && !StringUtils.isEmpty( this.indexUri.getPath() );
  120. }
  121. @Override
  122. public String toString() {
  123. StringBuilder str = new StringBuilder();
  124. return str.append("RemoteIndexFeature:{downloadRemoteIndex=").append(downloadRemoteIndex)
  125. .append(",indexURI=").append(indexUri)
  126. .append(",downloadOnStartup=").append(downloadRemoteIndexOnStartup)
  127. .append(",timeout=").append(downloadTimeout).append("}").toString();
  128. }
  129. }