1 package org.apache.archiva.repository.features;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
23 import org.apache.archiva.repository.Repository;
24 import org.apache.archiva.repository.event.RepositoryIndexEvent;
25 import org.apache.archiva.event.EventHandler;
26 import org.apache.archiva.repository.storage.StorageAsset;
27 import org.apache.commons.lang3.StringUtils;
30 import java.net.URISyntaxException;
32 import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
33 import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_PACKED_INDEX_PATH;
37 * This feature provides information about index creation.
39 * Repositories that support this feature are able to create indexes and download them from remote repositories.
41 * Repositories may have a normal and packed index. A normal index is used by repository search utilities, the packed
42 * index is for downloading purpose.
44 * A index may have a remote and a local representation. The remote representation is used for downloading and
45 * updating the local representation.
47 * The feature is throwing a {@link RepositoryIndexEvent}, if the URI of the index has been changed.
50 public class IndexCreationFeature extends AbstractFeature implements RepositoryFeature<IndexCreationFeature>{
53 private boolean skipPackedIndexCreation = false;
55 private URI indexPath;
57 private URI packedIndexPath;
59 private StorageAsset localIndexPath;
61 private StorageAsset localPackedIndexPath;
63 private Repository repo;
65 public IndexCreationFeature(Repository repository, EventHandler listener) {
67 this.repo = repository;
69 this.indexPath = new URI(DEFAULT_INDEX_PATH);
70 this.packedIndexPath = new URI(DEFAULT_PACKED_INDEX_PATH);
71 } catch (URISyntaxException e) {
77 public IndexCreationFeature(boolean skipPackedIndexCreation) {
78 this.skipPackedIndexCreation = skipPackedIndexCreation;
80 this.indexPath = new URI(DEFAULT_INDEX_PATH);
81 this.packedIndexPath = new URI(DEFAULT_PACKED_INDEX_PATH);
82 } catch (URISyntaxException e) {
89 public IndexCreationFeature get() {
94 * Returns true, if no packed index files should be created.
95 * @return True, if no packed index files are created, otherwise false.
97 public boolean isSkipPackedIndexCreation() {
98 return skipPackedIndexCreation;
102 * Sets the flag for packed index creation.
104 * @param skipPackedIndexCreation
106 public void setSkipPackedIndexCreation(boolean skipPackedIndexCreation) {
107 this.skipPackedIndexCreation = skipPackedIndexCreation;
111 * Returns the path that is used to store the index. The path may be a absolute URI or relative to the
112 * base URI of the repository.
114 * @return the uri (may be relative or absolute)
116 public URI getIndexPath( )
122 * Sets the path that is used to store the index. The path may be either absolute or a
123 * path that is relative to the repository storage path (either a local or remote path).
125 * @param indexPath the uri to the index path (may be relative)
127 public void setIndexPath( URI indexPath )
129 if ((this.indexPath==null && indexPath!=null) || !this.indexPath.equals(indexPath)) {
130 URI oldVal = this.indexPath;
131 this.indexPath = indexPath;
132 pushEvent(RepositoryIndexEvent.indexUriChange(this, repo, oldVal, this.indexPath));
138 * Returns true, if this repository has a index defined.
140 * @return <code>true</code>, if a index path is set, otherwise <code>false</code>
142 public boolean hasIndex() {
143 return this.indexPath!=null && !StringUtils.isEmpty( this.indexPath.getPath() );
147 * Returns the path where the index is stored physically.
151 public StorageAsset getLocalIndexPath() {
152 return localIndexPath;
156 * Sets the path where the index is stored locally.
158 * @param localIndexPath
160 public void setLocalIndexPath(StorageAsset localIndexPath) {
161 this.localIndexPath = localIndexPath;
166 * Returns the path of the packed index.
169 public URI getPackedIndexPath() {
170 return packedIndexPath;
174 * Sets the path (relative or absolute) of the packed index.
176 * Throws a {@link RepositoryIndexEvent.Index#PACKED_INDEX_URI_CHANGE}, if the value changes.
178 * @param packedIndexPath the new path uri for the packed index
180 public void setPackedIndexPath(URI packedIndexPath) {
181 URI oldVal = this.packedIndexPath;
182 this.packedIndexPath = packedIndexPath;
183 pushEvent(RepositoryIndexEvent.packedIndexUriChange(this, repo, oldVal, this.packedIndexPath));
187 * Returns the directory where the packed index is stored.
190 public StorageAsset getLocalPackedIndexPath() {
191 return localPackedIndexPath;
195 * Sets the path where the packed index is stored physically. This method should only be used by the
196 * MavenIndexProvider implementations.
198 * @param localPackedIndexPath
200 public void setLocalPackedIndexPath(StorageAsset localPackedIndexPath) {
201 this.localPackedIndexPath = localPackedIndexPath;
205 public String toString() {
206 StringBuilder sb = new StringBuilder();
207 sb.append("IndexCreationFeature:{").append("skipPackedIndexCreation=").append(skipPackedIndexCreation)
208 .append(",indexPath=").append(indexPath).append(",packedIndexPath=").append(packedIndexPath).append("}");
209 return sb.toString();