Search in sources :

Example 56 with Artifact

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

the class MetadataTools method gatherSnapshotVersions.

/**
 * Gather the set of snapshot versions found in a particular versioned reference.
 *
 * @return the Set of snapshot artifact versions found.
 * @throws LayoutException
 * @throws ContentNotFoundException
 */
public Set<String> gatherSnapshotVersions(ManagedRepositoryContent managedRepository, ItemSelector reference) throws LayoutException, IOException, ContentNotFoundException {
    Set<String> foundVersions = null;
    try {
        ArchivaItemSelector selector = ArchivaItemSelector.builder().withNamespace(reference.getNamespace()).withProjectId(reference.getArtifactId()).withArtifactId(reference.getArtifactId()).withVersion(reference.getVersion()).build();
        try (Stream<? extends Artifact> stream = managedRepository.getLayout(BaseRepositoryContentLayout.class).newArtifactStream(selector)) {
            foundVersions = stream.map(a -> a.getArtifactVersion()).filter(StringUtils::isNotEmpty).collect(Collectors.toSet());
        }
    } catch (ContentAccessException e) {
        log.error("Error while accessing content {}", e.getMessage());
        throw new IOException("Could not access repository content: " + e.getMessage());
    }
    // Next gather up the referenced 'latest' versions found in any proxied repositories
    // maven-metadata-${proxyId}.xml files that may be present.
    // Does this repository have a set of remote proxied repositories?
    Set<String> proxiedRepoIds = this.proxies.get(managedRepository.getId());
    if (CollectionUtils.isNotEmpty(proxiedRepoIds)) {
        String baseVersion = VersionUtil.getBaseVersion(reference.getVersion());
        baseVersion = baseVersion.substring(0, baseVersion.indexOf(VersionUtil.SNAPSHOT) - 1);
        // 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) {
                // There is no proxy metadata, skip it.
                continue;
            }
            // Is there some snapshot info?
            SnapshotVersion snapshot = proxyMetadata.getSnapshotVersion();
            if (snapshot != null) {
                String timestamp = snapshot.getTimestamp();
                int buildNumber = snapshot.getBuildNumber();
                // Only interested in the timestamp + buildnumber.
                if (StringUtils.isNotBlank(timestamp) && (buildNumber > 0)) {
                    foundVersions.add(baseVersion + "-" + timestamp + "-" + buildNumber);
                }
            }
        }
    }
    return foundVersions;
}
Also used : Arrays(java.util.Arrays) ConfigurationListener(org.apache.archiva.configuration.provider.ConfigurationListener) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) Date(java.util.Date) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) RegistryListener(org.apache.archiva.components.registry.RegistryListener) Matcher(java.util.regex.Matcher) Map(java.util.Map) ItemSelector(org.apache.archiva.repository.content.ItemSelector) ConfigurationEvent(org.apache.archiva.configuration.provider.ConfigurationEvent) ParseException(java.text.ParseException) ContentItem(org.apache.archiva.repository.content.ContentItem) RemoteRepositoryContent(org.apache.archiva.repository.RemoteRepositoryContent) FileTypes(org.apache.archiva.configuration.provider.FileTypes) TimeZone(java.util.TimeZone) Collection(java.util.Collection) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) Set(java.util.Set) Collectors(java.util.stream.Collectors) Plugin(org.apache.archiva.model.Plugin) List(java.util.List) Stream(java.util.stream.Stream) PostConstruct(javax.annotation.PostConstruct) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) Artifact(org.apache.archiva.repository.content.Artifact) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ConfigurationNames(org.apache.archiva.configuration.model.ConfigurationNames) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Calendar(java.util.Calendar) Service(org.springframework.stereotype.Service) ChecksumAlgorithm(org.apache.archiva.checksum.ChecksumAlgorithm) RepositoryMetadataException(org.apache.archiva.repository.metadata.RepositoryMetadataException) Named(javax.inject.Named) VersionComparator(org.apache.archiva.common.utils.VersionComparator) LinkedHashSet(java.util.LinkedHashSet) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) SnapshotVersion(org.apache.archiva.model.SnapshotVersion) ContentAccessException(org.apache.archiva.repository.content.ContentAccessException) Project(org.apache.archiva.repository.content.Project) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ContentNotFoundException(org.apache.archiva.repository.content.ContentNotFoundException) VersionUtil(org.apache.archiva.common.utils.VersionUtil) IOException(java.io.IOException) RepositoryType(org.apache.archiva.repository.RepositoryType) ChecksummedFile(org.apache.archiva.checksum.ChecksummedFile) Registry(org.apache.archiva.components.registry.Registry) MetadataReader(org.apache.archiva.repository.metadata.MetadataReader) NumberUtils(org.apache.commons.lang3.math.NumberUtils) LayoutException(org.apache.archiva.repository.content.LayoutException) Collections(java.util.Collections) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) IOException(java.io.IOException) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StringUtils(org.apache.commons.lang3.StringUtils) SnapshotVersion(org.apache.archiva.model.SnapshotVersion) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) ContentAccessException(org.apache.archiva.repository.content.ContentAccessException)

Example 57 with Artifact

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

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

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

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

Artifact (org.apache.archiva.repository.content.Artifact)78 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)63 Test (org.junit.Test)60 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)59 Path (java.nio.file.Path)54 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)26 ItemSelector (org.apache.archiva.repository.content.ItemSelector)21 LayoutException (org.apache.archiva.repository.content.LayoutException)21 ContentItem (org.apache.archiva.repository.content.ContentItem)19 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)15 IOException (java.io.IOException)13 ManagedRepository (org.apache.archiva.repository.ManagedRepository)13 Project (org.apache.archiva.repository.content.Project)13 MavenMetadataReader (org.apache.archiva.maven.metadata.MavenMetadataReader)12 Version (org.apache.archiva.repository.content.Version)12 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)12 Reader (java.io.Reader)11 List (java.util.List)11 Collectors (java.util.stream.Collectors)11 Inject (javax.inject.Inject)11