use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class ProjectVersionEnforcingManipulator method applyChanges.
/**
* For each project in the current build set, reset the version if using project.version
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final ProjectVersionEnforcingState state = session.getState(ProjectVersionEnforcingState.class);
if (!session.isEnabled() || !session.anyStateEnabled(State.activeByDefault) || state == null || !state.isEnabled()) {
logger.debug("Project version enforcement is disabled.");
return Collections.emptySet();
}
final Set<Project> changed = new HashSet<>();
for (final Project project : projects) {
final Model model = project.getModel();
if (model.getPackaging().equals("pom")) {
enforceProjectVersion(project, model.getDependencies(), changed);
if (model.getDependencyManagement() != null) {
enforceProjectVersion(project, model.getDependencyManagement().getDependencies(), changed);
}
final List<Profile> profiles = ProfileUtils.getProfiles(session, model);
if (profiles != null) {
for (final Profile profile : profiles) {
enforceProjectVersion(project, profile.getDependencies(), changed);
if (profile.getDependencyManagement() != null) {
enforceProjectVersion(project, profile.getDependencyManagement().getDependencies(), changed);
}
}
}
}
}
if (!changed.isEmpty()) {
logger.warn("Using ${project.version} in pom files may lead to unexpected errors with inheritance.");
}
return changed;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class DependencyManipulator method internalApplyChanges.
private Set<Project> internalApplyChanges(final List<Project> projects, Map<ArtifactRef, String> overrides) throws ManipulationException {
final DependencyState state = session.getState(DependencyState.class);
final Set<Project> result = new HashSet<>();
for (final Project project : projects) {
final Model model = project.getModel();
if (!overrides.isEmpty() || !state.getDependencyExclusions().isEmpty()) {
apply(project, model, overrides);
result.add(project);
}
}
// If we've changed something now update any old properties with the new values.
if (!result.isEmpty()) {
logger.info("Iterating for standard overrides...");
for (Project project : versionPropertyUpdateMap.keySet()) {
logger.debug("Checking property override within project {} ", project);
for (final Map.Entry<String, String> entry : versionPropertyUpdateMap.get(project).entrySet()) {
PropertiesUtils.PropertyUpdate found = PropertiesUtils.updateProperties(session, project, false, entry.getKey(), entry.getValue());
if (found == PropertiesUtils.PropertyUpdate.NOTFOUND) {
// Problem in this scenario is that we know we have a property update map but we have not found a
// property to update. Its possible this property has been inherited from a parent. Override in the
// top pom for safety.
logger.info("Unable to find a property for {} to update", entry.getKey());
logger.info("Adding property {} with {} ", entry.getKey(), entry.getValue());
// We know the inheritance root is at position 0 in the inherited list...
project.getInheritedList().get(0).getModel().getProperties().setProperty(entry.getKey(), entry.getValue());
}
}
}
logger.info("Iterating for explicit overrides...");
for (Project project : explicitVersionPropertyUpdateMap.keySet()) {
logger.debug("Checking property override within project {} ", project);
for (final Map.Entry<String, String> entry : explicitVersionPropertyUpdateMap.get(project).entrySet()) {
PropertiesUtils.PropertyUpdate found = PropertiesUtils.updateProperties(session, project, true, entry.getKey(), entry.getValue());
if (found == PropertiesUtils.PropertyUpdate.NOTFOUND) {
// Problem in this scenario is that we know we have a property update map but we have not found a
// property to update. Its possible this property has been inherited from a parent. Override in the
// top pom for safety.
logger.info("Unable to find a property for {} to update for explicit overrides", entry.getKey());
logger.info("Adding property {} with {} ", entry.getKey(), entry.getValue());
// We know the inheritance root is at position 0 in the inherited list...
project.getInheritedList().get(0).getModel().getProperties().setProperty(entry.getKey(), entry.getValue());
}
}
}
}
return result;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class DistributionEnforcingManipulator method applyChanges.
/**
* For each project in the current build set, enforce the value of the plugin-wide skip flag and that of the 'default-deploy' execution, if they
* exist. There are three possible modes for enforcement:
*
* <ul>
* <li><b>on</b> - Ensure install and deploy skip is <b>disabled</b>, and that these functions will happen during the build.</li>
* <li><b>off</b> - Ensure install and deploy skip is <b>enabled</b>, and that neither of these functions will happen during the build.</li>
* <li><b>detect</b> - Detect the proper flag value from the install plugin's <code>skip</code> flag (either in the plugin-wide config or the
* <code>default-install</code> execution, if it's specified in the main POM, not a profile). If not present, disable the skip flag.
* Enforce consistency with this value install/deploy.</li>
* </ul>
*
* <b>NOTE:</b> It's possible to specify an enforcement mode that's unique to a single project, using a command-line parameter of:
* <code>-DdistroExclusion.g:a=<mode></code>.
*
* @see DistributionEnforcingState
* @see EnforcingMode
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final DistributionEnforcingState state = session.getState(DistributionEnforcingState.class);
if (state == null || !state.isEnabled()) {
logger.debug("Distribution skip-flag enforcement is disabled.");
return Collections.emptySet();
}
final Map<String, String> excluded = state.getExcludedProjects();
final Set<Project> changed = new HashSet<>();
for (final Project project : projects) {
final String ga = ga(project);
EnforcingMode mode = state.getEnforcingMode();
final String override = excluded.get(ga);
if (override != null) {
mode = EnforcingMode.getMode(override);
}
if (mode == EnforcingMode.none) {
logger.debug("Install/Deploy skip-flag enforcement is disabled for: {}.", ga);
continue;
}
logger.debug("Applying skip-flag enforcement mode of: " + mode + " to: " + ga);
final Model model = project.getModel();
// this is 3-value logic, where skip == on == true, don't-skip == off == false, and (detect from install) == detect == null
Boolean baseSkipSetting = mode.defaultModificationValue();
baseSkipSetting = enforceSkipFlag(model, baseSkipSetting, project, changed, true);
final List<Profile> profiles = ProfileUtils.getProfiles(session, model);
if (profiles != null) {
for (final Profile profile : ProfileUtils.getProfiles(session, model)) {
enforceSkipFlag(profile, baseSkipSetting, project, changed, false);
}
}
if (baseSkipSetting == Boolean.FALSE && model.getProperties().containsKey("maven.deploy.skip")) {
model.getProperties().setProperty("maven.deploy.skip", "false");
}
}
return changed;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class JSONManipulator method applyChanges.
/**
* Apply the json changes to the specified file(s).
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final JSONState state = session.getState(JSONState.class);
if (!session.isEnabled() || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return Collections.emptySet();
}
final Set<Project> changed = new HashSet<>();
final List<JSONState.JSONOperation> scripts = state.getJSONOperations();
for (final Project project : projects) {
if (project.isExecutionRoot()) {
for (JSONState.JSONOperation operation : scripts) {
internalApplyChanges(project, operation);
changed.add(project);
}
break;
}
}
return changed;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class PluginInjectingManipulator method applyChanges.
/**
* If enabled, grab the execution root pom (which will be the topmost POM in terms of directory structure). Check for the
* presence of the project-sources-maven-plugin in the base build (/project/build/plugins/). Inject a new plugin execution for creating project
* sources if this plugin has not already been declared in the base build section.
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final PluginInjectingState state = session.getState(PluginInjectingState.class);
// This manipulator will only run if its enabled *and* at least one other manipulator is enabled.
if (state.isEnabled() && session.anyStateEnabled(State.activeByDefault)) {
for (final Project project : projects) {
if (project.isExecutionRoot()) {
logger.info("Examining {} to apply sources/metadata plugins.", project);
final Model model = project.getModel();
Build build = model.getBuild();
if (build == null) {
build = new Build();
model.setBuild(build);
}
boolean changed = false;
final Map<String, Plugin> pluginMap = build.getPluginsAsMap();
if (state.isProjectSourcesPluginEnabled() && !pluginMap.containsKey(PROJECT_SOURCES_COORD)) {
final PluginExecution execution = new PluginExecution();
execution.setId(PROJECT_SOURCES_EXEC_ID);
execution.setPhase(INITIALIZE_PHASE);
execution.setGoals(Collections.singletonList(PROJECT_SOURCES_GOAL));
final Plugin plugin = new Plugin();
plugin.setGroupId(PROJECT_SOURCES_GID);
plugin.setArtifactId(PROJECT_SOURCES_AID);
plugin.setVersion(state.getProjectSourcesPluginVersion());
plugin.addExecution(execution);
build.addPlugin(plugin);
changed = true;
}
if (state.isBuildMetadataPluginEnabled() && !pluginMap.containsKey(BMMP_COORD)) {
final PluginExecution execution = new PluginExecution();
execution.setId(BMMP_EXEC_ID);
execution.setPhase(INITIALIZE_PHASE);
execution.setGoals(Collections.singletonList(BMMP_GOAL));
final Xpp3Dom xml = new Xpp3Dom("configuration");
final Map<String, Object> config = new HashMap<>();
config.put("createPropertiesReport", true);
config.put("hideCommandLineInfo", false);
config.put("hideJavaOptsInfo", false);
config.put("activateOutputFileMapping", true);
config.put("addJavaRuntimeInfo", true);
// Default name is build.properties but we currently prefer build.metadata.
config.put("propertiesOutputFile", "build.metadata");
// Deactivate features we don't want.
config.put("createXmlReport", false);
config.put("addLocallyModifiedTagToFullVersion", false);
config.put("addToGeneratedSources", false);
config.put("validateCheckout", false);
config.put("forceNewProperties", true);
config.put("addBuildDateToFullVersion", false);
config.put("addHostInfo", false);
config.put("addBuildDateInfo", false);
config.put("addOsInfo", false);
config.put("addMavenExecutionInfo", false);
config.put("addToFilters", false);
final Xpp3Dom additionalLocations = new Xpp3Dom("addToLocations");
final Xpp3Dom additionalLocation = new Xpp3Dom("addToLocation");
xml.addChild(additionalLocations);
additionalLocations.addChild(additionalLocation);
additionalLocation.setValue("${session.executionRootDirectory}");
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);
final Plugin plugin = new Plugin();
plugin.setGroupId(BMMP_GID);
plugin.setArtifactId(BMMP_AID);
plugin.setVersion(state.getBuildMetadataPluginVersion());
plugin.addExecution(execution);
build.addPlugin(plugin);
changed = true;
}
if (changed) {
return Collections.singleton(project);
}
}
}
}
return Collections.emptySet();
}
Aggregations