in enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequirePluginVersions.java [441:471]
private Plugin findCurrentPlugin(Plugin plugin, MavenProject project) throws EnforcerRuleException {
Plugin found = null;
try {
Model model = project.getModel();
Map<String, Plugin> plugins = model.getBuild().getPluginsAsMap();
found = plugins.get(plugin.getKey());
} catch (NullPointerException e) {
// nothing to do here
}
if (found == null) {
Artifact artifact = factory.createPluginArtifact(
plugin.getGroupId(), plugin.getArtifactId(), VersionRange.createFromVersion("LATEST"));
try {
repositorySystem.resolveArtifact(
session.getRepositorySession(),
new ArtifactRequest(
RepositoryUtils.toArtifact(artifact),
session.getCurrentProject().getRemotePluginRepositories(),
"resolvePlugin"));
} catch (ArtifactResolutionException e) {
throw new EnforcerRuleException("Unable to resolve the plugin " + artifact.getArtifactId(), e);
}
plugin.setVersion(artifact.getVersion());
found = plugin;
}
return found;
}