Skip to content

Commit

Permalink
[MNG-8540] Add cache to API requests
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jan 24, 2025
1 parent 4a57f30 commit 5a848ca
Show file tree
Hide file tree
Showing 37 changed files with 495 additions and 44 deletions.
11 changes: 11 additions & 0 deletions api/maven-api-core/src/main/java/org/apache/maven/api/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@
@ThreadSafe
public interface Session extends ProtoSession {

/**
* Creates a new scoped session that shares the same repository system session
* and remote repositories but has its own independent caching context. This
* allows for isolated caching between different parts of the build without
* interfering with each other.
*
* @return A new Session instance with an independent cache scope
*/
@Nonnull
Session scopedSession();

/**
* Returns the current maven version.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.api.services;

import java.util.Objects;

import org.apache.maven.api.ArtifactCoordinates;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
Expand Down Expand Up @@ -235,6 +237,23 @@ public String getCoordinatesString() {
return coordinatesString;
}

@Override
public boolean equals(Object o) {
return o instanceof DefaultArtifactFactoryRequestArtifact that
&& Objects.equals(groupId, that.groupId)
&& Objects.equals(artifactId, that.artifactId)
&& Objects.equals(version, that.version)
&& Objects.equals(classifier, that.classifier)
&& Objects.equals(extension, that.extension)
&& Objects.equals(type, that.type)
&& Objects.equals(coordinatesString, that.coordinatesString);
}

@Override
public int hashCode() {
return Objects.hash(groupId, artifactId, version, classifier, extension, type, coordinatesString);
}

@Override
public String toString() {
return "ArtifactFactoryRequestArtifact[" + "groupId='"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Objects;

import org.apache.maven.api.ProducedArtifact;
import org.apache.maven.api.RemoteRepository;
Expand Down Expand Up @@ -144,6 +145,19 @@ public int getRetryFailedDeploymentCount() {
return retryFailedDeploymentCount;
}

@Override
public boolean equals(Object o) {
return o instanceof DefaultArtifactDeployerRequest that
&& retryFailedDeploymentCount == that.retryFailedDeploymentCount
&& Objects.equals(repository, that.repository)
&& Objects.equals(artifacts, that.artifacts);
}

@Override
public int hashCode() {
return Objects.hash(repository, artifacts, retryFailedDeploymentCount);
}

@Override
public String toString() {
return "ArtifactDeployerRequest[" + "repository="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.api.services;

import java.util.Objects;

import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
Expand Down Expand Up @@ -198,6 +200,22 @@ public String getType() {
return type;
}

@Override
public boolean equals(Object o) {
return o instanceof DefaultArtifactFactoryRequest that
&& Objects.equals(groupId, that.groupId)
&& Objects.equals(artifactId, that.artifactId)
&& Objects.equals(version, that.version)
&& Objects.equals(classifier, that.classifier)
&& Objects.equals(extension, that.extension)
&& Objects.equals(type, that.type);
}

@Override
public int hashCode() {
return Objects.hash(groupId, artifactId, version, classifier, extension, type);
}

@Override
public String toString() {
return "ArtifactFactoryRequest[" + "groupId='"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import org.apache.maven.api.ProducedArtifact;
import org.apache.maven.api.Session;
Expand Down Expand Up @@ -106,6 +107,16 @@ public Collection<ProducedArtifact> getArtifacts() {
return artifacts;
}

@Override
public boolean equals(Object o) {
return o instanceof DefaultArtifactInstallerRequest that && Objects.equals(artifacts, that.artifacts);
}

@Override
public int hashCode() {
return Objects.hashCode(artifacts);
}

@Override
public String toString() {
return "ArtifactInstallerRequest[" + "artifacts=" + artifacts + ']';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Objects;

import org.apache.maven.api.ArtifactCoordinates;
import org.apache.maven.api.RemoteRepository;
Expand Down Expand Up @@ -141,6 +142,18 @@ public List<RemoteRepository> getRepositories() {
return repositories;
}

@Override
public boolean equals(Object o) {
return o instanceof DefaultArtifactResolverRequest that
&& Objects.equals(coordinates, that.coordinates)
&& Objects.equals(repositories, that.repositories);
}

@Override
public int hashCode() {
return Objects.hash(coordinates, repositories);
}

@Override
public String toString() {
return "ArtifactResolverRequest[" + "coordinates="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;

import org.apache.maven.api.ArtifactCoordinates;
import org.apache.maven.api.Dependency;
Expand Down Expand Up @@ -301,6 +302,36 @@ public Collection<Exclusion> getExclusions() {
return exclusions;
}

@Override
public boolean equals(Object o) {
return o instanceof DefaultDependencyCoordinatesFactoryRequest that
&& optional == that.optional
&& Objects.equals(groupId, that.groupId)
&& Objects.equals(artifactId, that.artifactId)
&& Objects.equals(version, that.version)
&& Objects.equals(classifier, that.classifier)
&& Objects.equals(extension, that.extension)
&& Objects.equals(type, that.type)
&& Objects.equals(coordinateString, that.coordinateString)
&& Objects.equals(scope, that.scope)
&& Objects.equals(exclusions, that.exclusions);
}

@Override
public int hashCode() {
return Objects.hash(
groupId,
artifactId,
version,
classifier,
extension,
type,
coordinateString,
scope,
optional,
exclusions);
}

@Override
public String toString() {
return "DependencyCoordinatesFactoryRequest[" + "groupId='"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;

Expand Down Expand Up @@ -499,6 +500,36 @@ public List<RemoteRepository> getRepositories() {
return repositories;
}

@Override
public boolean equals(Object o) {
return o instanceof DefaultDependencyResolverRequest that
&& verbose == that.verbose
&& requestType == that.requestType
&& Objects.equals(project, that.project)
&& Objects.equals(rootArtifact, that.rootArtifact)
&& Objects.equals(root, that.root)
&& Objects.equals(dependencies, that.dependencies)
&& Objects.equals(managedDependencies, that.managedDependencies)
&& Objects.equals(pathScope, that.pathScope)
&& Objects.equals(pathTypeFilter, that.pathTypeFilter)
&& Objects.equals(repositories, that.repositories);
}

@Override
public int hashCode() {
return Objects.hash(
requestType,
project,
rootArtifact,
root,
dependencies,
managedDependencies,
verbose,
pathScope,
pathTypeFilter,
repositories);
}

@Override
public String toString() {
return "DependencyResolverRequest[" + "requestType="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session;
Expand Down Expand Up @@ -402,6 +403,40 @@ public ModelTransformer getLifecycleBindingsInjector() {
return lifecycleBindingsInjector;
}

@Override
public boolean equals(Object o) {
return o instanceof DefaultModelBuilderRequest that
&& locationTracking == that.locationTracking
&& recursive == that.recursive
&& requestType == that.requestType
&& Objects.equals(source, that.source)
&& Objects.equals(profiles, that.profiles)
&& Objects.equals(activeProfileIds, that.activeProfileIds)
&& Objects.equals(inactiveProfileIds, that.inactiveProfileIds)
&& Objects.equals(systemProperties, that.systemProperties)
&& Objects.equals(userProperties, that.userProperties)
&& repositoryMerging == that.repositoryMerging
&& Objects.equals(repositories, that.repositories)
&& Objects.equals(lifecycleBindingsInjector, that.lifecycleBindingsInjector);
}

@Override
public int hashCode() {
return Objects.hash(
requestType,
locationTracking,
recursive,
source,
profiles,
activeProfileIds,
inactiveProfileIds,
systemProperties,
userProperties,
repositoryMerging,
repositories,
lifecycleBindingsInjector);
}

@Override
public String toString() {
return "ModelBuilderRequest[" + "requestType="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.apache.maven.api.RemoteRepository;
Expand Down Expand Up @@ -188,6 +189,22 @@ public List<RemoteRepository> getRepositories() {
return repositories;
}

@Override
public boolean equals(Object o) {
return o instanceof DefaultProjectBuilderRequest that
&& allowStubModel == that.allowStubModel
&& recursive == that.recursive
&& processPlugins == that.processPlugins
&& Objects.equals(path, that.path)
&& Objects.equals(source, that.source)
&& Objects.equals(repositories, that.repositories);
}

@Override
public int hashCode() {
return Objects.hash(path, source, allowStubModel, recursive, processPlugins, repositories);
}

@Override
public String toString() {
return "ProjectBuilderRequest[" + "path="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ public interface Request<S extends ProtoSession> {
@Nullable
RequestTrace getTrace();

/**
* Returns a hashcode value for this request, based on all significant fields.
* Implementations must ensure that if two requests are equal according to
* {@link #equals(Object)}, they have the same hashcode.
*
* @return a hash code value for this request
*/
@Override
int hashCode();

/**
* Returns {@code true} if the specified object is equal to this request.
* Two requests are considered equal if they have the same type and all
* significant fields are equal.
*
* @param obj the object to compare with this request
* @return {@code true} if the objects are equal, {@code false} otherwise
*/
@Override
boolean equals(Object obj);

/**
* Returns a string representation of this request, used for debugging and logging purposes.
* The format should include the request type and any significant attributes that define the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;
import java.util.function.UnaryOperator;

Expand Down Expand Up @@ -222,6 +223,21 @@ public Optional<UnaryOperator<String>> getInterpolationSource() {
return Optional.ofNullable(interpolationSource);
}

@Override
public boolean equals(Object o) {
return o instanceof DefaultSettingsBuilderRequest that
&& Objects.equals(installationSettingsSource, that.installationSettingsSource)
&& Objects.equals(projectSettingsSource, that.projectSettingsSource)
&& Objects.equals(userSettingsSource, that.userSettingsSource)
&& Objects.equals(interpolationSource, that.interpolationSource);
}

@Override
public int hashCode() {
return Objects.hash(
installationSettingsSource, projectSettingsSource, userSettingsSource, interpolationSource);
}

@Override
public String toString() {
return "SettingsBuilderRequest[" + "installationSettingsSource="
Expand Down
Loading

0 comments on commit 5a848ca

Please sign in to comment.