use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.
the class DefaultMergeRepositoriesService method mergeBySkippingConflicts.
public void mergeBySkippingConflicts(String sourceRepositoryId, String targetRepositoryId) throws RepositoryMergerException, ArchivaRestServiceException {
RepositorySession repositorySession = repositorySessionFactory.createSession();
try {
List<ArtifactMetadata> conflictSourceArtifacts = repositoryMerger.getConflictingArtifacts(repositorySession.getRepository(), sourceRepositoryId, targetRepositoryId);
MetadataRepository metadataRepository = repositorySession.getRepository();
List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts(sourceRepositoryId);
sourceArtifacts.removeAll(conflictSourceArtifacts);
ManagedRepository repository = managedRepositoryAdmin.getManagedRepository(targetRepositoryId);
if (repository.isReleases() && !repository.isSnapshots()) {
mergeWithOutSnapshots(metadataRepository, sourceArtifacts, sourceRepositoryId, targetRepositoryId);
} else {
Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>(sourceArtifacts);
repositoryMerger.merge(metadataRepository, sourceRepositoryId, targetRepositoryId, artifactsWithOutConflicts);
for (ArtifactMetadata metadata : sourceArtifacts) {
triggerAuditEvent(targetRepositoryId, metadata.getId(), AuditEvent.MERGING_REPOSITORIES);
}
}
doScanRepository(targetRepositoryId, false);
} catch (MetadataRepositoryException e) {
throw new ArchivaRestServiceException(e.getMessage(), e);
} catch (RepositoryAdminException e) {
throw new ArchivaRestServiceException(e.getMessage(), e);
} finally {
repositorySession.close();
}
}
use of org.apache.archiva.admin.model.beans.ManagedRepository 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.ManagedRepository in project archiva by apache.
the class DownloadSnapshotTest method downloadSNAPSHOT.
@Test
public void downloadSNAPSHOT() throws Exception {
Path tmpIndexDir = Paths.get(System.getProperty("java.io.tmpdir") + "/tmpIndex");
if (Files.exists(tmpIndexDir)) {
org.apache.archiva.common.utils.FileUtils.deleteDirectory(tmpIndexDir);
}
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/snapshot-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);
RoleManagementService roleManagementService = getRoleManagementService(authorizationHeader);
if (!roleManagementService.templatedRoleExists(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id)) {
roleManagementService.createTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id);
}
getUserService(authorizationHeader).createGuestUser();
roleManagementService.assignRole(ArchivaRoleConstants.TEMPLATE_GUEST, "guest");
roleManagementService.assignTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id, "guest");
getUserService(authorizationHeader).removeFromCache("guest");
Path file = Paths.get("target/archiva-model-1.4-M4-SNAPSHOT.jar");
Files.deleteIfExists(file);
HttpWagon httpWagon = new HttpWagon();
httpWagon.connect(new Repository("foo", "http://localhost:" + port));
httpWagon.get("/repository/" + id + "/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-SNAPSHOT.jar", file.toFile());
ZipFile zipFile = new ZipFile(file.toFile());
List<String> entries = getZipEntriesNames(zipFile);
ZipEntry zipEntry = zipFile.getEntry("org/apache/archiva/model/ArchivaArtifact.class");
assertNotNull("cannot find zipEntry org/apache/archiva/model/ArchivaArtifact.class, entries: " + entries + ", content is: " + FileUtils.readFileToString(file.toFile(), Charset.forName("UTF-8")), zipEntry);
zipFile.close();
file.toFile().deleteOnExit();
}
use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.
the class ArchivaDavResourceFactoryTest method createManagedRepository.
private ManagedRepository createManagedRepository(String id, String location, String layout) {
ManagedRepository repoConfig = new ManagedRepository(Locale.getDefault());
repoConfig.setId(id);
repoConfig.setName(id);
repoConfig.setLocation(location);
repoConfig.setLayout(layout);
return repoConfig;
}
use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.
the class AbstractRepositoryServletTestCase method assertRepositoryValid.
protected void assertRepositoryValid(RepositoryServlet servlet, String repoId) throws Exception {
ManagedRepository repository = servlet.getRepository(repoId);
assertNotNull("Archiva Managed Repository id:<" + repoId + "> should exist.", repository);
Path repoRoot = Paths.get(repository.getLocation());
assertTrue("Archiva Managed Repository id:<" + repoId + "> should have a valid location on disk.", Files.exists(repoRoot) && Files.isDirectory(repoRoot));
}
Aggregations