You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2021/03/14 19:55:16 UTC
[maven] 02/04: [MNG-7116] add support for mirrorOf external:http:*
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to branch MNG-7118
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 5c5e71693978e2de7f4d1825d5eae7a4c09c0196
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Sat Mar 13 18:40:48 2021 +0100
[MNG-7116] add support for mirrorOf external:http:*
---
.../maven/repository/DefaultMirrorSelector.java | 41 ++++++++++++++++++++--
.../apache/maven/bridge/MavenRepositorySystem.java | 39 ++++++++++++++++++--
2 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java b/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java
index 1135c07..5c176e6 100644
--- a/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java
+++ b/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java
@@ -41,6 +41,8 @@ public class DefaultMirrorSelector
private static final String EXTERNAL_WILDCARD = "external:*";
+ private static final String EXTERNAL_HTTP_WILDCARD = "external:http:*";
+
public Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors )
{
String repoId = repository.getId();
@@ -72,6 +74,7 @@ public 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>
@@ -119,6 +122,12 @@ public 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( originalRepository ) )
+ {
+ result = true;
+ // don't stop processing in case a future segment explicitly excludes this repo
+ }
else if ( WILDCARD.equals( repo ) )
{
result = true;
@@ -140,8 +149,34 @@ public class DefaultMirrorSelector
try
{
URL url = new URL( originalRepository.getUrl() );
- return !( url.getHost().equals( "localhost" ) || url.getHost().equals( "127.0.0.1" )
- || url.getProtocol().equals( "file" ) );
+ return !( isLocal( url.getHost() ) || url.getProtocol().equals( "file" ) );
+ }
+ catch ( MalformedURLException e )
+ {
+ // bad url just skip it here. It should have been validated already, but the wagon lookup will deal with it
+ return false;
+ }
+ }
+
+ 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 originalRepository
+ * @return true if external.
+ */
+ static boolean isExternalHttpRepo( ArtifactRepository originalRepository )
+ {
+ try
+ {
+ URL url = new URL( originalRepository.getUrl() );
+ return ( "http".equalsIgnoreCase( url.getProtocol() ) || "dav".equalsIgnoreCase( url.getProtocol() )
+ || "dav:http".equalsIgnoreCase( url.getProtocol() )
+ || "dav+http".equalsIgnoreCase( url.getProtocol() ) ) && !isLocal( url.getHost() );
}
catch ( MalformedURLException e )
{
@@ -150,7 +185,7 @@ public class DefaultMirrorSelector
}
}
- static boolean matchesLayout( ArtifactRepository repository, Mirror mirror )
+ static boolean matchesLayout( ArtifactRepository repository, Mirror mirror )
{
return matchesLayout( RepositoryUtils.getLayout( repository ), mirror.getMirrorOfLayouts() );
}
diff --git a/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java b/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java
index b37a0ec..e37db04 100644
--- a/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java
+++ b/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java
@@ -713,6 +713,8 @@ public class MavenRepositorySystem
private static final String EXTERNAL_WILDCARD = "external:*";
+ private static final String EXTERNAL_HTTP_WILDCARD = "external:http:*";
+
public static Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors )
{
String repoId = repository.getId();
@@ -744,6 +746,7 @@ public class MavenRepositorySystem
* <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>
@@ -790,6 +793,12 @@ public class MavenRepositorySystem
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( originalRepository ) )
+ {
+ result = true;
+ // don't stop processing in case a future segment explicitly excludes this repo
+ }
else if ( WILDCARD.equals( repo ) )
{
result = true;
@@ -811,8 +820,34 @@ public class MavenRepositorySystem
try
{
URL url = new URL( originalRepository.getUrl() );
- return !( url.getHost().equals( "localhost" ) || url.getHost().equals( "127.0.0.1" )
- || url.getProtocol().equals( "file" ) );
+ return !( isLocal( url.getHost() ) || url.getProtocol().equals( "file" ) );
+ }
+ catch ( MalformedURLException e )
+ {
+ // bad url just skip it here. It should have been validated already, but the wagon lookup will deal with it
+ return false;
+ }
+ }
+
+ 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 originalRepository
+ * @return true if external.
+ */
+ static boolean isExternalHttpRepo( ArtifactRepository originalRepository )
+ {
+ try
+ {
+ URL url = new URL( originalRepository.getUrl() );
+ return ( "http".equalsIgnoreCase( url.getProtocol() ) || "dav".equalsIgnoreCase( url.getProtocol() )
+ || "dav:http".equalsIgnoreCase( url.getProtocol() )
+ || "dav+http".equalsIgnoreCase( url.getProtocol() ) ) && !isLocal( url.getHost() );
}
catch ( MalformedURLException e )
{