use of org.sonatype.nexus.repository.apt.internal.debian.ControlFile in project nexus-public by sonatype.
the class AptUploadHandler method handle.
@Override
public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException {
AptContentFacet aptContentFacet = repository.facet(AptContentFacet.class);
AptHostedFacet hostedFacet = repository.facet(AptHostedFacet.class);
PartPayload payload = upload.getAssetUploads().get(0).getPayload();
try (TempBlob tempBlob = aptContentFacet.getTempBlob(payload)) {
ControlFile controlFile = AptPackageParser.parsePackageInfo(tempBlob).getControlFile();
String assetPath = AptFacetHelper.buildAssetPath(controlFile);
Content content = hostedFacet.put(assetPath, payload, new PackageInfo(controlFile)).markAsCached(payload).download();
return new UploadResponse(Collections.singletonList(content), Collections.singletonList(assetPath));
}
}
use of org.sonatype.nexus.repository.apt.internal.debian.ControlFile in project nexus-public by sonatype.
the class AptContentFacetImpl method buildIndexSection.
private String buildIndexSection(final ControlFile controlFile, final FluentAsset asset) {
AssetBlob assetBlob = asset.blob().orElseThrow(() -> new IllegalStateException("Impossible build " + P_INDEX_SECTION + ". Asset blob couldn't be found for asset: " + asset.path()));
final Map<String, String> checksums = assetBlob.checksums();
return controlFile.getParagraphs().get(0).withFields(Arrays.asList(new ControlFile.ControlField("Filename", asset.path()), new ControlFile.ControlField("Size", Long.toString(assetBlob.blobSize())), new ControlFile.ControlField("MD5Sum", checksums.get(MD5.name())), new ControlFile.ControlField("SHA1", checksums.get(SHA1.name())), new ControlFile.ControlField("SHA256", checksums.get(SHA256.name())))).toString();
}
use of org.sonatype.nexus.repository.apt.internal.debian.ControlFile in project nexus-public by sonatype.
the class AptContentFacetImpl method findOrCreateDebAsset.
private FluentAsset findOrCreateDebAsset(final String path, final TempBlob tempBlob, @Nullable PackageInfo packageInfo) throws IOException {
if (packageInfo == null) {
packageInfo = AptPackageParser.parsePackageInfo(tempBlob);
}
FluentAsset asset = assets().path(normalizeAssetPath(path)).kind(DEB).component(findOrCreateComponent(packageInfo)).blob(tempBlob).save();
ControlFile controlFile = packageInfo.getControlFile();
populateAttributes(packageInfo, asset, controlFile);
return asset;
}
use of org.sonatype.nexus.repository.apt.internal.debian.ControlFile in project nexus-public by sonatype.
the class AptSnapshotFacetSupport method collectSnapshotItems.
protected Iterable<SnapshotItem> collectSnapshotItems(final SnapshotComponentSelector selector) throws IOException {
AptContentFacet aptFacet = getRepository().facet(AptContentFacet.class);
List<SnapshotItem> releaseIndexItems = fetchSnapshotItems(AptFacetHelper.getReleaseIndexSpecifiers(aptFacet.isFlat(), aptFacet.getDistribution()));
Map<SnapshotItem.Role, SnapshotItem> itemsByRole = new EnumMap<>(releaseIndexItems.stream().collect(Collectors.toMap((SnapshotItem item) -> item.specifier.role, item -> item)));
InputStream releaseStream = null;
SnapshotItem snapshotItem = itemsByRole.get(SnapshotItem.Role.RELEASE_INDEX);
if (snapshotItem != null) {
releaseStream = snapshotItem.content.openInputStream();
} else {
try (InputStream is = itemsByRole.get(SnapshotItem.Role.RELEASE_INLINE_INDEX).content.openInputStream()) {
if (is != null) {
ArmoredInputStream aIs = new ArmoredInputStream(is);
releaseStream = new AptFilterInputStream(aIs);
}
}
}
if (releaseStream == null) {
throw new IOException("Invalid upstream repository: no release index present");
}
Release release;
try {
ControlFile index = new ControlFileParser().parseControlFile(releaseStream);
release = new Release(index);
} finally {
releaseStream.close();
}
List<SnapshotItem> result = new ArrayList<>(releaseIndexItems);
if (aptFacet.isFlat()) {
result.addAll(fetchSnapshotItems(AptFacetHelper.getReleasePackageIndexes(aptFacet.isFlat(), aptFacet.getDistribution(), null, null)));
} else {
List<String> archs = selector.getArchitectures(release);
List<String> comps = selector.getComponents(release);
for (String arch : archs) {
for (String comp : comps) {
result.addAll(fetchSnapshotItems(AptFacetHelper.getReleasePackageIndexes(aptFacet.isFlat(), aptFacet.getDistribution(), comp, arch)));
}
}
}
return result;
}
use of org.sonatype.nexus.repository.apt.internal.debian.ControlFile in project nexus-public by sonatype.
the class OrientAptUploadHandler method handle.
@Override
public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException {
OrientAptHostedFacet hostedFacet = repository.facet(OrientAptHostedFacet.class);
StorageFacet storageFacet = repository.facet(StorageFacet.class);
try (TempBlob tempBlob = storageFacet.createTempBlob(upload.getAssetUploads().get(0).getPayload(), AptFacetHelper.hashAlgorithms)) {
ControlFile controlFile = AptPackageParser.parsePackageInfo(tempBlob).getControlFile();
String assetPath = AptFacetHelper.buildAssetPath(controlFile);
doValidation(repository, assetPath);
UnitOfWork.begin(storageFacet.txSupplier());
try {
Asset asset = hostedFacet.ingestAsset(upload.getAssetUploads().get(0).getPayload());
return new UploadResponse(asset);
} finally {
UnitOfWork.end();
}
}
}
Aggregations