]> source.dussan.org Git - archiva.git/commitdiff
Updating indexmanager interface and completing test case
authorMartin Stockhammer <martin.stockhammer@ars.de>
Tue, 21 Nov 2017 19:52:43 +0000 (20:52 +0100)
committerMartin Stockhammer <martin.stockhammer@ars.de>
Tue, 21 Nov 2017 19:52:43 +0000 (20:52 +0100)
archiva-modules/archiva-base/archiva-maven2-indexer/pom.xml
archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java
archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java
archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java
archiva-modules/archiva-base/archiva-maven2-indexer/src/test/resources/spring-context.xml
archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexManager.java
archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexingContext.java
archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/GenericIndexManager.java

index 2712e3a516e8dbc13b854018a30cf22dc28ec7a2..e51f82443cd97bc70b5ae8269d1f26badfa748cb 100644 (file)
       <artifactId>redback-common-test-resources</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-file</artifactId>
+      <scope>test</scope>
+    </dependency>
+
     <dependency>
       <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-http-lightweight</artifactId>
index 30cc72795da6ab206cfb182a0a9aa377ee147dd3..4ee80794dfc8800af961d85e73ccbc6c833d86e0 100644 (file)
@@ -84,6 +84,11 @@ public class MavenIndexContext implements ArchivaIndexingContext {
         delegate.close(deleteFiles);
     }
 
+    @Override
+    public void close() throws IOException {
+        delegate.close(false);
+    }
+
     @Override
     public void purge() throws IOException {
         delegate.purge();
index d54f868a0ed14f005988f1b7d3597757498b56cb..00e67e42f50d6ba38c3b497c697df6ae43b436bb 100644 (file)
@@ -242,13 +242,16 @@ public class MavenIndexManager implements ArchivaIndexManager
     }
 
     @Override
-    public void update( final ArchivaIndexingContext context, final URI remoteUpdateUri, final boolean fullUpdate ) throws IndexUpdateFailedException
+    public void update(final ArchivaIndexingContext context, final boolean fullUpdate) throws IndexUpdateFailedException
     {
         log.info( "start download remote index for remote repository {}", context.getRepository( ).getId( ) );
-
-        if ( !( context.getRepository( ) instanceof RemoteRepository ) )
+        URI remoteUpdateUri;
+        if ( !( context.getRepository( ) instanceof RemoteRepository ) || !(context.getRepository().supportsFeature(RemoteIndexFeature.class)) )
         {
-            throw new IndexUpdateFailedException( "The context is not associated to a remote repository " + context.getId( ) );
+            throw new IndexUpdateFailedException( "The context is not associated to a remote repository with remote index " + context.getId( ) );
+        } else {
+            RemoteIndexFeature rif = context.getRepository().getFeature(RemoteIndexFeature.class).get();
+            remoteUpdateUri = context.getRepository().getLocation().resolve(rif.getIndexUri());
         }
         final RemoteRepository remoteRepository = (RemoteRepository) context.getRepository( );
 
index 96876ad951caecd9b7cd42c32fc4b67cd2dcfcba..53cdaad817be2c9bc7e18d0b13ef0e0879e17614 100644 (file)
@@ -24,7 +24,9 @@ import org.apache.archiva.indexer.ArchivaIndexingContext;
 import org.apache.archiva.indexer.IndexCreationFailedException;
 import org.apache.archiva.repository.RepositoryType;
 import org.apache.archiva.repository.features.IndexCreationFeature;
+import org.apache.archiva.repository.features.RemoteIndexFeature;
 import org.apache.archiva.repository.maven2.MavenManagedRepository;
+import org.apache.archiva.repository.maven2.MavenRemoteRepository;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.apache.maven.index.MAVEN;
 import org.apache.maven.index.QueryCreator;
@@ -59,6 +61,7 @@ public class MavenIndexManagerTest {
     private Path indexPath;
     private MavenManagedRepository repository;
     private ArchivaIndexingContext ctx;
+    private MavenRemoteRepository repositoryRemote;
 
     @Inject
     MavenIndexManager mavenIndexManager;
@@ -84,6 +87,19 @@ public class MavenIndexManagerTest {
 
     @Test
     public void pack() throws Exception {
+        createTestContext();
+        Path destDir = repository.getLocalPath().resolve("org/apache/archiva/archiva-webapp/1.0");
+        Path srcDir = Paths.get("src/test/maven-search-test-repo/org/apache/archiva/archiva-webapp/1.0");
+        org.apache.commons.io.FileUtils.copyDirectory(srcDir.toFile(),destDir.toFile());
+        mavenIndexManager.scan(ctx);
+        mavenIndexManager.pack(ctx);
+        assertTrue(Files.list(indexPath).filter(path -> {
+            try {
+                return path.getFileName().toString().endsWith(".gz") && Files.size(path) > 0;
+            } catch (IOException e) {
+                return false;
+            }
+        }).findAny().isPresent());
     }
 
     @Test
@@ -101,8 +117,16 @@ public class MavenIndexManagerTest {
         assertEquals(4, mvnCtx.acquireIndexSearcher().count(q));
     }
 
+    /*
+     * Does only a index update via file uri, no HTTP uri
+     */
     @Test
     public void update() throws Exception {
+        createTestContext();
+        mavenIndexManager.pack(ctx);
+        ctx.close(false);
+        createTestContextForRemote();
+        mavenIndexManager.update(ctx, true);
     }
 
     @Test
@@ -162,6 +186,17 @@ public class MavenIndexManagerTest {
         return ctx;
     }
 
+    private ArchivaIndexingContext createTestContextForRemote() throws URISyntaxException, IndexCreationFailedException, IOException {
+        indexPath = Paths.get("target/repositories/test-repo/.index-test");
+        Path repoPath = Paths.get("target/repositories").toAbsolutePath();
+        repositoryRemote = new MavenRemoteRepository("test-repo", "Test Repo", repoPath);
+        repositoryRemote.setLocation(repoPath.resolve("test-repo").toUri());
+        RemoteIndexFeature icf = repositoryRemote.getFeature(RemoteIndexFeature.class).get();
+        icf.setIndexUri(new URI(".index-test"));
+        ctx = mavenIndexManager.createContext(repositoryRemote);
+        return ctx;
+    }
+
     @Test
     public void createContext() throws Exception {
         ArchivaIndexingContext ctx = createTestContext();
index 13ef95f3cf864ff631ee4132aa401a65ca3e3683..fbf53be07cd72b229df1cc90646dda9c47584ee1 100644 (file)
@@ -30,6 +30,9 @@
   <context:annotation-config/>
   <context:component-scan base-package="org.apache.archiva.indexer.maven" />
 
+
+  <bean name="wagon#file" scope="prototype" class="org.apache.maven.wagon.providers.file.FileWagon"/>
+
   <bean name="scheduler" class="org.apache.archiva.redback.components.scheduler.DefaultScheduler">
     <property name="properties">
       <props>
index 5e870d04fa32436a6734ddcf79e7b828507b930d..fb34eb2ffe2f96efe6916fd67349b7575e5323bc 100644 (file)
@@ -43,10 +43,9 @@ public interface ArchivaIndexManager {
     /**
      * Updates the index from the remote url.
      * @param context
-     * @param remoteUpdateUri
      * @param fullUpdate
      */
-    void update(ArchivaIndexingContext context, URI remoteUpdateUri, boolean fullUpdate) throws IndexUpdateFailedException;
+    void update(ArchivaIndexingContext context, boolean fullUpdate) throws IndexUpdateFailedException;
 
     /**
      * Adds a list of artifacts to the index.
index 7f31b04506d493fb8375e433301edf2130c0d984..95555a3c31377ae38cf72ba8015ee1b7b202912a 100644 (file)
@@ -83,6 +83,13 @@ public interface ArchivaIndexingContext {
      */
     void close(boolean deleteFiles) throws IOException;
 
+    /**
+     * Closes the context without deleting the files.
+     * Is identical to <code>close(false)</code>
+     * @throws IOException
+     */
+    void close() throws IOException;
+
     /**
      * Removes all entries from the index. After this method finished,
      * isEmpty() should return true.
index 02069773f2dd6da0c572628dea22f9b5eba21aec..d0f8034165945543af6b9dac549435c062241cc9 100644 (file)
@@ -40,7 +40,7 @@ public class GenericIndexManager implements ArchivaIndexManager {
     }
 
     @Override
-    public void update(ArchivaIndexingContext context, URI remoteUpdateUri, boolean fullUpdate) {
+    public void update(ArchivaIndexingContext context, boolean fullUpdate) {
 
     }