use of org.sonatype.nexus.repository.storage.Asset in project nexus-repository-r by sonatype-nexus-community.
the class RProxyFacetImpl method getAsset.
@TransactionalTouchBlob
protected Content getAsset(final String name) {
StorageTx tx = UnitOfWork.currentTx();
Asset asset = findAsset(tx, tx.findBucket(getRepository()), name);
if (asset == null) {
return null;
}
if (asset.markAsDownloaded()) {
tx.saveAsset(asset);
}
return toContent(asset, tx.requireBlob(asset.requireBlobRef()));
}
use of org.sonatype.nexus.repository.storage.Asset in project nexus-repository-r by sonatype-nexus-community.
the class RHostedFacetImpl method getArchive.
@Override
@TransactionalTouchBlob
public Content getArchive(final String archivePath) {
checkNotNull(archivePath);
StorageTx tx = UnitOfWork.currentTx();
Asset asset = findAsset(tx, tx.findBucket(getRepository()), archivePath);
if (asset == null) {
return null;
}
if (asset.markAsDownloaded()) {
tx.saveAsset(asset);
}
return toContent(asset, tx.requireBlob(asset.requireBlobRef()));
}
use of org.sonatype.nexus.repository.storage.Asset in project nexus-repository-r by sonatype-nexus-community.
the class RHostedFacetImpl method getPackages.
@Override
@TransactionalTouchMetadata
public Content getPackages(final String packagesPath) {
checkNotNull(packagesPath);
try {
// TODO: Do NOT do this on each request as there is at least some overhead, and memory usage is proportional to
// the number of packages contained in a particular path. We should be able to generate this when something has
// changed or via a scheduled task using an approach similar to the Yum implementation rather than this method.
StorageTx tx = UnitOfWork.currentTx();
RPackagesBuilder packagesBuilder = new RPackagesBuilder(packagesPath);
for (Asset asset : tx.browseAssets(tx.findBucket(getRepository()))) {
packagesBuilder.append(asset);
}
CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory();
ByteArrayOutputStream os = new ByteArrayOutputStream();
try (CompressorOutputStream cos = compressorStreamFactory.createCompressorOutputStream(GZIP, os)) {
try (OutputStreamWriter writer = new OutputStreamWriter(cos, UTF_8)) {
for (Entry<String, Map<String, String>> eachPackage : packagesBuilder.getPackageInformation().entrySet()) {
Map<String, String> packageInfo = eachPackage.getValue();
InternetHeaders headers = new InternetHeaders();
headers.addHeader(P_PACKAGE, packageInfo.get(P_PACKAGE));
headers.addHeader(P_VERSION, packageInfo.get(P_VERSION));
headers.addHeader(P_DEPENDS, packageInfo.get(P_DEPENDS));
headers.addHeader(P_IMPORTS, packageInfo.get(P_IMPORTS));
headers.addHeader(P_SUGGESTS, packageInfo.get(P_SUGGESTS));
headers.addHeader(P_LICENSE, packageInfo.get(P_LICENSE));
headers.addHeader(P_NEEDS_COMPILATION, packageInfo.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');
}
}
}
return new Content(new BytesPayload(os.toByteArray(), "application/x-gzip"));
} catch (CompressorException | IOException e) {
throw new RException(packagesPath, e);
}
}
use of org.sonatype.nexus.repository.storage.Asset in project nexus-repository-r by sonatype-nexus-community.
the class RHostedFacetImpl method doPutArchive.
@TransactionalStoreBlob
protected Asset doPutArchive(final String path, final TempBlob archiveContent, final Payload payload) throws IOException {
StorageTx tx = UnitOfWork.currentTx();
RFacet rFacet = facet(RFacet.class);
Map<String, String> attributes;
try (InputStream is = archiveContent.get()) {
attributes = extractDescriptionFromArchive(path, is);
}
Component component = rFacet.findOrCreateComponent(tx, path, attributes);
Asset asset = rFacet.findOrCreateAsset(tx, component, path, attributes);
saveAsset(tx, asset, archiveContent, payload);
return asset;
}
use of org.sonatype.nexus.repository.storage.Asset in project nexus-repository-r by sonatype-nexus-community.
the class RProxyFacetImpl method doPutMetadata.
@TransactionalStoreBlob
protected Content doPutMetadata(final String path, final TempBlob packagesContent, final Payload payload) throws IOException {
StorageTx tx = UnitOfWork.currentTx();
RFacet rFacet = facet(RFacet.class);
Asset asset = rFacet.findOrCreateAsset(tx, path);
return saveAsset(tx, asset, packagesContent, payload);
}
Aggregations