Java Code Examples for org.sonatype.nexus.repository.storage.TempBlob#get()

The following examples show how to use org.sonatype.nexus.repository.storage.TempBlob#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelmHostedFacetImpl.java    From nexus-repository-helm with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@TransactionalStoreBlob
public Asset upload(String path, TempBlob tempBlob, Payload payload, AssetKind assetKind) throws IOException {
  checkNotNull(path);
  checkNotNull(tempBlob);
  if (assetKind != HELM_PACKAGE && assetKind != HELM_PROVENANCE) {
    throw new IllegalArgumentException("Unsupported assetKind: " + assetKind);
  }

  StorageTx tx = UnitOfWork.currentTx();
  InputStream inputStream = tempBlob.get();
  HelmAttributes attributes = helmAttributeParser.getAttributes(assetKind, inputStream);
  final Asset asset =
      helmFacet.findOrCreateAsset(tx, path, assetKind, attributes);
  helmFacet.saveAsset(tx, asset, tempBlob, payload);
  return asset;
}
 
Example 2
Source File: RProxyFacetImpl.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalStoreBlob
protected Content doPutArchive(final String path,
                               final TempBlob archiveContent,
                               final Content content) throws IOException
{
  RFacet rFacet = facet(RFacet.class);
  StorageTx tx = UnitOfWork.currentTx();

  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);
  return saveAsset(tx, asset, archiveContent, content);
}
 
Example 3
Source File: RHostedFacetImpl.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: JarExtractor.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
private JarInputStream getJarStreamFromBlob(final TempBlob tempBlob, final String extension) throws IOException {
  if (extension.equals("jar")) {
    return new JarInputStream(tempBlob.get());
  }
  else {
    return new JarInputStream(tempBlobConverter.getJarFromPackGz(tempBlob));
  }
}
 
Example 5
Source File: TempBlobConverter.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
public InputStream getJarFromPackGz(final TempBlob tempBlob) throws IOException {
  Path tempFile = createTempFile("pack-file", "jar.pack");
  try (GZIPInputStream gzis = new GZIPInputStream(tempBlob.get()); OutputStream os = newOutputStream(tempFile)) {
    Unpacker unpacker = Pack200.newUnpacker();
    try (JarOutputStream jos = new JarOutputStream(os)) {
      unpacker.unpack(gzis, jos);
      return newInputStream(tempFile);
    }
  }
  finally {
    Files.delete(tempFile);
  }
}
 
Example 6
Source File: ArtifactsXmlAbsoluteUrlRemoverTest.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void removeAbsoluteUrlFromXz() throws Exception {
  when(artifactsXml.get()).thenReturn(getClass().getResourceAsStream(ARTIFACTS_XML_XZ));
  TempBlob modified = underTest.removeMirrorUrlFromArtifactsXml(artifactsXml, repository, "xml.xz");
  try (XZCompressorInputStream xz = new XZCompressorInputStream(modified.get())) {
    assertXmlMatches(xz, ARTIFACTS_XML_WITHOUT_ABSOLUTE);
  }
  catch (IOException e) {
    fail("Exception not expected. Is this file XZ compressed? " + e.getMessage());
  }
}
 
Example 7
Source File: ArtifactsXmlAbsoluteUrlRemoverTest.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void removeAbsoluteUrlFromJar() throws Exception {
  when(artifactsXml.get()).thenReturn(getClass().getResourceAsStream(ARTIFACTS_JAR));
  TempBlob modified = underTest.removeMirrorUrlFromArtifactsXml(artifactsXml, repository, "jar");
  try (ZipArchiveInputStream zip = new ZipArchiveInputStream(modified.get())) {
    zip.getNextZipEntry();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copy(zip, out);
    assertXmlMatches(new ByteArrayInputStream(out.toByteArray()), ARTIFACTS_XML_WITHOUT_ABSOLUTE);
  }
  catch (IOException e) {
    fail("Exception not expected. Is this file a JAR? " + e.getMessage());
  }
}
 
Example 8
Source File: NpmRequestParser.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@VisibleForTesting
NpmPublishRequest parseNpmPublish(final StorageFacet storageFacet,
                                  final TempBlob tempBlob,
                                  final Charset charset) throws IOException
{
  try (InputStreamReader reader = new InputStreamReader(tempBlob.get(), charset)) {
    try (JsonParser jsonParser = jsonFactory.createParser(reader)) {
      NpmPublishParser parser = npmPublishParserFor(jsonParser, storageFacet);
      return parser.parse(getUserId());
    }
  }
}
 
Example 9
Source File: MavenUploadHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private String createBasePathFromPom(final TempBlob tempBlob) throws IOException {
  try (InputStream in = tempBlob.get()) {
    Model model = MavenModels.readModel(in);
    validatePom(model);
    return createBasePath(getGroupId(model), getArtifactId(model), getVersion(model));
  }
}
 
Example 10
Source File: OrientPyPiHostedFacetImpl.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Map<String, String> extractMetadata(final TempBlob tempBlob) throws IOException {
  try (InputStream in = tempBlob.get()) {
    return PyPiInfoUtils.extractMetadata(in);
  }
}
 
Example 11
Source File: OrientPyPiProxyFacetImpl.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@TransactionalStoreBlob
protected Content doPutPackage(final String path,
                               final TempBlob tempBlob,
                               final Payload payload) throws IOException
{
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());

  String filename = extractFilenameFromPath(path);
  Map<String, String> attributes;
  try (InputStream is = tempBlob.get()) {
    attributes = extractMetadata(is);
  }

  if (!attributes.containsKey(P_NAME)) {
    log.debug("No name found in metadata for {}, extracting from filename.", filename);
    attributes.put(P_NAME, extractNameFromFilename(filename));
  }
  if (!attributes.containsKey(P_VERSION)) {
    log.debug("No version found in metadata for {}, extracting from filename.", filename);
    attributes.put(P_VERSION, extractVersionFromFilename(filename));
  }

  String name = attributes.get(P_NAME);
  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);
  }
  if (component.isNew() || attributes.containsKey(P_SUMMARY)) {
    component.formatAttributes().set(P_SUMMARY, attributes.get(P_SUMMARY));
    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, AssetKind.PACKAGE.name());
  }

  copyAttributes(asset, attributes);
  return saveAsset(tx, asset, tempBlob, payload);
}