Java Code Examples for org.sonatype.nexus.common.app.BaseUrlHolder#isSet()

The following examples show how to use org.sonatype.nexus.common.app.BaseUrlHolder#isSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenTestHelper.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private String url(final Repository repo, final String path) {
  boolean reset = false;
  if (!BaseUrlHolder.isSet()) {
    reset = true;
    BaseUrlHolder.set(nexusUrl.toString());
  }
  String repoPath = path.startsWith("/") ? path : '/' + path;
  try {
    return String.format("%s%s", repo.getUrl(), repoPath);
  }
  finally {
    if (reset) {
      BaseUrlHolder.unset();
    }
  }
}
 
Example 2
Source File: NpmMetadataUtils.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Rewrites dist/tarball entry URLs to point back to this Nexus instance and given repository.
 */
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) { // only if not incomplete
        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
            )
        );
      }
    }
  }
}
 
Example 3
Source File: NpmMetadataUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Rewrites dist/tarball entry URLs to point back to this Nexus instance and given repository.
 *
 * @param repositoryName    Name of the repository we want to point this at.
 * @param name              Name of the Asset/NPM Package ID
 * @param currentTarballUrl The real/original tarball url
 * @return String with local NXRM url
 */
static String rewriteTarballUrl(final String repositoryName, final String name, final String currentTarballUrl) {
  if (BaseUrlHolder.isSet()) {
    return String.format(
        "%s/repository/%s/%s/-/%s",
        BaseUrlHolder.get(),
        repositoryName,
        name,
        extractTarballName(currentTarballUrl));
  }

  return currentTarballUrl;
}
 
Example 4
Source File: RepositoryAuditor.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Map<String, Object> createFullAttributes(final Repository repository) {
  boolean baseUrlAbsent = !BaseUrlHolder.isSet();
  try {
    if (baseUrlAbsent) {
      BaseUrlHolder.set(""); // use empty base URL placeholder during conversion to avoid log-spam
    }

    AbstractApiRepository apiObject = convert(repository);

    ObjectWriter writer = mapper.writerFor(apiObject.getClass());

    String json = writer.writeValueAsString(apiObject);

    return mapper.readerFor(new TypeReference<Map<String, Object>>()
    {
    }).readValue(json);
  }
  catch (Exception e) {
    log.error("Failed to convert repo object falling back to simple", e);
    return createSimple(repository);
  }
  finally {
    if (baseUrlAbsent) {
      BaseUrlHolder.unset();
    }
  }
}