@@ -41,6 +41,8 @@ public class DefaultMirrorSelector
41
41
42
42
private static final String EXTERNAL_WILDCARD = "external:*" ;
43
43
44
+ private static final String EXTERNAL_HTTP_WILDCARD = "external:http:*" ;
45
+
44
46
public Mirror getMirror ( ArtifactRepository repository , List <Mirror > mirrors )
45
47
{
46
48
String repoId = repository .getId ();
@@ -68,9 +70,14 @@ public Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors )
68
70
}
69
71
70
72
/**
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>
74
81
*
75
82
* @param originalRepository to compare for a match.
76
83
* @param pattern used for match. Currently only '*' is supported.
@@ -115,6 +122,12 @@ else if ( EXTERNAL_WILDCARD.equals( repo ) && isExternalRepo( originalRepository
115
122
result = true ;
116
123
// don't stop processing in case a future segment explicitly excludes this repo
117
124
}
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
+ }
118
131
else if ( WILDCARD .equals ( repo ) )
119
132
{
120
133
result = true ;
@@ -136,8 +149,34 @@ static boolean isExternalRepo( ArtifactRepository originalRepository )
136
149
try
137
150
{
138
151
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 () );
141
180
}
142
181
catch ( MalformedURLException e )
143
182
{
@@ -146,7 +185,7 @@ static boolean isExternalRepo( ArtifactRepository originalRepository )
146
185
}
147
186
}
148
187
149
- static boolean matchesLayout ( ArtifactRepository repository , Mirror mirror )
188
+ static boolean matchesLayout ( ArtifactRepository repository , Mirror mirror )
150
189
{
151
190
return matchesLayout ( RepositoryUtils .getLayout ( repository ), mirror .getMirrorOfLayouts () );
152
191
}
0 commit comments