Clean up getPluginTransitiveDependencies() 34/104634/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 28 Feb 2023 23:32:19 +0000 (00:32 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 28 Feb 2023 23:33:48 +0000 (00:33 +0100)
Allocate the return map inside the method, reducing the number of
arguments and actually returining it.

Change-Id: I482251d2abd353ece9386040acfe614bce70d582
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/Util.java

index 15855c7515918d2cc0d87ac2d2cc17f2e707c979..20dd43ca806d72aa9838eff474940c72d072305f 100644 (file)
@@ -54,11 +54,8 @@ final class Util {
             return;
         }
 
-        final var pluginDependencies = new HashMap<Artifact, Set<Artifact>>();
-        getPluginTransitiveDependencies(plugin, pluginDependencies, repoSystem, localRepo, remoteRepos);
-
         final var projectDependencies = project.getDependencyArtifacts();
-        for (var entry : pluginDependencies.entrySet()) {
+        for (var entry : getPluginTransitiveDependencies(plugin, repoSystem, localRepo, remoteRepos).entrySet()) {
             checkArtifact(entry.getKey(), projectDependencies);
             for (var dependency : entry.getValue()) {
                 checkArtifact(dependency, projectDependencies);
@@ -70,14 +67,15 @@ final class Util {
      * Read transitive dependencies of given plugin and store them in map.
      *
      * @param plugin plugin to read
-     * @param map map, where founded transitive dependencies will be stored
      * @param repoSystem repository system
      * @param localRepository local repository
      * @param remoteRepos list of remote repositories
+     * @return a Map of transitive dependencies
      */
-    private static void getPluginTransitiveDependencies(final Plugin plugin,
-            final Map<Artifact, Set<Artifact>> map, final RepositorySystem repoSystem,
-            final ArtifactRepository localRepository, final List<ArtifactRepository> remoteRepos) {
+    private static Map<Artifact, Set<Artifact>> getPluginTransitiveDependencies(final Plugin plugin,
+            final RepositorySystem repoSystem, final ArtifactRepository localRepository,
+            final List<ArtifactRepository> remoteRepos) {
+        final var ret = new HashMap<Artifact, Set<Artifact>>();
         for (var dep : plugin.getDependencies()) {
             final var artifact = repoSystem.createDependencyArtifact(dep);
 
@@ -87,19 +85,17 @@ final class Util {
             request.setLocalRepository(localRepository);
             request.setRemoteRepositories(remoteRepos);
 
-            map.put(artifact, repoSystem.resolve(request).getArtifacts());
+            ret.put(artifact, repoSystem.resolve(request).getArtifacts());
         }
+        return ret;
     }
 
     /**
-     * Check artifact against collection of dependencies. If collection contains
-     * artifact with same groupId and artifactId, but different version, logs a
-     * warning.
+     * Check artifact against collection of dependencies. If collection contains artifact with same groupId and
+     * artifactId, but different version, logs a warning.
      *
-     * @param artifact
-     *            artifact to check
-     * @param dependencies
-     *            collection of dependencies
+     * @param artifact artifact to check
+     * @param dependencies collection of dependencies
      */
     private static void checkArtifact(final Artifact artifact, final Set<Artifact> dependencies) {
         for (var dep : dependencies) {