/** * Get plugin management version properties from a remote POM * * @return Map between the GA of the plugin and the version of the plugin. If the system property * is not set, returns an empty map. */ private static Map<String, String> loadRemotePluginVersionOverrides() throws MavenExecutionException { Properties systemProperties = System.getProperties(); String pluginMgmtCSV = systemProperties.getProperty(PLUGIN_MANAGEMENT_POM_PROPERTY); Map<String, String> versionOverrides = new HashMap<String, String>(0); if (pluginMgmtCSV == null) { return versionOverrides; } String[] pluginMgmtPomGAVs = pluginMgmtCSV.split(","); // Iterate in reverse order so that the first GAV in the list overwrites the last for (int i = (pluginMgmtPomGAVs.length - 1); i > -1; --i) { String nextGAV = pluginMgmtPomGAVs[i]; if (!MavenUtil.validGav(nextGAV)) { Log.getLog().warn("Skipping invalid plugin management GAV: " + nextGAV); continue; } try { AbstractEffectiveModelBuilder resolver = AbstractEffectiveModelBuilder.getInstance(); versionOverrides.putAll(resolver.getRemotePluginVersionOverrides(nextGAV)); } catch (Exception e) { Log.getLog().error("Unable to resolve remote pom: " + e); throw new MavenExecutionException("Unable to resolve remote pom", e); } } return versionOverrides; }
@Override public boolean updateModel(Model model) throws MavenExecutionException { Map<String, String> versionOverrides = getVersionOverrides(); if (versionOverrides.size() == 0) { return false; } // If the model doesn't have any plugin management set by default, create one for it PluginManagement pluginManagement = model.getBuild().getPluginManagement(); if (pluginManagement == null) { pluginManagement = new PluginManagement(); model.getBuild().setPluginManagement(pluginManagement); Log.getLog().debug("Created new Plugin Management for model"); } // Override plugin management versions applyOverrides(pluginManagement.getPlugins(), versionOverrides); // Override plugin versions List<Plugin> projectPlugins = model.getBuild().getPlugins(); applyOverrides(projectPlugins, versionOverrides); // Include the overrides in the built files for repeatability writeOverrideMap(model, getName(), versionOverrides); // Assuming the Model changed since overrides were given return true; }
/** * Set the versions of any plugins which match the contents of the list of plugin overrides * * @param plugins The list of plugins to modify * @param pluginVersionOverrides The list of version overrides to apply to the plugins */ private static void applyOverrides( List<Plugin> plugins, Map<String, String> pluginVersionOverrides) { for (Plugin plugin : plugins) { String groupIdArtifactId = plugin.getGroupId() + GAV_SEPERATOR + plugin.getArtifactId(); if (pluginVersionOverrides.containsKey(groupIdArtifactId)) { String overrideVersion = pluginVersionOverrides.get(groupIdArtifactId); plugin.setVersion(overrideVersion); Log.getLog().debug("Altered plugin: " + groupIdArtifactId + "=" + overrideVersion); } } }