use of org.apache.archiva.admin.model.beans.ProxyConnector in project archiva by apache.
the class AbstractRestService method getArtifactUrl.
protected String getArtifactUrl(Artifact artifact, String repositoryId) throws ArchivaRestServiceException {
try {
if (httpServletRequest == null) {
return null;
}
StringBuilder sb = new StringBuilder(getBaseUrl());
sb.append("/repository");
// we must replace it with a valid managed one available for the user.
if (StringUtils.isEmpty(repositoryId)) {
List<String> userRepos = userRepositories.getObservableRepositoryIds(getPrincipal());
// if not search the repo who is proxy for this remote
if (!userRepos.contains(artifact.getContext())) {
for (Map.Entry<String, List<ProxyConnector>> entry : proxyConnectorAdmin.getProxyConnectorAsMap().entrySet()) {
for (ProxyConnector proxyConnector : entry.getValue()) {
if (StringUtils.equals("remote-" + proxyConnector.getTargetRepoId(), //
artifact.getContext()) && userRepos.contains(entry.getKey())) {
sb.append('/').append(entry.getKey());
}
}
}
} else {
sb.append('/').append(artifact.getContext());
}
} else {
sb.append('/').append(repositoryId);
}
sb.append('/').append(StringUtils.replaceChars(artifact.getGroupId(), '.', '/'));
sb.append('/').append(artifact.getArtifactId());
if (VersionUtil.isSnapshot(artifact.getVersion())) {
sb.append('/').append(VersionUtil.getBaseVersion(artifact.getVersion()));
} else {
sb.append('/').append(artifact.getVersion());
}
sb.append('/').append(artifact.getArtifactId());
sb.append('-').append(artifact.getVersion());
if (StringUtils.isNotBlank(artifact.getClassifier())) {
sb.append('-').append(artifact.getClassifier());
}
// maven-plugin packaging is a jar
if (StringUtils.equals("maven-plugin", artifact.getPackaging())) {
sb.append("jar");
} else {
sb.append('.').append(artifact.getFileExtension());
}
return sb.toString();
} catch (Exception e) {
throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
}
}
use of org.apache.archiva.admin.model.beans.ProxyConnector 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.admin.model.beans.ProxyConnector in project archiva by apache.
the class DownloadMergedIndexTest method downloadMergedIndex.
@Test
public void downloadMergedIndex() throws Exception {
Path tmpIndexDir = Paths.get(System.getProperty("java.io.tmpdir"), "tmpIndex");
if (Files.exists(tmpIndexDir)) {
FileUtils.deleteDirectory(tmpIndexDir.toFile());
}
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(System.getProperty("java.io.tmpdir") + "/tmpIndex/" + 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);
repositoryGroup.setRepositories(Arrays.asList(id));
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(System.getProperty("java.io.tmpdir") + "/tmpIndex/" + id);
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(FakeCreateAdminService.ADMIN_TEST_PWD);
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.admin.model.beans.ProxyConnector in project archiva by apache.
the class MavenRepositorySearch method getRemoteIndexingContextIds.
@Override
public Set<String> getRemoteIndexingContextIds(String managedRepoId) throws RepositorySearchException {
Set<String> ids = new HashSet<>();
List<ProxyConnector> proxyConnectors = null;
try {
proxyConnectors = proxyConnectorAdmin.getProxyConnectorAsMap().get(managedRepoId);
} catch (RepositoryAdminException e) {
throw new RepositorySearchException(e.getMessage(), e);
}
if (proxyConnectors == null || proxyConnectors.isEmpty()) {
return ids;
}
for (ProxyConnector proxyConnector : proxyConnectors) {
String remoteId = "remote-" + proxyConnector.getTargetRepoId();
RemoteRepository repo = repositoryRegistry.getRemoteRepository(proxyConnector.getTargetRepoId());
if (repo.getType() == RepositoryType.MAVEN) {
try {
IndexingContext context = repo.getIndexingContext() != null ? repo.getIndexingContext().getBaseContext(IndexingContext.class) : null;
if (context != null && context.isSearchable()) {
ids.add(remoteId);
}
} catch (UnsupportedBaseContextException e) {
// Ignore this one
}
}
}
return ids;
}
use of org.apache.archiva.admin.model.beans.ProxyConnector in project archiva by apache.
the class Maven3DependencyTreeBuilder method buildDependencyTree.
@Override
public void buildDependencyTree(List<String> repositoryIds, String groupId, String artifactId, String version, DependencyVisitor dependencyVisitor) throws DependencyTreeBuilderException {
Artifact projectArtifact = factory.createProjectArtifact(groupId, artifactId, version);
ManagedRepository repository = null;
try {
repository = findArtifactInRepositories(repositoryIds, projectArtifact);
} catch (RepositoryAdminException e) {
// FIXME better exception
throw new DependencyTreeBuilderException("Cannot build project dependency tree " + e.getMessage(), e);
}
if (repository == null) {
// metadata could not be resolved
return;
}
List<RemoteRepository> remoteRepositories = new ArrayList<>();
Map<String, NetworkProxy> networkProxies = new HashMap<>();
try {
// MRM-1411
// TODO: this is a workaround for a lack of proxy capability in the resolvers - replace when it can all be
// handled there. It doesn't cache anything locally!
Map<String, List<ProxyConnector>> proxyConnectorsMap = proxyConnectorAdmin.getProxyConnectorAsMap();
List<ProxyConnector> proxyConnectors = proxyConnectorsMap.get(repository.getId());
if (proxyConnectors != null) {
for (ProxyConnector proxyConnector : proxyConnectors) {
remoteRepositories.add(remoteRepositoryAdmin.getRemoteRepository(proxyConnector.getTargetRepoId()));
NetworkProxy networkProxyConfig = networkProxyAdmin.getNetworkProxy(proxyConnector.getProxyId());
if (networkProxyConfig != null) {
// key/value: remote repo ID/proxy info
networkProxies.put(proxyConnector.getTargetRepoId(), networkProxyConfig);
}
}
}
} catch (RepositoryAdminException e) {
throw new DependencyTreeBuilderException(e.getMessage(), e);
}
// FIXME take care of relative path
ResolveRequest resolveRequest = new ResolveRequest();
resolveRequest.dependencyVisitor = dependencyVisitor;
resolveRequest.localRepoDir = repository.getLocation();
resolveRequest.groupId = groupId;
resolveRequest.artifactId = artifactId;
resolveRequest.version = version;
resolveRequest.remoteRepositories = remoteRepositories;
resolveRequest.networkProxies = networkProxies;
resolve(resolveRequest);
}
Aggregations