@@ -173,6 +173,12 @@ | |||
<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> |
@@ -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(); |
@@ -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( ); | |||
@@ -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(); |
@@ -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> |
@@ -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. |
@@ -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. |
@@ -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) { | |||
} | |||