use of org.commonjava.maven.ext.core.state.PropertyState in project pom-manipulation-ext by release-engineering.
the class PropertyManipulator method init.
@Override
public void init(final ManipulationSession session) {
this.session = session;
session.setState(new PropertyState(session.getUserProperties()));
}
use of org.commonjava.maven.ext.core.state.PropertyState in project pom-manipulation-ext by release-engineering.
the class PropertyManipulator method applyChanges.
/**
* Apply the property changes to the list of {@link Project}'s given.
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final PropertyState state = session.getState(PropertyState.class);
if (!session.isEnabled() || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return Collections.emptySet();
}
final Properties overrides = loadRemotePOMProperties(state.getRemotePropertyMgmt());
final Set<Project> changed = new HashSet<>();
for (final Project project : projects) {
final Model model = project.getModel();
if (!overrides.isEmpty()) {
// Only inject the new properties at the top level.
if (project.isInheritanceRoot()) {
logger.info("Applying property changes to: " + ga(project) + " with " + overrides);
model.getProperties().putAll(overrides);
changed.add(project);
} else {
// For any matching property that exists in the current project overwrite that value.
@SuppressWarnings({ "unchecked", "rawtypes" }) final Set<String> keyClone = new HashSet(model.getProperties().keySet());
keyClone.retainAll(overrides.keySet());
if (!keyClone.isEmpty()) {
final Iterator<String> keys = keyClone.iterator();
while (keys.hasNext()) {
final String matchingKey = keys.next();
logger.info("Overwriting property (" + matchingKey + " in: " + ga(project) + " with value " + overrides.get(matchingKey));
model.getProperties().put(matchingKey, overrides.get(matchingKey));
changed.add(project);
}
}
}
}
}
return changed;
}
Aggregations