Search in sources :

Example 51 with BaseRepositoryContentLayout

use of org.apache.archiva.repository.content.BaseRepositoryContentLayout 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 52 with BaseRepositoryContentLayout

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

the class ChecksumTransferTest method testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFailSetting.

@Test
public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFailSetting() throws Exception {
    String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
    setManagedOlderThanRemote(expectedFile, remoteFile);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    assertNotDownloaded(downloadedFile);
    assertNoTempFiles(expectedFile);
    // There are no hashcodes on the proxy side to download.
    // The FAIL policy will delete the checksums as bad.
    assertChecksums(expectedFile, "invalid checksum file", "invalid checksum file");
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 53 with BaseRepositoryContentLayout

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

the class ChecksumTransferTest method testGetChecksumCorrectSha1BadMd5UsingFixSetting.

@Test
public void testGetChecksumCorrectSha1BadMd5UsingFixSetting() throws Exception {
    String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    FileUtils.deleteDirectory(expectedFile.getParent());
    assertFalse(Files.exists(expectedFile));
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
    assertFileEquals(expectedFile, downloadedFile.getFilePath(), proxied1File);
    assertNoTempFiles(expectedFile);
    assertChecksums(expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar", "c35f3b76268b73a4ba617f6f275c49ab  get-checksum-sha1-bad-md5-1.0.jar");
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 54 with BaseRepositoryContentLayout

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

the class ChecksumTransferTest method testGetChecksumWhenConnectorIsDisabled.

@Test
public void testGetChecksumWhenConnectorIsDisabled() throws Exception {
    String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    org.apache.archiva.common.utils.FileUtils.deleteDirectory(expectedFile.getParent());
    assertFalse(Files.exists(expectedFile));
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true);
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    assertNull(downloadedFile);
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 55 with BaseRepositoryContentLayout

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

the class ChecksumTransferTest method testGetWithNoChecksumsUsingIgnoredSetting.

@Test
public void testGetWithNoChecksumsUsingIgnoredSetting() throws Exception {
    String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    FileUtils.deleteDirectory(expectedFile.getParent());
    assertFalse(Files.exists(expectedFile));
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
    assertFileEquals(expectedFile, downloadedFile.getFilePath(), proxied1File);
    assertNoTempFiles(expectedFile);
    assertChecksums(expectedFile, null, null);
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Aggregations

BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)62 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)55 Artifact (org.apache.archiva.repository.content.Artifact)50 Path (java.nio.file.Path)49 Test (org.junit.Test)45 LayoutException (org.apache.archiva.repository.content.LayoutException)10 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)9 ContentItem (org.apache.archiva.repository.content.ContentItem)7 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5 Project (org.apache.archiva.repository.content.Project)5 Version (org.apache.archiva.repository.content.Version)5 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)4 ContentAccessException (org.apache.archiva.repository.content.ContentAccessException)4 ItemSelector (org.apache.archiva.repository.content.ItemSelector)4 ResourceDoesNotExistException (org.apache.maven.wagon.ResourceDoesNotExistException)4 IOException (java.io.IOException)3 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)3 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 RepositoryException (org.apache.archiva.repository.RepositoryException)3