Search in sources :

Example 41 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class MetadataTransferTest method createGroupSelector.

private ItemSelector createGroupSelector(String requestedResource) throws RepositoryMetadataException {
    ItemSelector projectSelector = createProjectSelector(requestedResource);
    ArchivaItemSelector.Builder projectReference = ArchivaItemSelector.builder().withSelector(projectSelector);
    projectReference.withNamespace(projectSelector.getNamespace() + "." + projectSelector.getProjectId());
    projectReference.withArtifactId(null);
    projectReference.withProjectId(null);
    return projectReference.build();
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector)

Example 42 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class MetadataTransferTest method assertRepoSnapshotMetadataContents.

/**
 * Test for the existance of the proxied repository specific snapshot metadata in the default managed
 * repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
 *
 * @param proxiedRepoId       the repository id of the proxied repository.
 * @param requestedResource   the requested resource
 * @param expectedDate        the date in "yyyyMMdd" format
 * @param expectedTime        the time in "hhmmss" format
 * @param expectedBuildnumber the build number
 * @throws Exception
 */
private void assertRepoSnapshotMetadataContents(String proxiedRepoId, String requestedResource, String expectedDate, String expectedTime, int expectedBuildnumber) throws Exception {
    String proxiedFile = metadataTools.getRepositorySpecificName(proxiedRepoId, requestedResource);
    Path actualFile = managedDefaultDir.resolve(proxiedFile);
    assertTrue("Repo Specific Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile));
    ItemSelector actualMetadata = createVersionedSelector(requestedResource);
    assertSnapshotMetadata(actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber);
}
Also used : Path(java.nio.file.Path) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector)

Example 43 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class MetadataTransferTest method assertRepoReleaseMetadataContents.

/**
 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
 * list of expected versions within.
 *
 * @param proxiedRepoId
 * @param requestedResource
 */
private void assertRepoReleaseMetadataContents(String proxiedRepoId, String requestedResource) throws Exception {
    String proxiedFile = metadataTools.getRepositorySpecificName(proxiedRepoId, requestedResource);
    Path actualFile = managedDefaultDir.resolve(proxiedFile);
    assertTrue("Release metadata for repo should exist: " + actualFile, Files.exists(actualFile));
    ItemSelector metadata = createVersionedSelector(requestedResource);
    // Build expected metadata XML
    StringWriter expectedMetadataXml = new StringWriter();
    ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
    m.setGroupId(metadata.getNamespace());
    m.setArtifactId(metadata.getArtifactId());
    m.setVersion(metadata.getVersion());
    RepositoryMetadataWriter.write(m, expectedMetadataXml);
    // Compare the file to the actual contents.
    assertMetadataEquals(expectedMetadataXml.toString(), actualFile);
}
Also used : Path(java.nio.file.Path) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) StringWriter(java.io.StringWriter) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata)

Example 44 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class ArchivaDavResourceFactory method fetchContentFromProxies.

private boolean fetchContentFromProxies(ManagedRepository managedRepository, DavServletRequest request, LogicalResource resource) throws DavException {
    String path = resource.getPath();
    if (!proxyRegistry.hasHandler(managedRepository.getType())) {
        throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No proxy handler found for repository type " + managedRepository.getType());
    }
    RepositoryRequestInfo repositoryRequestInfo = managedRepository.getRequestInfo();
    RepositoryProxyHandler proxyHandler = proxyRegistry.getHandler(managedRepository.getType()).get(0);
    if (repositoryRequestInfo.isSupportFile(path)) {
        StorageAsset proxiedFile = proxyHandler.fetchFromProxies(managedRepository, path);
        return (proxiedFile != null);
    }
    // Is it a Metadata resource?
    if ("default".equals(repositoryRequestInfo.getLayout(path)) && repositoryRequestInfo.isMetadata(path)) {
        return proxyHandler.fetchMetadataFromProxies(managedRepository, path).isModified();
    }
    // Is it an Archetype Catalog?
    if (repositoryRequestInfo.isArchetypeCatalog(path)) {
        // FIXME we must implement a merge of remote archetype catalog from remote servers.
        StorageAsset proxiedFile = proxyHandler.fetchFromProxies(managedRepository, path);
        return (proxiedFile != null);
    }
    // Not any of the above? Then it's gotta be an artifact reference.
    try {
        // Get the artifact reference in a layout neutral way.
        // ArtifactReference artifact = repositoryRequestInfo.toArtifactReference( path );
        ItemSelector selector = repositoryRequestInfo.toItemSelector(path);
        if (selector != null) {
            String repositoryLayout = managedRepository.getLayout();
            RepositoryStorage repositoryStorage = this.applicationContext.getBean("repositoryStorage#" + repositoryLayout, RepositoryStorage.class);
            selector = repositoryStorage.applyServerSideRelocation(managedRepository, selector);
            StorageAsset proxiedFile = proxyHandler.fetchFromProxies(managedRepository, selector);
            resource.setPath(managedRepository.getContent().toPath(selector));
            log.debug("Proxied artifact '{}:{}:{}:{}'", selector.getNamespace(), selector.getArtifactId(), selector.getVersion(), selector.getArtifactVersion());
            return (proxiedFile != null);
        }
    } catch (LayoutException e) {
    /* eat it */
    } catch (ProxyDownloadException e) {
        log.error(e.getMessage(), e);
        throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to fetch artifact resource.");
    }
    return false;
}
Also used : RepositoryStorage(org.apache.archiva.metadata.repository.storage.RepositoryStorage) ItemSelector(org.apache.archiva.repository.content.ItemSelector) DavException(org.apache.jackrabbit.webdav.DavException) LayoutException(org.apache.archiva.repository.content.LayoutException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ProxyDownloadException(org.apache.archiva.policies.ProxyDownloadException) RepositoryRequestInfo(org.apache.archiva.repository.RepositoryRequestInfo) RepositoryProxyHandler(org.apache.archiva.proxy.model.RepositoryProxyHandler)

Example 45 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector 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)

Aggregations

ItemSelector (org.apache.archiva.repository.content.ItemSelector)76 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)74 Test (org.junit.Test)41 Path (java.nio.file.Path)16 Artifact (org.apache.archiva.repository.content.Artifact)16 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)13 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)12 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)12 LayoutException (org.apache.archiva.repository.content.LayoutException)12 IOException (java.io.IOException)11 ContentItem (org.apache.archiva.repository.content.ContentItem)11 Project (org.apache.archiva.repository.content.Project)11 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)10 Namespace (org.apache.archiva.repository.content.Namespace)9 Version (org.apache.archiva.repository.content.Version)9 VersionComparator (org.apache.archiva.common.utils.VersionComparator)8 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Stream (java.util.stream.Stream)6