Search in sources :

Example 6 with Project

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());
    }
}
Also used : Project(org.apache.archiva.repository.content.Project) RepositoryMetadataException(org.apache.archiva.repository.metadata.RepositoryMetadataException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset)

Example 7 with Project

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);
}
Also used : Arrays(java.util.Arrays) ArchivaNamespace(org.apache.archiva.repository.content.base.ArchivaNamespace) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Namespace(org.apache.archiva.repository.content.Namespace) StringUtils(org.apache.commons.lang3.StringUtils) LayoutRuntimeException(org.apache.archiva.repository.content.LayoutRuntimeException) Matcher(java.util.regex.Matcher) FileUtils(org.apache.archiva.common.utils.FileUtils) MavenMetadataReader(org.apache.archiva.maven.metadata.MavenMetadataReader) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Path(java.nio.file.Path) ContentItem(org.apache.archiva.repository.content.ContentItem) RepositoryStorage(org.apache.archiva.repository.storage.RepositoryStorage) FileTypes(org.apache.archiva.configuration.provider.FileTypes) ArtifactOptBuilder(org.apache.archiva.repository.content.base.builder.ArtifactOptBuilder) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Predicate(java.util.function.Predicate) BaseArtifactTypes(org.apache.archiva.repository.content.BaseArtifactTypes) Collectors(java.util.stream.Collectors) ManagedRepository(org.apache.archiva.repository.ManagedRepository) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) Pattern(java.util.regex.Pattern) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) Artifact(org.apache.archiva.repository.content.Artifact) ItemDeleteStatus(org.apache.archiva.repository.ItemDeleteStatus) ArchivaProject(org.apache.archiva.repository.content.base.ArchivaProject) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) Version(org.apache.archiva.repository.content.Version) ReferenceMap(org.apache.commons.collections4.map.ReferenceMap) Inject(javax.inject.Inject) Named(javax.inject.Named) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ContentAccessException(org.apache.archiva.repository.content.ContentAccessException) Project(org.apache.archiva.repository.content.Project) Files(java.nio.file.Files) FileLockManager(org.apache.archiva.common.filelock.FileLockManager) VersionUtil(org.apache.archiva.common.utils.VersionUtil) ManagedRepositoryContentLayout(org.apache.archiva.repository.content.ManagedRepositoryContentLayout) IOException(java.io.IOException) DataItem(org.apache.archiva.repository.content.DataItem) Consumer(java.util.function.Consumer) StorageUtil(org.apache.archiva.repository.storage.util.StorageUtil) ArchivaVersion(org.apache.archiva.repository.content.base.ArchivaVersion) LayoutException(org.apache.archiva.repository.content.LayoutException) Collections(java.util.Collections) ItemNotFoundException(org.apache.archiva.repository.content.ItemNotFoundException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset)

Example 8 with Project

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);
}
Also used : Path(java.nio.file.Path) Project(org.apache.archiva.repository.content.Project) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ContentItem(org.apache.archiva.repository.content.ContentItem) Test(org.junit.Test)

Example 9 with Project

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);
}
Also used : ChecksummedFile(org.apache.archiva.checksum.ChecksummedFile) Project(org.apache.archiva.repository.content.Project) ItemSelector(org.apache.archiva.repository.content.ItemSelector) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) RepositoryMetadataException(org.apache.archiva.repository.metadata.RepositoryMetadataException) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) ContentAccessException(org.apache.archiva.repository.content.ContentAccessException) Plugin(org.apache.archiva.model.Plugin)

Example 10 with Project

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);
}
Also used : Path(java.nio.file.Path) Project(org.apache.archiva.repository.content.Project) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ContentItem(org.apache.archiva.repository.content.ContentItem)

Aggregations

Project (org.apache.archiva.repository.content.Project)14 ContentItem (org.apache.archiva.repository.content.ContentItem)9 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)9 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)8 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)8 Path (java.nio.file.Path)7 ItemSelector (org.apache.archiva.repository.content.ItemSelector)7 Version (org.apache.archiva.repository.content.Version)7 Artifact (org.apache.archiva.repository.content.Artifact)6 Namespace (org.apache.archiva.repository.content.Namespace)6 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)6 Test (org.junit.Test)6 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)4 ManagedRepository (org.apache.archiva.repository.ManagedRepository)4 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)4 ItemNotFoundException (org.apache.archiva.repository.content.ItemNotFoundException)4 LayoutException (org.apache.archiva.repository.content.LayoutException)4 MavenManagedRepository (org.apache.archiva.maven.repository.MavenManagedRepository)3 ContentAccessException (org.apache.archiva.repository.content.ContentAccessException)3 IOException (java.io.IOException)2