Skip to content
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

Refactoring: MavenDependencyMediation with AnnotatedClassPath #2013

Merged
merged 5 commits into from
Apr 8, 2021

Conversation

suztomo
Copy link
Contributor

@suztomo suztomo commented Apr 7, 2021

This is a refactoring bofore implementing GradleDependencyMediation. This PR has no behavior change.

@google-cla google-cla bot added the cla: yes label Apr 7, 2021
@suztomo suztomo changed the title MavenDependencyMediation with AnnotatedClassPath Refactoring: MavenDependencyMediation with AnnotatedClassPath Apr 7, 2021
import com.google.cloud.tools.opensource.dependencies.DependencyGraph;

/**
* Algorithm to select artifacts when there are multiple versions for the same groupId and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about classifiers and types?

Copy link
Contributor Author

@suztomo suztomo Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified in the next paragraph. This doesn't read them.

Comment on lines -38 to 40
boolean selects(Artifact artifact) {
private boolean selects(Artifact artifact) {
return artifacts.contains(artifact);
}

void put(DependencyPath dependencyPath) {
private void put(DependencyPath dependencyPath) {
Artifact artifact = dependencyPath.getLeaf();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method put and selects assumed how they are called when traversing dependency graph. Because the call order was not applicable to Gradle, I didn't choose them as DependencyMediation's interface method.

* @param dependencyGraph dependency graph that may have duplicate artifacts that have the same
* groupId and artifactId combination
*/
AnnotatedClassPath mediate(DependencyGraph dependencyGraph);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface should work both Maven and Gradle.

new ClassPathResult(LinkedListMultimap.create(), ImmutableList.of()),
new ClassPathResult(new AnnotatedClassPath(), ImmutableList.of()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing obscure LinkedListMultimap in favor of AnnotatedClassPath, which deliver meaning in its name.

for (DependencyPath dependencyPath : dependencyPaths) {
Artifact artifact = dependencyPath.getLeaf();
mediation.put(dependencyPath);
if (mediation.selects(artifact)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has moved to MavenDependencyMediation. The logic of calling selects and put are too Maven specific; Gradle needs to select artifacts after visiting all nodes in the graph.

Comment on lines -47 to +34
private final ImmutableListMultimap<ClassPathEntry, DependencyPath> dependencyPaths;
private final AnnotatedClassPath annotatedClassPath;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The meaning of the variable with now clearer with more concrete type.

import com.google.cloud.tools.opensource.dependencies.DependencyGraph;

/**
* Algorithm to select artifacts when there are multiple versions for the same groupId and
Copy link
Contributor Author

@suztomo suztomo Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified in the next paragraph. This doesn't read them.

@@ -21,6 +21,8 @@
/**
* Algorithm to select artifacts when there are multiple versions for the same groupId and
* artifactId in a dependency graph.
*
* <p>The algorithm does not take classifier or extension into account.</p>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memo: Maven coordinates has <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version> format.

https://maven.apache.org/resolver/apidocs/org/eclipse/aether/artifact/DefaultArtifact.html#DefaultArtifact-java.lang.String-

@suztomo
Copy link
Contributor Author

suztomo commented Apr 7, 2021

@elharo PTAL

return ImmutableList.copyOf(classPathEntryToDependencyPaths.keySet());
}

ImmutableList<DependencyPath> dependencyPathOf(ClassPathEntry classPathEntry) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but feels like this maybe should be plural. I.e. I misread this when I first read it. Maybe pathsTo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to pathsTo. Thank you.

* Returns an {@link AnnotatedClassPath} that has class path entry and dependency paths
* relationship represented in {@code classPathEntryToDependencyPaths}.
*/
public static AnnotatedClassPath fromMultimap(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to only be used by tests. Maybe non-public and/or visible for testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added @VisibleForTesting.

@suztomo suztomo merged commit b054683 into master Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants