use of org.apache.archiva.metadata.repository.storage.ReadMetadataRequest in project archiva by apache.
the class Maven2RepositoryMetadataResolverTest method testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata.
@Test
public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata() throws Exception {
try {
storage.readProjectVersionMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "malformed-metadata", "1.0-SNAPSHOT"));
fail("Should not be found");
} catch (RepositoryStorageMetadataNotFoundException e) {
assertEquals("missing-pom", e.getId());
}
}
use of org.apache.archiva.metadata.repository.storage.ReadMetadataRequest in project archiva by apache.
the class ArchivaMetadataCreationConsumer method processFile.
@Override
public void processFile(String path) throws ConsumerException {
RepositorySession repositorySession = repositorySessionFactory.createSession();
try {
// note that we do minimal processing including checksums and POM information for performance of
// the initial scan. Any request for this information will be intercepted and populated on-demand
// or picked up by subsequent scans
ArtifactMetadata artifact = repositoryStorage.readArtifactMetadataFromPath(repoId, path);
ProjectMetadata project = new ProjectMetadata();
project.setNamespace(artifact.getNamespace());
project.setId(artifact.getProject());
String projectVersion = VersionUtil.getBaseVersion(artifact.getVersion());
MetadataRepository metadataRepository = repositorySession.getRepository();
boolean createVersionMetadata = false;
// FIXME: maybe not too efficient since it may have already been read and stored for this artifact
ProjectVersionMetadata versionMetadata = null;
try {
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(artifact.getNamespace()).projectId(artifact.getProject()).projectVersion(projectVersion);
versionMetadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
createVersionMetadata = true;
} catch (RepositoryStorageMetadataNotFoundException e) {
log.warn("Missing or invalid POM for artifact:{} (repository:{}); creating empty metadata", path, repoId);
versionMetadata = new ProjectVersionMetadata();
versionMetadata.setId(projectVersion);
versionMetadata.setIncomplete(true);
createVersionMetadata = true;
} catch (RepositoryStorageMetadataInvalidException e) {
log.warn("Error occurred resolving POM for artifact:{} (repository:{}); message: {}", new Object[] { path, repoId, e.getMessage() });
}
// read the metadata and update it if it is newer or doesn't exist
artifact.setWhenGathered(whenGathered);
metadataRepository.updateArtifact(repoId, project.getNamespace(), project.getId(), projectVersion, artifact);
if (createVersionMetadata) {
metadataRepository.updateProjectVersion(repoId, project.getNamespace(), project.getId(), versionMetadata);
}
metadataRepository.updateProject(repoId, project);
repositorySession.save();
} catch (MetadataRepositoryException e) {
log.warn("Error occurred persisting metadata for artifact:{} (repository:{}); message: {}", path, repoId, e.getMessage(), e);
repositorySession.revert();
} catch (RepositoryStorageRuntimeException e) {
log.warn("Error occurred persisting metadata for artifact:{} (repository:{}); message: {}", path, repoId, e.getMessage(), e);
repositorySession.revert();
} finally {
repositorySession.close();
}
}
use of org.apache.archiva.metadata.repository.storage.ReadMetadataRequest in project archiva by apache.
the class DefaultMetadataResolver method resolveProjectVersion.
@Override
public ProjectVersionMetadata resolveProjectVersion(RepositorySession session, String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
MetadataRepository metadataRepository = session.getRepository();
ProjectVersionMetadata metadata = metadataRepository.getProjectVersion(repoId, namespace, projectId, projectVersion);
// may then work here and be more efficient than always trying again)
if (metadata == null || metadata.isIncomplete()) {
try {
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(namespace).projectId(projectId).projectVersion(projectVersion).browsingRequest(true);
metadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
log.debug("Resolved project version metadata from storage: {}", metadata);
// eg. maven projects should be able to process parent here
if (!metadata.getDependencies().isEmpty()) {
ProjectVersionReference ref = new ProjectVersionReference();
ref.setNamespace(namespace);
ref.setProjectId(projectId);
ref.setProjectVersion(projectVersion);
ref.setReferenceType(ProjectVersionReference.ReferenceType.DEPENDENCY);
}
try {
for (RepositoryListener listener : listeners) {
listener.addArtifact(session, repoId, namespace, projectId, metadata);
}
metadataRepository.updateProjectVersion(repoId, namespace, projectId, metadata);
} catch (MetadataRepositoryException e) {
log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
}
session.markDirty();
} catch (RepositoryStorageMetadataInvalidException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
throw new MetadataResolutionException(e.getMessage(), e);
} catch (RepositoryStorageMetadataNotFoundException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
// no need to rethrow - return null
} catch (RepositoryStorageRuntimeException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
throw new MetadataResolutionException(e.getMessage(), e);
}
}
return metadata;
}
use of org.apache.archiva.metadata.repository.storage.ReadMetadataRequest in project archiva by apache.
the class DefaultMetadataResolver method resolveProjectVersions.
@Override
public Collection<String> resolveProjectVersions(RepositorySession session, String repoId, String namespace, String projectId) throws MetadataResolutionException {
try {
MetadataRepository metadataRepository = session.getRepository();
Collection<String> projectVersions = metadataRepository.getProjectVersions(repoId, namespace, projectId);
Collection<String> storageProjectVersions = repositoryStorage.listProjectVersions(repoId, namespace, projectId, new ExcludesFilter<String>(projectVersions));
if (storageProjectVersions != null && !storageProjectVersions.isEmpty()) {
log.debug("Resolved project versions from storage: {}", storageProjectVersions);
for (String projectVersion : storageProjectVersions) {
try {
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(namespace).projectId(projectId).projectVersion(projectVersion);
ProjectVersionMetadata versionMetadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
for (RepositoryListener listener : listeners) {
listener.addArtifact(session, repoId, namespace, projectId, versionMetadata);
}
metadataRepository.updateProjectVersion(repoId, namespace, projectId, versionMetadata);
} catch (MetadataRepositoryException e) {
log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
} catch (RepositoryStorageMetadataInvalidException e) {
log.warn("Not update project in metadata repository due to an error resolving it from storage: {}", e.getMessage());
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
} catch (RepositoryStorageMetadataNotFoundException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
}
}
session.markDirty();
projectVersions = new ArrayList<>(projectVersions);
projectVersions.addAll(storageProjectVersions);
}
return projectVersions;
} catch (RepositoryStorageRuntimeException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.storage.ReadMetadataRequest in project archiva by apache.
the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo.
@Test
public void testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo() throws Exception {
copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-module-a", "target/test-repository/com/example/test/test-artifact-module-a");
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(TEST_REPO_ID).namespace("com.example.test").projectId("missing-parent").projectVersion("1.1");
ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(readMetadataRequest);
assertEquals("1.1", metadata.getId());
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet(MavenProjectFacet.FACET_ID);
assertNotNull(facet);
assertEquals("com.example.test", facet.getGroupId());
assertEquals("missing-parent", facet.getArtifactId());
assertEquals("jar", facet.getPackaging());
List<String> paths = new ArrayList<>();
paths.add("target/test-repository/com/example/test/test-artifact-module-a");
paths.add("target/test-repository/com/example/test/test-artifact-parent");
paths.add("target/test-repository/com/example/test/test-artifact-root");
deleteTestArtifactWithParent(paths);
}
Aggregations