use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class PropertiesUtilsTest method testUpdateProjectVersionProperty.
@Test
public void testUpdateProjectVersionProperty() throws Exception {
Project pP = getProject();
ManipulationSession session = createUpdateSession();
assertFalse(updateProperties(session, pP, false, "project.version", "5.0.4.Final-redhat-1") == PropertiesUtils.PropertyUpdate.FOUND);
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class ManipulationManager method scanAndApply.
/**
* Encapsulates {@link #applyManipulations(List)}
*
* @param session the container session for manipulation.
* @throws ManipulationException if an error occurs.
*/
public void scanAndApply(final ManipulationSession session) throws ManipulationException {
final List<Project> projects = pomIO.parseProject(session.getPom());
session.setProjects(projects);
for (final Project project : projects) {
logger.debug("Got " + project + " (POM: " + project.getPom() + ")");
}
Set<Project> changed = applyManipulations(projects);
// Create a marker file if we made some changes to prevent duplicate runs.
if (!changed.isEmpty()) {
logger.info("Maven-Manipulation-Extension: Rewrite changed: " + projects);
GAV gav = pomIO.rewritePOMs(changed);
try {
final VersioningState state = session.getState(VersioningState.class);
state.setExecutionRootModified(gav);
new File(session.getTargetDir().getParentFile(), ManipulationManager.MARKER_PATH).mkdirs();
new File(session.getTargetDir().getParentFile(), ManipulationManager.MARKER_FILE).createNewFile();
try (FileWriter writer = new FileWriter(new File(session.getTargetDir().getParentFile(), RESULT_FILE))) {
writer.write(collectResults(session));
}
} catch (IOException e) {
logger.error("Unable to create marker or result file", e);
throw new ManipulationException("Marker/result file creation failed", e);
}
}
// Ensure shutdown of GalleyInfrastructure Executor Service
for (ExtensionInfrastructure e : infrastructure.values()) {
e.finish();
}
logger.info("Maven-Manipulation-Extension: Finished.");
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class PropertyResolver method resolveProperties.
/**
* This recursively checks the supplied value and recursively resolves it if its a property.
*
* @param session the current session
* @param projects set of projects
* @param value value to check
* @return the version string
* @throws ManipulationException if an error occurs
*/
public static String resolveProperties(MavenSessionHandler session, List<Project> projects, String value) throws ManipulationException {
final Properties amalgamated = new Properties();
// so therefore there is no need to save the execution root.
for (Project p : projects) {
amalgamated.putAll(p.getModel().getProperties());
amalgamated.putAll(searchProfiles(session, p));
}
PropertyInterpolator pi = new PropertyInterpolator(amalgamated, projects.get(0));
return pi.interp(value);
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class PluginManipulator method applyChanges.
/**
* Apply the alignment changes to the list of {@link Project}'s given.
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final PluginState state = session.getState(PluginState.class);
if (!session.isEnabled() || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return Collections.emptySet();
}
final Set<Project> changed = new HashSet<>();
final Set<Plugin> mgmtOverrides = loadRemoteBOM(PluginType.RemotePM);
final Set<Plugin> pluginOverrides = loadRemoteBOM(PluginType.RemoteP);
for (final Project project : projects) {
final Model model = project.getModel();
if (!mgmtOverrides.isEmpty()) {
apply(project, model, PluginType.RemotePM, mgmtOverrides);
changed.add(project);
}
if (!pluginOverrides.isEmpty()) {
apply(project, model, PluginType.RemoteP, pluginOverrides);
changed.add(project);
}
}
// If we've changed something now update any old properties with the new values.
if (!changed.isEmpty()) {
logger.info("Iterating for standard overrides...");
for (Project project : versionPropertyUpdateMap.keySet()) {
for (final Map.Entry<String, String> entry : versionPropertyUpdateMap.get(project).entrySet()) {
// Ignore strict alignment for plugins ; if we're attempting to use a differing plugin
// its unlikely to be an exact match.
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", entry.getKey());
for (final Project p : changed) {
if (p.isInheritanceRoot()) {
logger.info("Adding property {} with {} ", entry.getKey(), entry.getValue());
p.getModel().getProperties().setProperty(entry.getKey(), entry.getValue());
}
}
}
}
}
}
return changed;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class RelocationManipulator method applyChanges.
/**
* Apply the relocation changes to the list of {@link Project}'s given.
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final State state = session.getState(RelocationState.class);
if (!session.isEnabled() || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return Collections.emptySet();
}
final Set<Project> changed = new HashSet<>();
for (final Project project : projects) {
final Model model = project.getModel();
if (apply(project, model)) {
changed.add(project);
}
}
return changed;
}
Aggregations