Java Code Examples for org.sonatype.nexus.repository.view.matchers.token.TokenMatcher#State

The following examples show how to use org.sonatype.nexus.repository.view.matchers.token.TokenMatcher#State . 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: OrientPyPiProxyFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Content store(final Context context, final Content content) throws IOException {
  AssetKind assetKind = context.getAttributes().require(AssetKind.class);
  if (assetKind.equals(AssetKind.SEARCH)) {
    return content;  // we do not store search results
  }
  TokenMatcher.State state = matcherState(context);
  switch (assetKind) {
    case ROOT_INDEX:
      return putRootIndex(content);
    case INDEX:
      String name = name(state);
      return putIndex(name, content);
    case PACKAGE:
      return putPackage(path(state), content);
    default:
      throw new IllegalStateException();
  }
}
 
Example 2
Source File: ConanProxyFacet.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected String getUrl(@Nonnull final Context context) {
  AssetKind assetKind = context.getAttributes().require(AssetKind.class);

  if (DOWNLOAD_ASSET_KINDS.contains(assetKind)) {
    return context.getRequest().getPath().substring(1);
  }

  TokenMatcher.State state = context.getAttributes().require(TokenMatcher.State.class);
  ConanCoords coords = convertFromState(state);

  if (assetKind == CONAN_MANIFEST) {
    return getUrlForConanManifest(coords);
  }

  log.info("AssetKind {} to be fetched is {}", assetKind, context.getRequest().getPath());

  // TODO: There are two different URLs for DOWNLOAD_URL, this seems to only look in one of them, that seems problematic
  String download_urls = OrientConanProxyHelper.getProxyAssetPath(coords, DOWNLOAD_URL);
  return getUrlFromDownloadAsset(download_urls, assetKind.getFilename());
}
 
Example 3
Source File: GolangProxyFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Content store(final Context context, final Content content) throws IOException {
  AssetKind assetKind = context.getAttributes().require(AssetKind.class);
  TokenMatcher.State matcherState = golangPathUtils.matcherState(context);

  switch (assetKind) {
    case INFO:
    case MODULE:
    case PACKAGE:
      GolangAttributes golangAttributes = golangPathUtils.getAttributesFromMatcherState(matcherState);
      return putComponent(golangAttributes, content, golangPathUtils.assetPath(matcherState), assetKind);
    case LIST:
      return putAsset(content, golangPathUtils.listPath(matcherState), assetKind);
    case LATEST:
      return putAsset(content, golangPathUtils.latestPath(matcherState), assetKind);
    default:
      throw new IllegalStateException("Received an invalid AssetKind of type: " + assetKind.name());
  }
}
 
Example 4
Source File: ExampleContentHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Pull the parsed content path out of the context.
 */
private static String contentPath(final Context context) {
  TokenMatcher.State state = context.getAttributes().require(TokenMatcher.State.class);
  String path = state.getTokens().get("path");
  checkState(path != null, "Missing token: path");
  return path;
}
 
Example 5
Source File: ConanRoutesTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canMatchOnConanInfo() {
  when(request.getPath()).thenReturn("/vthiery/jsonformoderncpp/2.1.1/stable/packages/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/conaninfo.txt");
  assertTrue(underTest.conanInfo().handler(handler).create().getMatcher().matches(context));
  TokenMatcher.State matcherState = attributesMap.require(TokenMatcher.State.class);
  assertThat(matcherState.getTokens().get("group"), is(equalTo("vthiery")));
  assertThat(matcherState.getTokens().get("project"), is(equalTo("jsonformoderncpp")));
  assertThat(matcherState.getTokens().get("version"), is(equalTo("2.1.1")));
}
 
Example 6
Source File: ComposerPathUtils.java    From nexus-repository-composer with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Builds the path to a zipball based on the path contained in a particular context. For download routes the full
 * path including the name token will be present and will be constructed accordingly. For upload routes the full
 * path will not be known because the filename will not be present, so the name portion will be constructed from
 * the vendor, project, and version information contained in the other path segments.
 */
public static String buildZipballPath(final Context context) {
  TokenMatcher.State state = context.getAttributes().require(TokenMatcher.State.class);
  Map<String, String> tokens = state.getTokens();
  return buildZipballPath(
      tokens.get(VENDOR_TOKEN),
      tokens.get(PROJECT_TOKEN),
      tokens.get(VERSION_TOKEN),
      tokens.get(NAME_TOKEN));
}
 
Example 7
Source File: ConanRoutesTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canMatchOnConanPackage() {
  when(request.getPath()).thenReturn("/vthiery/jsonformoderncpp/2.1.1/stable/packages/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/conan_package.tgz");
  assertTrue(underTest.conanPackage().handler(handler).create().getMatcher().matches(context));
  TokenMatcher.State matcherState = attributesMap.require(TokenMatcher.State.class);
  assertThat(matcherState.getTokens().get("group"), is(equalTo("vthiery")));
  assertThat(matcherState.getTokens().get("project"), is(equalTo("jsonformoderncpp")));
  assertThat(matcherState.getTokens().get("version"), is(equalTo("2.1.1")));
}
 
Example 8
Source File: ConanProxyFacet.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Nullable
@Override
protected Content getCachedContent(final Context context) throws IOException {
  AssetKind assetKind = context.getAttributes().require(AssetKind.class);
  TokenMatcher.State state = context.getAttributes().require(TokenMatcher.State.class);
  ConanCoords conanCoords = convertFromState(state);
  String assetPath = getProxyAssetPath(conanCoords, assetKind);
  return  getAssetContent(assetPath, context, assetKind);
}
 
Example 9
Source File: HelmProxyFacetImpl.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
@Nullable
@Override
protected Content getCachedContent(final Context context) {
  AssetKind assetKind = context.getAttributes().require(AssetKind.class);
  switch (assetKind) {
    case HELM_INDEX:
      return getAsset(INDEX_YAML);
    case HELM_PACKAGE:
      TokenMatcher.State matcherState = helmPathUtils.matcherState(context);
      return getAsset(helmPathUtils.filename(matcherState));
    default:
      throw new IllegalStateException("Received an invalid AssetKind of type: " + assetKind.name());
  }
}
 
Example 10
Source File: ConanRoutesTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canMatchOnDownloadUrls() {
  when(request.getPath()).thenReturn("/v1/conans/jsonformoderncpp/2.1.1/vthiery/stable/download_urls");
  assertTrue(underTest.downloadUrls().handler(handler).create().getMatcher().matches(context));
  TokenMatcher.State matcherState = attributesMap.require(TokenMatcher.State.class);
  assertThat(matcherState.getTokens().get("group"), is(equalTo("vthiery")));
  assertThat(matcherState.getTokens().get("project"), is(equalTo("jsonformoderncpp")));
  assertThat(matcherState.getTokens().get("version"), is(equalTo("2.1.1")));
}
 
Example 11
Source File: ConanHostedRecipeTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canMatchOnConanfileUploadPackage() {
  when(request.getAction()).thenReturn(PUT);
  when(request.getPath()).thenReturn("/v1/conans/group/project/2.1.1/stable/packages/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/conanfile.py");

  assertTrue(ConanRoutes.uploadConanfile().handler(handler).create().getMatcher().matches(context));
  TokenMatcher.State matcherState = attributesMap.require(TokenMatcher.State.class);
  assertThat(matcherState.getTokens().get("group"), is(equalTo("group")));
  assertThat(matcherState.getTokens().get("project"), is(equalTo("project")));
  assertThat(matcherState.getTokens().get("version"), is(equalTo("2.1.1")));
  assertThat(matcherState.getTokens().get("sha"), is(equalTo("5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")));
}
 
Example 12
Source File: ConanRoutesTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canMatchOnPackagesDownloadUrl() {
  when(request.getPath()).thenReturn("/v1/conans/jsonformoderncpp/2.1.1/vthiery/stable/packages/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/download_urls");
  assertTrue(underTest.downloadUrls().handler(handler).create().getMatcher().matches(context));
  TokenMatcher.State matcherState = attributesMap.require(TokenMatcher.State.class);
  assertThat(matcherState.getTokens().get("group"), is(equalTo("vthiery")));
  assertThat(matcherState.getTokens().get("project"), is(equalTo("jsonformoderncpp")));
  assertThat(matcherState.getTokens().get("version"), is(equalTo("2.1.1")));
}
 
Example 13
Source File: GolangPathUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Utility method encapsulating getting a particular token by name from a matcher, including preconditions.
 */
private String match(final TokenMatcher.State state, final String name) {
  checkNotNull(state);
  String result = state.getTokens().get(name);
  checkNotNull(result);
  return result;
}
 
Example 14
Source File: OrientNpmProxyFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Content getCachedContent(final Context context) throws IOException
{
  ProxyTarget proxyTarget = context.getAttributes().require(ProxyTarget.class);

  if (proxyTarget.equals(ProxyTarget.SEARCH_V1_RESULTS)) {
    return null; // we do not cache search results
  }
  else if (ProxyTarget.PACKAGE == proxyTarget) {
    return getPackageRoot(context, packageId(matcherState(context)));
  }
  else if (ProxyTarget.DIST_TAGS == proxyTarget) {
    return getDistTags(packageId(matcherState(context)));
  }
  else if (ProxyTarget.TARBALL == proxyTarget) {
    TokenMatcher.State state = matcherState(context);
    return getTarball(packageId(state), tarballName(state));
  }
  else if (ProxyTarget.SEARCH_INDEX == proxyTarget) {
    Content fullIndex = getRepositoryRoot();
    if (fullIndex == null) {
      return null;
    }
    return NpmSearchIndexFilter.filterModifiedSince(
        fullIndex, NpmHandlers.indexSince(context.getRequest().getParameters()));
  }
  throw new IllegalStateException();
}
 
Example 15
Source File: RawProxyFacet.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Determines what 'component' this request relates to.
 */
private String componentPath(final Context context) {
  final TokenMatcher.State tokenMatcherState = context.getAttributes().require(TokenMatcher.State.class);
  return tokenMatcherState.getTokens().get("name");
}
 
Example 16
Source File: GolangPathUtils.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the extension from a {@link TokenMatcher.State}.
 */
public String extension(final TokenMatcher.State state) {
  return match(state, "extension");
}
 
Example 17
Source File: HelmPathUtils.java    From nexus-repository-helm with Eclipse Public License 1.0 4 votes vote down vote up
public String extension(final TokenMatcher.State state) {
  return match(state, "extension");
}
 
Example 18
Source File: GolangPathUtils.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Builds a go latest path from a {@link TokenMatcher.State}.
 */
public String latestPath(final TokenMatcher.State state) {
  String module = module(state);

  return String.format("%s/@latest", module);
}
 
Example 19
Source File: OrientNpmProxyFacet.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private TokenMatcher.State matcherState(final Context context) {
  return context.getAttributes().require(TokenMatcher.State.class);
}
 
Example 20
Source File: HelmPathUtils.java    From nexus-repository-helm with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the filename from a {@link TokenMatcher.State}.
 */
public String filename(final TokenMatcher.State state) {
  return match(state, "filename");
}