Search in sources :

Example 6 with Content

use of org.sonatype.nexus.repository.view.Content in project nexus-repository-r by sonatype-nexus-community.

the class RHostedFacetImpl method buildAndPutPackagesGz.

@Override
@TransactionalTouchMetadata
public Content buildAndPutPackagesGz(final String basePath) throws IOException {
    checkNotNull(basePath);
    StorageTx tx = UnitOfWork.currentTx();
    RPackagesBuilder packagesBuilder = new RPackagesBuilder();
    Iterable<Asset> archiveAssets = browseAllAssetsByKind(tx, tx.findBucket(getRepository()), ARCHIVE);
    // packageInfoBuilder doesn't support multithreading
    StreamSupport.stream(archiveAssets.spliterator(), false).filter(asset -> basePath.equals(getBasePath(asset.name()))).forEach(packagesBuilder::append);
    byte[] packagesBytes = packagesBuilder.buildPackagesGz();
    StorageFacet storageFacet = getRepository().facet(StorageFacet.class);
    try (InputStream is = new ByteArrayInputStream(packagesBytes)) {
        TempBlob tempPackagesGz = storageFacet.createTempBlob(is, RFacetUtils.HASH_ALGORITHMS);
        return doPutPackagesGz(tx, basePath, tempPackagesGz);
    }
}
Also used : StorageFacet(org.sonatype.nexus.repository.storage.StorageFacet) ARCHIVE(org.sonatype.nexus.repository.r.internal.AssetKind.ARCHIVE) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset) RFacet(org.sonatype.nexus.repository.r.RFacet) RFacetUtils(org.sonatype.nexus.repository.r.internal.util.RFacetUtils) RFacetUtils.toContent(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.toContent) Component(org.sonatype.nexus.repository.storage.Component) UnitOfWork(org.sonatype.nexus.transaction.UnitOfWork) ByteArrayInputStream(java.io.ByteArrayInputStream) RHostedFacet(org.sonatype.nexus.repository.r.RHostedFacet) Map(java.util.Map) Payload(org.sonatype.nexus.repository.view.Payload) StreamSupport(java.util.stream.StreamSupport) PACKAGES_GZ_FILENAME(org.sonatype.nexus.repository.r.internal.util.RPathUtils.PACKAGES_GZ_FILENAME) Named(javax.inject.Named) TransactionalStoreBlob(org.sonatype.nexus.repository.transaction.TransactionalStoreBlob) RDescriptionUtils.extractDescriptionFromArchive(org.sonatype.nexus.repository.r.internal.util.RDescriptionUtils.extractDescriptionFromArchive) TempBlob(org.sonatype.nexus.repository.storage.TempBlob) RPathUtils.getBasePath(org.sonatype.nexus.repository.r.internal.util.RPathUtils.getBasePath) TransactionalTouchBlob(org.sonatype.nexus.repository.transaction.TransactionalTouchBlob) FacetSupport(org.sonatype.nexus.repository.FacetSupport) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) IOException(java.io.IOException) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) Asset(org.sonatype.nexus.repository.storage.Asset) Content(org.sonatype.nexus.repository.view.Content) TransactionalTouchMetadata(org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata) RFacetUtils.browseAllAssetsByKind(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.browseAllAssetsByKind) RPathUtils.buildPath(org.sonatype.nexus.repository.r.internal.util.RPathUtils.buildPath) InputStream(java.io.InputStream) TempBlob(org.sonatype.nexus.repository.storage.TempBlob) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) Asset(org.sonatype.nexus.repository.storage.Asset) StorageFacet(org.sonatype.nexus.repository.storage.StorageFacet) TransactionalTouchMetadata(org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)

Example 7 with Content

use of org.sonatype.nexus.repository.view.Content in project nexus-repository-r by sonatype-nexus-community.

the class RPackagesUtils method buildPackages.

public static Content buildPackages(final Collection<Map<String, String>> entries) throws IOException {
    CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try (CompressorOutputStream cos = compressorStreamFactory.createCompressorOutputStream(GZIP, os)) {
        try (OutputStreamWriter writer = new OutputStreamWriter(cos, UTF_8)) {
            for (Map<String, String> entry : entries) {
                InternetHeaders headers = new InternetHeaders();
                headers.addHeader(P_PACKAGE, entry.get(P_PACKAGE));
                headers.addHeader(P_VERSION, entry.get(P_VERSION));
                headers.addHeader(P_DEPENDS, entry.get(P_DEPENDS));
                headers.addHeader(P_IMPORTS, entry.get(P_IMPORTS));
                headers.addHeader(P_SUGGESTS, entry.get(P_SUGGESTS));
                headers.addHeader(P_LINKINGTO, entry.get(P_LINKINGTO));
                headers.addHeader(P_LICENSE, entry.get(P_LICENSE));
                headers.addHeader(P_NEEDS_COMPILATION, entry.get(P_NEEDS_COMPILATION));
                Enumeration<String> headerLines = headers.getAllHeaderLines();
                while (headerLines.hasMoreElements()) {
                    String line = headerLines.nextElement();
                    writer.write(line, 0, line.length());
                    writer.write('\n');
                }
                writer.write('\n');
            }
        }
    } catch (CompressorException e) {
        throw new RException(null, e);
    }
    return new Content(new BytesPayload(os.toByteArray(), "application/x-gzip"));
}
Also used : InternetHeaders(javax.mail.internet.InternetHeaders) BytesPayload(org.sonatype.nexus.repository.view.payloads.BytesPayload) RException(org.sonatype.nexus.repository.r.internal.RException) CompressorException(org.apache.commons.compress.compressors.CompressorException) Content(org.sonatype.nexus.repository.view.Content) CompressorOutputStream(org.apache.commons.compress.compressors.CompressorOutputStream) CompressorStreamFactory(org.apache.commons.compress.compressors.CompressorStreamFactory) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 8 with Content

use of org.sonatype.nexus.repository.view.Content in project nexus-repository-r by sonatype-nexus-community.

the class RHostedFacetImplTest method getPackagesReturnsPackage.

@Test
public void getPackagesReturnsPackage() throws Exception {
    assets.add(asset);
    Content packages = underTest.getPackages(PACKAGE_PATH);
    try (InputStream in = packages.openInputStream()) {
        Map<String, String> attributes = extractDescriptionFromArchive(PACKAGE_NAME, in);
        assertThat(attributes.get(P_PACKAGE), is(equalTo(PACKAGE_NAME)));
        assertThat(attributes.get(P_VERSION), is(equalTo(VERSION)));
        assertThat(attributes.get(P_DEPENDS), is(equalTo(DEPENDS)));
        assertThat(attributes.get(P_IMPORTS), is(equalTo(IMPORTS)));
        assertThat(attributes.get(P_SUGGESTS), is(equalTo(SUGGESTS)));
        assertThat(attributes.get(P_LICENSE), is(equalTo(LICENSE)));
        assertThat(attributes.get(P_NEEDS_COMPILATION), is(equalTo(NEEDS_COMPILATION)));
    }
}
Also used : Content(org.sonatype.nexus.repository.view.Content) InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 9 with Content

use of org.sonatype.nexus.repository.view.Content in project nexus-repository-r by sonatype-nexus-community.

the class RHostedFacetImplTest method nullWhenAssetNullOnGetArchive.

@Test
public void nullWhenAssetNullOnGetArchive() throws Exception {
    when(storageTx.findAssetWithProperty(anyString(), anyString(), any(Bucket.class))).thenReturn(null);
    Content archive = underTest.getArchive(PACKAGE_PATH);
    assertThat(archive, is(nullValue()));
}
Also used : Bucket(org.sonatype.nexus.repository.storage.Bucket) Content(org.sonatype.nexus.repository.view.Content) Test(org.junit.Test)

Example 10 with Content

use of org.sonatype.nexus.repository.view.Content in project nexus-repository-r by sonatype-nexus-community.

the class RFacetUtils method saveAsset.

/**
 * Save an asset && create blob.
 *
 * @return blob content
 */
static Content saveAsset(final StorageTx tx, final Asset asset, final Supplier<InputStream> contentSupplier, final Payload payload) throws IOException {
    AttributesMap contentAttributes = null;
    String contentType = null;
    if (payload instanceof Content) {
        contentAttributes = ((Content) payload).getAttributes();
        contentType = payload.getContentType();
    }
    return saveAsset(tx, asset, contentSupplier, contentType, contentAttributes);
}
Also used : Content(org.sonatype.nexus.repository.view.Content) AttributesMap(org.sonatype.nexus.common.collect.AttributesMap)

Aggregations

Content (org.sonatype.nexus.repository.view.Content)17 Test (org.junit.Test)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 InternetHeaders (javax.mail.internet.InternetHeaders)3 CompressorException (org.apache.commons.compress.compressors.CompressorException)3 CompressorOutputStream (org.apache.commons.compress.compressors.CompressorOutputStream)3 CompressorStreamFactory (org.apache.commons.compress.compressors.CompressorStreamFactory)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Map (java.util.Map)2 AttributesMap (org.sonatype.nexus.common.collect.AttributesMap)2 RFacetUtils.toContent (org.sonatype.nexus.repository.r.internal.RFacetUtils.toContent)2 RFacetUtils.toContent (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.toContent)2 Asset (org.sonatype.nexus.repository.storage.Asset)2 Bucket (org.sonatype.nexus.repository.storage.Bucket)2 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)2 TransactionalTouchMetadata (org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)2 BlobPayload (org.sonatype.nexus.repository.view.payloads.BlobPayload)2 BytesPayload (org.sonatype.nexus.repository.view.payloads.BytesPayload)2