]> source.dussan.org Git - archiva.git/commitdiff
Updating indexing path
authorMartin Stockhammer <martin.stockhammer@ars.de>
Tue, 27 Mar 2018 05:32:34 +0000 (07:32 +0200)
committerMartin Stockhammer <martin.stockhammer@ars.de>
Tue, 27 Mar 2018 05:32:34 +0000 (07:32 +0200)
archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java

index 51a5f70d7d9d7c5cb8edc84cec07654e5b711617..718cd7dcb95662c534405b7dd3f0c4d91c64d284 100644 (file)
@@ -34,6 +34,7 @@ import org.apache.archiva.proxy.common.WagonFactory;
 import org.apache.archiva.proxy.common.WagonFactoryException;
 import org.apache.archiva.proxy.common.WagonFactoryRequest;
 import org.apache.archiva.repository.*;
+import org.apache.archiva.repository.features.IndexCreationEvent;
 import org.apache.archiva.repository.features.IndexCreationFeature;
 import org.apache.archiva.repository.features.RemoteIndexFeature;
 import org.apache.commons.lang.StringUtils;
@@ -64,6 +65,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -87,8 +89,7 @@ import java.util.stream.Collectors;
  * time of retries a IndexUpdateFailedException is thrown.
  */
 @Service( "archivaIndexManager#maven" )
-public class MavenIndexManager implements ArchivaIndexManager
-{
+public class MavenIndexManager implements ArchivaIndexManager {
 
     private static final Logger log = LoggerFactory.getLogger( MavenIndexManager.class );
 
@@ -122,6 +123,11 @@ public class MavenIndexManager implements ArchivaIndexManager
     @Inject
     private ArtifactContextProducer artifactContextProducer;
 
+    @Inject
+    RepositoryRegistry repositoryRegistry;
+
+    public static final String DEFAULT_INDEXER_DIR = ".indexer";
+
     private ConcurrentSkipListSet<Path> activeContexts = new ConcurrentSkipListSet<>( );
 
     private static final int WAIT_TIME = 100;
@@ -511,6 +517,18 @@ public class MavenIndexManager implements ArchivaIndexManager
         }
     }
 
+    @Override
+    public void updateLocalIndexPath(Repository repo) {
+        if (repo.supportsFeature(IndexCreationFeature.class)) {
+            IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
+            try {
+                icf.setLocalIndexPath(getIndexPath(repo));
+            } catch (IOException e) {
+                log.error("Could not set local index path for {}. New URI: {}", repo.getId(), icf.getIndexPath());
+            }
+        }
+    }
+
     private Path getIndexPath(Repository repo) throws IOException {
         IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
         Path repoDir = repo.getLocalPath();
@@ -528,7 +546,7 @@ public class MavenIndexManager implements ArchivaIndexManager
         }
         else
         {
-            indexDirectory = repoDir.resolve( ".index" );
+            indexDirectory = repoDir.resolve( DEFAULT_INDEXER_DIR );
         }
 
         if ( !Files.exists( indexDirectory ) )
@@ -644,7 +662,7 @@ public class MavenIndexManager implements ArchivaIndexManager
     {
         if ( rif.getIndexUri( ) == null )
         {
-            return baseUri.resolve( ".index" ).toString( );
+            return baseUri.resolve( DEFAULT_INDEXER_DIR ).toString( );
         }
         else
         {