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.

GenericIndexManager.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package org.apache.archiva.indexer;
  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.common.utils.PathUtil;
  21. import org.apache.archiva.repository.Repository;
  22. import org.apache.archiva.repository.RepositoryType;
  23. import org.apache.archiva.repository.features.IndexCreationFeature;
  24. import org.apache.commons.lang.StringUtils;
  25. import org.slf4j.Logger;
  26. import org.slf4j.LoggerFactory;
  27. import org.springframework.stereotype.Service;
  28. import java.io.IOException;
  29. import java.net.URI;
  30. import java.nio.file.Files;
  31. import java.nio.file.Path;
  32. import java.util.Collection;
  33. @Service("indexManager#none")
  34. public class GenericIndexManager implements ArchivaIndexManager {
  35. private final Logger log = LoggerFactory.getLogger(GenericIndexManager.class);
  36. public static final String DEFAULT_INDEXER_DIR = ".indexer";
  37. @Override
  38. public void pack(ArchivaIndexingContext context) {
  39. }
  40. @Override
  41. public void scan(ArchivaIndexingContext context) {
  42. }
  43. @Override
  44. public void update(ArchivaIndexingContext context, boolean fullUpdate) {
  45. }
  46. @Override
  47. public void addArtifactsToIndex(ArchivaIndexingContext context, Collection<URI> artifactReference) {
  48. }
  49. @Override
  50. public void removeArtifactsFromIndex(ArchivaIndexingContext context, Collection<URI> artifactReference) {
  51. }
  52. @Override
  53. public boolean supportsRepository(RepositoryType type) {
  54. return false;
  55. }
  56. @Override
  57. public ArchivaIndexingContext createContext(Repository repository) {
  58. return null;
  59. }
  60. @Override
  61. public ArchivaIndexingContext reset(ArchivaIndexingContext context) throws IndexUpdateFailedException {
  62. return null;
  63. }
  64. @Override
  65. public ArchivaIndexingContext move(ArchivaIndexingContext context, Repository repo) throws IndexCreationFailedException {
  66. return null;
  67. }
  68. @Override
  69. public void updateLocalIndexPath(Repository repo) {
  70. if (repo.supportsFeature(IndexCreationFeature.class)) {
  71. IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
  72. try {
  73. icf.setLocalIndexPath(getIndexPath(repo));
  74. } catch (IOException e) {
  75. log.error("Could not set local index path for {}. New URI: {}", repo.getId(), icf.getIndexPath());
  76. }
  77. }
  78. }
  79. private Path getIndexPath(Repository repo) throws IOException {
  80. IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
  81. Path repoDir = repo.getLocalPath();
  82. URI indexDir = icf.getIndexPath();
  83. Path indexDirectory = null;
  84. if ( ! StringUtils.isEmpty(indexDir.toString( ) ) )
  85. {
  86. indexDirectory = PathUtil.getPathFromUri( indexDir );
  87. // not absolute so create it in repository directory
  88. if ( !indexDirectory.isAbsolute( ) )
  89. {
  90. indexDirectory = repoDir.resolve( indexDirectory );
  91. }
  92. }
  93. else
  94. {
  95. indexDirectory = repoDir.resolve( DEFAULT_INDEXER_DIR);
  96. }
  97. if ( !Files.exists( indexDirectory ) )
  98. {
  99. Files.createDirectories( indexDirectory );
  100. }
  101. return indexDirectory;
  102. }
  103. }