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-8117] Maven PluginVersionResolver improvement #1502

Merged
Merged
Changes from 1 commit
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 @@ -39,6 +39,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 @@ -175,6 +176,7 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque
throws PluginVersionResolutionException {
String version = null;
ArtifactRepository repo = null;
boolean resolvedPluginVersions = !versions.versions.isEmpty();

if (versions.releaseVersion != null && !versions.releaseVersion.isEmpty()) {
version = versions.releaseVersion;
Expand All @@ -184,6 +186,10 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque
repo = versions.latestRepository;
}
if (version != null && !isCompatible(request, version)) {
logger.info(
"Latest version of plugin {}:{} failed compatibility check",
request.getGroupId(),
request.getArtifactId());
versions.versions.remove(version);
version = null;
}
Expand All @@ -206,16 +212,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 @@ -231,12 +247,18 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque
result.setVersion(version);
result.setRepository(repo);
} else {
logger.info(
"Could not find compatible version of plugin {}:{} 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 @@ -261,8 +283,12 @@ private boolean isCompatible(PluginVersionRequest request, String version) {

try {
pluginManager.checkPrerequisites(pluginDescriptor);
} catch (Exception e) {
logger.warn("Ignoring incompatible plugin version {}", version, e);
} catch (PluginIncompatibleException e) {
if (logger.isDebugEnabled()) {
logger.warn("Ignoring incompatible plugin version {}: {}", version, e.getMessage(), e);
michael-o marked this conversation as resolved.
Show resolved Hide resolved
} else {
logger.warn("Ignoring incompatible plugin version {}: {}", version, e.getMessage());
}
return false;
}

Expand Down