Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRESOLVER-645] Remove repeated LRM interaction #611

Merged
merged 9 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.eclipse.aether.repository;

import java.nio.file.Path;

import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.metadata.Metadata;
Expand All @@ -37,16 +39,44 @@ public interface LocalRepositoryManager {
*/
LocalRepository getRepository();

/**
* Gets the absolute path for a locally installed artifact. Note that the artifact need not actually exist yet at
* the returned location, the path merely indicates where the artifact would eventually be stored.
*
* @param artifact The artifact for which to determine the path, must not be {@code null}.
* @return The path, relative to the local repository's base directory.
* @since 2.0.5
*/
default Path getAbsolutePathForLocalArtifact(Artifact artifact) {
return getRepository().getBasePath().resolve(getPathForLocalArtifact(artifact));
}

/**
* Gets the relative path for a locally installed artifact. Note that the artifact need not actually exist yet at
* the returned location, the path merely indicates where the artifact would eventually be stored. The path uses the
* forward slash as directory separator regardless of the underlying file system.
*
* @param artifact The artifact for which to determine the path, must not be {@code null}.
* @return The path, relative to the local repository's base directory.
* @deprecated See {@link #getAbsolutePathForLocalArtifact(Artifact)}
*/
@Deprecated
String getPathForLocalArtifact(Artifact artifact);

/**
* Gets the absolute path for an artifact cached from a remote repository. Note that the artifact need not actually
* exist yet at the returned location, the path merely indicates where the artifact would eventually be stored.
*
* @param artifact The artifact for which to determine the path, must not be {@code null}.
* @param repository The source repository of the artifact, must not be {@code null}.
* @param context The resolution context in which the artifact is being requested, may be {@code null}.
* @return The path, relative to the local repository's base directory.
* @since 2.0.5
*/
default Path getAbsolutePathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
return getRepository().getBasePath().resolve(getPathForRemoteArtifact(artifact, repository, context));
}

/**
* Gets the relative path for an artifact cached from a remote repository. Note that the artifact need not actually
* exist yet at the returned location, the path merely indicates where the artifact would eventually be stored. The
Expand All @@ -56,19 +86,49 @@ public interface LocalRepositoryManager {
* @param repository The source repository of the artifact, must not be {@code null}.
* @param context The resolution context in which the artifact is being requested, may be {@code null}.
* @return The path, relative to the local repository's base directory.
* @deprecated See {@link #getAbsolutePathForRemoteArtifact(Artifact, RemoteRepository, String)}
*/
@Deprecated
String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context);

/**
* Gets the absolute path for locally installed metadata. Note that the metadata need not actually exist yet at the
* returned location, the path merely indicates where the metadata would eventually be stored.
*
* @param metadata The metadata for which to determine the path, must not be {@code null}.
* @return The path, relative to the local repository's base directory.
* @since 2.0.5
*/
default Path getAbsolutePathForLocalMetadata(Metadata metadata) {
return getRepository().getBasePath().resolve(getPathForLocalMetadata(metadata));
}

/**
* Gets the relative path for locally installed metadata. Note that the metadata need not actually exist yet at the
* returned location, the path merely indicates where the metadata would eventually be stored. The path uses the
* forward slash as directory separator regardless of the underlying file system.
*
* @param metadata The metadata for which to determine the path, must not be {@code null}.
* @return The path, relative to the local repository's base directory.
* @deprecated See {@link #getAbsolutePathForLocalMetadata(Metadata)}
*/
@Deprecated
String getPathForLocalMetadata(Metadata metadata);

/**
* Gets the absolute path for metadata cached from a remote repository. Note that the metadata need not actually
* exist yet at the returned location, the path merely indicates where the metadata would eventually be stored.
*
* @param metadata The metadata for which to determine the path, must not be {@code null}.
* @param repository The source repository of the metadata, must not be {@code null}.
* @param context The resolution context in which the metadata is being requested, may be {@code null}.
* @return The path, relative to the local repository's base directory.
* @since 2.0.5
*/
default Path getAbsolutePathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
return getRepository().getBasePath().resolve(getPathForRemoteMetadata(metadata, repository, context));
}

/**
* Gets the relative path for metadata cached from a remote repository. Note that the metadata need not actually
* exist yet at the returned location, the path merely indicates where the metadata would eventually be stored. The
Expand All @@ -78,7 +138,9 @@ public interface LocalRepositoryManager {
* @param repository The source repository of the metadata, must not be {@code null}.
* @param context The resolution context in which the metadata is being requested, may be {@code null}.
* @return The path, relative to the local repository's base directory.
* @deprecated See {@link #getAbsolutePathForRemoteMetadata(Metadata, RemoteRepository, String)}
*/
@Deprecated
String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,8 @@ private List<ArtifactDownload> gatherDownloads(RepositorySystemSession session,
download.setPath(item.local.getPath());
download.setExistenceCheck(true);
} else {
String path =
lrm.getPathForRemoteArtifact(artifact, group.repository, item.request.getRequestContext());
download.setPath(lrm.getRepository().getBasePath().resolve(path));
download.setPath(lrm.getAbsolutePathForRemoteArtifact(
artifact, group.repository, item.request.getRequestContext()));
}

boolean snapshot = artifact.isSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,7 @@ private void upload(
EventCatapult catapult)
throws DeploymentException {
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
Path basePath = lrm.getRepository().getBasePath();

Path dstPath = basePath.resolve(lrm.getPathForRemoteMetadata(metadata, repository, ""));
Path dstPath = lrm.getAbsolutePathForRemoteMetadata(metadata, repository, "");

if (metadata instanceof MergeableMetadata) {
if (!((MergeableMetadata) metadata).isMerged()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private void install(RepositorySystemSession session, RequestTrace trace, Artifa
throws InstallationException {
final LocalRepositoryManager lrm = session.getLocalRepositoryManager();
final Path srcPath = artifact.getPath();
final Path dstPath = lrm.getRepository().getBasePath().resolve(lrm.getPathForLocalArtifact(artifact));
final Path dstPath = lrm.getAbsolutePathForLocalArtifact(artifact);

artifactInstalling(session, trace, artifact, dstPath);

Expand All @@ -219,7 +219,7 @@ private void install(RepositorySystemSession session, RequestTrace trace, Metada
throws InstallationException {
LocalRepositoryManager lrm = session.getLocalRepositoryManager();

Path dstPath = lrm.getRepository().getBasePath().resolve(lrm.getPathForLocalMetadata(metadata));
Path dstPath = lrm.getAbsolutePathForLocalMetadata(metadata);

metadataInstalling(session, trace, metadata, dstPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,8 @@ private List<MetadataResult> resolve(
check.setItem(metadata);

// use 'main' installation file for the check (-> use requested repository)
Path checkPath = session.getLocalRepository()
.getBasePath()
.resolve(session.getLocalRepositoryManager()
.getPathForRemoteMetadata(metadata, repository, request.getRequestContext()));
Path checkPath = session.getLocalRepositoryManager()
.getAbsolutePathForRemoteMetadata(metadata, repository, request.getRequestContext());
check.setPath(checkPath);
check.setRepository(repository);
check.setAuthoritativeRepository(repo);
Expand All @@ -283,11 +281,9 @@ private List<MetadataResult> resolve(
RepositoryPolicy policy = getPolicy(session, repository, metadata.getNature());

// install path may be different from lookup path
Path installPath = session.getLocalRepository()
.getBasePath()
.resolve(session.getLocalRepositoryManager()
.getPathForRemoteMetadata(
metadata, request.getRepository(), request.getRequestContext()));
Path installPath = session.getLocalRepositoryManager()
.getAbsolutePathForRemoteMetadata(
metadata, request.getRepository(), request.getRequestContext());

ResolveTask task = new ResolveTask(
session, trace, result, installPath, checks, policy.getChecksumPolicy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,17 @@ public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRe
Artifact artifact = request.getArtifact();
LocalArtifactResult result = new LocalArtifactResult(request);

String path;
Path filePath;

// Local repository CANNOT have timestamped installed, they are created only during deploy
if (Objects.equals(artifact.getVersion(), artifact.getBaseVersion())) {
path = getPathForLocalArtifact(artifact);
filePath = getRepository().getBasePath().resolve(path);
filePath = getAbsolutePathForLocalArtifact(artifact);
checkFind(filePath, result);
}

if (!result.isAvailable()) {
for (RemoteRepository repository : request.getRepositories()) {
path = getPathForRemoteArtifact(artifact, repository, request.getContext());
filePath = getRepository().getBasePath().resolve(path);
filePath = getAbsolutePathForRemoteArtifact(artifact, repository, request.getContext());

checkFind(filePath, result);

Expand Down Expand Up @@ -208,10 +205,9 @@ private Collection<String> getRepositoryKeys(RemoteRepository repository, Collec
private void addArtifact(
Artifact artifact, Collection<String> repositories, RemoteRepository repository, String context) {
requireNonNull(artifact, "artifact cannot be null");
String path = repository == null
? getPathForLocalArtifact(artifact)
: getPathForRemoteArtifact(artifact, repository, context);
Path file = getRepository().getBasePath().resolve(path);
Path file = repository == null
? getAbsolutePathForLocalArtifact(artifact)
: getAbsolutePathForRemoteArtifact(artifact, repository, context);
addRepo(file, repositories);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,11 @@ public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRe
Artifact artifact = request.getArtifact();
LocalArtifactResult result = new LocalArtifactResult(request);

String path;
Path filePath;

// Local repository CANNOT have timestamped installed, they are created only during deploy
if (Objects.equals(artifact.getVersion(), artifact.getBaseVersion())) {
path = getPathForLocalArtifact(artifact);
filePath = getRepository().getBasePath().resolve(path);
filePath = getAbsolutePathForLocalArtifact(artifact);
if (Files.isRegularFile(filePath)) {
result.setPath(filePath);
result.setAvailable(true);
Expand All @@ -147,8 +145,7 @@ public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRe

if (!result.isAvailable()) {
for (RemoteRepository repository : request.getRepositories()) {
path = getPathForRemoteArtifact(artifact, repository, request.getContext());
filePath = getRepository().getBasePath().resolve(path);
filePath = getAbsolutePathForRemoteArtifact(artifact, repository, request.getContext());
if (Files.isRegularFile(filePath)) {
result.setPath(filePath);
result.setAvailable(true);
Expand Down
Loading
Loading