Search in sources :

Example 1 with FluentComponent

use of org.sonatype.nexus.repository.content.fluent.FluentComponent in project nexus-public by sonatype.

the class DataStoreMavenTestHelper method deleteComponents.

@Override
public void deleteComponents(final Repository repository, final String version, final int expectedNumber) {
    MavenContentFacet mavenContentFacet = repository.facet(MavenContentFacet.class);
    List<FluentComponent> components = findComponents(mavenContentFacet, version).collect(Collectors.toList());
    assertThat(components, hasSize(expectedNumber));
    ContentMaintenanceFacet contentMaintenanceFacet = repository.facet(ContentMaintenanceFacet.class);
    for (FluentComponent component : components) {
        contentMaintenanceFacet.deleteComponent(component);
    }
}
Also used : ContentMaintenanceFacet(org.sonatype.nexus.repository.content.maintenance.ContentMaintenanceFacet) FluentComponent(org.sonatype.nexus.repository.content.fluent.FluentComponent) MavenContentFacet(org.sonatype.nexus.content.maven.MavenContentFacet)

Example 2 with FluentComponent

use of org.sonatype.nexus.repository.content.fluent.FluentComponent in project nexus-public by sonatype.

the class DataStoreMavenTestHelper method loadComponents.

@Override
public List<MavenTestComponent> loadComponents(final Repository repository) {
    List<MavenTestComponent> components = new ArrayList<>();
    MavenContentFacet mavenContentFacet = repository.facet(MavenContentFacet.class);
    Iterable<FluentComponent> fluentComponents = iterableOf(mavenContentFacet.components()::browse);
    for (FluentComponent fluentComponent : fluentComponents) {
        components.add(new MavenTestComponent(fluentComponent.name(), fluentComponent.attributes().child("maven2").get("baseVersion").toString(), fluentComponent.version(), new DateTime(Date.from(fluentComponent.lastUpdated().toInstant()))));
    }
    return components;
}
Also used : FluentComponent(org.sonatype.nexus.repository.content.fluent.FluentComponent) ArrayList(java.util.ArrayList) MavenContentFacet(org.sonatype.nexus.content.maven.MavenContentFacet) DateTime(org.joda.time.DateTime)

Example 3 with FluentComponent

use of org.sonatype.nexus.repository.content.fluent.FluentComponent in project nexus-public by sonatype.

the class DatastoreRawTestHelper method createAsset.

@Override
public EntityId createAsset(final Repository repository, final String componentName, final String componentGroup, final String assetName) {
    try {
        String path = getGroupAndAsset(componentGroup, assetName);
        repository.facet(RawContentFacet.class).put(path, new StringPayload("Test", "text/plain"));
        Optional<FluentComponent> fluentComponent = repository.facet(RawContentFacet.class).components().name(path).namespace("/" + componentGroup).find();
        assertTrue(fluentComponent.isPresent());
        return InternalIds.toExternalId(InternalIds.internalComponentId(fluentComponent.get()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : FluentComponent(org.sonatype.nexus.repository.content.fluent.FluentComponent) RawContentFacet(org.sonatype.nexus.content.raw.RawContentFacet) StringPayload(org.sonatype.nexus.repository.view.payloads.StringPayload) IOException(java.io.IOException)

Example 4 with FluentComponent

use of org.sonatype.nexus.repository.content.fluent.FluentComponent in project nexus-public by sonatype.

the class MavenContentFacetImpl method createComponentAndAsset.

@Override
public FluentAsset createComponentAndAsset(final MavenPath mavenPath) {
    String assetName = "/" + mavenPath.getPath();
    String assetKind = assetKind(mavenPath, mavenPathParser);
    if (mavenPath.getCoordinates() == null) {
        return assets().path(assetName).kind(assetKind).save();
    } else {
        Coordinates coordinates = checkNotNull(mavenPath.getCoordinates());
        FluentComponent component = createOrGetComponent(coordinates);
        FluentAsset asset = component.asset(assetName).kind(assetKind).save();
        configureAssetAttributes(asset, coordinates);
        return asset;
    }
}
Also used : FluentComponent(org.sonatype.nexus.repository.content.fluent.FluentComponent) Coordinates(org.sonatype.nexus.repository.maven.MavenPath.Coordinates) FluentAsset(org.sonatype.nexus.repository.content.fluent.FluentAsset)

Example 5 with FluentComponent

use of org.sonatype.nexus.repository.content.fluent.FluentComponent in project nexus-public by sonatype.

the class MavenContentFacetImpl method createOrGetComponent.

private FluentComponent createOrGetComponent(final MavenPath mavenPath, final Optional<Model> model) {
    Optional<String> optionalKind = model.map(MavenAttributesHelper::getPackaging);
    Coordinates coordinates = mavenPath.getCoordinates();
    FluentComponent component = components().name(coordinates.getArtifactId()).namespace(coordinates.getGroupId()).version(coordinates.getVersion()).kind(optionalKind).getOrCreate();
    boolean isNew = isNewRepositoryContent(component);
    MavenAttributesHelper.setMavenAttributes((Maven2ComponentStore) stores().componentStore, component, coordinates, model, contentRepositoryId());
    if (isNew) {
        publishEvents(component);
    } else {
        // kind isn't set for existing components
        optionalKind.ifPresent(component::kind);
    }
    return component;
}
Also used : FluentComponent(org.sonatype.nexus.repository.content.fluent.FluentComponent) Coordinates(org.sonatype.nexus.repository.maven.MavenPath.Coordinates)

Aggregations

FluentComponent (org.sonatype.nexus.repository.content.fluent.FluentComponent)18 ContentFacet (org.sonatype.nexus.repository.content.facet.ContentFacet)4 FluentAsset (org.sonatype.nexus.repository.content.fluent.FluentAsset)4 MavenContentFacet (org.sonatype.nexus.content.maven.MavenContentFacet)3 Repository (org.sonatype.nexus.repository.Repository)3 FluentComponentBuilder (org.sonatype.nexus.repository.content.fluent.FluentComponentBuilder)3 FluentComponents (org.sonatype.nexus.repository.content.fluent.FluentComponents)3 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 Maven2ComponentData (org.sonatype.nexus.content.maven.store.Maven2ComponentData)2 Maven2ComponentStore (org.sonatype.nexus.content.maven.store.Maven2ComponentStore)2 Coordinates (org.sonatype.nexus.repository.maven.MavenPath.Coordinates)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 IOException (java.io.IOException)1 OffsetDateTime (java.time.OffsetDateTime)1 Comparator.reverseOrder (java.util.Comparator.reverseOrder)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1