[MNG-7838] Fix usage of older packaged artifacts from project local repository (#1199)

This commit is contained in:
Guillaume Nodet 2024-08-29 22:34:39 +02:00 committed by GitHub
parent b370e5e929
commit c0813a2b53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 13 deletions

View File

@ -101,9 +101,9 @@ public File findArtifact(Artifact artifact) {
MavenProject project = getProject(artifact);
if (project != null) {
File file = findArtifact(project, artifact);
File file = findArtifact(project, artifact, true);
if (file == null && project != project.getExecutionProject()) {
file = findArtifact(project.getExecutionProject(), artifact);
file = findArtifact(project.getExecutionProject(), artifact, true);
}
return file;
}
@ -133,7 +133,7 @@ public List<String> findVersions(Artifact artifact) {
.getOrDefault(artifact.getArtifactId(), Collections.emptyMap())
.values()
.stream()
.filter(p -> Objects.nonNull(findArtifact(p, artifact)))
.filter(p -> Objects.nonNull(findArtifact(p, artifact, false)))
.map(MavenProject::getVersion)
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
}
@ -148,30 +148,30 @@ public Model findModel(Artifact artifact) {
// Implementation
//
private File findArtifact(MavenProject project, Artifact artifact) {
private File findArtifact(MavenProject project, Artifact artifact, boolean checkUptodate) {
// POMs are always returned from the file system
if ("pom".equals(artifact.getExtension())) {
return project.getFile();
}
// First check in the project local repository
File packagedArtifactFile = findInProjectLocalRepository(artifact);
if (packagedArtifactFile != null
&& packagedArtifactFile.exists()
&& isPackagedArtifactUpToDate(project, packagedArtifactFile)) {
return packagedArtifactFile;
}
// Get the matching artifact from the project
Artifact projectArtifact = findMatchingArtifact(project, artifact);
if (projectArtifact != null) {
// If the artifact has been associated to a file, use it
packagedArtifactFile = projectArtifact.getFile();
File packagedArtifactFile = projectArtifact.getFile();
if (packagedArtifactFile != null && packagedArtifactFile.exists()) {
return packagedArtifactFile;
}
}
// Check in the project local repository
File packagedArtifactFile = findInProjectLocalRepository(artifact);
if (packagedArtifactFile != null
&& packagedArtifactFile.exists()
&& (!checkUptodate || isPackagedArtifactUpToDate(project, packagedArtifactFile))) {
return packagedArtifactFile;
}
if (!hasBeenPackagedDuringThisSession(project)) {
// fallback to loose class files only if artifacts haven't been packaged yet
// and only for plain old jars. Not war files, not ear files, not anything else.