Search in sources :

Example 46 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class ChecksumTransferTest method testGetChecksumBadSha1BadMd5FixSetting.

@Test
public void testGetChecksumBadSha1BadMd5FixSetting() 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.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, "4ec20a12dc91557330bd0b39d1805be5e329ae56  get-checksum-both-bad-1.0.jar", "a292491a35925465e693a44809a078b5  get-checksum-both-bad-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 47 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class ManagedDefaultRepositoryContent method toItem.

@Override
public ContentItem toItem(String path) throws LayoutException {
    StorageAsset asset = getRepository().getAsset(path);
    ContentItem item = getItemFromPath(asset);
    if (item instanceof DataItem) {
        Artifact artifact = adaptItem(Artifact.class, item);
        if (asset.getParent() == null) {
            throw new LayoutException("Path too short for maven artifact " + path);
        }
        String version = asset.getParent().getName();
        if (asset.getParent().getParent() == null) {
            throw new LayoutException("Path too short for maven artifact " + path);
        }
        String project = item.getAsset().getParent().getParent().getName();
        DataItem dataItem = (DataItem) item;
        if (StringUtils.isEmpty(dataItem.getExtension())) {
            throw new LayoutException("Missing type on maven artifact");
        }
        if (!project.equals(artifact.getId())) {
            throw new LayoutException("The maven artifact id " + artifact.getId() + " does not match the project id: " + project);
        }
        boolean versionIsGenericSnapshot = VersionUtil.isGenericSnapshot(version);
        boolean artifactVersionIsSnapshot = VersionUtil.isSnapshot(artifact.getArtifactVersion());
        if (versionIsGenericSnapshot && !artifactVersionIsSnapshot) {
            throw new LayoutException("The maven artifact has no snapshot version in snapshot directory " + dataItem);
        }
        if (!versionIsGenericSnapshot && artifactVersionIsSnapshot) {
            throw new LayoutException("The maven artifact version " + artifact.getArtifactVersion() + " is a snapshot version but inside a non snapshot directory " + version);
        }
        if (!versionIsGenericSnapshot && !version.equals(artifact.getArtifactVersion())) {
            throw new LayoutException("The maven artifact version " + artifact.getArtifactVersion() + " does not match the version directory " + version);
        }
    }
    return item;
}
Also used : DataItem(org.apache.archiva.repository.content.DataItem) LayoutException(org.apache.archiva.repository.content.LayoutException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Artifact(org.apache.archiva.repository.content.Artifact)

Example 48 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class ManagedDefaultRepositoryContent method getItemFileFilterFromSelector.

Predicate<StorageAsset> getItemFileFilterFromSelector(ItemSelector selector) {
    if (!selector.hasNamespace() && !selector.hasProjectId()) {
        throw new IllegalArgumentException("Selector must have at least namespace and projectid");
    }
    StringBuilder pathMatcher = new StringBuilder("^");
    if (selector.hasNamespace()) {
        String path = "/" + String.join("/", selector.getNamespace().split("\\."));
        if (path.contains("*")) {
            appendPatternRegex(pathMatcher, path);
        } else {
            pathMatcher.append(Pattern.quote(path));
        }
    }
    if (selector.hasProjectId()) {
        pathMatcher.append("/");
        if (selector.getProjectId().contains("*")) {
            appendPatternRegex(pathMatcher, selector.getProjectId());
        } else {
            pathMatcher.append(Pattern.quote(selector.getProjectId()));
        }
    }
    if (selector.hasVersion()) {
        pathMatcher.append("/");
        if (selector.getVersion().contains("*")) {
            appendPatternRegex(pathMatcher, selector.getVersion());
        } else {
            pathMatcher.append(Pattern.quote(selector.getVersion()));
        }
    }
    pathMatcher.append(".*");
    final Pattern pathPattern = Pattern.compile(pathMatcher.toString());
    final Predicate<StorageAsset> pathPredicate = (StorageAsset asset) -> pathPattern.matcher(asset.getPath()).matches();
    if (selector.hasArtifactId() || selector.hasArtifactVersion() || selector.hasClassifier() || selector.hasType() || selector.hasExtension()) {
        return getArtifactFileFilterFromSelector(selector).and(pathPredicate);
    } else {
        return pathPredicate;
    }
}
Also used : Pattern(java.util.regex.Pattern) StorageAsset(org.apache.archiva.repository.storage.StorageAsset)

Example 49 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class ManagedDefaultRepositoryContent method getArtifact.

@Override
public Artifact getArtifact(final ItemSelector selectorArg) throws ContentAccessException {
    ItemSelector selector = selectorArg;
    if (!selectorArg.hasProjectId()) {
        throw new IllegalArgumentException("Project id must be set");
    }
    if (!selectorArg.hasVersion()) {
        if (selectorArg.hasArtifactVersion() && VersionUtil.isSnapshot(selectorArg.getArtifactVersion())) {
            selector = ArchivaItemSelector.builder().withSelector(selectorArg).withVersion(VersionUtil.getBaseVersion(selectorArg.getArtifactVersion())).build();
        } else if (selectorArg.hasArtifactVersion()) {
            selector = ArchivaItemSelector.builder().withSelector(selectorArg).withVersion(selectorArg.getArtifactVersion()).build();
        } else {
            throw new IllegalArgumentException("Version must be set");
        }
    }
    if (!selectorArg.hasArtifactId()) {
        throw new IllegalArgumentException("Artifact id must be set");
    }
    final StorageAsset artifactDir = getAsset(selector.getNamespace(), selector.getProjectId(), selector.getVersion());
    final String artifactVersion = mavenContentHelper.getArtifactVersion(artifactDir, selector);
    final String classifier = MavenContentHelper.getClassifier(selector);
    final String extension = MavenContentHelper.getArtifactExtension(selector);
    final String artifactId = StringUtils.isEmpty(selector.getArtifactId()) ? selector.getProjectId() : selector.getArtifactId();
    final String fileName = MavenContentHelper.getArtifactFileName(artifactId, artifactVersion, classifier, extension);
    final StorageAsset path = getAsset(selector.getNamespace(), selector.getProjectId(), selector.getVersion(), fileName);
    try {
        return getArtifactFromPath(path);
    } catch (LayoutException e) {
        throw new IllegalArgumentException("The selector is not valid " + e.getMessage(), e);
    }
}
Also used : ItemSelector(org.apache.archiva.repository.content.ItemSelector) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) LayoutException(org.apache.archiva.repository.content.LayoutException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset)

Example 50 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class ChecksumTransferTest method testGetWithNoChecksumsUsingFailSetting.

@Test
public void testGetWithNoChecksumsUsingFailSetting() 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.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    assertNotDownloaded(downloadedFile);
    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

StorageAsset (org.apache.archiva.repository.storage.StorageAsset)191 Path (java.nio.file.Path)91 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)61 IOException (java.io.IOException)59 Test (org.junit.Test)59 Artifact (org.apache.archiva.repository.content.Artifact)54 ManagedRepository (org.apache.archiva.repository.ManagedRepository)27 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)22 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)22 List (java.util.List)20 Inject (javax.inject.Inject)20 RepositoryMetadataException (org.apache.archiva.repository.metadata.RepositoryMetadataException)20 Collectors (java.util.stream.Collectors)19 RemoteRepository (org.apache.archiva.repository.RemoteRepository)19 IndexingContext (org.apache.maven.index.context.IndexingContext)19 FilesystemStorage (org.apache.archiva.repository.storage.fs.FilesystemStorage)18 StringUtils (org.apache.commons.lang3.StringUtils)18 Logger (org.slf4j.Logger)18 LoggerFactory (org.slf4j.LoggerFactory)18 Map (java.util.Map)17