You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IndexCreationFeature.java 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. package org.apache.archiva.repository.features;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.archiva.repository.Repository;
  21. import org.apache.archiva.repository.event.RepositoryIndexEvent;
  22. import org.apache.archiva.event.EventHandler;
  23. import org.apache.archiva.repository.storage.StorageAsset;
  24. import org.apache.commons.lang3.StringUtils;
  25. import java.net.URI;
  26. import java.net.URISyntaxException;
  27. import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
  28. import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_PACKED_INDEX_PATH;
  29. /**
  30. *
  31. * This feature provides information about index creation.
  32. *
  33. * Repositories that support this feature are able to create indexes and download them from remote repositories.
  34. *
  35. * Repositories may have a normal and packed index. A normal index is used by repository search utilities, the packed
  36. * index is for downloading purpose.
  37. *
  38. * A index may have a remote and a local representation. The remote representation is used for downloading and
  39. * updating the local representation.
  40. *
  41. * The feature is throwing a {@link RepositoryIndexEvent}, if the URI of the index has been changed.
  42. *
  43. */
  44. public class IndexCreationFeature extends AbstractFeature implements RepositoryFeature<IndexCreationFeature>{
  45. private boolean skipPackedIndexCreation = false;
  46. private URI indexPath;
  47. private URI packedIndexPath;
  48. private StorageAsset localIndexPath;
  49. private StorageAsset localPackedIndexPath;
  50. private Repository repo;
  51. public IndexCreationFeature(Repository repository, EventHandler listener) {
  52. super(listener);
  53. this.repo = repository;
  54. try {
  55. this.indexPath = new URI(DEFAULT_INDEX_PATH);
  56. this.packedIndexPath = new URI(DEFAULT_PACKED_INDEX_PATH);
  57. } catch (URISyntaxException e) {
  58. // Does not happen
  59. e.printStackTrace();
  60. }
  61. }
  62. public IndexCreationFeature(boolean skipPackedIndexCreation) {
  63. this.skipPackedIndexCreation = skipPackedIndexCreation;
  64. try {
  65. this.indexPath = new URI(DEFAULT_INDEX_PATH);
  66. this.packedIndexPath = new URI(DEFAULT_PACKED_INDEX_PATH);
  67. } catch (URISyntaxException e) {
  68. // Does not happen
  69. e.printStackTrace();
  70. }
  71. }
  72. /**
  73. * Returns true, if no packed index files should be created.
  74. * @return True, if no packed index files are created, otherwise false.
  75. */
  76. public boolean isSkipPackedIndexCreation() {
  77. return skipPackedIndexCreation;
  78. }
  79. /**
  80. * Sets the flag for packed index creation.
  81. *
  82. * @param skipPackedIndexCreation
  83. */
  84. public void setSkipPackedIndexCreation(boolean skipPackedIndexCreation) {
  85. this.skipPackedIndexCreation = skipPackedIndexCreation;
  86. }
  87. /**
  88. * Returns the path that is used to store the index. The path may be a absolute URI or relative to the
  89. * base URI of the repository.
  90. *
  91. * @return the uri (may be relative or absolute)
  92. */
  93. public URI getIndexPath( )
  94. {
  95. return indexPath;
  96. }
  97. /**
  98. * Sets the path that is used to store the index. The path may be either absolute or a
  99. * path that is relative to the repository storage path (either a local or remote path).
  100. *
  101. * @param indexPath the uri to the index path (may be relative)
  102. */
  103. public void setIndexPath( URI indexPath )
  104. {
  105. if ((this.indexPath==null && indexPath!=null) || !this.indexPath.equals(indexPath)) {
  106. URI oldVal = this.indexPath;
  107. this.indexPath = indexPath;
  108. pushEvent(RepositoryIndexEvent.indexUriChange(this, repo, oldVal, this.indexPath));
  109. }
  110. }
  111. /**
  112. * Returns true, if this repository has a index defined.
  113. *
  114. * @return <code>true</code>, if a index path is set, otherwise <code>false</code>
  115. */
  116. public boolean hasIndex() {
  117. return this.indexPath!=null && !StringUtils.isEmpty( this.indexPath.getPath() );
  118. }
  119. /**
  120. * Returns the path where the index is stored physically.
  121. *
  122. * @return
  123. */
  124. public StorageAsset getLocalIndexPath() {
  125. return localIndexPath;
  126. }
  127. /**
  128. * Sets the path where the index is stored locally.
  129. *
  130. * @param localIndexPath
  131. */
  132. public void setLocalIndexPath(StorageAsset localIndexPath) {
  133. this.localIndexPath = localIndexPath;
  134. }
  135. /**
  136. * Returns the path of the packed index.
  137. * @return
  138. */
  139. public URI getPackedIndexPath() {
  140. return packedIndexPath;
  141. }
  142. /**
  143. * Sets the path (relative or absolute) of the packed index.
  144. *
  145. * Throws a {@link RepositoryIndexEvent#packedIndexUriChange(Object, Repository, URI, URI)}, if the value changes.
  146. *
  147. * @param packedIndexPath the new path uri for the packed index
  148. */
  149. public void setPackedIndexPath(URI packedIndexPath) {
  150. URI oldVal = this.packedIndexPath;
  151. this.packedIndexPath = packedIndexPath;
  152. pushEvent(RepositoryIndexEvent.packedIndexUriChange(this, repo, oldVal, this.packedIndexPath));
  153. }
  154. /**
  155. * Returns the directory where the packed index is stored.
  156. * @return
  157. */
  158. public StorageAsset getLocalPackedIndexPath() {
  159. return localPackedIndexPath;
  160. }
  161. /**
  162. * Sets the path where the packed index is stored physically. This method should only be used by the
  163. * MavenIndexProvider implementations.
  164. *
  165. * @param localPackedIndexPath
  166. */
  167. public void setLocalPackedIndexPath(StorageAsset localPackedIndexPath) {
  168. this.localPackedIndexPath = localPackedIndexPath;
  169. }
  170. @Override
  171. public String toString() {
  172. StringBuilder sb = new StringBuilder();
  173. sb.append("IndexCreationFeature:{").append("skipPackedIndexCreation=").append(skipPackedIndexCreation)
  174. .append(",indexPath=").append(indexPath).append(",packedIndexPath=").append(packedIndexPath).append("}");
  175. return sb.toString();
  176. }
  177. }