@Test public void whenMultipleDifferentResponsesBuildNewMergedPackageRoot() throws IOException { when(proxyResponse.getPayload()).thenReturn(toContent(createSimplePackageRoot("1.0"))); when(hostedResponse.getPayload()).thenReturn(toContent(createSimplePackageRoot("2.0"))); buildMergedPackageRoot(ImmutableMap.of(proxyRepository, proxyResponse, hostedRepository, hostedResponse)); assertMergedSimplePackageRoot(captureGroupStoredBlobInputStream(), "1.0", "2.0"); }
@Nullable @VisibleForTesting protected Content buildMergedPackageRoot(final Map<Repository, Response> responses, final Context context) throws IOException { checkNotNull(responses); checkNotNull(context); if (responses.isEmpty()) { log.debug("Unable to create package root for repository {}. Members had no metadata to merge.", context.getRepository().getName()); return null; } List<Content> contents = responses .values().stream().map(response -> (Content) response.getPayload()).collect(toList()); NestedAttributesMap result; NpmPackageId packageId = NpmPaths.packageId(matcherState(context)); if (shouldServeFirstResult(contents, packageId)) { result = parseContent(contents.get(0)); } else { log.debug("Merging results from {} repositories", responses.size()); reverse(contents); result = mergeContents(contents); } NpmMetadataUtils.rewriteTarballUrl(context.getRepository().getName(), result); return saveToCache(packageId, result); }
OrientNpmGroupDataFacet extends FacetSupport { @Nullable @VisibleForTesting protected Content buildMergedPackageRoot(final Map<Repository, Response> responses, final Context context) throws IOException { checkNotNull(responses); checkNotNull(context); if (responses.isEmpty()) { log.debug("Unable to create package root for repository {}. Members had no metadata to merge.", context.getRepository().getName()); return null; } List<Content> contents = responses .values().stream().map(response -> (Content) response.getPayload()).collect(toList()); NestedAttributesMap result; NpmPackageId packageId = NpmPaths.packageId(matcherState(context)); if (shouldServeFirstResult(contents, packageId)) { result = parseContent(contents.get(0)); } else { log.debug("Merging results from {} repositories", responses.size()); reverse(contents); result = mergeContents(contents); } NpmMetadataUtils.rewriteTarballUrl(context.getRepository().getName(), result); return saveToCache(packageId, result); } }
OrientNpmGroupDataFacet extends FacetSupport { @Nullable @VisibleForTesting protected Content buildMergedPackageRoot(final Map<Repository, Response> responses, final Context context) throws IOException { checkNotNull(responses); checkNotNull(context); if (responses.isEmpty()) { log.debug("Unable to create package root for repository {}. Members had no metadata to merge.", context.getRepository().getName()); return null; } List<Content> contents = responses .values().stream().map(response -> (Content) response.getPayload()).collect(toList()); NestedAttributesMap result; NpmPackageId packageId = NpmPaths.packageId(matcherState(context)); if (shouldServeFirstResult(contents, packageId)) { result = parseContent(contents.get(0)); } else { log.debug("Merging results from {} repositories", responses.size()); reverse(contents); result = mergeContents(contents); } NpmMetadataUtils.rewriteTarballUrl(context.getRepository().getName(), result); return saveToCache(packageId, result); } @Inject  OrientNpmGroupDataFacet(
      @Named("${nexus.npm.mergeGroupMetadata:-true}") final boolean mergeMetadata); }
OrientNpmGroupDataFacet extends FacetSupport { @Nullable @VisibleForTesting protected Content buildMergedPackageRoot(final Map<Repository, Response> responses, final Context context) throws IOException { checkNotNull(responses); checkNotNull(context); if (responses.isEmpty()) { log.debug("Unable to create package root for repository {}. Members had no metadata to merge.", context.getRepository().getName()); return null; } List<Content> contents = responses .values().stream().map(response -> (Content) response.getPayload()).collect(toList()); NestedAttributesMap result; NpmPackageId packageId = NpmPaths.packageId(matcherState(context)); if (shouldServeFirstResult(contents, packageId)) { result = parseContent(contents.get(0)); } else { log.debug("Merging results from {} repositories", responses.size()); reverse(contents); result = mergeContents(contents); } NpmMetadataUtils.rewriteTarballUrl(context.getRepository().getName(), result); return saveToCache(packageId, result); } @Inject  OrientNpmGroupDataFacet(
      @Named("${nexus.npm.mergeGroupMetadata:-true}") final boolean mergeMetadata); @Nullable Content buildPackageRoot(final Map<Repository, Response> responses, final Context context); @Nullable NpmContent getFromCache(final Map<Repository, Response> responses, final Context context); @Nullable NpmContent getFromCache(final Context context); @Subscribe @Guarded(by = STARTED) @AllowConcurrentEvents void on(final AssetDeletedEvent deleted); @Subscribe @Guarded(by = STARTED) @AllowConcurrentEvents void on(final AssetUpdatedEvent updated); Iterable<Repository> members(); }
OrientNpmGroupDataFacet extends FacetSupport { @Nullable @VisibleForTesting protected Content buildMergedPackageRoot(final Map<Repository, Response> responses, final Context context) throws IOException { checkNotNull(responses); checkNotNull(context); if (responses.isEmpty()) { log.debug("Unable to create package root for repository {}. Members had no metadata to merge.", context.getRepository().getName()); return null; } List<Content> contents = responses .values().stream().map(response -> (Content) response.getPayload()).collect(toList()); NestedAttributesMap result; NpmPackageId packageId = NpmPaths.packageId(matcherState(context)); if (shouldServeFirstResult(contents, packageId)) { result = parseContent(contents.get(0)); } else { log.debug("Merging results from {} repositories", responses.size()); reverse(contents); result = mergeContents(contents); } NpmMetadataUtils.rewriteTarballUrl(context.getRepository().getName(), result); return saveToCache(packageId, result); } @Inject  OrientNpmGroupDataFacet(
      @Named("${nexus.npm.mergeGroupMetadata:-true}") final boolean mergeMetadata); @Nullable Content buildPackageRoot(final Map<Repository, Response> responses, final Context context); @Nullable NpmContent getFromCache(final Map<Repository, Response> responses, final Context context); @Nullable NpmContent getFromCache(final Context context); @Subscribe @Guarded(by = STARTED) @AllowConcurrentEvents void on(final AssetDeletedEvent deleted); @Subscribe @Guarded(by = STARTED) @AllowConcurrentEvents void on(final AssetUpdatedEvent updated); Iterable<Repository> members();  }