use of org.sonatype.nexus.repository.storage.Asset in project nexus-repository-r by sonatype-nexus-community.
the class RProxyFacetImpl method doPutPackages.
@TransactionalStoreBlob
protected Content doPutPackages(final String path, final TempBlob packagesContent, final Payload payload) throws IOException {
StorageTx tx = UnitOfWork.currentTx();
Bucket bucket = tx.findBucket(getRepository());
String assetPath = packagesPath(path);
Asset asset = findAsset(tx, bucket, assetPath);
if (asset == null) {
asset = tx.createAsset(bucket, getRepository().getFormat());
asset.name(assetPath);
asset.formatAttributes().set(P_ASSET_KIND, PACKAGES.name());
}
return saveAsset(tx, asset, packagesContent, payload);
}
use of org.sonatype.nexus.repository.storage.Asset 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.storage.Asset in project nexus-repository-r by sonatype-nexus-community.
the class RProxyFacetImpl method doPutArchive.
@TransactionalStoreBlob
protected Content doPutArchive(final String path, final String filename, final TempBlob archiveContent, final Payload payload) throws IOException {
StorageTx tx = UnitOfWork.currentTx();
Bucket bucket = tx.findBucket(getRepository());
String assetPath = path(path, filename);
Map<String, String> attributes;
try (InputStream is = archiveContent.get()) {
attributes = extractDescriptionFromArchive(filename, is);
}
String name = attributes.get(P_PACKAGE);
String version = attributes.get(P_VERSION);
Component component = findComponent(tx, getRepository(), name, version);
if (component == null) {
component = tx.createComponent(bucket, getRepository().getFormat()).name(name).version(version);
}
tx.saveComponent(component);
Asset asset = findAsset(tx, bucket, assetPath);
if (asset == null) {
asset = tx.createAsset(bucket, component);
asset.name(assetPath);
asset.formatAttributes().set(P_ASSET_KIND, ARCHIVE.name());
}
// TODO: Make this a bit more robust (could be problematic if keys are removed in later versions, or if keys clash)
for (Entry<String, String> entry : attributes.entrySet()) {
asset.formatAttributes().set(entry.getKey(), entry.getValue());
}
return saveAsset(tx, asset, archiveContent, payload);
}
use of org.sonatype.nexus.repository.storage.Asset in project nexus-repository-r by sonatype-nexus-community.
the class RPackagesBuilderTest method createAsset.
private Asset createAsset(final String assetName, final String packageName, final String packageVersion) {
NestedAttributesMap formatAttributes = mock(NestedAttributesMap.class);
when(formatAttributes.get(P_PACKAGE, String.class)).thenReturn(packageName);
when(formatAttributes.get(P_VERSION, String.class)).thenReturn(packageVersion);
when(formatAttributes.get(P_DEPENDS, String.class)).thenReturn("Depends:" + assetName);
when(formatAttributes.get(P_IMPORTS, String.class)).thenReturn("Imports:" + assetName);
when(formatAttributes.get(P_SUGGESTS, String.class)).thenReturn("Suggests:" + assetName);
when(formatAttributes.get(P_LICENSE, String.class)).thenReturn("License:" + assetName);
when(formatAttributes.get(P_NEEDS_COMPILATION, String.class)).thenReturn("NeedsCompilation:" + assetName);
Asset asset = mock(Asset.class);
when(asset.formatAttributes()).thenReturn(formatAttributes);
when(asset.name()).thenReturn(assetName);
return asset;
}
use of org.sonatype.nexus.repository.storage.Asset in project nexus-repository-r by sonatype-nexus-community.
the class RHostedFacetImpl method doPutArchive.
@TransactionalStoreBlob
protected void doPutArchive(final String path, final TempBlob archiveContent, final Payload payload) throws IOException {
checkNotNull(path);
checkNotNull(archiveContent);
checkNotNull(payload);
StorageTx tx = UnitOfWork.currentTx();
Bucket bucket = tx.findBucket(getRepository());
Map<String, String> attributes;
try (InputStream is = archiveContent.get()) {
attributes = extractDescriptionFromArchive(path, is);
}
String name = attributes.get(P_PACKAGE);
String version = attributes.get(P_VERSION);
Component component = findComponent(tx, getRepository(), name, version);
if (component == null) {
component = tx.createComponent(bucket, getRepository().getFormat()).name(name).version(version);
}
tx.saveComponent(component);
Asset asset = findAsset(tx, bucket, path);
if (asset == null) {
asset = tx.createAsset(bucket, component);
asset.name(path);
asset.formatAttributes().set(P_ASSET_KIND, ARCHIVE.name());
}
// TODO: Make this a bit more robust (could be problematic if keys are removed in later versions, or if keys clash)
for (Entry<String, String> entry : attributes.entrySet()) {
asset.formatAttributes().set(entry.getKey(), entry.getValue());
}
saveAsset(tx, asset, archiveContent, payload);
}
Aggregations