-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow RevApi extensions to be configured via the configuration file #43751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alzimmermsft
merged 6 commits into
Azure:main
from
alzimmermsft:AzEng_MoreWorkToGenerifyTooling
Jan 9, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
354dac9
Allow RevApi extensions to be configured via the configuration file
alzimmermsft 4679a64
Move clientcore to its own RevApi configuration file
alzimmermsft fa70831
Add enabled flags to all transforms
alzimmermsft 696a575
Merge branch 'main' into AzEng_MoreWorkToGenerifyTooling
alzimmermsft e0172bb
Fix linting
alzimmermsft b309229
Fix clientcore linting
alzimmermsft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...-quality-reports/src/main/java/com/azure/tools/revapi/transforms/AllowedExternalApis.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.tools.revapi.transforms; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import org.revapi.AnalysisContext; | ||
| import org.revapi.Difference; | ||
| import org.revapi.Element; | ||
| import org.revapi.TransformationResult; | ||
| import org.revapi.base.BaseDifferenceTransform; | ||
| import org.revapi.java.spi.JavaTypeElement; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
| import javax.lang.model.element.TypeElement; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import static com.azure.tools.revapi.transforms.RevApiUtils.createPrefixMatchersFromConfiguration; | ||
| import static com.azure.tools.revapi.transforms.RevApiUtils.findOuterMostClass; | ||
|
|
||
| /** | ||
| * RevApi transformation that allows for ignoring external APIs that are allowed to be exposed. | ||
| * | ||
| * @param <E> Type of element to transform. | ||
| */ | ||
| public final class AllowedExternalApis<E extends Element<E>> extends BaseDifferenceTransform<E> { | ||
| private static final Pattern DIFFERENCE_CODE_PATTERN = Pattern.compile("java.class.externalClassExposedInAPI", | ||
| Pattern.LITERAL); | ||
|
|
||
| private boolean enabled = false; | ||
| private List<PrefixMatcher> allowedPrefixes = Collections.emptyList(); | ||
|
|
||
| @Override | ||
| public Pattern[] getDifferenceCodePatterns() { | ||
| return new Pattern[] { DIFFERENCE_CODE_PATTERN }; | ||
| } | ||
|
|
||
| @Override | ||
| public TransformationResult tryTransform(@Nullable E oldElement, @Nullable E newElement, Difference difference) { | ||
| if (!enabled || newElement == null || allowedPrefixes.isEmpty()) { | ||
| // Missing element to compare. | ||
| return TransformationResult.keep(); | ||
| } | ||
|
|
||
| if (!(newElement instanceof JavaTypeElement)) { | ||
| // Unknown element type. | ||
| return TransformationResult.keep(); | ||
| } | ||
|
|
||
| TypeElement outermostElement = findOuterMostClass(((JavaTypeElement) newElement).getDeclaringElement()); | ||
|
|
||
| if (outermostElement == null) { | ||
| return TransformationResult.keep(); | ||
| } | ||
|
|
||
| String className = outermostElement.getQualifiedName().toString(); | ||
|
|
||
| for (PrefixMatcher prefixMatcher : allowedPrefixes) { | ||
| if (prefixMatcher.test(className)) { | ||
| return TransformationResult.discard(); | ||
| } | ||
| } | ||
|
|
||
| return TransformationResult.keep(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getExtensionId() { | ||
| return "allowed-external-apis"; | ||
| } | ||
|
|
||
| @Override | ||
| public void initialize(@Nonnull AnalysisContext analysisContext) { | ||
| JsonNode enabledNode = analysisContext.getConfigurationNode().get("enabled"); | ||
| this.enabled = enabledNode != null && enabledNode.isBoolean() && enabledNode.booleanValue(); | ||
| this.allowedPrefixes = createPrefixMatchersFromConfiguration(analysisContext, "allowedPrefixes"); | ||
| } | ||
| } |
165 changes: 0 additions & 165 deletions
165
...-reports/src/main/java/com/azure/tools/revapi/transforms/AzureSdkAllowedExternalApis.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.