001package org.apache.archiva.indexer; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.archiva.common.utils.PathUtil; 023import org.apache.archiva.repository.Repository; 024import org.apache.archiva.repository.RepositoryType; 025import org.apache.archiva.repository.features.IndexCreationFeature; 026import org.apache.commons.lang.StringUtils; 027import org.slf4j.Logger; 028import org.slf4j.LoggerFactory; 029import org.springframework.stereotype.Service; 030 031import java.io.IOException; 032import java.net.URI; 033import java.nio.file.Files; 034import java.nio.file.Path; 035import java.util.Collection; 036 037@Service("indexManager#none") 038public class GenericIndexManager implements ArchivaIndexManager { 039 040 private final Logger log = LoggerFactory.getLogger(GenericIndexManager.class); 041 042 public static final String DEFAULT_INDEXER_DIR = ".indexer"; 043 044 @Override 045 public void pack(ArchivaIndexingContext context) { 046 047 } 048 049 @Override 050 public void scan(ArchivaIndexingContext context) { 051 052 } 053 054 @Override 055 public void update(ArchivaIndexingContext context, boolean fullUpdate) { 056 057 } 058 059 @Override 060 public void addArtifactsToIndex(ArchivaIndexingContext context, Collection<URI> artifactReference) { 061 062 } 063 064 @Override 065 public void removeArtifactsFromIndex(ArchivaIndexingContext context, Collection<URI> artifactReference) { 066 067 } 068 069 @Override 070 public boolean supportsRepository(RepositoryType type) { 071 return false; 072 } 073 074 @Override 075 public ArchivaIndexingContext createContext(Repository repository) { 076 return null; 077 } 078 079 @Override 080 public ArchivaIndexingContext reset(ArchivaIndexingContext context) throws IndexUpdateFailedException { 081 return null; 082 } 083 084 @Override 085 public ArchivaIndexingContext move(ArchivaIndexingContext context, Repository repo) throws IndexCreationFailedException { 086 return null; 087 } 088 089 @Override 090 public void updateLocalIndexPath(Repository repo) { 091 if (repo.supportsFeature(IndexCreationFeature.class)) { 092 IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get(); 093 try { 094 icf.setLocalIndexPath(getIndexPath(repo)); 095 } catch (IOException e) { 096 log.error("Could not set local index path for {}. New URI: {}", repo.getId(), icf.getIndexPath()); 097 } 098 } 099 } 100 101 private Path getIndexPath(Repository repo) throws IOException { 102 IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get(); 103 Path repoDir = repo.getLocalPath(); 104 URI indexDir = icf.getIndexPath(); 105 Path indexDirectory = null; 106 if ( ! StringUtils.isEmpty(indexDir.toString( ) ) ) 107 { 108 109 indexDirectory = PathUtil.getPathFromUri( indexDir ); 110 // not absolute so create it in repository directory 111 if ( !indexDirectory.isAbsolute( ) ) 112 { 113 indexDirectory = repoDir.resolve( indexDirectory ); 114 } 115 } 116 else 117 { 118 indexDirectory = repoDir.resolve( DEFAULT_INDEXER_DIR); 119 } 120 121 if ( !Files.exists( indexDirectory ) ) 122 { 123 Files.createDirectories( indexDirectory ); 124 } 125 return indexDirectory; 126 } 127 128}