|
|
@@ -45,12 +45,17 @@ import javax.inject.Inject; |
|
|
|
import java.io.IOException; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URISyntaxException; |
|
|
|
import java.nio.file.DirectoryStream; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.nio.file.attribute.*; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.EnumSet; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
@@ -138,19 +143,27 @@ public class MavenIndexManagerTest { |
|
|
|
public void addArtifactsToIndex() throws Exception { |
|
|
|
|
|
|
|
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 |
|
|
@@ -181,23 +194,32 @@ public class MavenIndexManagerTest { |
|
|
|
} |
|
|
|
|
|
|
|
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.setLocation(new URI("test-repo")); |
|
|
|
IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class).get(); |
|
|
|
icf.setIndexPath(new URI(".index-test")); |
|
|
|
icf.setIndexPath(new URI(indexPathName)); |
|
|
|
ctx = mavenIndexManager.createContext(repository); |
|
|
|
return ctx; |
|
|
|
} |
|
|
|
|
|
|
|
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(); |
|
|
|
repositoryRemote = MavenRemoteRepository.newLocalInstance("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")); |
|
|
|
icf.setIndexUri(new URI(indexPath.getFileName().toString())); |
|
|
|
ctx = mavenIndexManager.createContext(repositoryRemote); |
|
|
|
return ctx; |
|
|
|
} |