@Test public void rewriteTarballUrlTest() { try { assertThat(BaseUrlHolder.isSet(), is(false)); BaseUrlHolder.set("http: NestedAttributesMap packageRoot = new NestedAttributesMap("package", Maps.newHashMap()); packageRoot.set("_id", "id"); packageRoot.set("name", "package"); packageRoot.child("versions").child("1.0").set("name", "package"); packageRoot.child("versions").child("1.0").set("version", "1.0"); packageRoot.child("versions").child("1.0").child("dist") .set("tarball", "http: packageRoot.child("versions").set("2.0", "incomplete"); NpmMetadataUtils.rewriteTarballUrl("testRepo", packageRoot); String rewritten = packageRoot.child("versions").child("1.0").child("dist").get("tarball", String.class); assertThat(rewritten, equalTo("http: } finally { BaseUrlHolder.unset(); } }
public static void rewriteTarballUrl(final String repositoryName, final NestedAttributesMap packageRoot) { if (BaseUrlHolder.isSet()) { NestedAttributesMap versions = packageRoot.child(VERSIONS); for (String v : versions.keys()) { if (versions.get(v) instanceof Map) { NestedAttributesMap version = versions.child(v); NestedAttributesMap dist = version.child(DIST); String tarballName = extractTarballName(dist.get(TARBALL, String.class)); dist.set( TARBALL, String.format( "%s/repository/%s/%s/-/%s", BaseUrlHolder.get(), repositoryName, version.get(NAME), tarballName ) ); } } } }
NpmMetadataUtils { public static void rewriteTarballUrl(final String repositoryName, final NestedAttributesMap packageRoot) { if (BaseUrlHolder.isSet()) { NestedAttributesMap versions = packageRoot.child(VERSIONS); for (String v : versions.keys()) { if (versions.get(v) instanceof Map) { NestedAttributesMap version = versions.child(v); NestedAttributesMap dist = version.child(DIST); String tarballName = extractTarballName(dist.get(TARBALL, String.class)); dist.set( TARBALL, String.format( "%s/repository/%s/%s/-/%s", BaseUrlHolder.get(), repositoryName, version.get(NAME), tarballName ) ); } } } } }
NpmMetadataUtils { public static void rewriteTarballUrl(final String repositoryName, final NestedAttributesMap packageRoot) { if (BaseUrlHolder.isSet()) { NestedAttributesMap versions = packageRoot.child(VERSIONS); for (String v : versions.keys()) { if (versions.get(v) instanceof Map) { NestedAttributesMap version = versions.child(v); NestedAttributesMap dist = version.child(DIST); String tarballName = extractTarballName(dist.get(TARBALL, String.class)); dist.set( TARBALL, String.format( "%s/repository/%s/%s/-/%s", BaseUrlHolder.get(), repositoryName, version.get(NAME), tarballName ) ); } } } } private  NpmMetadataUtils(); }
NpmMetadataUtils { public static void rewriteTarballUrl(final String repositoryName, final NestedAttributesMap packageRoot) { if (BaseUrlHolder.isSet()) { NestedAttributesMap versions = packageRoot.child(VERSIONS); for (String v : versions.keys()) { if (versions.get(v) instanceof Map) { NestedAttributesMap version = versions.child(v); NestedAttributesMap dist = version.child(DIST); String tarballName = extractTarballName(dist.get(TARBALL, String.class)); dist.set( TARBALL, String.format( "%s/repository/%s/%s/-/%s", BaseUrlHolder.get(), repositoryName, version.get(NAME), tarballName ) ); } } } } private  NpmMetadataUtils(); @Nonnull static String extractTarballName(final String tarballUrl); @Nullable static String extractTarballName(final NestedAttributesMap packageMetadata); @Nullable static NestedAttributesMap selectVersionByTarballName(
      final NestedAttributesMap packageRoot,
      final String tarballName); static DateTime maintainTime(final NestedAttributesMap packageRoot); @Nullable static DateTime lastModified(final NestedAttributesMap packageRoot); static void rewriteTarballUrl(final String repositoryName, final NestedAttributesMap packageRoot); static String createRepositoryPath(final String name, final String version); static String createTarballName(final String name, final String version); @Nonnull static NestedAttributesMap shrink(final NestedAttributesMap packageRoot); @Nonnull static NestedAttributesMap overlay(final NestedAttributesMap recessive, final NestedAttributesMap dominant); @Nonnull static NestedAttributesMap merge(final String key, final List<NestedAttributesMap> packages); static NestedAttributesMap mergeContents(final List<Content> contents); static NestedAttributesMap parseContent(final Content content); static Map<String, Object> overlay(
      final Map<String, Object> recessive,
      final Map<String, Object> dominant,
      final boolean mergeVersionDocuments); static String getLatestVersionFromPackageRoot(final NestedAttributesMap pkg); static NestedAttributesMap retrievePackageRoot(
      final NpmPackageId packageId,
      final Context context,
      final Repository repository); static List<String> findCachedVersionsRemovedFromRemote(
      final NestedAttributesMap cachedRoot,
      final NestedAttributesMap newPackageRoot,
      final BiFunction<NpmPackageId, String, Boolean> componentExists); static NestedAttributesMap mergePackageRoots(
      final NestedAttributesMap newPackageRoot,
      final NestedAttributesMap existingPackageRoot, final List<String> cachedVersions); static void removeVersionsNotCachedAndNotInNewRoot(final NestedAttributesMap newPackageRoot,
                                                             final NestedAttributesMap existingPackageRoot,
                                                             final List<String> cachedVersions); }
NpmMetadataUtils { public static void rewriteTarballUrl(final String repositoryName, final NestedAttributesMap packageRoot) { if (BaseUrlHolder.isSet()) { NestedAttributesMap versions = packageRoot.child(VERSIONS); for (String v : versions.keys()) { if (versions.get(v) instanceof Map) { NestedAttributesMap version = versions.child(v); NestedAttributesMap dist = version.child(DIST); String tarballName = extractTarballName(dist.get(TARBALL, String.class)); dist.set( TARBALL, String.format( "%s/repository/%s/%s/-/%s", BaseUrlHolder.get(), repositoryName, version.get(NAME), tarballName ) ); } } } } private  NpmMetadataUtils(); @Nonnull static String extractTarballName(final String tarballUrl); @Nullable static String extractTarballName(final NestedAttributesMap packageMetadata); @Nullable static NestedAttributesMap selectVersionByTarballName(
      final NestedAttributesMap packageRoot,
      final String tarballName); static DateTime maintainTime(final NestedAttributesMap packageRoot); @Nullable static DateTime lastModified(final NestedAttributesMap packageRoot); static void rewriteTarballUrl(final String repositoryName, final NestedAttributesMap packageRoot); static String createRepositoryPath(final String name, final String version); static String createTarballName(final String name, final String version); @Nonnull static NestedAttributesMap shrink(final NestedAttributesMap packageRoot); @Nonnull static NestedAttributesMap overlay(final NestedAttributesMap recessive, final NestedAttributesMap dominant); @Nonnull static NestedAttributesMap merge(final String key, final List<NestedAttributesMap> packages); static NestedAttributesMap mergeContents(final List<Content> contents); static NestedAttributesMap parseContent(final Content content); static Map<String, Object> overlay(
      final Map<String, Object> recessive,
      final Map<String, Object> dominant,
      final boolean mergeVersionDocuments); static String getLatestVersionFromPackageRoot(final NestedAttributesMap pkg); static NestedAttributesMap retrievePackageRoot(
      final NpmPackageId packageId,
      final Context context,
      final Repository repository); static List<String> findCachedVersionsRemovedFromRemote(
      final NestedAttributesMap cachedRoot,
      final NestedAttributesMap newPackageRoot,
      final BiFunction<NpmPackageId, String, Boolean> componentExists); static NestedAttributesMap mergePackageRoots(
      final NestedAttributesMap newPackageRoot,
      final NestedAttributesMap existingPackageRoot, final List<String> cachedVersions); static void removeVersionsNotCachedAndNotInNewRoot(final NestedAttributesMap newPackageRoot,
                                                             final NestedAttributesMap existingPackageRoot,
                                                             final List<String> cachedVersions); @VisibleForTesting
  static final DateTimeFormatter NPM_TIMESTAMP_FORMAT; static final String NAME; static final String DIST_TAGS; static final String VERSIONS; static final String VERSION; static final String DEPRECATED; static final String TIME; static final String DIST; static final String TARBALL; static final String META_ID; static final String META_REV; static final String META_UPDATED; }