@@ -41,6 +41,8 @@ public class DefaultMirrorSelector
4141
4242    private  static  final  String  EXTERNAL_WILDCARD  = "external:*" ;
4343
44+     private  static  final  String  EXTERNAL_HTTP_WILDCARD  = "external:http:*" ;
45+ 
4446    public  Mirror  getMirror ( ArtifactRepository  repository , List <Mirror > mirrors  )
4547    {
4648        String  repoId  = repository .getId ();
@@ -68,9 +70,14 @@ public Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors )
6870    }
6971
7072    /** 
71-      * This method checks if the pattern matches the originalRepository. Valid patterns: * = 
72-      * everything external:* = everything not on the localhost and not file based. repo,repo1 = repo 
73-      * or repo1 *,!repo1 = everything except repo1 
73+      * This method checks if the pattern matches the originalRepository. Valid patterns: 
74+      * <ul> 
75+      * <li>{@code *} = everything,</li> 
76+      * <li>{@code external:*} = everything not on the localhost and not file based,</li> 
77+      * <li>{@code external:http:*} = any repository not on the localhost using HTTP,</li> 
78+      * <li>{@code repo,repo1} = {@code repo} or {@code repo1},</li> 
79+      * <li>{@code *,!repo1} = everything except {@code repo1}.</li> 
80+      * </ul> 
7481     * 
7582     * @param originalRepository to compare for a match. 
7683     * @param pattern used for match. Currently only '*' is supported. 
@@ -115,6 +122,12 @@ else if ( EXTERNAL_WILDCARD.equals( repo ) && isExternalRepo( originalRepository
115122                    result  = true ;
116123                    // don't stop processing in case a future segment explicitly excludes this repo 
117124                }
125+                 // check for external:http:* 
126+                 else  if  ( EXTERNAL_HTTP_WILDCARD .equals ( repo  ) && isExternalHttpRepo ( originalRepository  ) )
127+                 {
128+                     result  = true ;
129+                     // don't stop processing in case a future segment explicitly excludes this repo 
130+                 }
118131                else  if  ( WILDCARD .equals ( repo  ) )
119132                {
120133                    result  = true ;
@@ -136,8 +149,34 @@ static boolean isExternalRepo( ArtifactRepository originalRepository )
136149        try 
137150        {
138151            URL  url  = new  URL ( originalRepository .getUrl () );
139-             return  !( url .getHost ().equals ( "localhost"  ) || url .getHost ().equals ( "127.0.0.1"  )
140-                             || url .getProtocol ().equals ( "file"  ) );
152+             return  !( isLocal ( url .getHost () ) || url .getProtocol ().equals ( "file"  ) );
153+         }
154+         catch  ( MalformedURLException  e  )
155+         {
156+             // bad url just skip it here. It should have been validated already, but the wagon lookup will deal with it 
157+             return  false ;
158+         }
159+     }
160+ 
161+     private  static  boolean  isLocal ( String  host  )
162+     {
163+         return  "localhost" .equals ( host  ) || "127.0.0.1" .equals ( host  );
164+     }
165+ 
166+     /** 
167+      * Checks the URL to see if this repository refers to a non-localhost repository using HTTP. 
168+      * 
169+      * @param originalRepository 
170+      * @return true if external. 
171+      */ 
172+     static  boolean  isExternalHttpRepo ( ArtifactRepository  originalRepository  )
173+     {
174+         try 
175+         {
176+             URL  url  = new  URL ( originalRepository .getUrl () );
177+             return  ( "http" .equalsIgnoreCase ( url .getProtocol () ) || "dav" .equalsIgnoreCase ( url .getProtocol () )
178+                 || "dav:http" .equalsIgnoreCase ( url .getProtocol () )
179+                 || "dav+http" .equalsIgnoreCase ( url .getProtocol () ) ) && !isLocal ( url .getHost () );
141180        }
142181        catch  ( MalformedURLException  e  )
143182        {
@@ -146,7 +185,7 @@ static boolean isExternalRepo( ArtifactRepository originalRepository )
146185        }
147186    }
148187
149-      static  boolean  matchesLayout ( ArtifactRepository  repository , Mirror  mirror  )
188+    static  boolean  matchesLayout ( ArtifactRepository  repository , Mirror  mirror  )
150189    {
151190        return  matchesLayout ( RepositoryUtils .getLayout ( repository  ), mirror .getMirrorOfLayouts () );
152191    }
0 commit comments