use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method removeProject.
@Override
public void removeProject(String repositoryId, String namespace, String projectId) throws MetadataRepositoryException {
try {
Node root = getJcrSession().getRootNode();
String namespacePath = getNamespacePath(repositoryId, namespace);
if (root.hasNode(namespacePath)) {
Iterator<Node> nodeIterator = JcrUtils.getChildNodes(root.getNode(namespacePath)).iterator();
while (nodeIterator.hasNext()) {
Node node = nodeIterator.next();
if (node.isNodeType(PROJECT_NODE_TYPE) && projectId.equals(node.getName())) {
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 updateNamespace.
@Override
public void updateNamespace(String repositoryId, String namespace) throws MetadataRepositoryException {
try {
Node node = getOrAddNamespaceNode(repositoryId, namespace);
node.setProperty("namespace", namespace);
} 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 getRepositories.
@Override
public Collection<String> getRepositories() throws MetadataRepositoryException {
List<String> repositories;
try {
Node root = getJcrSession().getRootNode();
if (root.hasNode("repositories")) {
Node node = root.getNode("repositories");
repositories = new ArrayList<>();
NodeIterator i = node.getNodes();
while (i.hasNext()) {
Node n = i.nextNode();
repositories.add(n.getName());
}
} else {
repositories = Collections.emptyList();
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
return repositories;
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method updateProjectVersion.
@Override
public void updateProjectVersion(String repositoryId, String namespace, String projectId, ProjectVersionMetadata versionMetadata) throws MetadataRepositoryException {
updateProject(repositoryId, namespace, projectId);
try {
Node versionNode = getOrAddProjectVersionNode(repositoryId, namespace, projectId, versionMetadata.getId());
versionNode.setProperty("name", versionMetadata.getName());
versionNode.setProperty("description", versionMetadata.getDescription());
versionNode.setProperty("url", versionMetadata.getUrl());
versionNode.setProperty("incomplete", versionMetadata.isIncomplete());
// FIXME: decide how to treat these in the content repo
if (versionMetadata.getScm() != null) {
versionNode.setProperty("scm.connection", versionMetadata.getScm().getConnection());
versionNode.setProperty("scm.developerConnection", versionMetadata.getScm().getDeveloperConnection());
versionNode.setProperty("scm.url", versionMetadata.getScm().getUrl());
}
if (versionMetadata.getCiManagement() != null) {
versionNode.setProperty("ci.system", versionMetadata.getCiManagement().getSystem());
versionNode.setProperty("ci.url", versionMetadata.getCiManagement().getUrl());
}
if (versionMetadata.getIssueManagement() != null) {
versionNode.setProperty("issue.system", versionMetadata.getIssueManagement().getSystem());
versionNode.setProperty("issue.url", versionMetadata.getIssueManagement().getUrl());
}
if (versionMetadata.getOrganization() != null) {
versionNode.setProperty("org.name", versionMetadata.getOrganization().getName());
versionNode.setProperty("org.url", versionMetadata.getOrganization().getUrl());
}
int i = 0;
for (License license : versionMetadata.getLicenses()) {
versionNode.setProperty("license." + i + ".name", license.getName());
versionNode.setProperty("license." + i + ".url", license.getUrl());
i++;
}
i = 0;
for (MailingList mailingList : versionMetadata.getMailingLists()) {
versionNode.setProperty("mailingList." + i + ".archive", mailingList.getMainArchiveUrl());
versionNode.setProperty("mailingList." + i + ".name", mailingList.getName());
versionNode.setProperty("mailingList." + i + ".post", mailingList.getPostAddress());
versionNode.setProperty("mailingList." + i + ".unsubscribe", mailingList.getUnsubscribeAddress());
versionNode.setProperty("mailingList." + i + ".subscribe", mailingList.getSubscribeAddress());
versionNode.setProperty("mailingList." + i + ".otherArchives", join(mailingList.getOtherArchives()));
i++;
}
if (!versionMetadata.getDependencies().isEmpty()) {
Node dependenciesNode = JcrUtils.getOrAddNode(versionNode, "dependencies");
for (Dependency dependency : versionMetadata.getDependencies()) {
// Note that we deliberately don't alter the namespace path - not enough dependencies for
// number of nodes at a given depth to be an issue. Similarly, we don't add subnodes for each
// component of the ID as that creates extra depth and causes a great cost in space and memory
// FIXME: change group ID to namespace
// FIXME: change to artifact's ID - this is constructed by the Maven 2 format for now.
// This won't support types where the extension doesn't match the type.
// (see also Maven2RepositoryStorage#readProjectVersionMetadata construction of POM)
String id = dependency.getGroupId() + ";" + dependency.getArtifactId() + "-" + dependency.getVersion();
if (dependency.getClassifier() != null) {
id += "-" + dependency.getClassifier();
}
id += "." + dependency.getType();
Node n = JcrUtils.getOrAddNode(dependenciesNode, id);
n.addMixin(DEPENDENCY_NODE_TYPE);
// FIXME: remove temp code just to make it keep working
n.setProperty("groupId", dependency.getGroupId());
n.setProperty("artifactId", dependency.getArtifactId());
n.setProperty("version", dependency.getVersion());
n.setProperty("type", dependency.getType());
n.setProperty("classifier", dependency.getClassifier());
n.setProperty("scope", dependency.getScope());
n.setProperty("systemPath", dependency.getSystemPath());
n.setProperty("optional", dependency.isOptional());
// node has no native content at this time, just facets
// no need to list a type as it's implied by the path. Parents are Maven specific.
// FIXME: add scope, systemPath, type, version, classifier & maven2 specific IDs as a facet
// (should also have been added to the Dependency)
// TODO: add a property that is a weak reference to the originating artifact, creating it if
// necessary (without adding the archiva:artifact mixin so that it doesn't get listed as an
// artifact, which gives a different meaning to "incomplete" which is a known local project
// that doesn't have metadata yet but has artifacts). (Though we may want to give it the
// artifact mixin and another property to identify all non-local artifacts for the closure
// reports)
}
}
for (MetadataFacet facet : versionMetadata.getFacetList()) {
// recreate, to ensure properties are removed
if (versionNode.hasNode(facet.getFacetId())) {
versionNode.getNode(facet.getFacetId()).remove();
}
Node n = versionNode.addNode(facet.getFacetId());
n.addMixin(FACET_NODE_TYPE);
for (Map.Entry<String, String> entry : facet.toProperties().entrySet()) {
n.setProperty(entry.getKey(), entry.getValue());
}
}
} 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(String repositoryId, String namespace, String project, String projectVersion, MetadataFacet metadataFacet) throws MetadataRepositoryException {
try {
Node root = getJcrSession().getRootNode();
String path = getProjectVersionPath(repositoryId, namespace, project, projectVersion);
if (root.hasNode(path)) {
Node node = root.getNode(path);
for (Node n : JcrUtils.getChildNodes(node)) {
if (n.isNodeType(ARTIFACT_NODE_TYPE)) {
ArtifactMetadata artifactMetadata = getArtifactFromNode(repositoryId, n);
log.debug("artifactMetadata: {}", artifactMetadata);
MetadataFacet metadataFacetToRemove = artifactMetadata.getFacet(metadataFacet.getFacetId());
if (metadataFacetToRemove != null && metadataFacet.equals(metadataFacetToRemove)) {
n.remove();
}
}
}
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
Aggregations