-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring: MavenDependencyMediation with AnnotatedClassPath (#2013)
* Refactoring: AnnotatedClassPath to replace ListMultimap * format * Clarified classifier or extension * Applied review
- Loading branch information
Showing
12 changed files
with
264 additions
and
86 deletions.
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
74 changes: 74 additions & 0 deletions
74
...dencies/src/main/java/com/google/cloud/tools/opensource/classpath/AnnotatedClassPath.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,74 @@ | ||
/* | ||
* Copyright 2021 Google LLC. | ||
* | ||
* Licensed 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 com.google.cloud.tools.opensource.classpath; | ||
|
||
import com.google.cloud.tools.opensource.dependencies.DependencyPath; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.LinkedListMultimap; | ||
import com.google.common.collect.ListMultimap; | ||
|
||
/** | ||
* A class path that consists of a list of artifacts, each of which is annotated with dependency | ||
* paths. The dependency paths tell where an artifact appears in the dependency graph. Note that the | ||
* same artifact (having the same groupId, artifactId, and version) may appear in a graph multiple | ||
* times. | ||
*/ | ||
public class AnnotatedClassPath { | ||
|
||
/** | ||
* An ordered map from class path elements to one or more Maven dependency paths. | ||
* | ||
* <p>The keys of the returned map represent Maven artifacts in the resolved class path, including | ||
* transitive dependencies. The return value of {@link LinkedListMultimap#keySet()} preserves key | ||
* iteration order. | ||
* | ||
* <p>The values of the returned map for a key (class path entry) represent the different | ||
* dependency paths from {@code artifacts} to the Maven artifact. | ||
*/ | ||
private LinkedListMultimap<ClassPathEntry, DependencyPath> classPathEntryToDependencyPaths = | ||
LinkedListMultimap.create(); | ||
|
||
/** | ||
* Adds {@code classPathEntry} with {@code dependencyPath}. The dependency path represents a path | ||
* from the root of the dependency graph to the artifact. | ||
*/ | ||
public void put(ClassPathEntry classPathEntry, DependencyPath dependencyPath) { | ||
classPathEntryToDependencyPaths.put(classPathEntry, dependencyPath); | ||
} | ||
|
||
ImmutableList<ClassPathEntry> getClassPath() { | ||
// LinkedListMultimap.keySet preserves the iteration order | ||
return ImmutableList.copyOf(classPathEntryToDependencyPaths.keySet()); | ||
} | ||
|
||
ImmutableList<DependencyPath> pathsTo(ClassPathEntry classPathEntry) { | ||
return ImmutableList.copyOf(classPathEntryToDependencyPaths.get(classPathEntry)); | ||
} | ||
|
||
/** | ||
* Returns an {@link AnnotatedClassPath} that has class path entry and dependency paths | ||
* relationship represented in {@code classPathEntryToDependencyPaths}. | ||
*/ | ||
@VisibleForTesting | ||
public static AnnotatedClassPath fromMultimap( | ||
ListMultimap<ClassPathEntry, DependencyPath> classPathEntryToDependencyPaths) { | ||
AnnotatedClassPath annotatedClassPath = new AnnotatedClassPath(); | ||
annotatedClassPath.classPathEntryToDependencyPaths.putAll(classPathEntryToDependencyPaths); | ||
return annotatedClassPath; | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...encies/src/main/java/com/google/cloud/tools/opensource/classpath/DependencyMediation.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,37 @@ | ||
/* | ||
* Copyright 2021 Google LLC. | ||
* | ||
* Licensed 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 com.google.cloud.tools.opensource.classpath; | ||
|
||
import com.google.cloud.tools.opensource.dependencies.DependencyGraph; | ||
|
||
/** | ||
* 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. | ||
*/ | ||
public interface DependencyMediation { | ||
/** | ||
* Returns {@link AnnotatedClassPath} after performing dependency mediation. This means that the | ||
* returned list of class path entries has no duplicate artifacts in terms of the groupId and | ||
* artifactId combination. | ||
* | ||
* @param dependencyGraph dependency graph that may have duplicate artifacts that have the same | ||
* groupId and artifactId combination | ||
*/ | ||
AnnotatedClassPath mediate(DependencyGraph dependencyGraph); | ||
} |
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.