use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method removeArtifact.
@Override
public void removeArtifact(String repositoryId, String namespace, String projectId, String projectVersion, String id) throws MetadataRepositoryException {
try {
Node root = getJcrSession().getRootNode();
String path = getArtifactPath(repositoryId, namespace, projectId, projectVersion, id);
if (root.hasNode(path)) {
root.getNode(path).remove();
}
// remove version
path = getProjectPath(repositoryId, namespace, projectId);
Node nodeAtPath = root.getNode(path);
for (Node node : JcrUtils.getChildNodes(nodeAtPath)) {
if (//
node.isNodeType(PROJECT_VERSION_NODE_TYPE) && StringUtils.equals(node.getName(), projectVersion)) {
node.remove();
}
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method removeArtifact.
@Override
public void removeArtifact(ArtifactMetadata artifactMetadata, String baseVersion) throws MetadataRepositoryException {
String repositoryId = artifactMetadata.getRepositoryId();
try {
Node root = getJcrSession().getRootNode();
String path = getProjectVersionPath(repositoryId, artifactMetadata.getNamespace(), artifactMetadata.getProject(), baseVersion);
if (root.hasNode(path)) {
Node node = root.getNode(path);
for (Node n : JcrUtils.getChildNodes(node)) {
if (n.isNodeType(ARTIFACT_NODE_TYPE)) {
if (n.hasProperty("version")) {
String version = n.getProperty("version").getString();
if (StringUtils.equals(version, artifactMetadata.getVersion())) {
n.remove();
}
}
}
}
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method getMetadataFacet.
@Override
public MetadataFacet getMetadataFacet(String repositoryId, String facetId, String name) throws MetadataRepositoryException {
MetadataFacet metadataFacet = null;
try {
Node root = getJcrSession().getRootNode();
Node node = root.getNode(getFacetPath(repositoryId, facetId, name));
if (metadataFacetFactories == null) {
return metadataFacet;
}
MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get(facetId);
if (metadataFacetFactory != null) {
metadataFacet = metadataFacetFactory.createMetadataFacet(repositoryId, name);
Map<String, String> map = new HashMap<>();
for (Property property : JcrUtils.getProperties(node)) {
String p = property.getName();
if (!p.startsWith("jcr:")) {
map.put(p, property.getString());
}
}
metadataFacet.fromProperties(map);
}
} catch (PathNotFoundException e) {
// ignored - the facet doesn't exist, so return null
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
return metadataFacet;
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrRepositorySessionFactory method initialize.
public void initialize() {
// skip initialisation if not jcr
if (repositorySessionFactoryBean != null && !StringUtils.equals(repositorySessionFactoryBean.getId(), "jcr")) {
return;
}
StopWatch stopWatch = new StopWatch();
stopWatch.start();
metadataFacetFactories = applicationContext.getBeansOfType(MetadataFacetFactory.class);
// olamy with spring the "id" is now "metadataFacetFactory#hint"
// whereas was only hint with plexus so let remove metadataFacetFactory#
Map<String, MetadataFacetFactory> cleanedMetadataFacetFactories = new HashMap<>(metadataFacetFactories.size());
for (Map.Entry<String, MetadataFacetFactory> entry : metadataFacetFactories.entrySet()) {
cleanedMetadataFacetFactories.put(StringUtils.substringAfterLast(entry.getKey(), "#"), entry.getValue());
}
metadataFacetFactories = cleanedMetadataFacetFactories;
JcrMetadataRepository metadataRepository = null;
try {
repositoryFactory = new RepositoryFactory();
// FIXME this need to be configurable
Path directoryPath = Paths.get(System.getProperty("appserver.base"), "data/jcr");
repositoryFactory.setRepositoryPath(directoryPath);
try {
repository = repositoryFactory.createRepository();
} catch (InvalidFileStoreVersionException | IOException e) {
logger.error("Repository creation failed {}", e.getMessage());
throw new RuntimeException("Fatal error. Could not create metadata repository.");
}
metadataRepository = new JcrMetadataRepository(metadataFacetFactories, repository);
JcrMetadataRepository.initialize(metadataRepository.getJcrSession());
} catch (RepositoryException e) {
throw new RuntimeException(e.getMessage(), e);
} finally {
if (metadataRepository != null) {
try {
metadataRepository.close();
} catch (MetadataRepositoryException e) {
logger.error("Close of metadata repository failed {}", e.getMessage());
}
}
}
stopWatch.stop();
logger.info("time to initialize JcrRepositorySessionFactory: {}", stopWatch.getTime());
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class CleanupReleasedSnapshotsRepositoryPurge method process.
@Override
public void process(String path) throws RepositoryPurgeException {
try {
Path artifactFile = Paths.get(repository.getRepoRoot(), path);
if (!Files.exists(artifactFile)) {
// Nothing to do here, file doesn't exist, skip it.
return;
}
ArtifactReference artifactRef = repository.toArtifactReference(path);
if (!VersionUtil.isSnapshot(artifactRef.getVersion())) {
// Nothing to do here, not a snapshot, skip it.
return;
}
ProjectReference reference = new ProjectReference();
reference.setGroupId(artifactRef.getGroupId());
reference.setArtifactId(artifactRef.getArtifactId());
// Gether the released versions
List<String> releasedVersions = new ArrayList<>();
Collection<org.apache.archiva.repository.ManagedRepository> repos = repositoryRegistry.getManagedRepositories();
for (org.apache.archiva.repository.ManagedRepository repo : repos) {
if (repo.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)) {
try {
ManagedRepositoryContent repoContent = repo.getContent();
for (String version : repoContent.getVersions(reference)) {
if (!VersionUtil.isSnapshot(version)) {
releasedVersions.add(version);
}
}
} catch (RepositoryException e) {
// swallow
}
}
}
Collections.sort(releasedVersions, VersionComparator.getInstance());
// Now clean out any version that is earlier than the highest released version.
boolean needsMetadataUpdate = false;
VersionedReference versionRef = new VersionedReference();
versionRef.setGroupId(artifactRef.getGroupId());
versionRef.setArtifactId(artifactRef.getArtifactId());
MetadataRepository metadataRepository = repositorySession.getRepository();
if (releasedVersions.contains(VersionUtil.getReleaseVersion(artifactRef.getVersion()))) {
versionRef.setVersion(artifactRef.getVersion());
repository.deleteVersion(versionRef);
for (RepositoryListener listener : listeners) {
listener.deleteArtifact(metadataRepository, repository.getId(), artifactRef.getGroupId(), artifactRef.getArtifactId(), artifactRef.getVersion(), artifactFile.getFileName().toString());
}
metadataRepository.removeProjectVersion(repository.getId(), artifactRef.getGroupId(), artifactRef.getArtifactId(), artifactRef.getVersion());
needsMetadataUpdate = true;
}
if (needsMetadataUpdate) {
updateMetadata(artifactRef);
}
} catch (LayoutException e) {
log.debug("Not processing file that is not an artifact: {}", e.getMessage());
} catch (ContentNotFoundException e) {
throw new RepositoryPurgeException(e.getMessage(), e);
} catch (MetadataRepositoryException e) {
log.error("Could not remove metadata during cleanup of released snapshots of {}", path, e);
}
}
Aggregations