use of org.apache.archiva.maven2.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.maven2.model.Artifact in project archiva by apache.
the class BrowseServiceTest method searchArtifacts.
@Test
public void searchArtifacts() throws Exception {
// START SNIPPET: search-artifacts
BrowseService browseService = getBrowseService(authorizationHeader, true);
List<Artifact> artifactDownloadInfos = browseService.searchArtifacts("The Apache Software Foundation", TEST_REPO_ID, true);
assertThat(artifactDownloadInfos).isNotNull().isNotEmpty().hasSize(7);
// END SNIPPET: search-artifacts
}
use of org.apache.archiva.maven2.model.Artifact in project archiva by apache.
the class AbstractRestService method buildArtifacts.
protected List<Artifact> buildArtifacts(Collection<ArtifactMetadata> artifactMetadatas, String repositoryId) throws ArchivaRestServiceException {
try {
if (artifactMetadatas != null && !artifactMetadatas.isEmpty()) {
List<Artifact> artifacts = new ArrayList<>(artifactMetadatas.size());
for (ArtifactMetadata artifact : artifactMetadatas) {
String repoId = repositoryId != null ? repositoryId : artifact.getRepositoryId();
if (repoId == null) {
throw new IllegalStateException("Repository Id is null");
}
ManagedRepository repo = repositoryRegistry.getManagedRepository(repoId);
if (repo == null) {
throw new RepositoryException("Repository not found " + repoId);
}
ManagedRepositoryContent content = repo.getContent();
ArtifactBuilder builder = new ArtifactBuilder().forArtifactMetadata(artifact).withManagedRepositoryContent(content);
Artifact art = builder.build();
art.setUrl(getArtifactUrl(art, repositoryId));
artifacts.add(art);
}
return artifacts;
}
return Collections.emptyList();
} catch (RepositoryException e) {
log.error(e.getMessage(), e);
throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
}
}
use of org.apache.archiva.maven2.model.Artifact in project archiva by apache.
the class DownloadMergedIndexNonDefaultPathTest method downloadMergedIndexWithNonDefaultPath.
@Test
public void downloadMergedIndexWithNonDefaultPath() throws Exception {
Path indexBaseDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("archiva").resolve("remotedownloadtest");
String indexBase = indexBaseDir.toString();
FileUtils.deleteQuietly(indexBaseDir);
if (!Files.exists(indexBaseDir)) {
Files.createDirectories(indexBaseDir);
}
String id = Long.toString(System.currentTimeMillis());
ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
managedRepository.setId(id);
managedRepository.setName("name of " + id);
managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
managedRepository.setIndexDirectory(indexBase + "/index-" + id);
managedRepository.setPackedIndexDirectory(indexBase + "/indexPacked-" + id);
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.alreadyScanning(id)) {
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);
String path = ".fooooo";
repositoryGroup.setRepositories(Arrays.asList(id));
repositoryGroup.setMergedIndexPath(path);
repositoryGroupService.addRepositoryGroup(repositoryGroup);
// create a repo with a remote on the one with index
id = Long.toString(System.currentTimeMillis());
managedRepository = new ManagedRepository(Locale.getDefault());
managedRepository.setId(id);
managedRepository.setName("name of " + id);
managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
managedRepository.setIndexDirectory(indexBaseDir + "/index-" + id);
managedRepository.setPackedIndexDirectory(indexBase + "/tmpIndexPacked-" + id);
if (managedRepositoriesService.getManagedRepository(id) != null) {
managedRepositoriesService.deleteManagedRepository(id, false);
}
getManagedRepositoriesService().addManagedRepository(managedRepository);
String remoteId = Long.toString(System.currentTimeMillis());
RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
remoteRepository.setId(remoteId);
remoteRepository.setName(remoteId);
remoteRepository.setDownloadRemoteIndex(true);
remoteRepository.setUrl("http://localhost:" + port + "/repository/test-group");
remoteRepository.setRemoteIndexUrl("http://localhost:" + port + "/repository/test-group/" + path);
remoteRepository.setUserName(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME);
remoteRepository.setPassword(FakeCreateAdminService.ADMIN_TEST_PWD);
getRemoteRepositoriesService().addRemoteRepository(remoteRepository);
ProxyConnectorService proxyConnectorService = getProxyConnectorService();
ProxyConnector proxyConnector = new ProxyConnector();
proxyConnector.setProxyId("foo-bar2");
proxyConnector.setSourceRepoId(id);
proxyConnector.setTargetRepoId(remoteId);
proxyConnectorService.addProxyConnector(proxyConnector);
repositoriesService.scheduleDownloadRemoteIndex(remoteId, true, true);
// wait the end
while (!repositoriesService.getRunningRemoteDownloadIds().getStrings().isEmpty()) {
Thread.sleep(500);
log.debug("still running remote download");
}
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.maven2.model.Artifact in project archiva by apache.
the class MetadataTools method getFirstArtifact.
/**
* Get the first Artifact found in the provided VersionedReference location.
*
* @param managedRepository the repository to search within.
* @param reference the reference to the versioned reference to search within
* @return the ArtifactReference to the first artifact located within the versioned reference. or null if
* no artifact was found within the versioned reference.
* @throws IOException if the versioned reference is invalid (example: doesn't exist, or isn't a directory)
* @throws LayoutException
*/
public ArtifactReference getFirstArtifact(ManagedRepositoryContent managedRepository, VersionedReference reference) throws LayoutException, IOException {
String path = toPath(reference);
int idx = path.lastIndexOf('/');
if (idx > 0) {
path = path.substring(0, idx);
}
Path repoDir = Paths.get(managedRepository.getRepoRoot(), path);
if (!Files.exists(repoDir)) {
throw new IOException("Unable to gather the list of snapshot versions on a non-existant directory: " + repoDir.toAbsolutePath());
}
if (!Files.isDirectory(repoDir)) {
throw new IOException("Unable to gather the list of snapshot versions on a non-directory: " + repoDir.toAbsolutePath());
}
try (Stream<Path> stream = Files.list(repoDir)) {
String result = stream.filter(Files::isRegularFile).map(path1 -> PathUtil.getRelative(managedRepository.getRepoRoot(), path1)).filter(filetypes::matchesArtifactPattern).findFirst().orElse(null);
if (result != null) {
return managedRepository.toArtifactReference(result);
}
}
// No artifact was found.
return null;
}
Aggregations