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 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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.RepositoryEventListener;
  22. import org.apache.commons.lang.StringUtils;
  23. import java.net.URI;
  24. import java.net.URISyntaxException;
  25. import java.nio.file.Path;
  26. /**
  27. *
  28. * This feature provides some information about index creation.
  29. *
  30. */
  31. public class IndexCreationFeature extends AbstractFeature implements RepositoryFeature<IndexCreationFeature>{
  32. public static final String DEFAULT_INDEX_PATH = ".indexer";
  33. public static final String DEFAULT_PACKED_INDEX_PATH = ".index";
  34. private boolean skipPackedIndexCreation = false;
  35. private URI indexPath;
  36. private URI packedIndexPath;
  37. private Path localIndexPath;
  38. private Path localPackedIndexPath;
  39. private Repository repo;
  40. public IndexCreationFeature(Repository repoId, RepositoryEventListener listener) {
  41. super(listener);
  42. this.repo = repoId;
  43. try {
  44. this.indexPath = new URI(DEFAULT_INDEX_PATH);
  45. this.packedIndexPath = new URI(DEFAULT_PACKED_INDEX_PATH);
  46. } catch (URISyntaxException e) {
  47. // Does not happen
  48. e.printStackTrace();
  49. }
  50. }
  51. public IndexCreationFeature(boolean skipPackedIndexCreation) {
  52. this.skipPackedIndexCreation = skipPackedIndexCreation;
  53. try {
  54. this.indexPath = new URI(DEFAULT_INDEX_PATH);
  55. this.packedIndexPath = new URI(DEFAULT_PACKED_INDEX_PATH);
  56. } catch (URISyntaxException e) {
  57. // Does not happen
  58. e.printStackTrace();
  59. }
  60. }
  61. @Override
  62. public IndexCreationFeature get() {
  63. return this;
  64. }
  65. /**
  66. * Returns true, if no packed index files should be created.
  67. * @return True, if no packed index files are created, otherwise false.
  68. */
  69. public boolean isSkipPackedIndexCreation() {
  70. return skipPackedIndexCreation;
  71. }
  72. /**
  73. * Sets the flag for packed index creation.
  74. *
  75. * @param skipPackedIndexCreation
  76. */
  77. public void setSkipPackedIndexCreation(boolean skipPackedIndexCreation) {
  78. this.skipPackedIndexCreation = skipPackedIndexCreation;
  79. }
  80. /**
  81. * Returns the path that is used to store the index.
  82. * @return the uri (may be relative or absolute)
  83. */
  84. public URI getIndexPath( )
  85. {
  86. return indexPath;
  87. }
  88. /**
  89. * Sets the path that is used to store the index.
  90. * @param indexPath the uri to the index path (may be relative)
  91. */
  92. public void setIndexPath( URI indexPath )
  93. {
  94. URI oldVal = this.indexPath;
  95. this.indexPath = indexPath;
  96. raiseEvent(IndexCreationEvent.indexUriChange(repo, oldVal, this.indexPath));
  97. }
  98. public boolean hasIndex() {
  99. return this.indexPath!=null && !StringUtils.isEmpty( this.indexPath.getPath() );
  100. }
  101. /**
  102. * Returns the path where the index is stored physically.
  103. *
  104. * @return
  105. */
  106. public Path getLocalIndexPath() {
  107. return localIndexPath;
  108. }
  109. /**
  110. * Sets the path where the index is stored physically. This method should only be used by the
  111. * MavenIndexProvider implementations.
  112. *
  113. * @param localIndexPath
  114. */
  115. public void setLocalIndexPath(Path localIndexPath) {
  116. this.localIndexPath = localIndexPath;
  117. }
  118. /**
  119. * Returns the path of the packed index.
  120. * @return
  121. */
  122. public URI getPackedIndexPath() {
  123. return packedIndexPath;
  124. }
  125. /**
  126. * Sets the path (relative or absolute) of the packed index.
  127. * @param packedIndexPath
  128. */
  129. public void setPackedIndexPath(URI packedIndexPath) {
  130. URI oldVal = this.packedIndexPath;
  131. this.packedIndexPath = packedIndexPath;
  132. raiseEvent(IndexCreationEvent.packedIndexUriChange(repo, oldVal, this.packedIndexPath));
  133. }
  134. /**
  135. * Returns the directory where the packed index is stored.
  136. * @return
  137. */
  138. public Path getLocalPackedIndexPath() {
  139. return localPackedIndexPath;
  140. }
  141. /**
  142. * Sets the path where the packed index is stored physically. This method should only be used by the
  143. * MavenIndexProvider implementations.
  144. *
  145. * @param localPackedIndexPath
  146. */
  147. public void setLocalPackedIndexPath(Path localPackedIndexPath) {
  148. this.localPackedIndexPath = localPackedIndexPath;
  149. }
  150. @Override
  151. public String toString() {
  152. StringBuilder sb = new StringBuilder();
  153. sb.append("IndexCreationFeature:{").append("skipPackedIndexCreation=").append(skipPackedIndexCreation)
  154. .append(",indexPath=").append(indexPath).append(",packedIndexPath=").append(packedIndexPath).append("}");
  155. return sb.toString();
  156. }
  157. }