You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2015/04/04 14:01:37 UTC

maven git commit: [MNG-5794] Warn about Proxies with duplicate id, but different protocols Patch contributed by Thomas Meyer, verified by Robert Scholte

Repository: maven
Updated Branches:
  refs/heads/master da98af988 -> 874eaef72


[MNG-5794] Warn about Proxies with duplicate id, but different protocols
Patch contributed by Thomas Meyer, verified by Robert Scholte


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/874eaef7
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/874eaef7
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/874eaef7

Branch: refs/heads/master
Commit: 874eaef72543828be8f3bcc64799b94b3f390297
Parents: da98af9
Author: Robert Scholte <rf...@codehaus.org>
Authored: Sat Apr 4 14:00:59 2015 +0200
Committer: Robert Scholte <rf...@codehaus.org>
Committed: Sat Apr 4 14:00:59 2015 +0200

----------------------------------------------------------------------
 maven-settings-builder/pom.xml                  |  6 ++++
 .../validation/DefaultSettingsValidator.java    | 26 ++++++++++++---
 .../DefaultSettingsValidatorTest.java           | 33 ++++++++++++++++++++
 3 files changed, 61 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/874eaef7/maven-settings-builder/pom.xml
----------------------------------------------------------------------
diff --git a/maven-settings-builder/pom.xml b/maven-settings-builder/pom.xml
index ff4fcd4..7ca6081 100644
--- a/maven-settings-builder/pom.xml
+++ b/maven-settings-builder/pom.xml
@@ -39,6 +39,12 @@ under the License.
     <tag>HEAD</tag>
   </scm>
 
+  <contributors>
+    <contributor>
+      <name>Thomas Meyer</name>
+    </contributor>
+  </contributors>
+
   <dependencies>
     <dependency>
       <groupId>org.apache.maven</groupId>

http://git-wip-us.apache.org/repos/asf/maven/blob/874eaef7/maven-settings-builder/src/main/java/org/apache/maven/settings/validation/DefaultSettingsValidator.java
----------------------------------------------------------------------
diff --git a/maven-settings-builder/src/main/java/org/apache/maven/settings/validation/DefaultSettingsValidator.java b/maven-settings-builder/src/main/java/org/apache/maven/settings/validation/DefaultSettingsValidator.java
index aa4d303..b324711 100644
--- a/maven-settings-builder/src/main/java/org/apache/maven/settings/validation/DefaultSettingsValidator.java
+++ b/maven-settings-builder/src/main/java/org/apache/maven/settings/validation/DefaultSettingsValidator.java
@@ -26,6 +26,7 @@ import java.util.Set;
 import org.apache.maven.settings.Mirror;
 import org.apache.maven.settings.Profile;
 import org.apache.maven.settings.Repository;
+import org.apache.maven.settings.Proxy;
 import org.apache.maven.settings.Server;
 import org.apache.maven.settings.Settings;
 import org.apache.maven.settings.building.SettingsProblem.Severity;
@@ -141,6 +142,23 @@ public class DefaultSettingsValidator
                     + "pluginRepositories.pluginRepository" );
             }
         }
+
+        List<Proxy> proxies = settings.getProxies();
+
+        if ( proxies != null )
+        {
+            Set<String> proxyIds = new HashSet<String>();
+            
+            for ( Proxy proxy : proxies )
+            {
+                if ( !proxyIds.add( proxy.getId() ) )
+                {
+                    addViolation( problems, Severity.WARNING, "proxies.proxy.id", null,
+                                  "must be unique but found duplicate proxy with id " + proxy.getId() );
+                }
+                validateStringNotEmpty( problems, "proxies.proxy.host", proxy.getHost(), proxy.getId() );
+            }
+        }
     }
 
     private void validateRepositories( SettingsProblemCollector problems, List<Repository> repositories, String prefix )
@@ -189,7 +207,7 @@ public class DefaultSettingsValidator
      * <li><code>string.length > 0</code>
      * </ul>
      */
-    private boolean validateStringNotEmpty( SettingsProblemCollector problems, String fieldName, String string,
+    private static boolean validateStringNotEmpty( SettingsProblemCollector problems, String fieldName, String string,
                                             String sourceHint )
     {
         if ( !validateNotNull( problems, fieldName, string, sourceHint ) )
@@ -214,7 +232,7 @@ public class DefaultSettingsValidator
      * <li><code>string != null</code>
      * </ul>
      */
-    private boolean validateNotNull( SettingsProblemCollector problems, String fieldName, Object object,
+    private static boolean validateNotNull( SettingsProblemCollector problems, String fieldName, Object object,
                                      String sourceHint )
     {
         if ( object != null )
@@ -227,7 +245,7 @@ public class DefaultSettingsValidator
         return false;
     }
 
-    private boolean validateBannedCharacters( SettingsProblemCollector problems, String fieldName, Severity severity,
+    private static boolean validateBannedCharacters( SettingsProblemCollector problems, String fieldName, Severity severity,
                                               String string, String sourceHint, String banned )
     {
         if ( string != null )
@@ -247,7 +265,7 @@ public class DefaultSettingsValidator
         return true;
     }
 
-    private void addViolation( SettingsProblemCollector problems, Severity severity, String fieldName,
+    private static void addViolation( SettingsProblemCollector problems, Severity severity, String fieldName,
                                String sourceHint, String message )
     {
         StringBuilder buffer = new StringBuilder( 256 );

http://git-wip-us.apache.org/repos/asf/maven/blob/874eaef7/maven-settings-builder/src/test/java/org/apache/maven/settings/validation/DefaultSettingsValidatorTest.java
----------------------------------------------------------------------
diff --git a/maven-settings-builder/src/test/java/org/apache/maven/settings/validation/DefaultSettingsValidatorTest.java b/maven-settings-builder/src/test/java/org/apache/maven/settings/validation/DefaultSettingsValidatorTest.java
index fe6988b..8c7f21d 100644
--- a/maven-settings-builder/src/test/java/org/apache/maven/settings/validation/DefaultSettingsValidatorTest.java
+++ b/maven-settings-builder/src/test/java/org/apache/maven/settings/validation/DefaultSettingsValidatorTest.java
@@ -26,6 +26,7 @@ import junit.framework.TestCase;
 
 import org.apache.maven.settings.Mirror;
 import org.apache.maven.settings.Profile;
+import org.apache.maven.settings.Proxy;
 import org.apache.maven.settings.Repository;
 import org.apache.maven.settings.Server;
 import org.apache.maven.settings.Settings;
@@ -195,6 +196,38 @@ public class DefaultSettingsValidatorTest
             + " but found duplicate repository with id test" );
     }
 
+    public void testValidateUniqueProxyId()
+        throws Exception
+    {
+        Settings settings = new Settings();
+        Proxy proxy = new Proxy();
+        String id = null;
+        proxy.setId( id );
+        proxy.setHost("www.example.com");
+        settings.addProxy( proxy );
+        settings.addProxy( proxy );
+
+        SimpleProblemCollector problems = new SimpleProblemCollector();
+        validator.validate( settings, problems );
+        assertEquals( 1, problems.messages.size() );
+        assertContains( problems.messages.get( 0 ), "'proxies.proxy.id' must be unique"
+            + " but found duplicate proxy with id " + id );
+
+    }
+
+    public void testValidateProxy()
+        throws Exception
+    {
+        Settings settings = new Settings();
+        Proxy proxy1 = new Proxy();
+        settings.addProxy( proxy1 );
+
+        SimpleProblemCollector problems = new SimpleProblemCollector();
+        validator.validate( settings, problems );
+        assertEquals( 1, problems.messages.size() );
+        assertContains( problems.messages.get( 0 ), "'proxies.proxy.host' for default is missing" );
+    }
+
     private static class SimpleProblemCollector
         implements SettingsProblemCollector
     {