org.sonatype.nexus.repository.view.matchers.token.TokenMatcher.State Java Examples
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: NpmHandlers.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { State state = context.getAttributes().require(TokenMatcher.State.class); Repository repository = context.getRepository(); log.debug("[getPackage] repository: {} tokens: {}", repository.getName(), state.getTokens()); NpmPackageId packageId = packageId(state); Content content = repository.facet(NpmHostedFacet.class) .getPackage(packageId); if (content != null) { return NpmResponses.ok(content); } else { return NpmResponses.packageNotFound(packageId); } }
Example #2
Source File: NpmHandlers.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { State state = context.getAttributes().require(TokenMatcher.State.class); Repository repository = context.getRepository(); log.debug("[deletePackage] repository: {} tokens: {}", repository.getName(), state.getTokens()); NpmPackageId packageId = packageId(state); Set<String> deleted = repository.facet(NpmHostedFacet.class).deletePackage(packageId, revision(state)); if (!deleted.isEmpty()) { return NpmResponses.ok(); } else { return NpmResponses.packageNotFound(packageId); } }
Example #3
Source File: NpmHandlers.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { State state = context.getAttributes().require(TokenMatcher.State.class); Repository repository = context.getRepository(); log.debug("[getTarball] repository: {} tokens: {}", repository.getName(), state.getTokens()); NpmPackageId packageId = packageId(state); String tarballName = tarballName(state); Content content = repository.facet(NpmHostedFacet.class).getTarball(packageId, tarballName); if (content != null) { return NpmResponses.ok(content); } else { return NpmResponses.tarballNotFound(packageId, tarballName); } }
Example #4
Source File: NpmHandlers.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { State state = context.getAttributes().require(TokenMatcher.State.class); Repository repository = context.getRepository(); log.debug("[deleteTarball] repository: {} tokens: {}", repository.getName(), state.getTokens()); NpmPackageId packageId = packageId(state); String tarballName = tarballName(state); Set<String> deleted = repository.facet(NpmHostedFacet.class).deleteTarball(packageId, tarballName); if (!deleted.isEmpty()) { return NpmResponses.ok(); } else { return NpmResponses.tarballNotFound(packageId, tarballName); } }
Example #5
Source File: NpmHandlers.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { State state = context.getAttributes().require(TokenMatcher.State.class); Repository repository = context.getRepository(); log.debug("[putDistTags] repository: {} tokens: {}", repository.getName(), state.getTokens()); try { repository.facet(NpmHostedFacet.class) .deleteDistTags(packageId(state), state.getTokens().get(T_PACKAGE_TAG), context.getRequest().getPayload()); return NpmResponses.ok(); } catch (IOException e) { //NOSONAR return NpmResponses.badRequest(e.getMessage()); } }
Example #6
Source File: NpmHandlers.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { State state = context.getAttributes().require(TokenMatcher.State.class); Repository repository = context.getRepository(); log.debug("[getPackage] repository: {} tokens: {}", repository.getName(), state.getTokens()); NpmPackageId packageId = packageId(state); Content content = repository.facet(NpmHostedFacet.class) .getDistTags(packageId); if (content != null) { return NpmResponses.ok(content); } else { return NpmResponses.packageNotFound(packageId); } }
Example #7
Source File: NpmHandlers.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { State state = context.getAttributes().require(TokenMatcher.State.class); Repository repository = context.getRepository(); log.debug("[putDistTags] repository: {} tokens: {}", repository.getName(), state.getTokens()); try { repository.facet(NpmHostedFacet.class) .putDistTags(packageId(state), state.getTokens().get(T_PACKAGE_TAG), context.getRequest().getPayload()); return NpmResponses.ok(); } catch (IOException e) { //NOSONAR return NpmResponses.badRequest(e.getMessage()); } }
Example #8
Source File: ConanUrlIndexer.java From nexus-repository-conan with Eclipse Public License 1.0 | 6 votes |
public String updateAbsoluteUrls(final Context context, final Content content, final Repository repository) throws IOException { Map<String, URL> downloadUrlContents = readIndex(content.openInputStream()); Map<String, String> remappedContents = new HashMap<>(); State state = context.getAttributes().require(TokenMatcher.State.class); ConanCoords coords = OrientConanProxyHelper.convertFromState(state); for (Map.Entry<String, URL> entry : downloadUrlContents.entrySet()) { String fileName = entry.getKey(); AssetKind assetKind = OrientConanProxyHelper.ASSET_KIND_FILENAMES.get(fileName); remappedContents.put(entry.getKey(), repository.getUrl() + "/" + getProxyAssetPath(coords, assetKind)); } return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(remappedContents); }
Example #9
Source File: NpmNegativeCacheHandler.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected Response buildResponse(final Status status, final Context context) { if (status.getCode() == HttpStatus.SC_NOT_FOUND) { State state = context.getAttributes().require(TokenMatcher.State.class); NpmPackageId packageId = NpmHandlers.packageId(state); return NpmResponses.packageNotFound(packageId); } return super.buildResponse(status, context); }
Example #10
Source File: CondaPathUtils.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
public static String buildCondaPackagePath(final State matcherState) { return String.format("%s/%s/%s-%s-%s%s", path(matcherState), arch(matcherState), name(matcherState), version(matcherState), build(matcherState), format(matcherState)); }
Example #11
Source File: NpmHandlers.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Nonnull public static NpmPackageId packageId(final TokenMatcher.State state) { checkNotNull(state); String packageName = state.getTokens().get(T_PACKAGE_NAME); checkNotNull(packageName); String version = state.getTokens().get(T_PACKAGE_VERSION); if (!isBlank(version)) { packageName += "-" + version; } String packageScope = state.getTokens().get(T_PACKAGE_SCOPE); return new NpmPackageId(packageScope, packageName); }
Example #12
Source File: NpmHandlers.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { State state = context.getAttributes().require(TokenMatcher.State.class); Repository repository = context.getRepository(); log.debug("[putPackage] repository: {} tokens: {}", repository.getName(), state.getTokens()); repository.facet(NpmHostedFacet.class) .putPackage(packageId(state), revision(state), context.getRequest().getPayload()); return NpmResponses.ok(); }
Example #13
Source File: NpmHandlers.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { State state = context.getAttributes().require(TokenMatcher.State.class); Repository repository = context.getRepository(); log.debug("[createToken] repository: {} tokens: {}", repository.getName(), state.getTokens()); return repository.facet(NpmTokenFacet.class).login(context); }
Example #14
Source File: NpmHandlers.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { State state = context.getAttributes().require(TokenMatcher.State.class); Repository repository = context.getRepository(); log.debug("[deleteToken] repository: {} tokens: {}", repository.getName(), state.getTokens()); return repository.facet(NpmTokenFacet.class).logout(context); }
Example #15
Source File: P2PathUtils.java From nexus-repository-p2 with Eclipse Public License 1.0 | 5 votes |
public static P2Attributes toP2AttributesBinary(final TokenMatcher.State state) { return P2Attributes.builder() .pluginName(name(state)) .componentName(name(state)) .componentVersion(version(state)) .path(binaryPath(path(state), name(state), version(state))) .build(); }
Example #16
Source File: P2PathUtils.java From nexus-repository-p2 with Eclipse Public License 1.0 | 5 votes |
public static P2Attributes toP2Attributes(final TokenMatcher.State state) { return P2Attributes.builder() .componentName(componentName(state)) .componentVersion(componentVersion(state)) .extension(extension(state)) .fileName(filename(state)) .path(path(path(state), filename(state))) .build(); }
Example #17
Source File: OrientNpmGroupPackageHandlerTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Before @SuppressWarnings("unchecked") public void setUp() throws Exception { underTest = new OrientNpmGroupPackageHandler(); AttributesMap attributesMap = new AttributesMap(); attributesMap.set(TokenMatcher.State.class, state); when(context.getAttributes()).thenReturn(attributesMap); when(context.getRepository()).thenReturn(group); when(context.getRequest()).thenReturn(request); when(group.getName()).thenReturn(OrientNpmGroupFacetTest.class.getSimpleName() + "-group"); when(group.facet(GroupFacet.class)).thenReturn(groupFacet); when(group.facet(StorageFacet.class)).thenReturn(storageFacet); when(groupFacet.buildPackageRoot(anyMap(), eq(context))) .thenReturn(new Content(new BytesPayload("test".getBytes(), ""))); when(viewFacet.dispatch(request, context)) .thenReturn(new Response.Builder().status(success(OK)).build()); when(proxy.facet(ViewFacet.class)).thenReturn(viewFacet); when(hosted.facet(ViewFacet.class)).thenReturn(viewFacet); when(request.getHeaders()).thenReturn(new Headers()); when(request.getAttributes()).thenReturn(new AttributesMap()); when(storageFacet.txSupplier()).thenReturn(() -> storageTx); UnitOfWork.beginBatch(storageTx); }
Example #18
Source File: P2PathUtils.java From nexus-repository-p2 with Eclipse Public License 1.0 | 5 votes |
/** * Utility method encapsulating getting a particular token by name from a matcher, including preconditions. */ private static String match(final TokenMatcher.State state, final String name) { checkNotNull(state); String result = state.getTokens().get(name); checkNotNull(result); return result; }
Example #19
Source File: P2PathUtils.java From nexus-repository-p2 with Eclipse Public License 1.0 | 5 votes |
public static String maybePath(final TokenMatcher.State state) { checkNotNull(state); String path = state.getTokens().get("path"); if (isNullOrEmpty(path)) { return String.format("%s.%s", match(state, "name"), match(state, "extension")); } return String.format("%s/%s.%s", path, match(state, "name"), match(state, "extension")); }
Example #20
Source File: OrientNpmGroupFacetTest.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@Before public void setUp() throws Exception { BaseUrlHolder.set("http://localhost:8080/"); setupNpmGroupFacet(); underTest.attach(groupRepository); when(state.getTokens()).thenReturn(ImmutableMap.of(T_PACKAGE_NAME, "test")); AttributesMap attributesMap = new AttributesMap(); attributesMap.set(TokenMatcher.State.class, state); when(context.getAttributes()).thenReturn(attributesMap); when(context.getRepository()).thenReturn(groupRepository); when(context.getRequest()).thenReturn(request); when(request.getPath()).thenReturn("/simple"); when(groupRepository.getName()).thenReturn(OrientNpmGroupFacetTest.class.getSimpleName() + "-group"); when(groupRepository.getFormat()).thenReturn(new NpmFormat()); when(groupRepository.facet(ConfigurationFacet.class)).thenReturn(configurationFacet); when(groupRepository.facet(StorageFacet.class)).thenReturn(storageFacet); when(packageRootAsset.formatAttributes()).thenReturn(new NestedAttributesMap("metadata", new HashMap<>())); when(packageRootAsset.attributes()).thenReturn(new NestedAttributesMap("content", new HashMap<>())); when(packageRootAsset.name(any())).thenReturn(packageRootAsset); when(packageRootAsset.requireBlobRef()).thenReturn(blobRef); when(storageFacet.txSupplier()).thenReturn(() -> storageTx); when(storageFacet.blobStore()).thenReturn(blobStore); when(blobStore.get(any())).thenReturn(blob); when(storageTx.createAsset(any(), any(NpmFormat.class))).thenReturn(packageRootAsset); when(storageTx.createBlob(any(), any(), any(), any(), any(), anyBoolean())).thenReturn(assetBlob); when(storageTx.requireBlob(blobRef)).thenReturn(blob); when(asset.blobRef()).thenReturn(blobRef); when(missingAssetBlobException.getAsset()).thenReturn(asset); underTest.doInit(configuration); UnitOfWork.beginBatch(storageTx); }
Example #21
Source File: HostedHandlers.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private Content getList(final Context context) { State state = context.getAttributes().require(State.class); String module = pathUtils.module(state); return context.getRepository().facet(GolangHostedFacet.class).getList(module); }
Example #22
Source File: HostedHandlers.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private Content getPackage(final Context context) { State state = context.getAttributes().require(State.class); String path = pathUtils.assetPath(state); return context.getRepository().facet(GolangHostedFacet.class).getPackage(path); }
Example #23
Source File: HostedHandlers.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private Content getModule(final Context context) { State state = context.getAttributes().require(State.class); String path = pathUtils.assetPath(state); return context.getRepository().facet(GolangHostedFacet.class).getMod(path); }
Example #24
Source File: P2PathUtils.java From nexus-repository-p2 with Eclipse Public License 1.0 | 4 votes |
/** * * Returns the path from a {@link TokenMatcher.State}. */ public static String path(final TokenMatcher.State state) { return match(state, "path"); }
Example #25
Source File: NpmHandlers.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@Nullable private static String revision(final TokenMatcher.State state) { checkNotNull(state); return state.getTokens().get(T_REVISION); }
Example #26
Source File: HostedHandlers.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private Content getInfo(final Context context) { State state = context.getAttributes().require(State.class); String path = pathUtils.assetPath(state); GolangAttributes golangAttributes = pathUtils.getAttributesFromMatcherState(state); return context.getRepository().facet(GolangHostedFacet.class).getInfo(path, golangAttributes); }
Example #27
Source File: CondaPathUtils.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
public static String arch(final State state) { return match(state, "arch"); }
Example #28
Source File: P2PathUtils.java From nexus-repository-p2 with Eclipse Public License 1.0 | 4 votes |
/** * Returns the name from a {@link TokenMatcher.State}. */ public static String name(final TokenMatcher.State state) { return match(state, "name"); }
Example #29
Source File: P2PathUtils.java From nexus-repository-p2 with Eclipse Public License 1.0 | 4 votes |
/** * Returns the name and extension from a {@link TokenMatcher.State}. */ public static String filename(final TokenMatcher.State state) { return name(state) + '.' + extension(state); }
Example #30
Source File: P2PathUtils.java From nexus-repository-p2 with Eclipse Public License 1.0 | 4 votes |
/** * Returns the extension from a {@link TokenMatcher.State}. */ public static String extension(final TokenMatcher.State state) { return match(state, "extension"); }