Search in sources :

Example 11 with Component

use of org.sonatype.nexus.repository.storage.Component in project nexus-repository-r by sonatype-nexus-community.

the class RProxyFacetImpl method doPutArchive.

@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);
}
Also used : RFacet(org.sonatype.nexus.repository.r.RFacet) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) InputStream(java.io.InputStream) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) Asset(org.sonatype.nexus.repository.storage.Asset) Component(org.sonatype.nexus.repository.storage.Component) TransactionalStoreBlob(org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)

Example 12 with Component

use of org.sonatype.nexus.repository.storage.Component in project nexus-repository-r by sonatype-nexus-community.

the class RBrowseNodeGeneratorTest method shouldComputeAssetAndComponentPath.

@Test
public void shouldComputeAssetAndComponentPath() {
    final String commonPath = "bin/macosx/el-capitan/contrib/3.6";
    final String lastSegment = "devtools_2.2.1.tgz";
    final String assetPath = commonPath + "/" + lastSegment;
    final String componentName = "devtools";
    final String componentVersion = "2.2.1";
    final String componentBrowsePath = commonPath + "/" + componentName + "/" + componentVersion;
    final String assetBrowsePath = componentBrowsePath + "/" + lastSegment;
    Component component = createComponent(componentName, commonPath, componentVersion);
    Asset asset = createAsset(assetPath);
    List<BrowsePaths> pathsAsset = generator.computeAssetPaths(asset, component);
    List<BrowsePaths> pathsComponent = generator.computeComponentPaths(asset, component);
    assertPaths(Arrays.asList(assetBrowsePath.split("/")), pathsAsset);
    assertPaths(Arrays.asList(componentBrowsePath.split("/")), pathsComponent, true);
}
Also used : Asset(org.sonatype.nexus.repository.storage.Asset) BrowsePaths(org.sonatype.nexus.repository.browse.BrowsePaths) Component(org.sonatype.nexus.repository.storage.Component) Test(org.junit.Test)

Example 13 with Component

use of org.sonatype.nexus.repository.storage.Component in project nexus-repository-r by sonatype-nexus-community.

the class RHostedIT method testDeletingRemainingAssetAlsoDeletesComponent.

@Test
public void testDeletingRemainingAssetAlsoDeletesComponent() {
    final Asset asset = findAsset(repository, AGRICOLAE_121_TARGZ.fullPath);
    assertNotNull(asset);
    assertNotNull(asset.componentId());
    final Component component = findComponentById(repository, asset.componentId());
    assertNotNull(component);
    assertThat(findAssetsByComponent(repository, component).size(), is(1));
    componentAssetTestHelper.removeAsset(repository, AGRICOLAE_121_TARGZ.fullPath);
    assertThat(componentAssetTestHelper.assetExists(repository, AGRICOLAE_121_TARGZ.fullPath), is(false));
    assertThat(componentAssetTestHelper.componentExists(repository, AGRICOLAE_121_TARGZ.packageName, AGRICOLAE_121_TARGZ.packageVersion), is(false));
}
Also used : Asset(org.sonatype.nexus.repository.storage.Asset) Component(org.sonatype.nexus.repository.storage.Component) Test(org.junit.Test)

Example 14 with Component

use of org.sonatype.nexus.repository.storage.Component in project nexus-repository-r by sonatype-nexus-community.

the class RHostedIT method testMetadataProcessing.

@Test
public void testMetadataProcessing() throws Exception {
    // Uploading package with same name and lower version that should be skipped in src metadata
    uploadSinglePackage(AGRICOLAE_101_TARGZ);
    Thread.sleep(METADATA_PROCESSING_WAIT_INTERVAL_MILLIS);
    final String agricolae121Content = new String(Files.readAllBytes(testData.resolveFile(PACKAGES_AGRICOLAE_121_FILENAME).toPath()));
    final String agricolae131Content = new String(Files.readAllBytes(testData.resolveFile(PACKAGES_AGRICOLAE_131_FILENAME).toPath()));
    // Verify PACKAGES(metadata) contain appropriate content about source R package (version 1.0-1 is skipped)
    final InputStream contentSrc = client.fetch(PACKAGES_SRC_GZ.fullPath).getEntity().getContent();
    verifyTextGzipContent(is(equalTo(agricolae121Content)), contentSrc);
    assertThat(componentAssetTestHelper.assetExists(repository, PACKAGES_SRC_GZ.fullPath), is(true));
    // Verify PACKAGES(metadata) contain appropriate content about bin R package
    final InputStream contentBin = client.fetch(PACKAGES_BIN_GZ.fullPath).getEntity().getContent();
    verifyTextGzipContent(is(equalTo(agricolae131Content)), contentBin);
    assertThat(componentAssetTestHelper.assetExists(repository, PACKAGES_BIN_GZ.fullPath), is(true));
    // Verify PACKAGES(metadata) is clean if component has been deleted
    ComponentMaintenance maintenanceFacet = repository.facet(ComponentMaintenance.class);
    final List<Component> allComponents = RITSupport.getAllComponents(repository);
    allComponents.stream().forEach(component -> maintenanceFacet.deleteComponent(component.getEntityMetadata().getId(), true));
    Thread.sleep(METADATA_PROCESSING_WAIT_INTERVAL_MILLIS);
    final InputStream contentSrcAfterDelete = client.fetch(PACKAGES_SRC_GZ.fullPath).getEntity().getContent();
    verifyTextGzipContent(is(equalTo("")), contentSrcAfterDelete);
    assertThat(componentAssetTestHelper.assetExists(repository, PACKAGES_SRC_GZ.fullPath), is(true));
    final InputStream contentBinAfterDelete = client.fetch(PACKAGES_BIN_GZ.fullPath).getEntity().getContent();
    verifyTextGzipContent(is(equalTo("")), contentBinAfterDelete);
    assertThat(componentAssetTestHelper.assetExists(repository, PACKAGES_BIN_GZ.fullPath), is(true));
}
Also used : ComponentMaintenance(org.sonatype.nexus.repository.storage.ComponentMaintenance) InputStream(java.io.InputStream) Component(org.sonatype.nexus.repository.storage.Component) Test(org.junit.Test)

Example 15 with Component

use of org.sonatype.nexus.repository.storage.Component in project nexus-repository-r by sonatype-nexus-community.

the class RHostedIT method testPackageUpload.

@Test
public void testPackageUpload() throws Exception {
    // Verify DB contains data about uploaded component and asset
    Component component = findComponent(repository, AGRICOLAE_121_TARGZ.packageName);
    assertThat(component.name(), is(equalTo(AGRICOLAE_121_TARGZ.packageName)));
    assertThat(component.version(), is(equalTo(AGRICOLAE_121_TARGZ.packageVersion)));
    assertThat(component.group(), is(equalTo(AGRICOLAE_121_TARGZ.basePath)));
    // Verify Asset is created.
    Asset asset = findAsset(repository, AGRICOLAE_121_TARGZ.fullPath);
    assertThat(asset.name(), is(equalTo(AGRICOLAE_121_TARGZ.fullPath)));
    assertThat(asset.format(), is(equalTo(R_FORMAT_NAME)));
}
Also used : Asset(org.sonatype.nexus.repository.storage.Asset) Component(org.sonatype.nexus.repository.storage.Component) Test(org.junit.Test)

Aggregations

Component (org.sonatype.nexus.repository.storage.Component)19 Test (org.junit.Test)12 Asset (org.sonatype.nexus.repository.storage.Asset)12 InputStream (java.io.InputStream)6 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)6 RFacetUtils.findComponent (org.sonatype.nexus.repository.r.internal.RFacetUtils.findComponent)4 TransactionalStoreBlob (org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)4 RFacet (org.sonatype.nexus.repository.r.RFacet)3 RFacetUtils.findComponent (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findComponent)3 Bucket (org.sonatype.nexus.repository.storage.Bucket)3 ComponentMaintenance (org.sonatype.nexus.repository.storage.ComponentMaintenance)3 BrowsePaths (org.sonatype.nexus.repository.browse.BrowsePaths)2 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset)2 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset)2 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset)2 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 AttributesMap (org.sonatype.nexus.common.collect.AttributesMap)1 EntityId (org.sonatype.nexus.common.entity.EntityId)1 TransactionalDeleteBlob (org.sonatype.nexus.repository.transaction.TransactionalDeleteBlob)1