1package org.apache.archiva.repository.features;
23/*4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */212223import org.apache.commons.lang3.StringUtils;
2425import java.net.URI;
26import java.net.URISyntaxException;
27import java.time.Duration;
2829/**30 * Feature for remote index download.31 */32publicclassRemoteIndexFeatureimplements RepositoryFeature<RemoteIndexFeature> {
3334privateboolean downloadRemoteIndex = false;
35private URI indexUri;
3637 {
38try {
39 indexUri = new URI(".index");
40 } catch (URISyntaxException e) {
41// Ignore42 }
43 }
4445privateboolean downloadRemoteIndexOnStartup = false;
46private Duration downloadTimeout = Duration.ofSeconds( 600 );
47private String proxyId = "";
484950 @Override
51publicRemoteIndexFeature get() {
52returnthis;
53 }
5455/**56 * True, if the remote index should be downloaded.57 * @return True if download, otherwise false.58 */59publicboolean isDownloadRemoteIndex() {
60return downloadRemoteIndex;
61 }
6263publicvoid setDownloadRemoteIndex(boolean downloadRemoteIndex) {
64this.downloadRemoteIndex = downloadRemoteIndex;
65 }
6667/**68 * The URI to access the remote index. May be a relative URI that is relative to the69 * repository URI.70 *71 * @return72 */73public URI getIndexUri() {
74return indexUri;
75 }
7677/**78 * Sets the URI to access the remote index. May be a relative URI that is relative to the79 * repository URI. The allowed URI schemes are dependent on the repository type.80 *81 * @param indexUri The URI of the index82 */83publicvoid setIndexUri(URI indexUri) {
84this.indexUri = indexUri;
85 }
8687/**88 * Returns true, if the remote index should be downloaded on startup of the repository.89 * @return true, if the index should be downloaded during startup, otherwise false.90 */91publicboolean isDownloadRemoteIndexOnStartup() {
92return downloadRemoteIndexOnStartup;
93 }
9495/**96 * Sets the flag for download of the remote repository index.97 *98 * @param downloadRemoteIndexOnStartup99 */100publicvoid setDownloadRemoteIndexOnStartup(boolean downloadRemoteIndexOnStartup) {
101this.downloadRemoteIndexOnStartup = downloadRemoteIndexOnStartup;
102 }
103104/**105 * Returns the timeout after that the remote index download is aborted.106 * @return the time duration after that, the download is aborted.107 */108public Duration getDownloadTimeout() {
109returnthis.downloadTimeout;
110 }
111112/**113 * Sets the timeout after that a remote index download will be aborted.114 * @param timeout The duration115 */116publicvoid setDownloadTimeout(Duration timeout) {
117this.downloadTimeout = timeout;
118 }
119120/**121 * Returns the id of the proxy, that should be used to download the remote index.122 * @return The proxy id123 */124public String getProxyId( )
125 {
126return proxyId;
127 }
128129/**130 * Sets the id of the proxy that should be used to download the remote index.131 * @param proxyId132 */133publicvoid setProxyId( String proxyId )
134 {
135this.proxyId = proxyId;
136 }
137138/**139 * Returns true, if there is a index available.140 *141 * @return142 */143publicboolean hasIndex() {
144returnthis.indexUri!=null && !StringUtils.isEmpty( this.indexUri.getPath() );
145 }
146147 @Override
148public String toString() {
149 StringBuilder str = new StringBuilder();
150return str.append("RemoteIndexFeature:{downloadRemoteIndex=").append(downloadRemoteIndex)
151 .append(",indexURI=").append(indexUri)
152 .append(",downloadOnStartup=").append(downloadRemoteIndexOnStartup)
153 .append(",timeout=").append(downloadTimeout).append("}").toString();
154 }
155 }