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);
}
}
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"));
}
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)));
}
}
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()));
}
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);
}
Aggregations