use of org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata in project nexus-repository-r by sonatype-nexus-community.
the class RProxyFacetImpl method setCacheInfo.
@TransactionalTouchMetadata
public void setCacheInfo(final Content content, final CacheInfo cacheInfo) throws IOException {
StorageTx tx = UnitOfWork.currentTx();
Asset asset = Content.findAsset(tx, tx.findBucket(getRepository()), content);
if (asset == null) {
log.debug("Attempting to set cache info for non-existent R asset {}", content.getAttributes().require(Asset.class));
return;
}
log.debug("Updating cacheInfo of {} to {}", asset, cacheInfo);
CacheInfo.applyToAsset(asset, cacheInfo);
tx.saveAsset(asset);
}
use of org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata 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.transaction.TransactionalTouchMetadata in project nexus-repository-r by sonatype-nexus-community.
the class RProxyFacetImpl method setCacheInfo.
@TransactionalTouchMetadata
public void setCacheInfo(final Content content, final CacheInfo cacheInfo) {
StorageTx tx = UnitOfWork.currentTx();
Asset asset = Content.findAsset(tx, tx.findBucket(getRepository()), content);
if (asset == null) {
log.debug("Attempting to set cache info for non-existent R asset {}", content.getAttributes().require(Asset.class));
return;
}
log.debug("Updating cacheInfo of {} to {}", asset, cacheInfo);
CacheInfo.applyToAsset(asset, cacheInfo);
tx.saveAsset(asset);
}
use of org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata 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);
}
}
Aggregations