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 18:29:29 UTC

[maven-resolver] branch master updated (9b829bb -> 17c2a90)

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git.


    from 9b829bb  Update Wagon to latest release 3.4.3
     new 41144bf  [MRESOLVER-165] add support for mirrorOf external:http:*
     new 17c2a90  [MRESOLVER-166] add support for blocked repository/mirror

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../aether/repository/RemoteRepository.java        | 38 +++++++++++++-
 .../internal/impl/DefaultArtifactResolver.java     | 14 +++++
 .../util/repository/DefaultMirrorSelector.java     | 60 ++++++++++++++++++----
 3 files changed, 101 insertions(+), 11 deletions(-)


[maven-resolver] 02/02: [MRESOLVER-166] add support for blocked repository/mirror

Posted by hb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git

commit 17c2a90775f5486bb081d210fb0df5d2862aaefb
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Sun Mar 7 08:48:37 2021 +0100

    [MRESOLVER-166] add support for blocked repository/mirror
---
 .../aether/repository/RemoteRepository.java        | 38 +++++++++++++++++++++-
 .../internal/impl/DefaultArtifactResolver.java     | 14 ++++++++
 .../util/repository/DefaultMirrorSelector.java     | 21 +++++++++---
 3 files changed, 68 insertions(+), 5 deletions(-)

diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RemoteRepository.java b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RemoteRepository.java
index eb57588..73403c5 100644
--- a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RemoteRepository.java
+++ b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RemoteRepository.java
@@ -61,6 +61,8 @@ public final class RemoteRepository
 
     private final boolean repositoryManager;
 
+    private boolean blocked;
+
     RemoteRepository( Builder builder )
     {
         if ( builder.prototype != null )
@@ -78,6 +80,7 @@ public final class RemoteRepository
             repositoryManager =
                 ( builder.delta & Builder.REPOMAN ) != 0 ? builder.repositoryManager
                                 : builder.prototype.repositoryManager;
+            blocked = ( builder.delta & Builder.BLOCKED ) != 0 ? builder.blocked : builder.prototype.blocked;
             mirroredRepositories =
                 ( builder.delta & Builder.MIRRORED ) != 0 ? copy( builder.mirroredRepositories )
                                 : builder.prototype.mirroredRepositories;
@@ -92,6 +95,7 @@ public final class RemoteRepository
             proxy = builder.proxy;
             authentication = builder.authentication;
             repositoryManager = builder.repositoryManager;
+            blocked = builder.blocked;
             mirroredRepositories = copy( builder.mirroredRepositories );
         }
 
@@ -210,6 +214,16 @@ public final class RemoteRepository
         return repositoryManager;
     }
 
+    /**
+     * Indicates whether this repository is blocked against any download request.
+     * 
+     * @return {@code true} if this repository is blocked against any download request, {@code false} otherwise.
+     */
+    public boolean isBlocked()
+    {
+        return blocked;
+    }
+
     @Override
     public String toString()
     {
@@ -238,6 +252,10 @@ public final class RemoteRepository
         {
             buffer.append( ", managed" );
         }
+        if ( isBlocked() )
+        {
+            buffer.append( ", blocked" );
+        }
         buffer.append( ")" );
         return buffer.toString();
     }
@@ -294,7 +312,7 @@ public final class RemoteRepository
         private static final RepositoryPolicy DEFAULT_POLICY = new RepositoryPolicy();
 
         static final int ID = 0x0001, TYPE = 0x0002, URL = 0x0004, RELEASES = 0x0008, SNAPSHOTS = 0x0010,
-                        PROXY = 0x0020, AUTH = 0x0040, MIRRORED = 0x0080, REPOMAN = 0x0100;
+                        PROXY = 0x0020, AUTH = 0x0040, MIRRORED = 0x0080, REPOMAN = 0x0100, BLOCKED = 0x0200;
 
         int delta;
 
@@ -318,6 +336,8 @@ public final class RemoteRepository
 
         boolean repositoryManager;
 
+        boolean blocked;
+
         /**
          * Creates a new repository builder.
          * 
@@ -575,6 +595,22 @@ public final class RemoteRepository
             return this;
         }
 
+
+        /**
+         * Marks the repository as blocked or not.
+         * 
+         * @param blocked {@code true} if the repository should not be allowed to get any request.
+         * @return This builder for chaining, never {@code null}.
+         */
+        public Builder setBlocked( boolean blocked )
+        {
+            this.blocked = blocked;
+            if ( prototype != null )
+            {
+                delta( BLOCKED, this.blocked, prototype.isBlocked() );
+            }
+            return this;
+        }
     }
 
 }
diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultArtifactResolver.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultArtifactResolver.java
index fde3575..0923bd9 100644
--- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultArtifactResolver.java
+++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultArtifactResolver.java
@@ -495,6 +495,20 @@ public class DefaultArtifactResolver
 
         try
         {
+            RemoteRepository repo = group.repository;
+            if ( repo.isBlocked() )
+            {
+                if ( repo.getMirroredRepositories().isEmpty() )
+                {
+                    throw new NoRepositoryConnectorException( repo, "Blocked repository: " + repo );
+                }
+                else
+                {
+                    throw new NoRepositoryConnectorException( repo, "Blocking mirror for repositories: "
+                        + repo.getMirroredRepositories() );
+                }
+            }
+
             try ( RepositoryConnector connector =
                           repositoryConnectorProvider.newRepositoryConnector( session, group.repository ) )
             {
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 83acad4..dfb413d 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
@@ -41,6 +41,13 @@ public final class DefaultMirrorSelector
 
     private final List<MirrorDef> mirrors = new ArrayList<>();
 
+    @Deprecated
+    public DefaultMirrorSelector add( String id, String url, String type, boolean repositoryManager,
+                                      String mirrorOfIds, String mirrorOfTypes )
+    {
+        return add( id, url, type, repositoryManager, false, mirrorOfIds, mirrorOfTypes );
+    }
+
     /**
      * Adds the specified mirror to this selector.
      * 
@@ -48,6 +55,7 @@ public final class DefaultMirrorSelector
      * @param url The URL of the mirror, must not be {@code null}.
      * @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 blocked A flag whether the mirror blocks any download request.
      * @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 "*", "external:http:*" and
      *            "external:*" can be used to match all (external) repositories, prefixing a repo id with an
@@ -57,10 +65,10 @@ public final class DefaultMirrorSelector
      *            wildcard "*" and the "!" negation syntax are supported. For example "*,!p2".
      * @return This selector for chaining, never {@code null}.
      */
-    public DefaultMirrorSelector add( String id, String url, String type, boolean repositoryManager,
+    public DefaultMirrorSelector add( String id, String url, String type, boolean repositoryManager, boolean blocked,
                                       String mirrorOfIds, String mirrorOfTypes )
     {
-        mirrors.add( new MirrorDef( id, url, type, repositoryManager, mirrorOfIds, mirrorOfTypes ) );
+        mirrors.add( new MirrorDef( id, url, type, repositoryManager, blocked, mirrorOfIds, mirrorOfTypes ) );
 
         return this;
     }
@@ -79,6 +87,8 @@ public final class DefaultMirrorSelector
 
         builder.setRepositoryManager( mirror.repositoryManager );
 
+        builder.setBlocked( mirror.blocked );
+
         if ( mirror.type != null && mirror.type.length() > 0 )
         {
             builder.setContentType( mirror.type );
@@ -285,17 +295,20 @@ public final class DefaultMirrorSelector
 
         final boolean repositoryManager;
 
+        final boolean blocked;
+
         final String mirrorOfIds;
 
         final String mirrorOfTypes;
 
-        MirrorDef( String id, String url, String type, boolean repositoryManager, String mirrorOfIds,
-                          String mirrorOfTypes )
+        MirrorDef( String id, String url, String type, boolean repositoryManager, boolean blocked, String mirrorOfIds,
+                   String mirrorOfTypes )
         {
             this.id = id;
             this.url = url;
             this.type = type;
             this.repositoryManager = repositoryManager;
+            this.blocked = blocked;
             this.mirrorOfIds = mirrorOfIds;
             this.mirrorOfTypes = mirrorOfTypes;
         }


[maven-resolver] 01/02: [MRESOLVER-165] add support for mirrorOf external:http:*

Posted by hb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git

commit 41144bf449aaa7e88ffa5acc86e751cc29cfda4b
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Sat Mar 6 19:59:14 2021 +0100

    [MRESOLVER-165] add support for mirrorOf 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.
      *