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-8229][MNG-8090] Fix jenkins build #1693

Merged
merged 2 commits into from
Aug 30, 2024
Merged
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 @@ -71,6 +71,7 @@
import org.apache.maven.api.model.Plugin;
import org.apache.maven.api.model.Profile;
import org.apache.maven.api.model.ReportPlugin;
import org.apache.maven.api.services.MavenException;
import org.apache.maven.api.services.ModelBuilder;
import org.apache.maven.api.services.ModelBuilderException;
import org.apache.maven.api.services.ModelBuilderRequest;
Expand Down Expand Up @@ -101,6 +102,9 @@
import org.apache.maven.model.root.RootLocator;
import org.apache.maven.repository.internal.ArtifactDescriptorUtils;
import org.apache.maven.utils.Os;
import org.codehaus.plexus.interpolation.AbstractValueSource;
import org.codehaus.plexus.interpolation.InterpolationException;
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.RequestTrace;
Expand Down Expand Up @@ -308,6 +312,7 @@ class BuildSession implements AutoCloseable {
private final ExecutorService executor;
private final ModelCache modelCache;
private final ModelResolver modelResolver;
private final Map<String, String> ciFriendlyVersions = new ConcurrentHashMap<>();

BuildSession(ProjectBuildingRequest request, boolean localProjects) {
this.request = request;
Expand Down Expand Up @@ -471,7 +476,7 @@ ProjectBuildingResult build(Artifact artifact, boolean allowStubModel) throws Pr
try {
ArtifactRequest pomRequest = new ArtifactRequest();
pomRequest.setArtifact(pomArtifact);
pomRequest.setRepositories(repositories);
pomRequest.setRepositories(RepositoryUtils.toRepos(request.getRemoteRepositories()));
ArtifactResult pomResult = repoSystem.resolveArtifact(session, pomRequest);

pomArtifact = pomResult.getArtifact();
Expand Down Expand Up @@ -618,7 +623,10 @@ private InterimResult build(

Model model = result.getActivatedFileModel();

modelPool.put(model.getPomFile(), model);
// In case the model is using CI friendly versions, at this point, it will contain uninterpolated version
// such as ${revision}${changelist}, so we need to take care of it now
Model modelWithVersion = getModelWithInterpolatedVersion(model, result.getProblems()::add);
modelPool.put(model.getPomFile(), modelWithVersion);

InterimResult interimResult = new InterimResult(pomFile, modelBuildingRequest, result, project, isRoot);

Expand Down Expand Up @@ -697,6 +705,59 @@ private InterimResult build(
return interimResult;
}

private Model getModelWithInterpolatedVersion(
Model model, Consumer<org.apache.maven.api.services.ModelProblem> problems) {
String version = model.getVersion();
if (version == null && model.getParent() != null) {
version = model.getParent().getVersion();
}
if (version != null && version.contains("${")) {
try {
StringSearchInterpolator interpolator = new StringSearchInterpolator();
interpolator.addValueSource(new AbstractValueSource(false) {
@Override
public String getValue(String key) {
String val = request.getUserProperties().getProperty(key);
if (val == null) {
val = model.getProperties().get(key);
if (val == null) {
val = request.getSystemProperties().getProperty(key);
if (val == null) {
val = ciFriendlyVersions.get(key);
}
}
}
if (val != null) {
String oldVal = ciFriendlyVersions.put(key, val);
if (oldVal != null && !val.equals(oldVal)) {
throw new MavenException("Non unique property value detected for key '" + key
+ "' which is bound to '" + oldVal + "' and '" + val + "'");
}
}
return val;
}
});
version = interpolator.interpolate(version);
} catch (InterpolationException | MavenException e) {
ModelProblem problem = new org.apache.maven.internal.impl.model.DefaultModelProblem(
"Unable to interpolate ",
ModelProblem.Severity.ERROR,
ModelProblem.Version.BASE,
model,
-1,
-1,
null);
problems.accept(problem);
}
if (model.getVersion() != null) {
return model.withVersion(version);
} else {
return model.withParent(model.getParent().withVersion(version));
}
}
return model;
}

private List<ProjectBuildingResult> build(
Map<File, MavenProject> projectIndex, List<InterimResult> interimResults) {
// The transformation may need to access dependencies raw models,
Expand Down