use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class RepositoryInjectionManipulator method applyChanges.
/**
* Apply the repository injection changes to the the top level pom.
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final RepositoryInjectionState state = session.getState(RepositoryInjectionState.class);
if (!session.isEnabled() || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return Collections.emptySet();
}
final Set<Project> changed = new HashSet<>();
final Model remoteModel = modelBuilder.resolveRawModel(state.getRemoteRepositoryInjectionMgmt());
final List<Repository> remoteRepositories = remoteModel.getRepositories();
final List<Repository> remotePluginRepositories = remoteModel.getPluginRepositories();
for (final Project project : projects) {
final String ga = ga(project);
logger.info("Applying changes to: " + ga);
final Model model = project.getModel();
if (checkProject(state, project)) {
// inject repositories
final List<Repository> repositories = model.getRepositories();
if (!remoteRepositories.isEmpty()) {
final Iterator<Repository> i1 = remoteRepositories.iterator();
while (i1.hasNext()) {
addRepository(repositories, i1.next());
}
changed.add(project);
}
// inject plugin repositories
final List<Repository> pluginRepositories = model.getPluginRepositories();
if (!remotePluginRepositories.isEmpty()) {
final Iterator<Repository> i2 = remotePluginRepositories.iterator();
while (i2.hasNext()) {
addRepository(pluginRepositories, i2.next());
}
changed.add(project);
}
}
}
return changed;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class VersionCalculator method calculateVersioningChanges.
/**
* Calculate any project version changes for the given set of projects, and return them in a Map keyed by project
* GA.
*
* @param projects the Projects to adjust.
* @param session the container session.
* @return a collection of GAV : new Version
* @throws ManipulationException if an error occurs.
*/
public Map<ProjectVersionRef, String> calculateVersioningChanges(final List<Project> projects, final ManipulationSession session) throws ManipulationException {
final VersioningState state = session.getState(VersioningState.class);
final Map<ProjectVersionRef, String> versionsByGAV = new HashMap<>();
final Set<String> vesionsWithBuildNums = new HashSet<>();
for (final Project project : projects) {
String originalVersion = PropertyResolver.resolveInheritedProperties(session, project, project.getVersion());
String modifiedVersion = calculate(project.getGroupId(), project.getArtifactId(), originalVersion, session);
if (state.osgi()) {
modifiedVersion = Version.getOsgiVersion(modifiedVersion);
}
versionsByGAV.put(project.getKey(), modifiedVersion);
if (Version.hasBuildNumber(modifiedVersion)) {
vesionsWithBuildNums.add(modifiedVersion);
}
}
// between projects in the reactor.
for (final Project project : projects) {
final String originalVersion = project.getVersion();
String modifiedVersion = versionsByGAV.get(project.getKey());
// This also fixes the problem where there is a single version and leading zeros.
if (vesionsWithBuildNums.size() > 1) {
int buildNumber = findHighestMatchingBuildNumber(modifiedVersion, vesionsWithBuildNums);
// set the build number to avoid version conflicts.
if (buildNumber > 0) {
String paddedBuildNum = StringUtils.leftPad(Integer.toString(buildNumber), state.getIncrementalSerialSuffixPadding(), '0');
modifiedVersion = Version.setBuildNumber(modifiedVersion, paddedBuildNum);
}
}
vesionsWithBuildNums.add(modifiedVersion);
logger.debug(gav(project) + " has updated version: {}. Marking for rewrite.", modifiedVersion);
if (!originalVersion.equals(modifiedVersion)) {
versionsByGAV.put(project.getKey(), modifiedVersion);
}
}
return versionsByGAV;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class DistributionEnforcingManipulatorTest method applyTest.
private void applyTest(final EnforcingMode mode, final Model model, final Model expectChanged) throws Exception {
setModeProperty(mode);
setMavenSession();
manipulator.init(session);
final Project project = new Project(model);
final List<Project> projects = new ArrayList<>();
projects.add(project);
final Set<Project> changed = manipulator.applyChanges(projects);
if (expectChanged != null) {
assertThat(changed.isEmpty(), equalTo(false));
assertThat(changed.contains(new Project(expectChanged)), equalTo(true));
} else {
assertThat(changed.isEmpty(), equalTo(true));
}
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class PropertiesUtils method updateProperties.
/**
* Recursively update properties.
*
* @param session the DependencyState
* @param project the current set of projects we are scanning.
* @param ignoreStrict whether to ignore strict alignment.
* @param key a key to look for.
* @param newValue a value to look for.
* @return {@code PropertyUpdate} enumeration showing status of any changes.
* @throws ManipulationException if an error occurs
*/
public static PropertyUpdate updateProperties(ManipulationSession session, Project project, boolean ignoreStrict, String key, String newValue) throws ManipulationException {
final String resolvedValue = PropertyResolver.resolveProperties(session, project.getInheritedList(), "${" + key + '}');
logger.debug("Fully resolvedValue is {} for {} ", resolvedValue, key);
if ("project.version".equals(key)) {
logger.debug("Not updating key {} with {} ", key, newValue);
return PropertyUpdate.IGNORE;
}
for (final Project p : project.getReverseInheritedList()) {
if (p.getModel().getProperties().containsKey(key)) {
logger.trace("Searching properties of {} ", p);
return internalUpdateProperty(session, p, ignoreStrict, key, newValue, resolvedValue, p.getModel().getProperties());
} else {
for (Profile pr : ProfileUtils.getProfiles(session, p.getModel())) {
logger.trace("Searching properties of profile {} within project {} ", pr.getId(), p);
// Lets check the profiles for property updates...
if (pr.getProperties().containsKey(key)) {
return internalUpdateProperty(session, p, ignoreStrict, key, newValue, resolvedValue, pr.getProperties());
}
}
}
}
return PropertyUpdate.NOTFOUND;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class XMLManipulator method applyChanges.
/**
* Apply the xml changes to the specified file(s).
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final XMLState state = session.getState(XMLState.class);
if (!session.isEnabled() || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return Collections.emptySet();
}
final Set<Project> changed = new HashSet<>();
final List<XMLState.XMLOperation> scripts = state.getXMLOperations();
for (final Project project : projects) {
if (project.isExecutionRoot()) {
for (XMLState.XMLOperation operation : scripts) {
internalApplyChanges(project, operation);
changed.add(project);
}
break;
}
}
return changed;
}
Aggregations