You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2021/03/15 19:08:48 UTC
[maven-resolver] 01/03: [MRESOLVER-165] Add support for mirror
selector on external:http:*
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch 1.6.x_2
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
commit 85888c3f5e4b6b3fec205d8d8e72571b9071b9af
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Sat Mar 6 19:59:14 2021 +0100
[MRESOLVER-165] Add support for mirror selector on external:http:*
---
.../util/repository/DefaultMirrorSelector.java | 39 ++++++++++++++++++----
1 file changed, 33 insertions(+), 6 deletions(-)
diff --git a/maven-resolver-util/src/main/java/org/eclipse/aether/util/repository/DefaultMirrorSelector.java b/maven-resolver-util/src/main/java/org/eclipse/aether/util/repository/DefaultMirrorSelector.java
index 8ee2644..83acad4 100644
--- a/maven-resolver-util/src/main/java/org/eclipse/aether/util/repository/DefaultMirrorSelector.java
+++ b/maven-resolver-util/src/main/java/org/eclipse/aether/util/repository/DefaultMirrorSelector.java
@@ -37,6 +37,8 @@ public final class DefaultMirrorSelector
private static final String EXTERNAL_WILDCARD = "external:*";
+ private static final String EXTERNAL_HTTP_WILDCARD = "external:http:*";
+
private final List<MirrorDef> mirrors = new ArrayList<>();
/**
@@ -47,9 +49,9 @@ public final class DefaultMirrorSelector
* @param type The content type of the mirror, must not be {@code null}.
* @param repositoryManager A flag whether the mirror is a repository manager or a simple server.
* @param mirrorOfIds The identifier(s) of remote repositories to mirror, must not be {@code null}. Multiple
- * identifiers can be separated by comma and additionally the wildcards "*" and "external:*" can be used
- * to match all (external) repositories, prefixing a repo id with an exclamation mark allows to express
- * an exclusion. For example "external:*,!central".
+ * identifiers can be separated by comma and additionally the wildcards "*", "external:http:*" and
+ * "external:*" can be used to match all (external) repositories, prefixing a repo id with an
+ * exclamation mark allows to express an exclusion. For example "external:*,!central".
* @param mirrorOfTypes The content type(s) of remote repositories to mirror, may be {@code null} or empty to match
* any content type. Similar to the repo id specification, multiple types can be comma-separated, the
* wildcard "*" and the "!" negation syntax are supported. For example "*,!p2".
@@ -123,6 +125,7 @@ public final class DefaultMirrorSelector
* <ul>
* <li>{@code *} = everything,</li>
* <li>{@code external:*} = everything not on the localhost and not file based,</li>
+ * <li>{@code external:http:*} = any repository not on the localhost using HTTP,</li>
* <li>{@code repo,repo1} = {@code repo} or {@code repo1},</li>
* <li>{@code *,!repo1} = everything except {@code repo1}.</li>
* </ul>
@@ -169,6 +172,12 @@ public final class DefaultMirrorSelector
result = true;
// don't stop processing in case a future segment explicitly excludes this repo
}
+ // check for external:http:*
+ else if ( EXTERNAL_HTTP_WILDCARD.equals( repo ) && isExternalHttpRepo( repository ) )
+ {
+ result = true;
+ // don't stop processing in case a future segment explicitly excludes this repo
+ }
else if ( WILDCARD.equals( repo ) )
{
result = true;
@@ -187,12 +196,30 @@ public final class DefaultMirrorSelector
*/
static boolean isExternalRepo( RemoteRepository repository )
{
- boolean local =
- "localhost".equals( repository.getHost() ) || "127.0.0.1".equals( repository.getHost() )
- || "file".equalsIgnoreCase( repository.getProtocol() );
+ boolean local = isLocal( repository.getHost() ) || "file".equalsIgnoreCase( repository.getProtocol() );
return !local;
}
+ private static boolean isLocal( String host )
+ {
+ return "localhost".equals( host ) || "127.0.0.1".equals( host );
+ }
+
+ /**
+ * Checks the URL to see if this repository refers to a non-localhost repository using HTTP.
+ *
+ * @param repository The repository to check, must not be {@code null}.
+ * @return {@code true} if external, {@code false} otherwise.
+ */
+ static boolean isExternalHttpRepo( RemoteRepository repository )
+ {
+ return ( "http".equalsIgnoreCase( repository.getProtocol() )
+ || "dav".equalsIgnoreCase( repository.getProtocol() )
+ || "dav:http".equalsIgnoreCase( repository.getProtocol() )
+ || "dav+http".equalsIgnoreCase( repository.getProtocol() ) )
+ && !isLocal( repository.getHost() );
+ }
+
/**
* Checks whether the types configured for a mirror match with the type of the repository.
*