use of org.apache.archiva.xml.XMLException in project archiva by apache.
the class MetadataTools method updateMetadata.
/**
* Update the metadata to represent the all versions/plugins of
* the provided groupId:artifactId project or group reference,
* based off of information present in the repository,
* the maven-metadata.xml files, and the proxy/repository specific
* metadata file contents.
* <p>
* We must treat this as a group or a project metadata file as there is no way to know in advance
*
* @param managedRepository the managed repository where the metadata is kept.
* @param reference the reference to update.
* @throws LayoutException
* @throws RepositoryMetadataException
* @throws IOException
* @throws ContentNotFoundException
* @deprecated
*/
public void updateMetadata(ManagedRepositoryContent managedRepository, ProjectReference reference) throws LayoutException, RepositoryMetadataException, IOException, ContentNotFoundException {
Path metadataFile = Paths.get(managedRepository.getRepoRoot(), toPath(reference));
long lastUpdated = getExistingLastUpdated(metadataFile);
ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();
metadata.setGroupId(reference.getGroupId());
metadata.setArtifactId(reference.getArtifactId());
// Gather up all versions found in the managed repository.
Set<String> allVersions = managedRepository.getVersions(reference);
// Gather up all plugins found in the managed repository.
// TODO: do we know this information instead?
// Set<Plugin> allPlugins = managedRepository.getPlugins( reference );
Set<Plugin> allPlugins;
if (Files.exists(metadataFile)) {
try {
allPlugins = new LinkedHashSet<Plugin>(MavenMetadataReader.read(metadataFile).getPlugins());
} catch (XMLException e) {
throw new RepositoryMetadataException(e.getMessage(), e);
}
} else {
allPlugins = new LinkedHashSet<Plugin>();
}
// Does this repository have a set of remote proxied repositories?
Set<String> proxiedRepoIds = this.proxies.get(managedRepository.getId());
if (CollectionUtils.isNotEmpty(proxiedRepoIds)) {
// Add in the proxied repo version ids too.
Iterator<String> it = proxiedRepoIds.iterator();
while (it.hasNext()) {
String proxyId = it.next();
ArchivaRepositoryMetadata proxyMetadata = readProxyMetadata(managedRepository, reference, proxyId);
if (proxyMetadata != null) {
allVersions.addAll(proxyMetadata.getAvailableVersions());
allPlugins.addAll(proxyMetadata.getPlugins());
long proxyLastUpdated = getLastUpdated(proxyMetadata);
lastUpdated = Math.max(lastUpdated, proxyLastUpdated);
}
}
}
if (!allVersions.isEmpty()) {
updateMetadataVersions(allVersions, metadata);
} else {
// Add the plugins to the metadata model.
metadata.setPlugins(new ArrayList<>(allPlugins));
// artifact ID was actually the last part of the group
metadata.setGroupId(metadata.getGroupId() + "." + metadata.getArtifactId());
metadata.setArtifactId(null);
}
if (lastUpdated > 0) {
metadata.setLastUpdatedTimestamp(toLastUpdatedDate(lastUpdated));
}
// Save the metadata model to disk.
RepositoryMetadataWriter.write(metadata, metadataFile);
ChecksummedFile checksum = new ChecksummedFile(metadataFile);
checksum.fixChecksums(algorithms);
}
use of org.apache.archiva.xml.XMLException in project archiva by apache.
the class MetadataTools method readProxyMetadata.
public ArchivaRepositoryMetadata readProxyMetadata(ManagedRepositoryContent managedRepository, String logicalResource, String proxyId) {
String metadataPath = getRepositorySpecificName(proxyId, logicalResource);
Path metadataFile = Paths.get(managedRepository.getRepoRoot(), metadataPath);
if (!Files.exists(metadataFile) || !Files.isRegularFile(metadataFile)) {
// Nothing to do. return null.
return null;
}
try {
return MavenMetadataReader.read(metadataFile);
} catch (XMLException e) {
// TODO: [monitor] consider a monitor for this event.
// TODO: consider a read-redo on monitor return code?
log.warn("Unable to read metadata: {}", metadataFile.toAbsolutePath(), e);
return null;
}
}
use of org.apache.archiva.xml.XMLException in project archiva by apache.
the class MetadataTools method readProxyMetadata.
public ArchivaRepositoryMetadata readProxyMetadata(ManagedRepositoryContent managedRepository, ProjectReference reference, String proxyId) {
String metadataPath = getRepositorySpecificName(proxyId, toPath(reference));
Path metadataFile = Paths.get(managedRepository.getRepoRoot(), metadataPath);
if (!Files.exists(metadataFile) || !Files.isRegularFile(metadataFile)) {
// Nothing to do. return null.
return null;
}
try {
return MavenMetadataReader.read(metadataFile);
} catch (XMLException e) {
// TODO: [monitor] consider a monitor for this event.
// TODO: consider a read-redo on monitor return code?
log.warn("Unable to read metadata: {}", metadataFile.toAbsolutePath(), e);
return null;
}
}
use of org.apache.archiva.xml.XMLException in project archiva by apache.
the class RepositoryMetadataWriter method write.
public static void write(ArchivaRepositoryMetadata metadata, Writer writer) throws RepositoryMetadataException {
Document doc = DocumentHelper.createDocument();
Element root = DocumentHelper.createElement("metadata");
doc.setRootElement(root);
addOptionalElementText(root, "groupId", metadata.getGroupId());
addOptionalElementText(root, "artifactId", metadata.getArtifactId());
addOptionalElementText(root, "version", metadata.getVersion());
if (CollectionUtils.isNotEmpty(metadata.getPlugins())) {
Element plugins = root.addElement("plugins");
List<Plugin> pluginList = metadata.getPlugins();
Collections.sort(pluginList, PluginComparator.INSTANCE);
for (Plugin plugin : metadata.getPlugins()) {
Element p = plugins.addElement("plugin");
p.addElement("prefix").setText(plugin.getPrefix());
p.addElement("artifactId").setText(plugin.getArtifactId());
addOptionalElementText(p, "name", plugin.getName());
}
}
if (//
CollectionUtils.isNotEmpty(metadata.getAvailableVersions()) || //
StringUtils.isNotBlank(metadata.getReleasedVersion()) || //
StringUtils.isNotBlank(metadata.getLatestVersion()) || //
StringUtils.isNotBlank(metadata.getLastUpdated()) || (metadata.getSnapshotVersion() != null)) {
Element versioning = root.addElement("versioning");
addOptionalElementText(versioning, "latest", metadata.getLatestVersion());
addOptionalElementText(versioning, "release", metadata.getReleasedVersion());
if (metadata.getSnapshotVersion() != null) {
Element snapshot = versioning.addElement("snapshot");
String bnum = String.valueOf(metadata.getSnapshotVersion().getBuildNumber());
addOptionalElementText(snapshot, "buildNumber", bnum);
addOptionalElementText(snapshot, "timestamp", metadata.getSnapshotVersion().getTimestamp());
}
if (CollectionUtils.isNotEmpty(metadata.getAvailableVersions())) {
Element versions = versioning.addElement("versions");
Iterator<String> it = metadata.getAvailableVersions().iterator();
while (it.hasNext()) {
String version = it.next();
versions.addElement("version").setText(version);
}
}
addOptionalElementText(versioning, "lastUpdated", metadata.getLastUpdated());
}
try {
XMLWriter.write(doc, writer);
} catch (XMLException e) {
throw new RepositoryMetadataException("Unable to write xml contents to writer: " + e.getMessage(), e);
}
}
use of org.apache.archiva.xml.XMLException in project archiva by apache.
the class ArchivaDavResourceFactory method evaluatePathWithVersion.
private //
String evaluatePathWithVersion(//
ArchivaDavResourceLocator archivaLocator, //
ManagedRepositoryContent managedRepositoryContent, String contextPath) throws DavException {
String layout = managedRepositoryContent.getRepository() == null ? "default" : managedRepositoryContent.getRepository().getLayout();
RepositoryStorage repositoryStorage = this.applicationContext.getBean("repositoryStorage#" + layout, RepositoryStorage.class);
try {
return //
repositoryStorage.getFilePathWithVersion(//
archivaLocator.getResourcePath(), managedRepositoryContent);
} catch (RelocationException e) {
String path = e.getPath();
log.debug("Relocation to {}", path);
throw new BrowserRedirectException(addHrefPrefix(contextPath, path), e.getRelocationType());
} catch (XMLException e) {
log.error(e.getMessage(), e);
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
}
}
Aggregations