-
Notifications
You must be signed in to change notification settings - Fork 3k
Feat: Add id attribute (gav) support to Dependency, Exclusion, Mixin #11904
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
Open
rbygrave
wants to merge
13
commits into
apache:master
Choose a base branch
from
rbygrave:feature/dependency-id-attribute
base: master
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
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3f19909
Feat: Add id attribute (gav) support to Dependency, Exclusion, Mixin
rbygrave feeedab
Add more validation tests for dependency and exclusion id conflicts
rbygrave ed38c98
Merge master into feature/dependency-id-attribute
gnodet 24067aa
Fix review comments: expand id attribute in dependency management and…
gnodet 5a8fcdb
[GH-11904] Add dependency id attribute support for Maven 4.2.0
gnodet e83a24f
[GH-11904] Add mvnup strategy to collapse dependencies into id attrib…
gnodet 3d4ddbe
[GH-11904] Support managed-version formats in dependency id attribute
gnodet c08e34f
Add scope and optional support to dependency id attribute
gnodet 60dde52
Merge branch 'feature/gh-11904-dependency-id-attribute' into feature/…
gnodet fdf544a
Support empty segments in dependency id for inference
gnodet 74e6d74
Fix id attribute documentation to use correct coordinate order
gnodet a804d9a
Add full formal syntax to id attribute documentation
gnodet 2fd1b98
Clean up review findings in DependencyIdStrategy and DefaultModelVali…
gnodet 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
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,8 @@ | |||||||||
| import org.apache.maven.api.di.Singleton; | ||||||||||
| import org.apache.maven.api.model.Build; | ||||||||||
| import org.apache.maven.api.model.Dependency; | ||||||||||
| import org.apache.maven.api.model.Exclusion; | ||||||||||
| import org.apache.maven.api.model.Mixin; | ||||||||||
| import org.apache.maven.api.model.Model; | ||||||||||
| import org.apache.maven.api.model.Plugin; | ||||||||||
| import org.apache.maven.api.services.ModelBuilderRequest; | ||||||||||
|
|
@@ -49,6 +51,9 @@ public class DefaultModelNormalizer implements ModelNormalizer { | |||||||||
| public Model mergeDuplicates(Model model, ModelBuilderRequest request, ModelProblemCollector problems) { | ||||||||||
| Model.Builder builder = Model.newBuilder(model); | ||||||||||
|
|
||||||||||
| // Expand id attributes on mixins | ||||||||||
| builder.mixins(injectList(model.getMixins(), this::expandMixinGav)); | ||||||||||
|
|
||||||||||
| Build build = model.getBuild(); | ||||||||||
| if (build != null) { | ||||||||||
| List<Plugin> plugins = build.getPlugins(); | ||||||||||
|
|
@@ -76,15 +81,20 @@ public Model mergeDuplicates(Model model, ModelBuilderRequest request, ModelProb | |||||||||
| * the way 2.x works. When we're in strict mode, the removal of duplicates just saves other merging steps from | ||||||||||
| * aftereffects and bogus error messages. | ||||||||||
| */ | ||||||||||
| // Expand id attributes on dependencies (and their exclusions), then deduplicate | ||||||||||
| List<Dependency> dependencies = model.getDependencies(); | ||||||||||
| Map<String, Dependency> normalized = new LinkedHashMap<>(dependencies.size() * 2); | ||||||||||
| List<Dependency> expanded = injectList(dependencies, this::expandDependencyId); | ||||||||||
| if (expanded != null) { | ||||||||||
|
gnodet marked this conversation as resolved.
Outdated
|
||||||||||
| dependencies = expanded; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| Map<String, Dependency> normalizedDeps = new LinkedHashMap<>(dependencies.size() * 2); | ||||||||||
| for (Dependency dependency : dependencies) { | ||||||||||
| normalized.put(dependency.getManagementKey(), dependency); | ||||||||||
| normalizedDeps.put(dependency.getManagementKey(), dependency); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (dependencies.size() != normalized.size()) { | ||||||||||
| builder.dependencies(normalized.values()); | ||||||||||
| if (expanded != null || dependencies.size() != normalizedDeps.size()) { | ||||||||||
| builder.dependencies(normalizedDeps.values()); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return builder.build(); | ||||||||||
|
|
@@ -144,4 +154,92 @@ private <T> List<T> injectList(List<T> list, UnaryOperator<T> modifer) { | |||||||||
| } | ||||||||||
| return newList; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Expands the {@code id} attribute on a dependency into its component fields. | ||||||||||
| * The id format is {@code groupId:artifactId:version}. | ||||||||||
| */ | ||||||||||
| Dependency expandDependencyId(Dependency d) { | ||||||||||
| String id = d.getId(); | ||||||||||
| if (id == null || id.isEmpty()) { | ||||||||||
| // No id attribute, but still expand exclusion ids | ||||||||||
| List<Exclusion> expanded = injectList(d.getExclusions(), this::expandExclusionId); | ||||||||||
| return expanded != null ? d.withExclusions(expanded) : d; | ||||||||||
| } | ||||||||||
| String[] parts = id.split(":"); | ||||||||||
|
gnodet marked this conversation as resolved.
Outdated
|
||||||||||
| if (parts.length != 3) { | ||||||||||
| // Invalid format — will be caught by the validator | ||||||||||
| return d; | ||||||||||
| } | ||||||||||
| Dependency.Builder builder = Dependency.newBuilder(d); | ||||||||||
| if (isBlank(d.getGroupId())) { | ||||||||||
| builder.groupId(parts[0]); | ||||||||||
| } | ||||||||||
| if (isBlank(d.getArtifactId())) { | ||||||||||
| builder.artifactId(parts[1]); | ||||||||||
| } | ||||||||||
| if (isBlank(d.getVersion())) { | ||||||||||
| builder.version(parts[2]); | ||||||||||
| } | ||||||||||
| List<Exclusion> expanded = injectList(d.getExclusions(), this::expandExclusionId); | ||||||||||
| if (expanded != null) { | ||||||||||
| builder.exclusions(expanded); | ||||||||||
| } | ||||||||||
| return builder.build(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Expands the {@code id} attribute on an exclusion into its component fields. | ||||||||||
| * The id format is {@code groupId:artifactId}. | ||||||||||
| */ | ||||||||||
| Exclusion expandExclusionId(Exclusion e) { | ||||||||||
| String id = e.getId(); | ||||||||||
| if (id == null || id.isEmpty()) { | ||||||||||
| return e; | ||||||||||
| } | ||||||||||
| String[] parts = id.split(":"); | ||||||||||
| if (parts.length != 2) { | ||||||||||
| // Invalid format — will be caught by the validator | ||||||||||
| return e; | ||||||||||
| } | ||||||||||
| Exclusion.Builder builder = Exclusion.newBuilder(e); | ||||||||||
| if (isBlank(e.getGroupId())) { | ||||||||||
| builder.groupId(parts[0]); | ||||||||||
| } | ||||||||||
| if (isBlank(e.getArtifactId())) { | ||||||||||
| builder.artifactId(parts[1]); | ||||||||||
| } | ||||||||||
| return builder.build(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Expands the {@code id} (XML attribute) / {@code gav} (Java field) on a mixin | ||||||||||
| * into its component fields. The format is {@code groupId:artifactId:version}. | ||||||||||
| */ | ||||||||||
| Mixin expandMixinGav(Mixin m) { | ||||||||||
| String gav = m.getGav(); | ||||||||||
| if (gav == null || gav.isEmpty()) { | ||||||||||
| return m; | ||||||||||
| } | ||||||||||
| String[] parts = gav.split(":"); | ||||||||||
| if (parts.length != 3) { | ||||||||||
| // Invalid format — will be caught by the validator | ||||||||||
| return m; | ||||||||||
| } | ||||||||||
| Mixin.Builder builder = Mixin.newBuilder(m); | ||||||||||
| if (isBlank(m.getGroupId())) { | ||||||||||
| builder.groupId(parts[0]); | ||||||||||
| } | ||||||||||
| if (isBlank(m.getArtifactId())) { | ||||||||||
| builder.artifactId(parts[1]); | ||||||||||
| } | ||||||||||
| if (isBlank(m.getVersion())) { | ||||||||||
| builder.version(parts[2]); | ||||||||||
| } | ||||||||||
| return builder.build(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
Contributor
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. Nit: this method name is misleading --
Suggested change
|
||||||||||
| private static boolean isBlank(String s) { | ||||||||||
| return s == null || s.isEmpty(); | ||||||||||
| } | ||||||||||
| } | ||||||||||
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
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.
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.
Using field name
gavwith attribute nameid... in order to avoid the conflict with the existingParent.getId()