From febfd2b5c95c255156ac2fe7044a06abd5e3bc94 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 2 May 2024 18:33:18 +0200 Subject: [PATCH] Resolver updates (#1495) --- .../apache/maven/internal/impl/AbstractSession.java | 11 ++++------- .../maven/internal/impl/DefaultArtifactResolver.java | 2 +- .../maven/internal/impl/DefaultLocalRepository.java | 2 +- .../internal/impl/DefaultLocalRepositoryManager.java | 2 +- .../maven/internal/impl/DefaultRepositoryFactory.java | 2 +- .../apache/maven/internal/impl/DefaultTransport.java | 4 ++-- .../maven/internal/impl/resolver/MavenMetadata.java | 1 + .../impl/resolver/MavenSessionBuilderSupplier.java | 4 ++-- .../src/main/java/org/apache/maven/ReactorReader.java | 2 +- .../maven/internal/impl/DefaultArtifactManager.java | 6 +----- .../maven/repository/TestRepositoryConnector.java | 4 ++-- .../maven/model/building/DefaultModelBuilder.java | 2 +- 12 files changed, 18 insertions(+), 24 deletions(-) diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java index 3b9149289a..464941d23c 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java @@ -214,7 +214,7 @@ public abstract class AbstractSession implements InternalSession { public Session withLocalRepository(@Nonnull LocalRepository localRepository) { nonNull(localRepository, "localRepository"); if (session.getLocalRepository() != null - && Objects.equals(session.getLocalRepository().getBasedir().toPath(), localRepository.getPath())) { + && Objects.equals(session.getLocalRepository().getBasePath(), localRepository.getPath())) { return this; } org.eclipse.aether.repository.LocalRepository repository = toRepository(localRepository); @@ -293,13 +293,10 @@ public abstract class AbstractSession implements InternalSession { @Override public org.eclipse.aether.artifact.Artifact toArtifact(Artifact artifact) { - File file = getService(ArtifactManager.class) - .getPath(artifact) - .map(Path::toFile) - .orElse(null); + Path path = getService(ArtifactManager.class).getPath(artifact).orElse(null); if (artifact instanceof DefaultArtifact) { org.eclipse.aether.artifact.Artifact a = ((DefaultArtifact) artifact).getArtifact(); - if (Objects.equals(file, a.getFile())) { + if (Objects.equals(path, a.getPath())) { return a; } } @@ -310,7 +307,7 @@ public abstract class AbstractSession implements InternalSession { artifact.getExtension(), artifact.getVersion().toString(), null, - file); + path); } @Override diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultArtifactResolver.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultArtifactResolver.java index 9fe55007b2..e8db03dd48 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultArtifactResolver.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultArtifactResolver.java @@ -69,7 +69,7 @@ public class DefaultArtifactResolver implements ArtifactResolver { session.getRepositorySystem().resolveArtifacts(session.getSession(), requests); for (ArtifactResult result : results) { Artifact artifact = session.getArtifact(result.getArtifact()); - Path path = result.getArtifact().getFile().toPath(); + Path path = result.getArtifact().getPath(); artifactManager.setPath(artifact, path); paths.put(artifact, path); } diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultLocalRepository.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultLocalRepository.java index 4c6797599e..3ca2d59f79 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultLocalRepository.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultLocalRepository.java @@ -53,6 +53,6 @@ public class DefaultLocalRepository implements LocalRepository { @Nonnull @Override public Path getPath() { - return repository.getBasedir().toPath(); + return repository.getBasePath(); } } diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultLocalRepositoryManager.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultLocalRepositoryManager.java index da5558fe5e..32c98135cf 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultLocalRepositoryManager.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultLocalRepositoryManager.java @@ -52,7 +52,7 @@ public class DefaultLocalRepositoryManager implements LocalRepositoryManager { InternalSession session, LocalRepository local) { org.eclipse.aether.repository.LocalRepository repository = session.toRepository(local); if ("enhanced".equals(repository.getContentType())) { - repository = new org.eclipse.aether.repository.LocalRepository(repository.getBasedir(), ""); + repository = new org.eclipse.aether.repository.LocalRepository(repository.getBasePath(), ""); } return session.getRepositorySystem().newLocalRepositoryManager(session.getSession(), repository); } diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultRepositoryFactory.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultRepositoryFactory.java index 9eff11343f..c2f4801fa4 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultRepositoryFactory.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultRepositoryFactory.java @@ -47,7 +47,7 @@ public class DefaultRepositoryFactory implements RepositoryFactory { @Override public LocalRepository createLocal(Path path) { - return new DefaultLocalRepository(new org.eclipse.aether.repository.LocalRepository(path.toFile())); + return new DefaultLocalRepository(new org.eclipse.aether.repository.LocalRepository(path)); } @Override diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultTransport.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultTransport.java index 9c609a26fc..5eabf7f64a 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultTransport.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultTransport.java @@ -54,7 +54,7 @@ public class DefaultTransport implements Transport { throw new IllegalArgumentException("Supplied relative URI escapes baseUrl"); } GetTask getTask = new GetTask(source); - getTask.setDataFile(target.toFile()); + getTask.setDataPath(target); try { transporter.get(getTask); return true; @@ -110,7 +110,7 @@ public class DefaultTransport implements Transport { } PutTask putTask = new PutTask(target); - putTask.setDataFile(source.toFile()); + putTask.setDataPath(source); try { transporter.put(putTask); } catch (Exception e) { diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenMetadata.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenMetadata.java index 80946c622d..0d8e653119 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenMetadata.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenMetadata.java @@ -89,6 +89,7 @@ abstract class MavenMetadata extends AbstractMetadata implements MergeableMetada return path; } + @Deprecated public void merge(File existing, File result) throws RepositoryException { merge(existing != null ? existing.toPath() : null, result != null ? result.toPath() : null); } diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenSessionBuilderSupplier.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenSessionBuilderSupplier.java index dbb5d22786..8b79d2bbae 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenSessionBuilderSupplier.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenSessionBuilderSupplier.java @@ -46,8 +46,8 @@ import org.eclipse.aether.util.graph.manager.ClassicDependencyManager; import org.eclipse.aether.util.graph.selector.AndDependencySelector; import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector; import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer; +import org.eclipse.aether.util.graph.transformer.ConfigurableVersionSelector; import org.eclipse.aether.util.graph.transformer.ConflictResolver; -import org.eclipse.aether.util.graph.transformer.NearestVersionSelector; import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector; import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy; @@ -98,7 +98,7 @@ public class MavenSessionBuilderSupplier implements Supplier { protected DependencyGraphTransformer getDependencyGraphTransformer() { return new ChainedDependencyGraphTransformer( new ConflictResolver( - new NearestVersionSelector(), new ManagedScopeSelector(getScopeManager()), + new ConfigurableVersionSelector(), new ManagedScopeSelector(getScopeManager()), new SimpleOptionalitySelector(), new ManagedScopeDeriver(getScopeManager())), new ManagedDependencyContextRefiner(getScopeManager())); } diff --git a/maven-core/src/main/java/org/apache/maven/ReactorReader.java b/maven-core/src/main/java/org/apache/maven/ReactorReader.java index 25d3ba0b9e..2c7995bdcf 100644 --- a/maven-core/src/main/java/org/apache/maven/ReactorReader.java +++ b/maven-core/src/main/java/org/apache/maven/ReactorReader.java @@ -409,7 +409,7 @@ class ReactorReader implements MavenWorkspaceReader { LOGGER.info("Copying {} to project local repository", artifact); Files.createDirectories(target.getParent()); Files.copy( - artifact.getFile().toPath(), + artifact.getPath(), target, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultArtifactManager.java b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultArtifactManager.java index 3835e81250..be0ae1d5ba 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultArtifactManager.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultArtifactManager.java @@ -21,7 +21,6 @@ package org.apache.maven.internal.impl; import javax.inject.Inject; import javax.inject.Named; -import java.io.File; import java.nio.file.Path; import java.util.Map; import java.util.Objects; @@ -67,10 +66,7 @@ public class DefaultArtifactManager implements ArtifactManager { } Path path = paths.get(id); if (path == null && artifact instanceof DefaultArtifact) { - File file = ((DefaultArtifact) artifact).getArtifact().getFile(); - if (file != null) { - path = file.toPath(); - } + path = ((DefaultArtifact) artifact).getArtifact().getPath(); } return Optional.ofNullable(path); } diff --git a/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java b/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java index 1cc4eff2d7..e9ab683c31 100644 --- a/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java +++ b/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java @@ -75,7 +75,7 @@ public class TestRepositoryConnector implements RepositoryConnector { for (ArtifactDownload download : artifactDownloads) { File remoteFile = new File(basedir, path(download.getArtifact())); try { - Path dest = download.getFile().toPath(); + Path dest = download.getPath(); Files.createDirectories(dest.getParent()); Files.copy(remoteFile.toPath(), dest); } catch (IOException e) { @@ -91,7 +91,7 @@ public class TestRepositoryConnector implements RepositoryConnector { for (final MetadataDownload download : metadataDownloads) { File remoteFile = new File(basedir, path(download.getMetadata())); try { - Path dest = download.getFile().toPath(); + Path dest = download.getPath(); Files.createDirectories(dest.getParent()); Files.copy(remoteFile.toPath(), dest); } catch (IOException e) { diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 69ec67a2f4..3bfcdbe4c8 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -1217,7 +1217,7 @@ public class DefaultModelBuilder implements ModelBuilder { } if (modelSource instanceof FileModelSource) { - model = model.withPomFile(((FileModelSource) modelSource).getFile().toPath()); + model = model.withPomFile(((FileModelSource) modelSource).getPath()); } Model retModel = new Model(model);