use of org.apache.archiva.repository.content.Project in project archiva by apache.
the class MetadataUpdaterConsumer method updateProjectMetadata.
private void updateProjectMetadata(Artifact artifact, String path) {
try {
Project proj = artifact.getProject();
String metadataPath = repository.toPath(proj);
StorageAsset projectMetadata = this.repositoryDir.resolve(metadataPath);
if (projectMetadata.exists() && (projectMetadata.getModificationTime().toEpochMilli() >= this.scanStartTimestamp)) {
// This metadata is up to date. skip it.
log.debug("Skipping uptodate metadata: {}", metadataPath);
return;
}
metadataTools.updateMetadata(this.repository, metadataPath);
log.debug("Updated metadata: {}", metadataPath);
} catch (RepositoryMetadataException e) {
log.error("Unable to write project metadat for artifact [{}]:", path, e);
triggerConsumerError(TYPE_METADATA_WRITE_FAILURE, "Unable to write project metadata for artifact [" + path + "]: " + e.getMessage());
}
}
use of org.apache.archiva.repository.content.Project in project archiva by apache.
the class ManagedDefaultRepositoryContent method newItemStream.
@Override
public Stream<? extends ContentItem> newItemStream(ItemSelector selector, boolean parallel) throws ContentAccessException, IllegalArgumentException {
final Predicate<StorageAsset> filter = getItemFileFilterFromSelector(selector);
StorageAsset startDir;
if (selector.getNamespace().contains("*")) {
startDir = getAsset("");
} else if (selector.hasProjectId() && selector.getProjectId().contains("*")) {
startDir = getAsset(selector.getNamespace());
} else if (selector.hasProjectId() && selector.hasVersion() && selector.getVersion().contains("*")) {
startDir = getAsset(selector.getNamespace(), selector.getProjectId());
} else if (selector.hasProjectId() && selector.hasVersion()) {
startDir = getAsset(selector.getNamespace(), selector.getProjectId(), selector.getVersion());
} else if (selector.hasProjectId()) {
startDir = getAsset(selector.getNamespace(), selector.getProjectId());
} else {
startDir = getAsset(selector.getNamespace());
if (!selector.recurse()) {
// We descend into 2 subdirectories (project and version)
return startDir.list().stream().flatMap(a -> getChildrenDF(a, 1)).map(this::getItemFromPath);
}
}
return StorageUtil.newAssetStream(startDir, parallel).filter(filter).map(this::getItemFromPath);
}
use of org.apache.archiva.repository.content.Project in project archiva by apache.
the class MetadataTransferTest method testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled.
@Test
public void testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled() throws Exception {
// New project metadata that does not exist locally but exists on remote.
String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
setupTestableManagedRepository(requestedResource);
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true);
assertResourceNotFound(requestedResource);
assertNoRepoMetadata(ID_PROXIED1, requestedResource);
Path expectedFile = managedDefaultDir.resolve(requestedResource);
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
ContentItem metaItem = managedDefaultRepository.toItem(requestedResource);
Project project = layout.adaptItem(Project.class, managedDefaultRepository.getParent(metaItem));
assertNotNull(project);
String metaPath = managedDefaultRepository.toPath(layout.getMetadataItem(project));
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies(managedDefaultRepository.getRepository(), metaPath).getFile();
assertNull("Should not have downloaded a file.", downloadedFile);
assertNoTempFiles(expectedFile);
}
use of org.apache.archiva.repository.content.Project in project archiva by apache.
the class MetadataTools method updateProjectMetadata.
/**
* 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 updateProjectMetadata(ManagedRepositoryContent managedRepository, ItemSelector reference) throws LayoutException, RepositoryMetadataException, IOException, ContentNotFoundException {
StorageAsset metadataFile = managedRepository.getRepository().getAsset(toPath(reference));
ArchivaRepositoryMetadata existingMetadata = readMetadataFile(managedRepository, metadataFile);
BaseRepositoryContentLayout layout = managedRepository.getLayout(BaseRepositoryContentLayout.class);
long lastUpdated = getExistingLastUpdated(existingMetadata);
ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();
metadata.setGroupId(reference.getNamespace());
metadata.setArtifactId(reference.getProjectId());
// Gather up all versions found in the managed repository.
ItemSelector selector = ArchivaItemSelector.builder().withNamespace(reference.getNamespace()).withProjectId(reference.getProjectId()).build();
Set<String> allVersions = null;
try {
Project project = layout.getProject(selector);
allVersions = layout.getVersions(project).stream().map(v -> v.getId()).collect(Collectors.toSet());
} catch (ContentAccessException e) {
log.error("Error while accessing repository: {}", e.getMessage(), e);
throw new RepositoryMetadataException("Error while accessing repository " + e.getMessage(), e);
}
// 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 (existingMetadata != null) {
allPlugins = new LinkedHashSet<Plugin>(existingMetadata.getPlugins());
} 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.getFilePath());
checksum.fixChecksums(algorithms);
}
use of org.apache.archiva.repository.content.Project in project archiva by apache.
the class MetadataTransferTest method assertFetchProjectOrGroupFailed.
/**
* Transfer the metadata file, not expected to succeed.
*
* @param requestedResource the requested resource
* @throws Exception
*/
private void assertFetchProjectOrGroupFailed(String requestedResource) throws Exception {
Path expectedFile = managedDefaultDir.resolve(requestedResource);
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
ContentItem metaItem = managedDefaultRepository.toItem(requestedResource);
Project project = layout.adaptItem(Project.class, managedDefaultRepository.getParent(metaItem));
assertNotNull(project);
String metaPath = managedDefaultRepository.toPath(layout.getMetadataItem(project));
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies(managedDefaultRepository.getRepository(), metaPath).getFile();
assertNull(downloadedFile);
assertNoTempFiles(expectedFile);
}
Aggregations