use of org.apache.archiva.maven.model.Artifact in project archiva by apache.
the class BrowseServiceTest method searchArtifactsByField.
@Test
public void searchArtifactsByField() throws Exception {
// START SNIPPET: search-artifacts-by-field
BrowseService browseService = getBrowseService(authorizationHeader, true);
List<Artifact> artifactDownloadInfos = browseService.searchArtifacts("org.name", "The Apache Software Foundation", TEST_REPO_ID, true);
assertThat(artifactDownloadInfos).isNotNull().isNotEmpty().hasSize(7);
// END SNIPPET: search-artifacts-by-field
}
use of org.apache.archiva.maven.model.Artifact in project archiva by apache.
the class DownloadMergedIndexTest method downloadMergedIndex.
@Test
public void downloadMergedIndex() throws Exception {
String id = Long.toString(System.currentTimeMillis());
Path srcRep = getProjectDirectory().resolve("src/test/repositories/test-repo");
Path testRep = getBasedir().resolve("target").resolve("test-repo-" + id).toAbsolutePath();
FileUtils.copyDirectory(srcRep.toFile(), testRep.toFile());
createdPaths.add(testRep);
ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
managedRepository.setId(id);
managedRepository.setName("name of " + id);
managedRepository.setLocation(testRep.toString());
managedRepository.setIndexDirectory(indexDir.resolve("index-" + id).toString());
ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
if (managedRepositoriesService.getManagedRepository(id) != null) {
managedRepositoriesService.deleteManagedRepository(id, false);
}
getManagedRepositoriesService().addManagedRepository(managedRepository);
RepositoriesService repositoriesService = getRepositoriesService();
repositoriesService.scanRepositoryNow(id, true);
// wait a bit to ensure index is finished
int timeout = 20000;
while (timeout > 0 && repositoriesService.getScanStatus(id).isAlreadyScanning()) {
Thread.sleep(500);
timeout -= 500;
}
RepositoryGroupService repositoryGroupService = getRepositoryGroupService();
String repoGroupId = "test-group";
if (repositoryGroupService.getRepositoryGroup(repoGroupId) != null) {
repositoryGroupService.deleteRepositoryGroup(repoGroupId);
}
RepositoryGroup repositoryGroup = new RepositoryGroup();
repositoryGroup.setId(repoGroupId);
repositoryGroup.setRepositories(Arrays.asList(id));
repositoryGroupService.addRepositoryGroup(repositoryGroup);
// create a repo with a remote on the one with index
id = Long.toString(System.currentTimeMillis());
Path srcRep2 = getProjectDirectory().resolve("src/test/repositories/test-repo");
Path testRep2 = getBasedir().resolve("target").resolve("test-repo-" + id).toAbsolutePath();
FileUtils.copyDirectory(srcRep2.toFile(), testRep2.toFile());
createdPaths.add(testRep2);
managedRepository = new ManagedRepository(Locale.getDefault());
managedRepository.setId(id);
managedRepository.setName("name of " + id);
managedRepository.setLocation(testRep2.toString());
managedRepository.setIndexDirectory(indexDir.resolve("index-" + id).toString());
if (managedRepositoriesService.getManagedRepository(id) != null) {
managedRepositoriesService.deleteManagedRepository(id, false);
}
getManagedRepositoriesService().addManagedRepository(managedRepository);
RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
remoteRepository.setId("all-merged");
remoteRepository.setName("all-merged");
remoteRepository.setDownloadRemoteIndex(true);
remoteRepository.setUrl("http://localhost:" + port + "/repository/test-group");
remoteRepository.setRemoteIndexUrl("http://localhost:" + port + "/repository/test-group/.index");
remoteRepository.setUserName(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME);
remoteRepository.setPassword(BaseSetup.getAdminPwd());
if (getRemoteRepositoriesService().getRemoteRepository(remoteRepository.getId()) != null) {
getRemoteRepositoriesService().deleteRemoteRepository(remoteRepository.getId());
}
getRemoteRepositoriesService().addRemoteRepository(remoteRepository);
ProxyConnectorService proxyConnectorService = getProxyConnectorService();
ProxyConnector proxyConnector = new ProxyConnector();
proxyConnector.setProxyId("foo-bar1");
proxyConnector.setSourceRepoId(id);
proxyConnector.setTargetRepoId("all-merged");
proxyConnectorService.addProxyConnector(proxyConnector);
repositoriesService.scheduleDownloadRemoteIndex("all-merged", true, true);
// wait a bit
timeout = 20000;
while (timeout > 0) {
Thread.sleep(500);
timeout -= 500;
}
SearchService searchService = getSearchService();
SearchRequest request = new SearchRequest();
request.setRepositories(Arrays.asList(id));
request.setGroupId("org.apache.felix");
List<Artifact> artifacts = searchService.searchArtifacts(request);
assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
}
use of org.apache.archiva.maven.model.Artifact in project archiva by apache.
the class DependencyTreeBuilderTestMaven3 method testBuilderDependencies.
@Test
public void testBuilderDependencies() throws Exception {
List<TreeEntry> treeEntries = builder.buildDependencyTree(Collections.singletonList(TEST_REPO_ID), TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION);
Artifact artifact = new Artifact(TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "", "");
artifact.setFileExtension("jar");
assertThat(treeEntries).isNotNull().isNotEmpty().contains(new TreeEntry(artifact));
artifact = new Artifact("commons-lang", "commons-lang", "2.2", "compile", "");
artifact.setFileExtension("jar");
assertThat(treeEntries.get(0).getChilds()).isNotNull().isNotEmpty().contains(new TreeEntry(artifact));
}
use of org.apache.archiva.maven.model.Artifact in project archiva by apache.
the class DefaultBrowseService method getDependees.
@Override
public List<Artifact> getDependees(String groupId, String artifactId, String version, String repositoryId) throws ArchivaRestServiceException {
List<ProjectVersionReference> references = new ArrayList<>();
// TODO: what if we get duplicates across repositories?
RepositorySession repositorySession = null;
try {
repositorySession = repositorySessionFactory.createSession();
} catch (MetadataRepositoryException e) {
e.printStackTrace();
}
try {
MetadataResolver metadataResolver = repositorySession.getResolver();
for (String repoId : getObservableRepos()) {
// TODO: what about if we want to see this irrespective of version?
references.addAll(metadataResolver.resolveProjectReferences(repositorySession, repoId, groupId, artifactId, version));
}
} catch (MetadataResolutionException e) {
throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
} finally {
repositorySession.close();
}
List<Artifact> artifacts = new ArrayList<>(references.size());
for (ProjectVersionReference projectVersionReference : references) {
artifacts.add(new Artifact(projectVersionReference.getNamespace(), projectVersionReference.getProjectId(), projectVersionReference.getProjectVersion()));
}
return artifacts;
}
use of org.apache.archiva.maven.model.Artifact in project archiva by apache.
the class DefaultBrowseService method getArtifactDownloadInfos.
@Override
public List<Artifact> getArtifactDownloadInfos(String groupId, String artifactId, String version, String repositoryId) throws ArchivaRestServiceException {
List<String> selectedRepos = getSelectedRepos(repositoryId);
List<Artifact> artifactDownloadInfos = new ArrayList<>();
try (RepositorySession session = repositorySessionFactory.createSession()) {
MetadataResolver metadataResolver = session.getResolver();
for (String repoId : selectedRepos) {
List<ArtifactMetadata> artifacts = new ArrayList<>(metadataResolver.resolveArtifacts(session, repoId, groupId, artifactId, version));
Collections.sort(artifacts, ArtifactMetadataVersionComparator.INSTANCE);
if (artifacts != null && !artifacts.isEmpty()) {
return buildArtifacts(artifacts, repoId);
}
}
} catch (MetadataResolutionException e) {
log.error(e.getMessage(), e);
throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
} catch (MetadataRepositoryException e) {
e.printStackTrace();
}
return artifactDownloadInfos;
}
Aggregations