Search in sources :

Example 1 with ControlFile

use of org.sonatype.nexus.repository.apt.internal.debian.ControlFile in project nexus-public by sonatype.

the class AptUploadHandler method handle.

@Override
public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException {
    AptContentFacet aptContentFacet = repository.facet(AptContentFacet.class);
    AptHostedFacet hostedFacet = repository.facet(AptHostedFacet.class);
    PartPayload payload = upload.getAssetUploads().get(0).getPayload();
    try (TempBlob tempBlob = aptContentFacet.getTempBlob(payload)) {
        ControlFile controlFile = AptPackageParser.parsePackageInfo(tempBlob).getControlFile();
        String assetPath = AptFacetHelper.buildAssetPath(controlFile);
        Content content = hostedFacet.put(assetPath, payload, new PackageInfo(controlFile)).markAsCached(payload).download();
        return new UploadResponse(Collections.singletonList(content), Collections.singletonList(assetPath));
    }
}
Also used : UploadResponse(org.sonatype.nexus.repository.upload.UploadResponse) TempBlob(org.sonatype.nexus.repository.view.payloads.TempBlob) Content(org.sonatype.nexus.repository.view.Content) PackageInfo(org.sonatype.nexus.repository.apt.internal.debian.PackageInfo) PartPayload(org.sonatype.nexus.repository.view.PartPayload) AptHostedFacet(org.sonatype.nexus.repository.apt.datastore.internal.hosted.AptHostedFacet) ControlFile(org.sonatype.nexus.repository.apt.internal.debian.ControlFile)

Example 2 with ControlFile

use of org.sonatype.nexus.repository.apt.internal.debian.ControlFile in project nexus-public by sonatype.

the class AptContentFacetImpl method buildIndexSection.

private String buildIndexSection(final ControlFile controlFile, final FluentAsset asset) {
    AssetBlob assetBlob = asset.blob().orElseThrow(() -> new IllegalStateException("Impossible build " + P_INDEX_SECTION + ". Asset blob couldn't be found for asset: " + asset.path()));
    final Map<String, String> checksums = assetBlob.checksums();
    return controlFile.getParagraphs().get(0).withFields(Arrays.asList(new ControlFile.ControlField("Filename", asset.path()), new ControlFile.ControlField("Size", Long.toString(assetBlob.blobSize())), new ControlFile.ControlField("MD5Sum", checksums.get(MD5.name())), new ControlFile.ControlField("SHA1", checksums.get(SHA1.name())), new ControlFile.ControlField("SHA256", checksums.get(SHA256.name())))).toString();
}
Also used : AssetBlob(org.sonatype.nexus.repository.content.AssetBlob) ControlFile(org.sonatype.nexus.repository.apt.internal.debian.ControlFile)

Example 3 with ControlFile

use of org.sonatype.nexus.repository.apt.internal.debian.ControlFile in project nexus-public by sonatype.

the class AptContentFacetImpl method findOrCreateDebAsset.

private FluentAsset findOrCreateDebAsset(final String path, final TempBlob tempBlob, @Nullable PackageInfo packageInfo) throws IOException {
    if (packageInfo == null) {
        packageInfo = AptPackageParser.parsePackageInfo(tempBlob);
    }
    FluentAsset asset = assets().path(normalizeAssetPath(path)).kind(DEB).component(findOrCreateComponent(packageInfo)).blob(tempBlob).save();
    ControlFile controlFile = packageInfo.getControlFile();
    populateAttributes(packageInfo, asset, controlFile);
    return asset;
}
Also used : FluentAsset(org.sonatype.nexus.repository.content.fluent.FluentAsset) ControlFile(org.sonatype.nexus.repository.apt.internal.debian.ControlFile)

Example 4 with ControlFile

use of org.sonatype.nexus.repository.apt.internal.debian.ControlFile in project nexus-public by sonatype.

the class AptSnapshotFacetSupport method collectSnapshotItems.

protected Iterable<SnapshotItem> collectSnapshotItems(final SnapshotComponentSelector selector) throws IOException {
    AptContentFacet aptFacet = getRepository().facet(AptContentFacet.class);
    List<SnapshotItem> releaseIndexItems = fetchSnapshotItems(AptFacetHelper.getReleaseIndexSpecifiers(aptFacet.isFlat(), aptFacet.getDistribution()));
    Map<SnapshotItem.Role, SnapshotItem> itemsByRole = new EnumMap<>(releaseIndexItems.stream().collect(Collectors.toMap((SnapshotItem item) -> item.specifier.role, item -> item)));
    InputStream releaseStream = null;
    SnapshotItem snapshotItem = itemsByRole.get(SnapshotItem.Role.RELEASE_INDEX);
    if (snapshotItem != null) {
        releaseStream = snapshotItem.content.openInputStream();
    } else {
        try (InputStream is = itemsByRole.get(SnapshotItem.Role.RELEASE_INLINE_INDEX).content.openInputStream()) {
            if (is != null) {
                ArmoredInputStream aIs = new ArmoredInputStream(is);
                releaseStream = new AptFilterInputStream(aIs);
            }
        }
    }
    if (releaseStream == null) {
        throw new IOException("Invalid upstream repository: no release index present");
    }
    Release release;
    try {
        ControlFile index = new ControlFileParser().parseControlFile(releaseStream);
        release = new Release(index);
    } finally {
        releaseStream.close();
    }
    List<SnapshotItem> result = new ArrayList<>(releaseIndexItems);
    if (aptFacet.isFlat()) {
        result.addAll(fetchSnapshotItems(AptFacetHelper.getReleasePackageIndexes(aptFacet.isFlat(), aptFacet.getDistribution(), null, null)));
    } else {
        List<String> archs = selector.getArchitectures(release);
        List<String> comps = selector.getComponents(release);
        for (String arch : archs) {
            for (String comp : comps) {
                result.addAll(fetchSnapshotItems(AptFacetHelper.getReleasePackageIndexes(aptFacet.isFlat(), aptFacet.getDistribution(), comp, arch)));
            }
        }
    }
    return result;
}
Also used : AptFilterInputStream(org.sonatype.nexus.repository.apt.internal.snapshot.AptFilterInputStream) ArmoredInputStream(org.bouncycastle.bcpg.ArmoredInputStream) AptFilterInputStream(org.sonatype.nexus.repository.apt.internal.snapshot.AptFilterInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AptContentFacet(org.sonatype.nexus.repository.apt.datastore.AptContentFacet) SnapshotItem(org.sonatype.nexus.repository.apt.internal.snapshot.SnapshotItem) ArmoredInputStream(org.bouncycastle.bcpg.ArmoredInputStream) ControlFileParser(org.sonatype.nexus.repository.apt.internal.debian.ControlFileParser) EnumMap(java.util.EnumMap) Release(org.sonatype.nexus.repository.apt.internal.debian.Release) ControlFile(org.sonatype.nexus.repository.apt.internal.debian.ControlFile)

Example 5 with ControlFile

use of org.sonatype.nexus.repository.apt.internal.debian.ControlFile in project nexus-public by sonatype.

the class OrientAptUploadHandler method handle.

@Override
public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException {
    OrientAptHostedFacet hostedFacet = repository.facet(OrientAptHostedFacet.class);
    StorageFacet storageFacet = repository.facet(StorageFacet.class);
    try (TempBlob tempBlob = storageFacet.createTempBlob(upload.getAssetUploads().get(0).getPayload(), AptFacetHelper.hashAlgorithms)) {
        ControlFile controlFile = AptPackageParser.parsePackageInfo(tempBlob).getControlFile();
        String assetPath = AptFacetHelper.buildAssetPath(controlFile);
        doValidation(repository, assetPath);
        UnitOfWork.begin(storageFacet.txSupplier());
        try {
            Asset asset = hostedFacet.ingestAsset(upload.getAssetUploads().get(0).getPayload());
            return new UploadResponse(asset);
        } finally {
            UnitOfWork.end();
        }
    }
}
Also used : UploadResponse(org.sonatype.nexus.repository.upload.UploadResponse) TempBlob(org.sonatype.nexus.repository.view.payloads.TempBlob) OrientAptHostedFacet(org.sonatype.nexus.repository.apt.orient.internal.hosted.OrientAptHostedFacet) Asset(org.sonatype.nexus.repository.storage.Asset) StorageFacet(org.sonatype.nexus.repository.storage.StorageFacet) ControlFile(org.sonatype.nexus.repository.apt.internal.debian.ControlFile)

Aggregations

ControlFile (org.sonatype.nexus.repository.apt.internal.debian.ControlFile)9 InputStream (java.io.InputStream)4 ControlFileParser (org.sonatype.nexus.repository.apt.internal.debian.ControlFileParser)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ArmoredInputStream (org.bouncycastle.bcpg.ArmoredInputStream)2 PackageInfo (org.sonatype.nexus.repository.apt.internal.debian.PackageInfo)2 Release (org.sonatype.nexus.repository.apt.internal.debian.Release)2 AptFilterInputStream (org.sonatype.nexus.repository.apt.internal.snapshot.AptFilterInputStream)2 SnapshotItem (org.sonatype.nexus.repository.apt.internal.snapshot.SnapshotItem)2 OrientAptFacet (org.sonatype.nexus.repository.apt.orient.OrientAptFacet)2 Asset (org.sonatype.nexus.repository.storage.Asset)2 UploadResponse (org.sonatype.nexus.repository.upload.UploadResponse)2 TempBlob (org.sonatype.nexus.repository.view.payloads.TempBlob)2 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 ArchiveEntry (org.apache.commons.compress.archivers.ArchiveEntry)1 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)1 GzipCompressorInputStream (org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream)1 XZCompressorInputStream (org.apache.commons.compress.compressors.xz.XZCompressorInputStream)1