use of org.apache.maven.model.Plugin in project pom-manipulation-ext by release-engineering.
the class Project method getResolvedProfileManagedPlugins.
/**
* This method will scan the plugins in the pluginManagement section in the potentially active Profiles
* in this project and return a fully resolved list. Note that while updating the {@link Plugin}
* reference returned will be reflected in the Model as it is the same object, if you wish to remove
* or add items to the Model then you must use {@link #getModel()}
*
* @param session MavenSessionHandler, used by {@link PropertyResolver}
* @return a list of fully resolved {@link ProjectVersionRef} to the original {@link Plugin}
* @throws ManipulationException if an error occurs
*/
public HashMap<Profile, HashMap<ProjectVersionRef, Plugin>> getResolvedProfileManagedPlugins(MavenSessionHandler session) throws ManipulationException {
if (resolvedProfileManagedPlugins == null) {
resolvedProfileManagedPlugins = new HashMap<>();
for (final Profile profile : ProfileUtils.getProfiles(session, model)) {
HashMap<ProjectVersionRef, Plugin> profileDeps = new HashMap<>();
if (profile.getBuild() != null) {
final PluginManagement pm = profile.getBuild().getPluginManagement();
if (!(pm == null || pm.getPlugins() == null)) {
resolvePlugins(session, pm.getPlugins(), profileDeps);
}
}
resolvedProfileManagedPlugins.put(profile, profileDeps);
}
}
return resolvedProfileManagedPlugins;
}
use of org.apache.maven.model.Plugin in project pom-manipulation-ext by release-engineering.
the class DistributionEnforcingManipulator method getPluginMap.
private Map<String, Plugin> getPluginMap(final ModelBase base) {
final BuildBase build;
if (base instanceof Model) {
build = ((Model) base).getBuild();
} else {
build = ((Profile) base).getBuild();
}
if (build == null) {
return Collections.emptyMap();
}
final Map<String, Plugin> result = build.getPluginsAsMap();
if (result == null) {
return Collections.emptyMap();
}
return result;
}
use of org.apache.maven.model.Plugin in project pom-manipulation-ext by release-engineering.
the class DistributionEnforcingManipulator method findSkipRefs.
/**
* Go through the plugin / plugin-execution configurations and find references to the <code>skip</code> parameter for the given Maven plugin
* (specified by artifactId), both in managed and concrete plugin declarations (where available).
*/
private List<SkipReference> findSkipRefs(final ModelBase base, final String pluginArtifactId, final Project project) throws ManipulationException {
final String key = ga(MAVEN_PLUGIN_GROUPID, pluginArtifactId);
final List<SkipReference> result = new ArrayList<>();
Map<String, Plugin> pluginMap = getManagedPluginMap(base);
Plugin plugin = pluginMap.get(key);
result.addAll(findSkipRefs(plugin, project));
pluginMap = getPluginMap(base);
plugin = pluginMap.get(key);
result.addAll(findSkipRefs(plugin, project));
return result;
}
use of org.apache.maven.model.Plugin in project pom-manipulation-ext by release-engineering.
the class PluginRemovalManipulator method scanPlugins.
private boolean scanPlugins(List<ProjectRef> pluginsToRemove, List<Plugin> plugins) {
boolean result = false;
if (plugins != null) {
Iterator<Plugin> it = plugins.iterator();
while (it.hasNext()) {
Plugin p = it.next();
if (pluginsToRemove.contains(SimpleProjectRef.parse(p.getKey()))) {
logger.debug("Removing {} ", p.toString());
it.remove();
result = true;
}
}
}
return result;
}
use of org.apache.maven.model.Plugin in project pom-manipulation-ext by release-engineering.
the class BOMBuilderManipulator method applyChanges.
/**
* If enabled, grab the execution root pom (which will be the topmost POM in terms of directory structure). Within that
* handle the manipulation of the bom injection.
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final BOMInjectingState state = session.getState(BOMInjectingState.class);
if (!session.isEnabled() || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return Collections.emptySet();
}
List<Dependency> projectArtifacts = getArtifacts(projects);
for (final Project project : projects) {
if (project.isExecutionRoot()) {
logger.info("Examining {} to add BOM generation.", project);
final Model model = project.getModel();
Build build = model.getBuild();
if (build == null) {
build = new Build();
model.setBuild(build);
}
Model bomModel = createModel(project, IDBOM);
bomModel.setDescription("PME Generated BOM for other projects to use to align to.");
DependencyManagement dm = new DependencyManagement();
dm.setDependencies(projectArtifacts);
bomModel.setDependencyManagement(dm);
// Write new bom back out.
File pmebom = new File(session.getTargetDir(), IDBOM + ".xml");
session.getTargetDir().mkdir();
pomIO.writeModel(bomModel, pmebom);
final Map<String, Plugin> pluginMap = build.getPluginsAsMap();
if (!pluginMap.containsKey(POM_DEPLOYER_COORD)) {
final PluginExecution execution = new PluginExecution();
execution.setId(IDBOM);
execution.setPhase("install");
execution.setGoals(Collections.singletonList("add-pom"));
final Plugin plugin = new Plugin();
plugin.setGroupId(POM_DEPLOYER_GID);
plugin.setArtifactId(POM_DEPLOYER_AID);
plugin.setVersion(POM_DEPLOYER_VID);
plugin.addExecution(execution);
plugin.setInherited(false);
build.addPlugin(plugin);
final Xpp3Dom xml = new Xpp3Dom("configuration");
final Map<String, Object> config = new HashMap<>();
config.put("pomName", "target" + File.separatorChar + pmebom.getName());
config.put("errorOnMissing", false);
config.put("artifactId", bomModel.getArtifactId());
config.put("groupId", bomModel.getGroupId());
for (final Map.Entry<String, Object> entry : config.entrySet()) {
final Xpp3Dom child = new Xpp3Dom(entry.getKey());
if (entry.getValue() != null) {
child.setValue(entry.getValue().toString());
}
xml.addChild(child);
}
execution.setConfiguration(xml);
}
return Collections.singleton(project);
}
}
return Collections.emptySet();
}
Aggregations