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/14 18:52:45 UTC
[maven-resolver] 04/04: [MRESOLVER-166] add support for blocked
repository/mirror
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch 1.6.x
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
commit 514cec19743c4f441f0137cd6d035422a046e6a1
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 4f63fc2..7d47515 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
@@ -493,6 +493,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;
}