Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into MRESOLVER-390
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Oct 13, 2023
2 parents e662d99 + aa3945e commit f5d642d
Show file tree
Hide file tree
Showing 79 changed files with 1,585 additions and 172 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ jobs:
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v3
with:
ff-site-run: false

jdk-matrix: '[ "11", "17", "21" ]'

4 changes: 1 addition & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@
* under the License.
*/

// Currently we can only build with JDK8+ based on the usage
// of bnd-maven-plugin.
asfMavenTlpStdBuild( 'jdks' : [ "8", "11", "17" ] )
asfMavenTlpStdBuild( 'jdks' : [ "11", "17", "21" ] )

2 changes: 1 addition & 1 deletion maven-resolver-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver</artifactId>
<version>1.9.15-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>maven-resolver-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public String getUpdatePolicy() {
return getSession().getUpdatePolicy();
}

@Override
public String getMetadataUpdatePolicy() {
return getSession().getMetadataUpdatePolicy();
}

@Override
public LocalRepository getLocalRepository() {
return getSession().getLocalRepository();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,60 @@ public final class ConfigurationProperties {
*/
public static final int DEFAULT_HTTP_RETRY_HANDLER_COUNT = 3;

/**
* The initial retry interval of request to a remote server should be waited in case of "too many requests"
* (HTTP codes 429 and 503). Accepts long as milliseconds. This value is used if remote server does not use
* {@code Retry-After} header, in which case Server value is obeyed.
*
* @see #DEFAULT_HTTP_RETRY_HANDLER_INTERVAL
* @since 1.9.16
*/
public static final String HTTP_RETRY_HANDLER_INTERVAL = PREFIX_CONNECTOR + "http.retryHandler.interval";

/**
* The default initial retry interval to use if {@link #HTTP_RETRY_HANDLER_INTERVAL} isn't set.
* Default value 5000ms.
*
* @since 1.9.16
*/
public static final long DEFAULT_HTTP_RETRY_HANDLER_INTERVAL = 5000L;

/**
* The maximum retry interval of request to a remote server above which the request should be aborted instead.
* In theory, a malicious server could tell Maven "come back after 100 years" that would stall the build for
* some. Using this parameter Maven will fail the request instead, if interval is above this value.
*
* @see #DEFAULT_HTTP_RETRY_HANDLER_INTERVAL_MAX
* @since 1.9.16
*/
public static final String HTTP_RETRY_HANDLER_INTERVAL_MAX = PREFIX_CONNECTOR + "http.retryHandler.intervalMax";

/**
* The default retry interval maximum to use if {@link #HTTP_RETRY_HANDLER_INTERVAL_MAX} isn't set.
* Default value 5 minutes.
*
* @since 1.9.16
*/
public static final long DEFAULT_HTTP_RETRY_HANDLER_INTERVAL_MAX = 300_000L;

/**
* The HTTP codes of remote server responses that should be handled as "too many requests"
* (examples: HTTP codes 429 and 503). Accepts comma separated list of HTTP response codes.
*
* @see #DEFAULT_HTTP_RETRY_HANDLER_SERVICE_UNAVAILABLE
* @since 1.9.16
*/
public static final String HTTP_RETRY_HANDLER_SERVICE_UNAVAILABLE =
PREFIX_CONNECTOR + "http.retryHandler.serviceUnavailable";

/**
* The default HTTP codes of remote server responses that should be handled as "too many requests".
* Default value: "429,503".
*
* @since 1.9.16
*/
public static final String DEFAULT_HTTP_RETRY_HANDLER_SERVICE_UNAVAILABLE = "429,503";

/**
* Should HTTP client use preemptive auth (w/ BASIC) or not?
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public final class DefaultRepositorySystemSession implements RepositorySystemSes

private String updatePolicy;

private String metadataUpdatePolicy;

private LocalRepositoryManager localRepositoryManager;

private FileTransformerManager fileTransformerManager;
Expand Down Expand Up @@ -154,6 +156,7 @@ public DefaultRepositorySystemSession(RepositorySystemSession session) {
setArtifactDescriptorPolicy(session.getArtifactDescriptorPolicy());
setChecksumPolicy(session.getChecksumPolicy());
setUpdatePolicy(session.getUpdatePolicy());
setMetadataUpdatePolicy(session.getMetadataUpdatePolicy());
setLocalRepositoryManager(session.getLocalRepositoryManager());
setWorkspaceReader(session.getWorkspaceReader());
setRepositoryListener(session.getRepositoryListener());
Expand Down Expand Up @@ -293,6 +296,28 @@ public DefaultRepositorySystemSession setUpdatePolicy(String updatePolicy) {
return this;
}

@Override
public String getMetadataUpdatePolicy() {
return metadataUpdatePolicy;
}

/**
* Sets the global metadata update policy. If set, the global update policy overrides the update policies of the remote
* repositories being used for resolution.
*
* @param metadataUpdatePolicy The global update policy, may be {@code null}/empty to apply the per-repository policies.
* @return This session for chaining, never {@code null}.
* @see RepositoryPolicy#UPDATE_POLICY_ALWAYS
* @see RepositoryPolicy#UPDATE_POLICY_DAILY
* @see RepositoryPolicy#UPDATE_POLICY_NEVER
* @since TBD
*/
public DefaultRepositorySystemSession setMetadataUpdatePolicy(String metadataUpdatePolicy) {
verifyStateForMutation();
this.metadataUpdatePolicy = metadataUpdatePolicy;
return this;
}

@Override
public LocalRepository getLocalRepository() {
LocalRepositoryManager lrm = getLocalRepositoryManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public interface RepositorySystemSession {
String getChecksumPolicy();

/**
* Gets the global update policy. If set, the global update policy overrides the update policies of the remote
* Gets the global data update policy. If set, the global update policy overrides the update policies of the remote
* repositories being used for resolution.
*
* @return The global update policy or {@code null}/empty if not set and the per-repository policies apply.
Expand All @@ -104,6 +104,18 @@ public interface RepositorySystemSession {
*/
String getUpdatePolicy();

/**
* Gets the global metadata update policy. If set, the global update policy overrides the update policies of the remote
* repositories being used for resolution.
*
* @return The global update policy or {@code null}/empty if not set and the per-repository policies apply.
* @see RepositoryPolicy#UPDATE_POLICY_ALWAYS
* @see RepositoryPolicy#UPDATE_POLICY_DAILY
* @see RepositoryPolicy#UPDATE_POLICY_NEVER
* @since TBD
*/
String getMetadataUpdatePolicy();

/**
* Gets the local repository used during this session. This is a convenience method for
* {@link LocalRepositoryManager#getRepository()}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,40 @@ public final class RepositoryPolicy {

private final String updatePolicy;

private final String metadataUpdatePolicy;

private final String checksumPolicy;

/**
* Creates a new policy with checksum warnings and daily update checks.
*/
public RepositoryPolicy() {
this(true, UPDATE_POLICY_DAILY, CHECKSUM_POLICY_WARN);
this(true, UPDATE_POLICY_DAILY, UPDATE_POLICY_DAILY, CHECKSUM_POLICY_WARN);
}

/**
* Creates a new policy with the specified settings (uses same update policy for data and metadata, retains old
* resolver behaviour).
*/
public RepositoryPolicy(boolean enabled, String updatePolicy, String checksumPolicy) {
this(enabled, updatePolicy, updatePolicy, checksumPolicy);
}

/**
* Creates a new policy with the specified settings.
*
* @param enabled A flag whether the associated repository should be accessed or not.
* @param updatePolicy The update interval after which locally cached data from the repository is considered stale
* and should be refetched, may be {@code null}.
* and should be re-fetched, may be {@code null}.
* @param metadataUpdatePolicy The update interval after which locally cached metadata from the repository is considered stale
* and should be re-fetched, may be {@code null}.
* @param checksumPolicy The way checksum verification should be handled, may be {@code null}.
* @since TBD
*/
public RepositoryPolicy(boolean enabled, String updatePolicy, String checksumPolicy) {
public RepositoryPolicy(boolean enabled, String updatePolicy, String metadataUpdatePolicy, String checksumPolicy) {
this.enabled = enabled;
this.updatePolicy = (updatePolicy != null) ? updatePolicy : "";
this.metadataUpdatePolicy = (metadataUpdatePolicy != null) ? metadataUpdatePolicy : "";
this.checksumPolicy = (checksumPolicy != null) ? checksumPolicy : "";
}

Expand All @@ -103,6 +117,16 @@ public String getUpdatePolicy() {
return updatePolicy;
}

/**
* Gets the update policy for locally cached metadata from the repository.
*
* @return The update policy, never {@code null}.
* @since TBD
*/
public String getMetadataUpdatePolicy() {
return metadataUpdatePolicy;
}

/**
* Gets the policy for checksum validation.
*
Expand All @@ -114,11 +138,10 @@ public String getChecksumPolicy() {

@Override
public String toString() {
StringBuilder buffer = new StringBuilder(256);
buffer.append("enabled=").append(isEnabled());
buffer.append(", checksums=").append(getChecksumPolicy());
buffer.append(", updates=").append(getUpdatePolicy());
return buffer.toString();
return "enabled=" + isEnabled()
+ ", checksums=" + getChecksumPolicy()
+ ", updates=" + getUpdatePolicy()
+ ", metadataUpdates=" + getMetadataUpdatePolicy();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion maven-resolver-connector-basic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver</artifactId>
<version>1.9.15-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>maven-resolver-connector-basic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
* {@link org.eclipse.aether.spi.connector.transport.TransporterFactory transporters} and
* {@link org.eclipse.aether.spi.connector.layout.RepositoryLayoutFactory repository layouts} for the transfers.
*/
@Named("basic")
@Named(BasicRepositoryConnectorFactory.NAME)
public final class BasicRepositoryConnectorFactory implements RepositoryConnectorFactory, Service {
public static final String NAME = "basic";
private TransporterProvider transporterProvider;

private RepositoryLayoutProvider layoutProvider;
Expand All @@ -63,12 +64,13 @@ public final class BasicRepositoryConnectorFactory implements RepositoryConnecto
* clients, the new factory needs to be configured via its various mutators before first use or runtime errors will
* occur.
*/
@Deprecated
public BasicRepositoryConnectorFactory() {
// enables default constructor
}

@Inject
BasicRepositoryConnectorFactory(
public BasicRepositoryConnectorFactory(
TransporterProvider transporterProvider,
RepositoryLayoutProvider layoutProvider,
ChecksumPolicyProvider checksumPolicyProvider,
Expand Down
4 changes: 2 additions & 2 deletions maven-resolver-demos/maven-resolver-demo-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-demos</artifactId>
<version>1.9.15-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>resolver-demo-maven-plugin</artifactId>
Expand All @@ -33,7 +33,7 @@
<description>A simple Maven plugin using Maven Artifact Resolver with Maven repositories.</description>

<prerequisites>
<maven>${mavenVersion}</maven>
<maven>${minimalMavenBuildVersion}</maven>
</prerequisites>

<dependencies>
Expand Down
6 changes: 5 additions & 1 deletion maven-resolver-demos/maven-resolver-demo-snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-demos</artifactId>
<version>1.9.15-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>maven-resolver-demo-snippets</artifactId>
Expand Down Expand Up @@ -65,6 +65,10 @@
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-supplier</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-resolver-provider</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
import org.apache.maven.model.building.DefaultModelBuilderFactory;
import org.apache.maven.model.building.ModelBuilder;
import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader;
import org.apache.maven.repository.internal.DefaultModelCacheFactory;
import org.apache.maven.repository.internal.DefaultVersionRangeResolver;
import org.apache.maven.repository.internal.DefaultVersionResolver;
import org.apache.maven.repository.internal.ModelCacheFactory;
import org.apache.maven.repository.internal.SnapshotMetadataGeneratorFactory;
import org.apache.maven.repository.internal.VersionsMetadataGeneratorFactory;
import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
Expand Down Expand Up @@ -142,4 +144,9 @@ Set<MetadataGeneratorFactory> provideMetadataGeneratorFactories(
ModelBuilder provideModelBuilder() {
return new DefaultModelBuilderFactory().newInstance();
}

@Provides
ModelCacheFactory provideModelCacheFactory() {
return new DefaultModelCacheFactory();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.resolver.examples.supplier;

import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.supplier.RepositorySystemSupplier;

/**
* A factory for repository system instances that employs Maven Artifact Resolver's provided supplier.
*/
public class SupplierRepositorySystemFactory {
public static RepositorySystem newRepositorySystem() {
return new RepositorySystemSupplier().get();
}
}
Loading

0 comments on commit f5d642d

Please sign in to comment.