Copilot commented on code in PR #650:
URL:
https://github.com/apache/maven-project-info-reports-plugin/pull/650#discussion_r3741222185
##########
src/main/java/org/apache/maven/report/projectinfo/dependencies/RepositoryUtils.java:
##########
@@ -47,21 +60,63 @@ public class RepositoryUtils {
private final ProjectBuilder projectBuilder;
+ private final ArtifactHandlerManager artifactHandlerManager;
+
private final RepositorySystem repositorySystem;
private final Provider<MavenSession> sessionProvider;
/**
* @param projectBuilder {@link ProjectBuilder}
+ * @param artifactHandlerManager {@link ArtifactHandlerManager}
+ * @param repositorySystem {@link RepositorySystem}
+ * @param sessionProvider the current {@link MavenSession}
*/
@Inject
public RepositoryUtils(
- ProjectBuilder projectBuilder, RepositorySystem repositorySystem,
Provider<MavenSession> sessionProvider) {
+ ProjectBuilder projectBuilder,
+ ArtifactHandlerManager artifactHandlerManager,
+ RepositorySystem repositorySystem,
+ Provider<MavenSession> sessionProvider) {
this.projectBuilder = projectBuilder;
+ this.artifactHandlerManager = artifactHandlerManager;
this.repositorySystem = repositorySystem;
this.sessionProvider = sessionProvider;
}
+ /**
+ * Create an artifact of type <code>pom</code> for the given coordinates.
+ *
+ * @param groupId the group id
+ * @param artifactId the artifact id
+ * @param version the version, may be a version range
+ * @return the artifact, never {@code null}
+ */
+ public Artifact createProjectArtifact(String groupId, String artifactId,
String version) {
+ return createArtifact(groupId, artifactId, version, null, "pom");
+ }
+
+ /**
+ * Create an artifact for the given coordinates.
+ *
+ * @param groupId the group id
+ * @param artifactId the artifact id
+ * @param version the version, may be a version range
+ * @param scope the dependency scope, may be {@code null}
+ * @param type the artifact type
+ * @return the artifact, never {@code null}
+ */
+ public Artifact createArtifact(String groupId, String artifactId, String
version, String scope, String type) {
+ return new DefaultArtifact(
+ groupId,
+ artifactId,
+ VersionRange.createFromVersion(version),
+ scope,
+ type,
+ null,
+ artifactHandlerManager.getArtifactHandler(type));
+ }
Review Comment:
`createArtifact(..)` documents that `version` may be a version range, but it
currently uses `VersionRange.createFromVersion(version)`, which does not parse
range specs (e.g. "[1.0,)" / "[1.0,2.0)") into restrictions. This can lead to
incorrect behavior when the artifact is later converted to an Aether artifact
for `resolveVersionRange`, because the request may not carry proper range
semantics.
##########
src/main/java/org/apache/maven/report/projectinfo/dependencies/RepositoryUtils.java:
##########
@@ -79,6 +134,33 @@ public void resolve(Artifact artifact) throws
ArtifactResolutionException {
artifact.setResolved(true);
}
+ /**
+ * Retrieve the versions available in the given remote repositories for
the artifact, whose version may be a
+ * version range. Only the versions matching that range are returned,
sorted in ascending order.
+ *
+ * @param artifact the artifact, its version may be a version range
+ * @param remoteRepositories the remote repositories to look the versions
up in
+ * @return the matching versions, possibly empty, never {@code null}
+ * @throws VersionRangeResolutionException if the version range could not
be resolved at all
+ */
+ public List<ArtifactVersion> getAvailableVersions(Artifact artifact,
List<ArtifactRepository> remoteRepositories)
+ throws VersionRangeResolutionException {
+
+ MavenSession session = sessionProvider.get();
+
+ VersionRangeRequest request = new VersionRangeRequest(
+ org.apache.maven.RepositoryUtils.toArtifact(artifact),
+ org.apache.maven.RepositoryUtils.toRepos(remoteRepositories),
+ null);
+ VersionRangeResult result =
repositorySystem.resolveVersionRange(session.getRepositorySession(), request);
+
+ List<ArtifactVersion> versions = new
ArrayList<>(result.getVersions().size());
+ for (Version version : result.getVersions()) {
+ versions.add(new DefaultArtifactVersion(version.toString()));
+ }
+ return versions;
+ }
Review Comment:
`getAvailableVersions(..)` Javadoc promises the returned versions are
"sorted in ascending order", but the implementation returns them in whatever
order the resolver provides. Sorting before returning will make the method
behavior deterministic and match the contract.
##########
src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependencyManagementRenderer.java:
##########
@@ -216,15 +202,8 @@ private String[] getDependencyRow(Dependency dependency,
boolean hasClassifier)
// MPIR-216: no direct version but version range: need to
choose one precise version
log.debug("Resolving range for DependencyManagement on " +
artifact.getId());
Review Comment:
The range-resolution path is now driven by Resolver (`resolveVersionRange`),
which intentionally changes how SNAPSHOTs participate in open-ended ranges
compared to the old `ArtifactMetadataSource` implementation. There are IT
fixtures for a range like `[1.0,)` (e.g. `src/it/full-pom`), but none that
verifies behavior when a matching SNAPSHOT is present in metadata; adding such
a fixture would lock down the intended user-visible behavior change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]