use of org.commonjava.maven.ext.core.state.BOMInjectingState 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();
}
use of org.commonjava.maven.ext.core.state.BOMInjectingState in project pom-manipulation-ext by release-engineering.
the class BOMBuilderManipulator method init.
@Override
public void init(final ManipulationSession session) throws ManipulationException {
this.session = session;
session.setState(new BOMInjectingState(session.getUserProperties()));
}
Aggregations