This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.repository.features;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022
023import org.apache.commons.lang3.StringUtils;
024
025import java.net.URI;
026import java.net.URISyntaxException;
027import java.time.Duration;
028
029/**
030 * Feature for remote index download.
031 */
032public class RemoteIndexFeature implements RepositoryFeature<RemoteIndexFeature> {
033
034    private boolean downloadRemoteIndex = false;
035    private URI indexUri;
036
037    {
038        try {
039            indexUri = new URI(".index");
040        } catch (URISyntaxException e) {
041            // Ignore
042        }
043    }
044
045    private boolean downloadRemoteIndexOnStartup = false;
046    private Duration downloadTimeout = Duration.ofSeconds( 600 );
047    private String proxyId = "";
048
049
050    @Override
051    public RemoteIndexFeature get() {
052        return this;
053    }
054
055    /**
056     * True, if the remote index should be downloaded.
057     * @return True if download, otherwise false.
058     */
059    public boolean isDownloadRemoteIndex() {
060        return downloadRemoteIndex;
061    }
062
063    public void setDownloadRemoteIndex(boolean downloadRemoteIndex) {
064        this.downloadRemoteIndex = downloadRemoteIndex;
065    }
066
067    /**
068     * The URI to access the remote index. May be a relative URI that is relative to the
069     * repository URI.
070     *
071     * @return
072     */
073    public URI getIndexUri() {
074        return indexUri;
075    }
076
077    /**
078     * Sets the URI to access the remote index. May be a relative URI that is relative to the
079     * repository URI. The allowed URI schemes are dependent on the repository type.
080     *
081     * @param indexUri The URI of the index
082     */
083    public void setIndexUri(URI indexUri) {
084        this.indexUri = indexUri;
085    }
086
087    /**
088     * Returns true, if the remote index should be downloaded on startup of the repository.
089     * @return true, if the index should be downloaded during startup, otherwise false.
090     */
091    public boolean isDownloadRemoteIndexOnStartup() {
092        return downloadRemoteIndexOnStartup;
093    }
094
095    /**
096     * Sets the flag for download of the remote repository index.
097     *
098     * @param downloadRemoteIndexOnStartup
099     */
100    public void setDownloadRemoteIndexOnStartup(boolean downloadRemoteIndexOnStartup) {
101        this.downloadRemoteIndexOnStartup = downloadRemoteIndexOnStartup;
102    }
103
104    /**
105     * Returns the timeout after that the remote index download is aborted.
106     * @return the time duration after that, the download is aborted.
107     */
108    public Duration getDownloadTimeout() {
109        return this.downloadTimeout;
110    }
111
112    /**
113     * Sets the timeout after that a remote index download will be aborted.
114     * @param timeout The duration
115     */
116    public void setDownloadTimeout(Duration timeout) {
117        this.downloadTimeout = timeout;
118    }
119
120    /**
121     * Returns the id of the proxy, that should be used to download the remote index.
122     * @return The proxy id
123     */
124    public String getProxyId( )
125    {
126        return proxyId;
127    }
128
129    /**
130     * Sets the id of the proxy that should be used to download the remote index.
131     * @param proxyId
132     */
133    public void setProxyId( String proxyId )
134    {
135        this.proxyId = proxyId;
136    }
137
138    /**
139     * Returns true, if there is a index available.
140     *
141     * @return
142     */
143    public boolean hasIndex() {
144        return this.indexUri!=null && !StringUtils.isEmpty( this.indexUri.getPath() );
145    }
146
147    @Override
148    public String toString() {
149        StringBuilder str = new StringBuilder();
150        return 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}