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

[MNG-8325][MNG-8326][MNG-8327] Fix bugs #1818

Merged
merged 3 commits into from
Oct 18, 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 @@ -59,6 +59,7 @@ default ModelSource resolveModel(
parent.getGroupId(),
parent.getArtifactId(),
parent.getVersion(),
null,
version -> modified.set(parent.withVersion(version)));
}

Expand All @@ -85,6 +86,7 @@ default ModelSource resolveModel(
dependency.getGroupId(),
dependency.getArtifactId(),
dependency.getVersion(),
dependency.getClassifier(),
version -> modified.set(dependency.withVersion(version)));
}

Expand All @@ -95,6 +97,7 @@ ModelSource resolveModel(
@Nonnull String groupId,
@Nonnull String artifactId,
@Nonnull String version,
@Nullable String classifier,
@Nonnull Consumer<String> resolvedVersion)
throws ModelResolverException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public ModelSource resolveModel(
parent.getArtifactId(),
parent.getVersion(),
"parent",
null,
parent.getLocation("version"),
version -> modified.set(parent.withVersion(version)));
}
Expand All @@ -89,6 +90,7 @@ public ModelSource resolveModel(
dependency.getArtifactId(),
dependency.getVersion(),
"dependency",
dependency.getClassifier(),
dependency.getLocation("version"),
version -> modified.set(dependency.withVersion(version)));
}
Expand All @@ -100,9 +102,11 @@ public ModelSource resolveModel(
@Nonnull String groupId,
@Nonnull String artifactId,
@Nonnull String version,
@Nullable String classifier,
@Nonnull Consumer<String> resolvedVersion)
throws ModelResolverException {
return resolveModel(session, repositories, groupId, artifactId, version, null, null, resolvedVersion);
return resolveModel(
session, repositories, groupId, artifactId, version, null, classifier, null, resolvedVersion);
}

@SuppressWarnings("checkstyle:ParameterNumber")
Expand All @@ -113,11 +117,13 @@ public ModelSource resolveModel(
String artifactId,
String version,
String type,
String classifier,
InputLocation location,
Consumer<String> resolvedVersion)
throws ModelResolverException {
try {
ArtifactCoordinates coords = session.createArtifactCoordinates(groupId, artifactId, version, "pom");
ArtifactCoordinates coords =
session.createArtifactCoordinates(groupId, artifactId, version, classifier, "pom", null);
if (coords.getVersionConstraint().getVersionRange() != null
&& coords.getVersionConstraint().getVersionRange().getUpperBoundary() == null) {
// Message below is checked for in the MNG-2199 core IT.
Expand All @@ -143,7 +149,7 @@ public ModelSource resolveModel(
resolvedVersion.accept(newVersion);
}

Path path = getPath(session, repositories, groupId, artifactId, newVersion);
Path path = getPath(session, repositories, groupId, artifactId, newVersion, classifier);
return new ResolverModelSource(path, groupId + ":" + artifactId + ":" + newVersion);
} catch (VersionRangeResolverException | ArtifactResolverException e) {
throw new ModelResolverException(
Expand All @@ -163,9 +169,10 @@ protected Path getPath(
List<RemoteRepository> repositories,
String groupId,
String artifactId,
String newVersion) {
String version,
String classifier) {
DownloadedArtifact resolved = session.resolveArtifact(
session.createArtifactCoordinates(groupId, artifactId, newVersion, "pom"), repositories);
session.createArtifactCoordinates(groupId, artifactId, version, classifier, "pom", null), repositories);
return resolved.getPath();
}

Expand Down
21 changes: 20 additions & 1 deletion maven-core/src/main/java/org/apache/maven/ReactorReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.maven.api.feature.Features;
import org.apache.maven.api.model.Model;
import org.apache.maven.api.services.Lookup;
import org.apache.maven.eventspy.EventSpy;
Expand Down Expand Up @@ -412,7 +413,20 @@ private boolean isRegularFile(Artifact artifact) {
}

private void installIntoProjectLocalRepository(Artifact artifact) {
Path target = getArtifactPath(artifact);
String extension = artifact.getExtension();
String classifier = artifact.getClassifier();
if (Features.consumerPom(session.getUserProperties())) {
if ("pom".equals(extension)) {
if (classifier == null || classifier.isEmpty()) {
classifier = "build";
} else if (classifier.equals("consumer")) {
classifier = null;
}
}
}

Path target = getArtifactPath(
artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), classifier, extension);
try {
LOGGER.info("Copying {} to project local repository", artifact);
Files.createDirectories(target.getParent());
Expand All @@ -432,6 +446,11 @@ private Path getArtifactPath(Artifact artifact) {
String version = artifact.getBaseVersion();
String classifier = artifact.getClassifier();
String extension = artifact.getExtension();
return getArtifactPath(groupId, artifactId, version, classifier, extension);
}

private Path getArtifactPath(
String groupId, String artifactId, String version, String classifier, String extension) {
Path repo = getProjectLocalRepo();
return repo.resolve(groupId)
.resolve(artifactId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,12 @@ class BuildSession implements AutoCloseable {
RepositoryUtils.overlay(request.getLocalRepository(), request.getRepositorySession(), repoSystem);
InternalSession iSession = InternalSession.from(session);
this.modelBuilderSession = modelBuilder.newSession();
iSession.getData().set(SessionData.key(ModelBuilder.ModelBuilderSession.class), modelBuilderSession);
// Save the ModelBuilderSession for later retrieval by the DefaultConsumerPomBuilder.
// Use replace(key, null, value) to make sure the *main* session, i.e. the one used
// to load the projects, is stored. This is to avoid the session being overwritten
// if a plugin uses the ProjectBuilder.
iSession.getData()
.replace(SessionData.key(ModelBuilder.ModelBuilderSession.class), null, modelBuilderSession);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public ModelSource resolveModel(
String groupId,
String artifactId,
String version,
String classifier,
Consumer<String> resolvedVersion)
throws ModelResolverException {
String id = groupId + ":" + artifactId + ":" + version;
Expand Down