Search in sources :

Example 61 with Artifact

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

the class ChecksumTransferTest method testGetChecksumBadSha1BadMd5IgnoredSetting.

@Test
public void testGetChecksumBadSha1BadMd5IgnoredSetting() throws Exception {
    String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-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, "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 62 with Artifact

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

the class ChecksumTransferTest method testGetWithNoChecksumsUsingFixSetting.

@Test
public void testGetWithNoChecksumsUsingFixSetting() 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.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, "1f12821c5e43e1a0b76b9564a6ddb0548ccb9486  get-default-layout-1.0.jar", "3f7341545f21226b6f49a3c2704cb9be  get-default-layout-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 63 with Artifact

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

the class ChecksumTransferTest method testGetChecksumBothCorrect.

@Test
public void testGetChecksumBothCorrect() 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, false);
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
    assertFileEquals(expectedFile, downloadedFile.getFilePath(), proxied1File);
    assertNoTempFiles(expectedFile);
    assertChecksums(expectedFile, "066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar", "e58f30c6a150a2e843552438d18e15cb *get-checksum-both-right-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 64 with Artifact

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

the class ChecksumTransferTest method testGetChecksumNoSha1CorrectMd5UsingFixSetting.

@Test
public void testGetChecksumNoSha1CorrectMd5UsingFixSetting() throws Exception {
    String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-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, "71f7dc3f72053a3f2d9fdd6fef9db055ef957ffb  get-checksum-md5-only-1.0.jar", "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-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 65 with Artifact

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

the class Maven2RepositoryStorage method applyServerSideRelocation.

@Override
public ItemSelector applyServerSideRelocation(ManagedRepository managedRepository, ItemSelector artifactSelector) throws ProxyDownloadException {
    if ("pom".equals(artifactSelector.getType())) {
        return artifactSelector;
    }
    // Build the artifact POM reference
    BaseRepositoryContentLayout layout;
    try {
        layout = managedRepository.getContent().getLayout(BaseRepositoryContentLayout.class);
    } catch (LayoutException e) {
        throw new ProxyDownloadException("Could not set layout " + e.getMessage(), new HashMap<>());
    }
    RepositoryType repositoryType = managedRepository.getType();
    if (!proxyRegistry.hasHandler(repositoryType)) {
        throw new ProxyDownloadException("No proxy handler found for repository type " + repositoryType, new HashMap<>());
    }
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace(artifactSelector.getNamespace()).withProjectId(artifactSelector.getArtifactId()).withArtifactId(artifactSelector.getArtifactId()).withVersion(artifactSelector.getVersion()).withArtifactVersion(artifactSelector.getVersion()).withType("pom").build();
    Artifact pom = layout.getArtifact(selector);
    RepositoryProxyHandler proxyHandler = proxyRegistry.getHandler(repositoryType).get(0);
    // Get the artifact POM from proxied repositories if needed
    proxyHandler.fetchFromProxies(managedRepository, pom);
    if (!pom.exists()) {
        return artifactSelector;
    }
    try {
        // MavenXpp3Reader leaves the file open, so we need to close it ourselves.
        Model model;
        try (Reader reader = Channels.newReader(pom.getAsset().getReadChannel(), Charset.defaultCharset().name())) {
            model = MAVEN_XPP_3_READER.read(reader);
        }
        DistributionManagement dist = model.getDistributionManagement();
        if (dist != null) {
            Relocation relocation = dist.getRelocation();
            if (relocation != null) {
                ArchivaItemSelector.Builder relocatedBuilder = ArchivaItemSelector.builder();
                // artifact is relocated : update the repositoryPath
                if (relocation.getGroupId() != null) {
                    relocatedBuilder.withNamespace(relocation.getGroupId());
                } else {
                    relocatedBuilder.withNamespace(artifactSelector.getNamespace());
                }
                if (relocation.getArtifactId() != null) {
                    relocatedBuilder.withArtifactId(relocation.getArtifactId());
                } else {
                    relocatedBuilder.withArtifactId(artifactSelector.getArtifactId());
                }
                if (relocation.getVersion() != null) {
                    relocatedBuilder.withVersion(relocation.getVersion());
                } else {
                    relocatedBuilder.withVersion(artifactSelector.getVersion());
                }
                return relocatedBuilder.withArtifactVersion(artifactSelector.getArtifactVersion()).withClassifier(artifactSelector.getClassifier()).withType(artifactSelector.getType()).withProjectId(artifactSelector.getProjectId()).withExtension(artifactSelector.getExtension()).build();
            }
        }
    } catch (IOException e) {
    // Unable to read POM : ignore.
    } catch (XmlPullParserException e) {
    // Invalid POM : ignore
    }
    return artifactSelector;
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) HashMap(java.util.HashMap) RepositoryType(org.apache.archiva.repository.RepositoryType) MavenMetadataReader(org.apache.archiva.maven.metadata.MavenMetadataReader) Reader(java.io.Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) IOException(java.io.IOException) ProxyDownloadException(org.apache.archiva.policies.ProxyDownloadException) Artifact(org.apache.archiva.repository.content.Artifact) ItemSelector(org.apache.archiva.repository.content.ItemSelector) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) LayoutException(org.apache.archiva.repository.content.LayoutException) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) Model(org.apache.maven.model.Model) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) DistributionManagement(org.apache.maven.model.DistributionManagement) Relocation(org.apache.maven.model.Relocation) RepositoryProxyHandler(org.apache.archiva.proxy.model.RepositoryProxyHandler)

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