@Test public void testPutPackage() throws Exception { when(assetBlob.getBlob()).thenReturn(blob); when(tx.findBucket(repository)).thenReturn(bucket); when(repository.getFormat()).thenReturn(format); when(blob.getInputStream()).thenReturn(this.getClass().getResourceAsStream("/org/sonatype/nexus/repository/pypi/internal/sample-1.2.0.tar.gz")); when(tx.findComponents(any(), eq(ImmutableList.of(repository)))).thenReturn(emptyList()); when(tx.createComponent(bucket, format)).thenReturn(component); when(component.formatAttributes()).thenReturn(componentFormatAttributes); when(tx.createAsset(bucket, component)).thenReturn(asset); when(asset.formatAttributes()).thenReturn(assetFormatAttributes); when(blob.getMetrics()).thenReturn(blobMetrics); when(blobMetrics.getCreationTime()).thenReturn(createdDateTime); underTest.put(PACKAGE_PATH, assetBlob); verify(tx).createComponent(bucket, format); verify(component).name(PACKAGE_NAME); verify(component).version(PACKAGE_VERSION); verify(componentFormatAttributes).set(P_SUMMARY, PACKAGE_SUMMARY); verify(tx).saveComponent(component); verify(asset).name(PACKAGE_PATH); verify(assetFormatAttributes).set(P_ASSET_KIND, AssetKind.PACKAGE); verify(assetFormatAttributes).set("name", PACKAGE_NAME); verify(assetFormatAttributes).set("version", PACKAGE_VERSION); verify(assetFormatAttributes).set("platform", "UNKNOWN"); verify(assetFormatAttributes).set(eq("description"), startsWith("A sample Python project\n=====")); verify(assetFormatAttributes).set("summary", PACKAGE_SUMMARY); verify(assetFormatAttributes).set("license", "MIT"); verify(assetFormatAttributes).set("keywords", "sample setuptools development"); verify(assetFormatAttributes).set("author", "The Python Packaging Authority"); verify(assetFormatAttributes).set("author_email", "pypa-dev@googlegroups.com"); verify(assetFormatAttributes).set("home_page", "https: verify(assetFormatAttributes).set(eq("classifiers"), startsWith("Development Status :: 3 - Alpha\n")); verify(tx).attachBlob(asset, assetBlob); verify(asset).blobCreated(createdDateTime); verify(tx).saveAsset(asset); verifyNoMoreInteractions(componentFormatAttributes, assetFormatAttributes); }
@Override public Asset putPackage(final String path, final AssetBlob assetBlob) throws IOException { final StorageTx tx = UnitOfWork.currentTx(); final Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, bucket, path); if (asset == null) { final String filename = extractFilenameFromPath(path); Map<String, String> attributes; try (InputStream is = assetBlob.getBlob().getInputStream()) { attributes = extractMetadata(is); } if (!attributes.containsKey(P_NAME)) { log.debug("No name found in metadata for {}, extracting from filename.", filename); attributes.put(P_NAME, normalizeName(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)); } final String name = attributes.get(P_NAME); final String version = attributes.get(P_VERSION); Component component = findComponent(tx, getRepository(), name, version); if (component == null) { component = tx.createComponent(bucket, getRepository().getFormat()); component.name(name); component.version(version); component.formatAttributes().set(P_SUMMARY, attributes.get(P_SUMMARY)); tx.saveComponent(component); } asset = tx.createAsset(bucket, component); asset.name(path); copyAttributes(asset, attributes); saveAsset(tx, asset, assetBlob, AssetKind.PACKAGE); } return asset; }
OrientPyPiFacetImpl extends FacetSupport implements PyPiFacet { @Override public Asset putPackage(final String path, final AssetBlob assetBlob) throws IOException { final StorageTx tx = UnitOfWork.currentTx(); final Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, bucket, path); if (asset == null) { final String filename = extractFilenameFromPath(path); Map<String, String> attributes; try (InputStream is = assetBlob.getBlob().getInputStream()) { attributes = extractMetadata(is); } if (!attributes.containsKey(P_NAME)) { log.debug("No name found in metadata for {}, extracting from filename.", filename); attributes.put(P_NAME, normalizeName(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)); } final String name = attributes.get(P_NAME); final String version = attributes.get(P_VERSION); Component component = findComponent(tx, getRepository(), name, version); if (component == null) { component = tx.createComponent(bucket, getRepository().getFormat()); component.name(name); component.version(version); component.formatAttributes().set(P_SUMMARY, attributes.get(P_SUMMARY)); tx.saveComponent(component); } asset = tx.createAsset(bucket, component); asset.name(path); copyAttributes(asset, attributes); saveAsset(tx, asset, assetBlob, AssetKind.PACKAGE); } return asset; } }
OrientPyPiFacetImpl extends FacetSupport implements PyPiFacet { @Override public Asset putPackage(final String path, final AssetBlob assetBlob) throws IOException { final StorageTx tx = UnitOfWork.currentTx(); final Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, bucket, path); if (asset == null) { final String filename = extractFilenameFromPath(path); Map<String, String> attributes; try (InputStream is = assetBlob.getBlob().getInputStream()) { attributes = extractMetadata(is); } if (!attributes.containsKey(P_NAME)) { log.debug("No name found in metadata for {}, extracting from filename.", filename); attributes.put(P_NAME, normalizeName(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)); } final String name = attributes.get(P_NAME); final String version = attributes.get(P_VERSION); Component component = findComponent(tx, getRepository(), name, version); if (component == null) { component = tx.createComponent(bucket, getRepository().getFormat()); component.name(name); component.version(version); component.formatAttributes().set(P_SUMMARY, attributes.get(P_SUMMARY)); tx.saveComponent(component); } asset = tx.createAsset(bucket, component); asset.name(path); copyAttributes(asset, attributes); saveAsset(tx, asset, assetBlob, AssetKind.PACKAGE); } return asset; } @Inject  OrientPyPiFacetImpl(final AssetEntityAdapter assetEntityAdapter); }
OrientPyPiFacetImpl extends FacetSupport implements PyPiFacet { @Override public Asset putPackage(final String path, final AssetBlob assetBlob) throws IOException { final StorageTx tx = UnitOfWork.currentTx(); final Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, bucket, path); if (asset == null) { final String filename = extractFilenameFromPath(path); Map<String, String> attributes; try (InputStream is = assetBlob.getBlob().getInputStream()) { attributes = extractMetadata(is); } if (!attributes.containsKey(P_NAME)) { log.debug("No name found in metadata for {}, extracting from filename.", filename); attributes.put(P_NAME, normalizeName(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)); } final String name = attributes.get(P_NAME); final String version = attributes.get(P_VERSION); Component component = findComponent(tx, getRepository(), name, version); if (component == null) { component = tx.createComponent(bucket, getRepository().getFormat()); component.name(name); component.version(version); component.formatAttributes().set(P_SUMMARY, attributes.get(P_SUMMARY)); tx.saveComponent(component); } asset = tx.createAsset(bucket, component); asset.name(path); copyAttributes(asset, attributes); saveAsset(tx, asset, assetBlob, AssetKind.PACKAGE); } return asset; } @Inject  OrientPyPiFacetImpl(final AssetEntityAdapter assetEntityAdapter); @Override boolean assetExists(final String name); @Override @Nullable Asset put(final String path, final AssetBlob assetBlob); @Override Asset putPackage(final String path, final AssetBlob assetBlob); @Override Asset putIndex(final String path, final AssetBlob assetBlob); }
OrientPyPiFacetImpl extends FacetSupport implements PyPiFacet { @Override public Asset putPackage(final String path, final AssetBlob assetBlob) throws IOException { final StorageTx tx = UnitOfWork.currentTx(); final Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, bucket, path); if (asset == null) { final String filename = extractFilenameFromPath(path); Map<String, String> attributes; try (InputStream is = assetBlob.getBlob().getInputStream()) { attributes = extractMetadata(is); } if (!attributes.containsKey(P_NAME)) { log.debug("No name found in metadata for {}, extracting from filename.", filename); attributes.put(P_NAME, normalizeName(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)); } final String name = attributes.get(P_NAME); final String version = attributes.get(P_VERSION); Component component = findComponent(tx, getRepository(), name, version); if (component == null) { component = tx.createComponent(bucket, getRepository().getFormat()); component.name(name); component.version(version); component.formatAttributes().set(P_SUMMARY, attributes.get(P_SUMMARY)); tx.saveComponent(component); } asset = tx.createAsset(bucket, component); asset.name(path); copyAttributes(asset, attributes); saveAsset(tx, asset, assetBlob, AssetKind.PACKAGE); } return asset; } @Inject  OrientPyPiFacetImpl(final AssetEntityAdapter assetEntityAdapter); @Override boolean assetExists(final String name); @Override @Nullable Asset put(final String path, final AssetBlob assetBlob); @Override Asset putPackage(final String path, final AssetBlob assetBlob); @Override Asset putIndex(final String path, final AssetBlob assetBlob);  }