-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[MNG-7344] track dependencyManagement import location in effective Model for MPH-183 #603
Merged
gnodet
merged 17 commits into
apache:master
from
infosupport:MPH-183_dependency-management-hierarchy-inputsource
Aug 15, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2767730
[MPH-183] [WIP] BOM hierarchy in InputSource
jjkester 550bb4d
Formatting
mthmulders 198c581
WIP and notes
mthmulders 38dc034
[MNG-7344] Recursive imported from tracking
juulhobert 069ae93
[MNG-7344] Imported from in the v3 model
juulhobert 3cd4d9d
[MPH-183] Fix error in import path and small refactor
Giovds b50cda2
[MPH-183] Remove indentation for readability
Giovds 9881c22
[MPH-183] Add getLocationKeys for help plugin
Giovds 941b502
[MNG-7344] Unit tests for updatedWithImportedFrom
juulhobert 71c2989
[MPH-183] Rename test to better match behaviour
Giovds 21541ed
[MNG-7344] Removed line that changed the importedFrom in the dep mgmt…
juulhobert 1a9aa52
[MNG-7344] Improve comment on getImportedFrom method
Giovds 237de75
[MNG-7344] Remove unused method and make constructor public
Giovds 73f5ff2
[MNG-7344] Add since and docs to methods
Giovds b27c457
Merge remote-tracking branch 'origin/master' into MPH-183_dependency-…
gnodet 78b912c
Move code to new implementation
gnodet 1918fdc
Merge branch 'master' of github.com:apache/maven into MPH-183_depende…
juulhobert 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 |
---|---|---|
|
@@ -20,4 +20,13 @@ | |
|
||
public interface InputLocationTracker { | ||
InputLocation getLocation(Object field); | ||
|
||
/** | ||
* Gets the parent InputLocation where this InputLocation may have been imported from. | ||
* Can return {@code null}. | ||
* | ||
* @return InputLocation | ||
* @since 4.0.0 | ||
*/ | ||
InputLocation getImportedFrom(); | ||
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. same |
||
} |
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 |
---|---|---|
|
@@ -33,17 +33,24 @@ public class InputSource implements Serializable { | |
private final String modelId; | ||
private final String location; | ||
private final List<InputSource> inputs; | ||
private final InputLocation importedFrom; | ||
|
||
public InputSource(String modelId, String location) { | ||
this(modelId, location, null); | ||
} | ||
|
||
public InputSource(String modelId, String location, InputLocation importedFrom) { | ||
this.modelId = modelId; | ||
this.location = location; | ||
this.inputs = null; | ||
this.importedFrom = importedFrom; | ||
} | ||
|
||
public InputSource(Collection<InputSource> inputs) { | ||
this.modelId = null; | ||
this.location = null; | ||
this.inputs = ImmutableCollections.copy(inputs); | ||
this.importedFrom = null; | ||
} | ||
|
||
/** | ||
|
@@ -64,6 +71,17 @@ public String getModelId() { | |
return this.modelId; | ||
} | ||
|
||
/** | ||
* Gets the parent InputLocation where this InputLocation may have been imported from. | ||
* Can return {@code null}. | ||
* | ||
* @return InputLocation | ||
* @since 4.0.0 | ||
*/ | ||
public InputLocation getImportedFrom() { | ||
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. same |
||
return importedFrom; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
|
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
124 changes: 124 additions & 0 deletions
124
...st/java/org/apache/maven/internal/impl/model/DefaultDependencyManagementImporterTest.java
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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.maven.internal.impl.model; | ||
|
||
import org.apache.maven.api.model.Dependency; | ||
import org.apache.maven.api.model.DependencyManagement; | ||
import org.apache.maven.api.model.InputLocation; | ||
import org.apache.maven.api.model.InputSource; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class DefaultDependencyManagementImporterTest { | ||
@Test | ||
void testUpdateWithImportedFrom_dependencyLocationAndBomLocationAreNull_dependencyReturned() { | ||
final Dependency dependency = Dependency.newBuilder().build(); | ||
final DependencyManagement depMgmt = DependencyManagement.newBuilder().build(); | ||
final Dependency result = DefaultDependencyManagementImporter.updateWithImportedFrom(dependency, depMgmt); | ||
|
||
assertThat(dependency).isEqualTo(result); | ||
} | ||
|
||
@Test | ||
void testUpdateWithImportedFrom_dependencyManagementAndDependencyHaveSameSource_dependencyImportedFromSameSource() { | ||
final InputSource source = new InputSource("SINGLE_SOURCE", ""); | ||
final Dependency dependency = Dependency.newBuilder() | ||
.location("", new InputLocation(1, 1, source)) | ||
.build(); | ||
final DependencyManagement bom = DependencyManagement.newBuilder() | ||
.location("", new InputLocation(1, 1, source)) | ||
.build(); | ||
|
||
final Dependency result = DefaultDependencyManagementImporter.updateWithImportedFrom(dependency, bom); | ||
|
||
assertThat(result).isNotNull(); | ||
assertThat(result.getImportedFrom().toString()) | ||
.isEqualTo(bom.getLocation("").toString()); | ||
} | ||
|
||
@Test | ||
public void testUpdateWithImportedFrom_singleLevel_importedFromSet() { | ||
// Arrange | ||
final InputSource dependencySource = new InputSource("DEPENDENCY", "DEPENDENCY"); | ||
final InputSource bomSource = new InputSource("BOM", "BOM"); | ||
final Dependency dependency = Dependency.newBuilder() | ||
.location("", new InputLocation(1, 1, dependencySource)) | ||
.build(); | ||
final DependencyManagement bom = DependencyManagement.newBuilder() | ||
.location("", new InputLocation(2, 2, bomSource)) | ||
.build(); | ||
|
||
// Act | ||
final Dependency result = DefaultDependencyManagementImporter.updateWithImportedFrom(dependency, bom); | ||
|
||
// Assert | ||
assertThat(result).isNotNull(); | ||
assertThat(result.getImportedFrom().toString()) | ||
.isEqualTo(bom.getLocation("").toString()); | ||
} | ||
|
||
@Test | ||
public void testUpdateWithImportedFrom_multiLevel_importedFromSetChanged() { | ||
// Arrange | ||
final InputSource bomSource = new InputSource("BOM", "BOM"); | ||
final InputSource intermediateSource = | ||
new InputSource("INTERMEDIATE", "INTERMEDIATE", new InputLocation(bomSource)); | ||
final InputSource dependencySource = | ||
new InputSource("DEPENDENCY", "DEPENDENCY", new InputLocation(intermediateSource)); | ||
final InputLocation bomLocation = new InputLocation(2, 2, bomSource); | ||
final Dependency dependency = Dependency.newBuilder() | ||
.location("", new InputLocation(1, 1, dependencySource)) | ||
.importedFrom(bomLocation) | ||
.build(); | ||
final DependencyManagement bom = | ||
DependencyManagement.newBuilder().location("", bomLocation).build(); | ||
|
||
// Act | ||
final Dependency result = DefaultDependencyManagementImporter.updateWithImportedFrom(dependency, bom); | ||
|
||
// Assert | ||
assertThat(result.getImportedFrom().toString()) | ||
.isEqualTo(bom.getLocation("").toString()); | ||
} | ||
|
||
@Test | ||
public void testUpdateWithImportedFrom_multiLevelAlreadyFoundInDifferentSource_importedFromSetMaintained() { | ||
// Arrange | ||
final InputSource bomSource = new InputSource("BOM", "BOM"); | ||
final InputSource intermediateSource = | ||
new InputSource("INTERMEDIATE", "INTERMEDIATE", new InputLocation(bomSource)); | ||
final InputSource dependencySource = | ||
new InputSource("DEPENDENCY", "DEPENDENCY", new InputLocation(intermediateSource)); | ||
final Dependency dependency = Dependency.newBuilder() | ||
.location("", new InputLocation(1, 1, dependencySource)) | ||
.build(); | ||
final DependencyManagement differentSource = DependencyManagement.newBuilder() | ||
.location("", new InputLocation(2, 2, new InputSource("BOM2", "BOM2"))) | ||
.build(); | ||
|
||
// Act | ||
final Dependency result = | ||
DefaultDependencyManagementImporter.updateWithImportedFrom(dependency, differentSource); | ||
|
||
// Assert | ||
assertThat(result.getImportedFrom().toString()) | ||
.isEqualTo(differentSource.getLocation("").toString()); | ||
} | ||
} |
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
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.
we need an
@since
here to rememberThere 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.
"that caused this model to be read."?
I need to dig more into code to propose another description, but this one is not clear