This project has retired. For details please refer to its Attic page.
RemoteIndexFeature xref
View Javadoc
1   package org.apache.archiva.repository.features;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  
23  import org.apache.commons.lang3.StringUtils;
24  
25  import java.net.URI;
26  import java.net.URISyntaxException;
27  import java.time.Duration;
28  
29  /**
30   * Feature for remote index download.
31   */
32  public class RemoteIndexFeature implements RepositoryFeature<RemoteIndexFeature> {
33  
34      private boolean downloadRemoteIndex = false;
35      private URI indexUri;
36  
37      {
38          try {
39              indexUri = new URI(".index");
40          } catch (URISyntaxException e) {
41              // Ignore
42          }
43      }
44  
45      private boolean downloadRemoteIndexOnStartup = false;
46      private Duration downloadTimeout = Duration.ofSeconds( 600 );
47      private String proxyId = "";
48  
49  
50      @Override
51      public RemoteIndexFeature get() {
52          return this;
53      }
54  
55      /**
56       * True, if the remote index should be downloaded.
57       * @return True if download, otherwise false.
58       */
59      public boolean isDownloadRemoteIndex() {
60          return downloadRemoteIndex;
61      }
62  
63      public void setDownloadRemoteIndex(boolean downloadRemoteIndex) {
64          this.downloadRemoteIndex = downloadRemoteIndex;
65      }
66  
67      /**
68       * The URI to access the remote index. May be a relative URI that is relative to the
69       * repository URI.
70       *
71       * @return
72       */
73      public URI getIndexUri() {
74          return indexUri;
75      }
76  
77      /**
78       * Sets the URI to access the remote index. May be a relative URI that is relative to the
79       * repository URI. The allowed URI schemes are dependent on the repository type.
80       *
81       * @param indexUri The URI of the index
82       */
83      public void setIndexUri(URI indexUri) {
84          this.indexUri = indexUri;
85      }
86  
87      /**
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       */
91      public boolean isDownloadRemoteIndexOnStartup() {
92          return downloadRemoteIndexOnStartup;
93      }
94  
95      /**
96       * Sets the flag for download of the remote repository index.
97       *
98       * @param downloadRemoteIndexOnStartup
99       */
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 }