-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Maven Shade support #5967
Open
smowton
wants to merge
6
commits into
github:main
Choose a base branch
from
smowton:smowton/feature/shade-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Maven Shade support #5967
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eb7053f
Add classes representing Maven shade relocations; use them to recogni…
smowton c10b15f
Recognise Shade plugin specified without an explicit groupId
smowton 52fe6f7
Document Maven shade support classes and predicates.
smowton 6b6bc1f
Account for shade reloc specifications within an expectation, and add…
smowton 7229db2
Fix package of SnakeYaml's Yaml class
smowton d6663f8
Improve doc style
smowton 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 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
This file contains 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 |
---|---|---|
|
@@ -485,3 +485,85 @@ class MavenRepoJar extends File { | |
else getVersion().matches(pom.getVersionString() + "%") | ||
} | ||
} | ||
|
||
/** | ||
* A `<plugin>` element in a Maven POM file. | ||
*/ | ||
class MavenPlugin extends ProtoPom { | ||
MavenPlugin() { this.hasName("plugin") } | ||
} | ||
|
||
/** | ||
* A `maven-shade-plugin` plugin element in a Maven POM file. | ||
*/ | ||
class MavenShadePlugin extends MavenPlugin { | ||
MavenShadePlugin() { | ||
( | ||
this.getGroup().getValue() = "org.apache.maven.plugins" or | ||
not exists(this.getGroup()) // org.apache.maven.plugins is the default | ||
) and | ||
this.getArtifact().getValue() = "maven-shade-plugin" | ||
} | ||
|
||
MavenShadeRelocation getARelocation() { result.getPlugin() = this } | ||
} | ||
|
||
/** | ||
* A `<relocation>` specification within a `maven-shade-plugin` configuration. | ||
*/ | ||
class MavenShadeRelocation extends XMLElement { | ||
MavenShadePlugin plugin; | ||
|
||
MavenShadeRelocation() { | ||
this.getParent().(XMLElement).getParent().(XMLElement).getParent() = plugin and | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be good to add a comment explaining the hierarchy here, i.e. It is also possible to specify the configuration per execution, as it was done in the example of the Maven Shade Plugin, see also the POM Reference. |
||
this.hasName("relocation") | ||
} | ||
|
||
/** | ||
* Gets the `<plugin>` ancestor of this relocation. | ||
*/ | ||
MavenShadePlugin getPlugin() { result = plugin } | ||
|
||
/** | ||
* Gets the pattern this relocation replaces (e.g. `org.foo`) | ||
*/ | ||
string getPattern() { | ||
exists(XMLElement el | el.getName() = "pattern" and el.getParent() = this | | ||
result = el.getTextValue() | ||
) | ||
} | ||
|
||
/** | ||
* Gets the shaded package that replaces `getPattern()` (e.g. `org.bar.shaded.org.foo`). | ||
*/ | ||
string getShadedPattern() { | ||
exists(XMLElement el | el.getName() = "shadedPattern" and el.getParent() = this | | ||
result = el.getTextValue() | ||
) | ||
} | ||
|
||
/** | ||
* Holds if this `<relocation>` specification relocates `fromPackage` to `toPackage`. | ||
*/ | ||
predicate relocates(string fromPackage, string toPackage) { | ||
this.getPattern() = fromPackage and this.getShadedPattern() = toPackage | ||
} | ||
} | ||
|
||
/** | ||
* Returns a package name that may be used to refer to `package` after shading, including `package` | ||
* itself. | ||
* | ||
* For example, if `package` is `org.foo.sub` and we have a `<relocation>` specification relocating | ||
* `org.foo` to `org.bar.shaded.org.foo` then this will return `{"org.foo.sub", "org.bar.shaded.org.foo.sub"}`. | ||
smowton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
bindingset[package] | ||
string getAShadedPackage(string package) { | ||
result = package | ||
or | ||
exists(string originalPackage, string shadedPackage, MavenShadeRelocation relocDirective | | ||
relocDirective.relocates(originalPackage, shadedPackage) | ||
| | ||
result = package.regexpReplaceAll("^" + originalPackage, shadedPackage) | ||
) | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this changed on purpose, shouldn't it be the following? (might require formatting)