You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2019/03/23 08:21:16 UTC

[maven-dependency-plugin] branch IMPROVED_CODE updated: - Refactored code.

This is an automated email from the ASF dual-hosted git repository.

khmarbaise pushed a commit to branch IMPROVED_CODE
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git


The following commit(s) were added to refs/heads/IMPROVED_CODE by this push:
     new 8c6cff0  - Refactored code.
8c6cff0 is described below

commit 8c6cff065eef78377c9f599fc03e3a917c750a5e
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Sat Mar 23 09:21:06 2019 +0100

    - Refactored code.
---
 .../dependency/analyze/AnalyzeDuplicateMojo.java   | 58 ++++++++++------------
 1 file changed, 25 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java
index 09e5ea6..183c9e5 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java
@@ -50,6 +50,8 @@ import org.codehaus.plexus.util.ReaderFactory;
 public class AnalyzeDuplicateMojo
     extends AbstractMojo
 {
+    public static final String MESSAGE_DUPLICATE_DEP_IN_DEPENDENCIES = "List of duplicate dependencies defined in <dependencies/> in your pom.xml:\n";
+    public static final String MESSAGE_DUPLICATE_DEP_IN_DEPMGMT = "List of duplicate dependencies defined in <dependencyManagement/> in your pom.xml:\n";
     /**
      * Skip plugin execution completely.
      *
@@ -113,39 +115,8 @@ public class AnalyzeDuplicateMojo
         {
             StringBuilder sb = new StringBuilder();
 
-            if ( !duplicateDependencies.isEmpty() )
-            {
-                sb.append( "List of duplicate dependencies defined in <dependencies/> in your pom.xml:\n" );
-                for ( Iterator<String> it = duplicateDependencies.iterator(); it.hasNext(); )
-                {
-                    String dup = it.next();
-
-                    sb.append( "\to " ).append( dup );
-                    if ( it.hasNext() )
-                    {
-                        sb.append( "\n" );
-                    }
-                }
-            }
-
-            if ( !duplicateDependenciesManagement.isEmpty() )
-            {
-                if ( sb.length() > 0 )
-                {
-                    sb.append( "\n" );
-                }
-                sb.append( "List of duplicate dependencies defined in <dependencyManagement/> in your pom.xml:\n" );
-                for ( Iterator<String> it = duplicateDependenciesManagement.iterator(); it.hasNext(); )
-                {
-                    String dup = it.next();
-
-                    sb.append( "\to " ).append( dup );
-                    if ( it.hasNext() )
-                    {
-                        sb.append( "\n" );
-                    }
-                }
-            }
+            createMessage(duplicateDependencies, sb, MESSAGE_DUPLICATE_DEP_IN_DEPENDENCIES);
+            createMessage(duplicateDependenciesManagement, sb, MESSAGE_DUPLICATE_DEP_IN_DEPMGMT);
 
             if ( sb.length() > 0 )
             {
@@ -158,6 +129,27 @@ public class AnalyzeDuplicateMojo
         }
     }
 
+    private void createMessage(Set<String> duplicateDependencies, StringBuilder sb, String messageDuplicateDepInDependencies) {
+        if ( !duplicateDependencies.isEmpty() )
+        {
+            if (sb.length() > 0)
+            {
+                sb.append("\n");
+            }
+            sb.append(messageDuplicateDepInDependencies);
+            for (Iterator<String> it = duplicateDependencies.iterator(); it.hasNext(); )
+            {
+                String dup = it.next();
+
+                sb.append( "\to " ).append( dup );
+                if ( it.hasNext() )
+                {
+                    sb.append( "\n" );
+                }
+            }
+        }
+    }
+
     private Set<String> findDuplicateDependencies( List<Dependency> modelDependencies )
     {
         List<String> modelDependencies2 = new ArrayList<String>();