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.archiva.repository.Repository;
24import org.apache.archiva.repository.event.RepositoryIndexEvent;
25import org.apache.archiva.event.EventHandler;
26import org.apache.archiva.repository.storage.StorageAsset;
27import org.apache.commons.lang3.StringUtils;
2829import java.net.URI;
30import java.net.URISyntaxException;
3132importstatic org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
33importstatic org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_PACKED_INDEX_PATH;
3435/**36 *37 * This feature provides information about index creation.38 *39 * Repositories that support this feature are able to create indexes and download them from remote repositories.40 *41 * Repositories may have a normal and packed index. A normal index is used by repository search utilities, the packed42 * index is for downloading purpose.43 *44 * A index may have a remote and a local representation. The remote representation is used for downloading and45 * updating the local representation.46 *47 * The feature is throwing a {@link RepositoryIndexEvent}, if the URI of the index has been changed.48 *49 */50publicclassIndexCreationFeatureextendsAbstractFeatureimplements RepositoryFeature<IndexCreationFeature>{
515253privateboolean skipPackedIndexCreation = false;
5455private URI indexPath;
5657private URI packedIndexPath;
5859private StorageAsset localIndexPath;
6061private StorageAsset localPackedIndexPath;
6263privateRepository repo;
6465publicIndexCreationFeature(Repository repository, EventHandler listener) {
66super(listener);
67this.repo = repository;
68try {
69this.indexPath = new URI(DEFAULT_INDEX_PATH);
70this.packedIndexPath = new URI(DEFAULT_PACKED_INDEX_PATH);
71 } catch (URISyntaxException e) {
72// Does not happen73 e.printStackTrace();
74 }
75 }
7677publicIndexCreationFeature(boolean skipPackedIndexCreation) {
78this.skipPackedIndexCreation = skipPackedIndexCreation;
79try {
80this.indexPath = new URI(DEFAULT_INDEX_PATH);
81this.packedIndexPath = new URI(DEFAULT_PACKED_INDEX_PATH);
82 } catch (URISyntaxException e) {
83// Does not happen84 e.printStackTrace();
85 }
86 }
8788 @Override
89publicIndexCreationFeature get() {
90returnthis;
91 }
9293/**94 * Returns true, if no packed index files should be created.95 * @return True, if no packed index files are created, otherwise false.96 */97publicboolean isSkipPackedIndexCreation() {
98return skipPackedIndexCreation;
99 }
100101/**102 * Sets the flag for packed index creation.103 *104 * @param skipPackedIndexCreation105 */106publicvoid setSkipPackedIndexCreation(boolean skipPackedIndexCreation) {
107this.skipPackedIndexCreation = skipPackedIndexCreation;
108 }
109110/**111 * Returns the path that is used to store the index. The path may be a absolute URI or relative to the112 * base URI of the repository.113 *114 * @return the uri (may be relative or absolute)115 */116public URI getIndexPath( )
117 {
118return indexPath;
119 }
120121/**122 * Sets the path that is used to store the index. The path may be either absolute or a123 * path that is relative to the repository storage path (either a local or remote path).124 *125 * @param indexPath the uri to the index path (may be relative)126 */127publicvoid setIndexPath( URI indexPath )
128 {
129if ((this.indexPath==null && indexPath!=null) || !this.indexPath.equals(indexPath)) {
130 URI oldVal = this.indexPath;
131this.indexPath = indexPath;
132 pushEvent(RepositoryIndexEvent.indexUriChange(this, repo, oldVal, this.indexPath));
133 }
134135 }
136137/**138 * Returns true, if this repository has a index defined.139 *140 * @return <code>true</code>, if a index path is set, otherwise <code>false</code>141 */142publicboolean hasIndex() {
143returnthis.indexPath!=null && !StringUtils.isEmpty( this.indexPath.getPath() );
144 }
145146/**147 * Returns the path where the index is stored physically.148 *149 * @return150 */151public StorageAsset getLocalIndexPath() {
152return localIndexPath;
153 }
154155/**156 * Sets the path where the index is stored locally.157 *158 * @param localIndexPath159 */160publicvoid setLocalIndexPath(StorageAsset localIndexPath) {
161this.localIndexPath = localIndexPath;
162 }
163164165/**166 * Returns the path of the packed index.167 * @return168 */169public URI getPackedIndexPath() {
170return packedIndexPath;
171 }
172173/**174 * Sets the path (relative or absolute) of the packed index.175 *176 * Throws a {@link RepositoryIndexEvent.Index#PACKED_INDEX_URI_CHANGE}, if the value changes.177 *178 * @param packedIndexPath the new path uri for the packed index179 */180publicvoid setPackedIndexPath(URI packedIndexPath) {
181 URI oldVal = this.packedIndexPath;
182this.packedIndexPath = packedIndexPath;
183 pushEvent(RepositoryIndexEvent.packedIndexUriChange(this, repo, oldVal, this.packedIndexPath));
184 }
185186/**187 * Returns the directory where the packed index is stored.188 * @return189 */190public StorageAsset getLocalPackedIndexPath() {
191return localPackedIndexPath;
192 }
193194/**195 * Sets the path where the packed index is stored physically. This method should only be used by the196 * MavenIndexProvider implementations.197 *198 * @param localPackedIndexPath199 */200publicvoid setLocalPackedIndexPath(StorageAsset localPackedIndexPath) {
201this.localPackedIndexPath = localPackedIndexPath;
202 }
203204 @Override
205public 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("}");
209return sb.toString();
210 }
211 }