use of org.apache.archiva.repository.RepositoryRegistry in project archiva by apache.
the class CleanupReleasedSnapshotsRepositoryPurgeTest method testReleasedSnapshotsExistsInDifferentRepo.
@Test
public void testReleasedSnapshotsExistsInDifferentRepo() throws Exception {
RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class);
ManagedRepository managedRepository = repositoryRegistry.getManagedRepository(TEST_REPO_ID);
repositoryRegistry.removeRepository(TEST_REPO_ID);
repositoryRegistry.putRepository(getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME));
repositoryRegistry.putRepository(getRepoConfiguration(RELEASES_TEST_REPO_ID, RELEASES_TEST_REPO_NAME));
String repoRoot = prepareTestRepos();
String projectNs = "org.apache.archiva";
String projectPath = projectNs.replaceAll("\\.", "/");
String projectName = "released-artifact-in-diff-repo";
String projectVersion = "1.0-SNAPSHOT";
String releaseVersion = "1.0";
String projectRoot = repoRoot + "/" + projectPath + "/" + projectName;
Path repo = getTestRepoRootPath();
Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
Path releaseDir = repo.getParent().resolve(RELEASES_TEST_REPO_ID).resolve(projectPath).resolve(projectName).resolve(releaseVersion);
Set<String> deletedVersions = new HashSet<>();
deletedVersions.add("1.0-SNAPSHOT");
// test listeners for the correct artifacts
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.archiva", "released-artifact-in-diff-repo", "1.0-SNAPSHOT", "released-artifact-in-diff-repo-1.0-SNAPSHOT.jar");
listenerControl.replay();
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir);
when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
List<ArtifactMetadata> ml2 = getArtifactMetadataFromDir(RELEASES_TEST_REPO_ID, projectName, repo.getParent(), releaseDir);
when(metadataRepository.getArtifacts(RELEASES_TEST_REPO_ID, projectNs, projectName, releaseVersion)).thenReturn(ml2);
repoPurge.process(PATH_TO_RELEASED_SNAPSHOT_IN_DIFF_REPO);
listenerControl.verify();
// Verify the metadataRepository invocations
// Complete version removal for cleanup
verify(metadataRepository, times(1)).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
verify(metadataRepository, never()).removeProjectVersion(eq(RELEASES_TEST_REPO_ID), eq(projectNs), eq(projectName), eq(releaseVersion));
// check if the snapshot was removed
assertDeleted(projectRoot + "/1.0-SNAPSHOT");
assertDeleted(projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar");
assertDeleted(projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar.md5");
assertDeleted(projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar.sha1");
assertDeleted(projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom");
assertDeleted(projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom.md5");
assertDeleted(projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom.sha1");
String releasesProjectRoot = AbstractRepositoryPurgeTest.fixPath(Paths.get("target/test-" + getName() + "/releases-test-repo-one").toAbsolutePath().toString() + "/org/apache/archiva/released-artifact-in-diff-repo");
// check if the released version was not removed
assertExists(releasesProjectRoot + "/1.0");
assertExists(releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar");
assertExists(releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar.md5");
assertExists(releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar.sha1");
assertExists(releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom");
assertExists(releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom.md5");
assertExists(releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom.sha1");
// remove RELEASES_TEST_REPO_ID so this test will be more independant
applicationContext.getBean(ManagedRepositoryAdmin.class).deleteManagedRepository(RELEASES_TEST_REPO_ID, null, false);
}
use of org.apache.archiva.repository.RepositoryRegistry in project archiva by apache.
the class CleanupReleasedSnapshotsRepositoryPurgeTest method testReleasedSnapshotsExistsInSameRepo.
@Test
public void testReleasedSnapshotsExistsInSameRepo() throws Exception {
RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class);
repositoryRegistry.removeRepository(TEST_REPO_ID);
repositoryRegistry.putRepository(getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME));
String repoRoot = prepareTestRepos();
String projectNs = "org.apache.maven.plugins";
String projectPath = projectNs.replaceAll("\\.", "/");
String projectName = "maven-plugin-plugin";
String projectVersion = "2.3-SNAPSHOT";
String projectRoot = repoRoot + "/" + projectPath + "/" + projectName;
Path repo = getTestRepoRootPath();
Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
Set<String> deletedVersions = new HashSet<>();
deletedVersions.add("2.3-SNAPSHOT");
// test listeners for the correct artifacts
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-plugin-plugin", "2.3-SNAPSHOT", "maven-plugin-plugin-2.3-SNAPSHOT.jar");
listenerControl.replay();
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir);
when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
repoPurge.process(PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO);
listenerControl.verify();
// Verify the metadataRepository invocations
// complete snapshot version removal for released
verify(metadataRepository, times(1)).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq("2.3"));
// check if the snapshot was removed
assertDeleted(projectRoot + "/2.3-SNAPSHOT");
assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar");
assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5");
assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1");
assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom");
assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5");
assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1");
// check if the released version was not removed
assertExists(projectRoot + "/2.3");
assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar");
assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar.md5");
assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar.sha1");
assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3.jar");
assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3.jar.md5");
assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3.jar.sha1");
assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3.pom");
assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3.pom.md5");
assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3.pom.sha1");
// check if metadata file was updated
Path artifactMetadataFile = Paths.get(projectRoot + "/maven-metadata.xml");
String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString(artifactMetadataFile, Charset.defaultCharset());
String expectedVersions = "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>";
XMLAssert.assertXpathEvaluatesTo("2.3", "//metadata/versioning/release", metadataXml);
XMLAssert.assertXpathEvaluatesTo("2.3", "//metadata/versioning/latest", metadataXml);
System.out.println(metadataXml);
XMLAssert.assertXpathsEqual("//expected/versions/version", expectedVersions, "//metadata/versioning/versions/version", metadataXml);
XMLAssert.assertXpathEvaluatesTo("20070315032817", "//metadata/versioning/lastUpdated", metadataXml);
}
use of org.apache.archiva.repository.RepositoryRegistry in project archiva by apache.
the class RepositoryPurgeConsumerTest method removeRepoFromConfiguration.
private void removeRepoFromConfiguration(String configHint, org.apache.archiva.repository.ManagedRepository repoConfiguration) throws Exception {
RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class);
repositoryRegistry.removeRepository(repoConfiguration);
}
use of org.apache.archiva.repository.RepositoryRegistry in project archiva by apache.
the class DefaultManagedRepositoryAdmin method deleteManagedRepository.
private Boolean deleteManagedRepository(ManagedRepositoryConfiguration repository, boolean deleteContent, Configuration config, boolean stagedOne) throws RepositoryAdminException {
if (!stagedOne) {
RepositorySession repositorySession = getRepositorySessionFactory().createSession();
try {
MetadataRepository metadataRepository = repositorySession.getRepository();
metadataRepository.removeRepository(repository.getId());
// invalidate cache
namespacesCache.remove(repository.getId());
log.debug("call repositoryStatisticsManager.deleteStatistics");
getRepositoryStatisticsManager().deleteStatistics(metadataRepository, repository.getId());
repositorySession.save();
} catch (MetadataRepositoryException e) {
// throw new RepositoryAdminException( e.getMessage(), e );
log.warn("skip error during removing repository from MetadataRepository:{}", e.getMessage(), e);
} finally {
repositorySession.close();
}
}
if (deleteContent) {
// TODO could be async ? as directory can be huge
Path dir = Paths.get(repository.getLocation());
org.apache.archiva.common.utils.FileUtils.deleteQuietly(dir);
}
// olamy: copy list for reading as a unit test in webapp fail with ConcurrentModificationException
List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>(config.getProxyConnectors());
for (ProxyConnectorConfiguration proxyConnector : proxyConnectors) {
if (StringUtils.equals(proxyConnector.getSourceRepoId(), repository.getId())) {
config.removeProxyConnector(proxyConnector);
}
}
Map<String, List<String>> repoToGroupMap = config.getRepositoryToGroupMap();
if (repoToGroupMap != null) {
if (repoToGroupMap.containsKey(repository.getId())) {
List<String> repoGroups = repoToGroupMap.get(repository.getId());
for (String repoGroup : repoGroups) {
// copy to prevent UnsupportedOperationException
RepositoryGroupConfiguration repositoryGroupConfiguration = config.findRepositoryGroupById(repoGroup);
List<String> repos = new ArrayList<>(repositoryGroupConfiguration.getRepositories());
config.removeRepositoryGroup(repositoryGroupConfiguration);
repos.remove(repository.getId());
repositoryGroupConfiguration.setRepositories(repos);
config.addRepositoryGroup(repositoryGroupConfiguration);
}
}
}
try {
removeRepositoryRoles(repository);
} catch (RoleManagerException e) {
throw new RepositoryAdminException("fail to remove repository roles for repository " + repository.getId() + " : " + e.getMessage(), e);
}
try {
final RepositoryRegistry reg = getRepositoryRegistry();
if (reg.getManagedRepository(repository.getId()) != null) {
reg.removeRepository(reg.getManagedRepository(repository.getId()));
}
} catch (RepositoryException e) {
throw new RepositoryAdminException("Removal of repository " + repository.getId() + " failed: " + e.getMessage());
}
saveConfiguration(config);
return Boolean.TRUE;
}
use of org.apache.archiva.repository.RepositoryRegistry in project archiva by apache.
the class HttpProxyTransferTest method setUp.
@Before
public void setUp() throws Exception {
proxyHandler = applicationContext.getBean("repositoryProxyConnectors#test", RepositoryProxyConnectors.class);
config = applicationContext.getBean("archivaConfiguration#mock", ArchivaConfiguration.class);
// clear from previous tests - TODO the spring context should be initialised per test instead, or the config
// made a complete mock
config.getConfiguration().getProxyConnectors().clear();
// Setup source repository (using default layout)
String repoPath = "target/test-repository/managed/" + getClass().getSimpleName();
Path destRepoDir = Paths.get(repoPath);
// Cleanout destination dirs.
if (Files.exists(destRepoDir)) {
FileUtils.deleteDirectory(destRepoDir.toFile());
}
// Make the destination dir.
Files.createDirectories(destRepoDir);
MavenManagedRepository repo = new MavenManagedRepository(MANAGED_ID, "Default Managed Repository", Paths.get(repoPath).getParent());
repo.setLocation(new URI(repoPath));
repo.setLayout("default");
RepositoryContentProvider provider = applicationContext.getBean("repositoryContentProvider#maven", RepositoryContentProvider.class);
ManagedRepositoryContent repoContent = provider.createManagedContent(repo);
managedDefaultRepository = repoContent;
((DefaultManagedRepositoryAdmin) applicationContext.getBean(ManagedRepositoryAdmin.class)).setArchivaConfiguration(config);
RepositoryRegistry managedRepositoryAdmin = applicationContext.getBean(RepositoryRegistry.class);
if (managedRepositoryAdmin.getManagedRepository(repo.getId()) == null) {
managedRepositoryAdmin.putRepository(repo);
}
// config.getConfiguration().addManagedRepository( repo );
Handler handler = new AbstractHandler() {
@Override
public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/plain");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().print("get-default-layout-1.0.jar\n\n");
assertNotNull(request.getHeader("Proxy-Connection"));
((Request) request).setHandled(true);
}
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException {
response.setContentType("text/plain");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().print("get-default-layout-1.0.jar\n\n");
assertNotNull(request.getHeader("Proxy-Connection"));
((Request) request).setHandled(true);
}
};
server = new Server();
ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory());
server.addConnector(serverConnector);
server.setHandler(handler);
server.start();
int port = serverConnector.getLocalPort();
NetworkProxyConfiguration proxyConfig = new NetworkProxyConfiguration();
proxyConfig.setHost("localhost");
proxyConfig.setPort(port);
proxyConfig.setProtocol("http");
proxyConfig.setId(PROXY_ID);
config.getConfiguration().addNetworkProxy(proxyConfig);
// Setup target (proxied to) repository.
RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration();
repoConfig.setId(PROXIED_ID);
repoConfig.setName("Proxied Repository 1");
repoConfig.setLayout("default");
repoConfig.setUrl("http://www.example.com/");
config.getConfiguration().addRemoteRepository(repoConfig);
}
Aggregations