Skip to content

Commit

Permalink
[MNG-8118] Backport to Maven 3.9.x (#1505)
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas authored May 9, 2024
1 parent c1c114d commit c44304f
Showing 1 changed file with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.maven.model.Build;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MavenPluginManager;
import org.apache.maven.plugin.PluginIncompatibleException;
import org.apache.maven.plugin.PluginResolutionException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.version.PluginVersionRequest;
Expand Down Expand Up @@ -158,6 +159,8 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque
throws PluginVersionResolutionException {
String version = null;
ArtifactRepository repo = null;
boolean resolvedPluginVersions = !versions.versions.isEmpty();
boolean searchPerformed = false;

if (StringUtils.isNotEmpty(versions.releaseVersion)) {
version = versions.releaseVersion;
Expand All @@ -167,8 +170,11 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque
repo = versions.latestRepository;
}
if (version != null && !isCompatible(request, version)) {
logger.info("Latest version of plugin " + request.getGroupId() + ":" + request.getArtifactId()
+ " failed compatibility check");
versions.versions.remove(version);
version = null;
searchPerformed = true;
}

if (version == null) {
Expand All @@ -191,16 +197,26 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque
}
}

for (Version v : releases) {
String ver = v.toString();
if (isCompatible(request, ver)) {
version = ver;
repo = versions.versions.get(version);
break;
if (!releases.isEmpty()) {
logger.info("Looking for compatible RELEASE version of plugin "
+ request.getGroupId()
+ ":"
+ request.getArtifactId());
for (Version v : releases) {
String ver = v.toString();
if (isCompatible(request, ver)) {
version = ver;
repo = versions.versions.get(version);
break;
}
}
}

if (version == null) {
if (version == null && !snapshots.isEmpty()) {
logger.info("Looking for compatible SNAPSHOT version of plugin "
+ request.getGroupId()
+ ":"
+ request.getArtifactId());
for (Version v : snapshots) {
String ver = v.toString();
if (isCompatible(request, ver)) {
Expand All @@ -213,15 +229,27 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque
}

if (version != null) {
// if LATEST worked out of the box, remain silent as today, otherwise inform user about search result
if (searchPerformed) {
logger.info("Selected plugin " + request.getGroupId() + ":" + request.getArtifactId() + ":" + version);
}
result.setVersion(version);
result.setRepository(repo);
} else {
logger.warn((resolvedPluginVersions
? "Could not find compatible version of plugin in any plugin repository: "
: "Plugin not found in any plugin repository: ")
+ request.getGroupId()
+ ":"
+ request.getArtifactId());
throw new PluginVersionResolutionException(
request.getGroupId(),
request.getArtifactId(),
request.getRepositorySession().getLocalRepository(),
request.getRepositories(),
"Plugin not found in any plugin repository");
resolvedPluginVersions
? "Could not find compatible plugin version in any plugin repository"
: "Plugin not found in any plugin repository");
}
}

Expand All @@ -246,8 +274,12 @@ private boolean isCompatible(PluginVersionRequest request, String version) {

try {
pluginManager.checkRequiredMavenVersion(pluginDescriptor);
} catch (Exception e) {
logger.debug("Ignoring incompatible plugin version " + version + ": " + e.getMessage());
} catch (PluginIncompatibleException e) {
if (logger.isDebugEnabled()) {
logger.warn("Ignoring incompatible plugin version " + version, e);
} else {
logger.warn("Ignoring incompatible plugin version " + version + ": " + e.getMessage());
}
return false;
}

Expand Down

0 comments on commit c44304f

Please sign in to comment.