Browse Source

[MRM-2011] Using unique index directories for maven indexer

pull/60/head
Martin Stockhammer 4 years ago
parent
commit
3a4b72c2e7

+ 40
- 18
archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java View File

import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.attribute.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;


import static org.junit.Assert.*; import static org.junit.Assert.*;


public void addArtifactsToIndex() throws Exception { public void addArtifactsToIndex() throws Exception {


ArchivaIndexingContext ctx = createTestContext(); ArchivaIndexingContext ctx = createTestContext();
Path destDir = repository.getAsset( "" ).getFilePath().resolve("org/apache/archiva/archiva-search/1.0");
Path srcDir = Paths.get("src/test/maven-search-test-repo/org/apache/archiva/archiva-search/1.0");
org.apache.commons.io.FileUtils.copyDirectory(srcDir.toFile(), destDir.toFile());
List<URI> uriList = new ArrayList<>();
uriList.add(destDir.resolve("archiva-search-1.0.jar").toUri());
uriList.add(destDir.resolve("archiva-search-1.0-sources.jar").toUri());
mavenIndexManager.addArtifactsToIndex(ctx, uriList);

IndexingContext mvnCtx = mavenIndexManager.getMvnContext(ctx);
String term = "org.apache.archiva";
Query q = new BooleanQuery.Builder().add( queryCreator.constructQuery( MAVEN.GROUP_ID, new UserInputSearchExpression( term ) ),
BooleanClause.Occur.SHOULD ).build();
assertEquals(2, mvnCtx.acquireIndexSearcher().count(q));
try {
Path destDir = repository.getAsset("").getFilePath().resolve("org/apache/archiva/archiva-search/1.0");
Path srcDir = Paths.get("src/test/maven-search-test-repo/org/apache/archiva/archiva-search/1.0");
org.apache.commons.io.FileUtils.copyDirectory(srcDir.toFile(), destDir.toFile());
List<URI> uriList = new ArrayList<>();
uriList.add(destDir.resolve("archiva-search-1.0.jar").toUri());
uriList.add(destDir.resolve("archiva-search-1.0-sources.jar").toUri());
mavenIndexManager.addArtifactsToIndex(ctx, uriList);

IndexingContext mvnCtx = mavenIndexManager.getMvnContext(ctx);
String term = "org.apache.archiva";
Query q = new BooleanQuery.Builder().add(queryCreator.constructQuery(MAVEN.GROUP_ID, new UserInputSearchExpression(term)),
BooleanClause.Occur.SHOULD).build();
assertEquals(2, mvnCtx.acquireIndexSearcher().count(q));
} finally {
try {
ctx.close(true);
} catch (IOException e) {
// Ignore
}
}
} }


@Test @Test
} }


private ArchivaIndexingContext createTestContext() throws URISyntaxException, IndexCreationFailedException, IOException { private ArchivaIndexingContext createTestContext() throws URISyntaxException, IndexCreationFailedException, IOException {
indexPath = Paths.get("target/repositories/test-repo/.index-test");
FileUtils.deleteDirectory(indexPath);
String indexPathName = ".index-test." + System.nanoTime();
indexPath = Paths.get("target/repositories/test-repo" ).resolve(indexPathName);
if (Files.exists(indexPath)) {

try {
FileUtils.deleteDirectory(indexPath);
} catch (IOException e) {
String destName = indexPath.getFileName().toString() + "." + System.currentTimeMillis();
Files.move(indexPath, indexPath.getParent().resolve(destName));
}
}
repository = MavenManagedRepository.newLocalInstance("test-repo", "Test Repo", Paths.get("target/repositories")); repository = MavenManagedRepository.newLocalInstance("test-repo", "Test Repo", Paths.get("target/repositories"));
// repository.setLocation(new URI("test-repo")); // repository.setLocation(new URI("test-repo"));
IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class).get(); IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class).get();
icf.setIndexPath(new URI(".index-test"));
icf.setIndexPath(new URI(indexPathName));
ctx = mavenIndexManager.createContext(repository); ctx = mavenIndexManager.createContext(repository);
return ctx; return ctx;
} }


private ArchivaIndexingContext createTestContextForRemote() throws URISyntaxException, IndexCreationFailedException, IOException { private ArchivaIndexingContext createTestContextForRemote() throws URISyntaxException, IndexCreationFailedException, IOException {
indexPath = Paths.get("target/repositories/test-repo/.index-test");
// indexPath = Paths.get("target/repositories/test-repo/.index-test");
Path repoPath = Paths.get("target/repositories").toAbsolutePath(); Path repoPath = Paths.get("target/repositories").toAbsolutePath();
repositoryRemote = MavenRemoteRepository.newLocalInstance("test-repo", "Test Repo", repoPath); repositoryRemote = MavenRemoteRepository.newLocalInstance("test-repo", "Test Repo", repoPath);
repositoryRemote.setLocation(repoPath.resolve("test-repo").toUri()); repositoryRemote.setLocation(repoPath.resolve("test-repo").toUri());
RemoteIndexFeature icf = repositoryRemote.getFeature(RemoteIndexFeature.class).get(); RemoteIndexFeature icf = repositoryRemote.getFeature(RemoteIndexFeature.class).get();
icf.setIndexUri(new URI(".index-test"));
icf.setIndexUri(new URI(indexPath.getFileName().toString()));
ctx = mavenIndexManager.createContext(repositoryRemote); ctx = mavenIndexManager.createContext(repositoryRemote);
return ctx; return ctx;
} }

Loading…
Cancel
Save