Created
June 26, 2014 15:56
-
-
Save Riduidel/2df79e859bfbf83c0e5c to your computer and use it in GitHub Desktop.
Get version of an unversionned plugin to use with Mojo Executor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Creates a plugin from source one with version set according to project dependency management and other rules .. | |
| * @param environment | |
| * @param plugin | |
| * @return | |
| */ | |
| private static Plugin findVersionOf(MavenEnvironment environment, final Plugin plugin) { | |
| SortedSet<Plugin> candidates = new TreeSet<Plugin>(); | |
| if(plugin.getVersion()!=null) | |
| return plugin; | |
| Iterable<Plugin> plugins = Iterables.concat(environment.project.getPluginManagement().getPlugins(), environment.project.getBuildPlugins()); | |
| Iterable<Plugin> matching = Iterables.filter(plugins, new Predicate<Plugin>() { | |
| @Override | |
| public boolean apply(Plugin input) { | |
| return input.getArtifactId().equals(plugin.getArtifactId()) && input.getGroupId().equals(plugin.getGroupId()); | |
| }}); | |
| Plugin found = Iterables.getFirst(matching, null); | |
| if(found==null) | |
| throw new UnsupportedMavenPluginException("plugin "+plugin+" isn't declared in this project. You should set its version by hand !"); | |
| return found; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment