use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class PluginRemovalManipulator method applyChanges.
/**
* Apply the alignment changes to the list of {@link Project}'s given.
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) {
final State state = session.getState(PluginRemovalState.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;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class ProfileRemovalManipulator method applyChanges.
/**
* Apply the profile removal changes to all pom files.
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) {
final ProfileRemovalState state = session.getState(ProfileRemovalState.class);
if (!session.isEnabled() || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return Collections.emptySet();
}
final List<String> profilesToRemove = state.getProfileRemoval();
final Set<Project> changed = new HashSet<>();
for (final Project project : projects) {
final String ga = ga(project);
logger.info("Applying changes to: " + ga);
final Model model = project.getModel();
final List<Profile> profiles = model.getProfiles();
Iterator<Profile> i = profiles.iterator();
while (i.hasNext()) {
Profile p = i.next();
for (String id : profilesToRemove) {
if (p.getId().equals(id)) {
logger.debug("Removing profile {}", p.getId());
i.remove();
break;
}
}
}
}
return changed;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class ProjectVersioningManipulator method applyChanges.
/**
* Apply any project versioning changes accumulated in the {@link VersioningState} instance associated with the {@link ManipulationSession} to
* the list of {@link Project}'s given. This happens near the end of the Maven session-bootstrapping sequence, before the projects are
* discovered/read by the main Maven build initialization.
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final VersioningState state = session.getState(VersioningState.class);
if (!session.isEnabled() || state == null || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return Collections.emptySet();
}
/*
* Use the {@link VersionCalculator} to calculate any project version changes, and store them in the {@link VersioningState} that was associated
* with the {@link ManipulationSession} via the {@link ProjectVersioningManipulator#init(ManipulationSession)}
*/
logger.info("Version Manipulator: Calculating the necessary versioning changes.");
state.setVersionsByGAVMap(calculator.calculateVersioningChanges(projects, session));
final Set<Project> changed = new HashSet<>();
for (final Project project : projects) {
if (applyVersioningChanges(project, state)) {
changed.add(project);
}
}
return changed;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class RESTCollector method establishAllDependencies.
/**
* Scans a list of projects and accumulates all dependencies and returns them.
*
* @param session the ManipulationSession
* @param projects the projects to scan.
* @param activeProfiles which profiles to check
* @return an unsorted set of ArtifactRefs used.
* @throws ManipulationException if an error occurs
*/
public static Set<ArtifactRef> establishAllDependencies(ManipulationSession session, final List<Project> projects, Set<String> activeProfiles) throws ManipulationException {
Set<ArtifactRef> localDeps = new TreeSet<>();
Set<String> activeModules = new HashSet<>();
boolean scanAll = false;
if (activeProfiles != null && !activeProfiles.isEmpty()) {
for (final Project project : projects) {
if (project.isInheritanceRoot()) {
activeModules.addAll(project.getModel().getModules());
List<Profile> profiles = project.getModel().getProfiles();
if (profiles != null) {
for (Profile p : profiles) {
if (activeProfiles.contains(p.getId())) {
logger.debug("Adding modules for profile {}", p.getId());
activeModules.addAll(p.getModules());
}
}
}
}
}
logger.debug("Found {} active modules with {} active profiles.", activeModules, activeProfiles);
} else {
scanAll = true;
}
// Iterate over current project set and populate list of dependencies
for (final Project project : projects) {
if (project.isInheritanceRoot() || scanAll || activeModules.contains(project.getPom().getParentFile().getName())) {
if (project.getModelParent() != null) {
SimpleProjectVersionRef parent = new SimpleProjectVersionRef(project.getModelParent().getGroupId(), project.getModelParent().getArtifactId(), project.getModelParent().getVersion());
localDeps.add(new SimpleArtifactRef(parent, new SimpleTypeAndClassifier("pom", null)));
}
recordDependencies(session, project, localDeps, project.getResolvedManagedDependencies(session));
recordDependencies(session, project, localDeps, project.getResolvedDependencies(session));
recordPlugins(localDeps, project.getResolvedManagedPlugins(session));
recordPlugins(localDeps, project.getResolvedPlugins(session));
List<Profile> profiles = project.getModel().getProfiles();
if (profiles != null) {
for (Profile p : profiles) {
if (!scanAll && !activeProfiles.contains(p.getId())) {
continue;
}
recordDependencies(session, project, localDeps, project.getResolvedProfileManagedDependencies(session).get(p));
recordDependencies(session, project, localDeps, project.getResolvedProfileDependencies(session).get(p));
recordPlugins(localDeps, project.getResolvedProfileManagedPlugins(session).get(p));
recordPlugins(localDeps, project.getResolvedProfilePlugins(session).get(p));
}
}
}
}
return localDeps;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class RESTCollector method parseVersions.
/**
* Parse the rest result for the project GAs and store them in versioning state for use
* there by incremental suffix calculation.
*/
private Map<ProjectRef, Set<String>> parseVersions(ManipulationSession session, List<Project> projects, RESTState state, ArrayList<ProjectVersionRef> newProjectKeys, Map<ProjectVersionRef, String> restResult) throws ManipulationException {
Map<ProjectRef, Set<String>> versionStates = new HashMap<>();
for (final ProjectVersionRef p : newProjectKeys) {
if (restResult.containsKey(p)) {
// Found part of the current project to store in Versioning State
Set<String> versions = versionStates.get(p.asProjectRef());
if (versions == null) {
versions = new HashSet<>();
versionStates.put(p.asProjectRef(), versions);
}
versions.add(restResult.get(p));
}
}
logger.debug("Added the following ProjectRef:Version from REST call into VersionState {}", versionStates);
// We know we have ProjectVersionRef(s) of the current project(s). We need to establish potential
// blacklist by calling
// GET /listings/blacklist/ga?groupid=GROUP_ID&artifactid=ARTIFACT_ID
// passing in the groupId and artifactId.
// From the results we then need to establish whether the community version occurs in the blacklist
// causing a total abort and whether any redhat versions occur in the blacklist. If they do, that will
// affect the incremental potential options. The simplest option is simply to add those results to versionStates
// list. This will cause the incremental build number to be set to greater than those.
List<ProjectVersionRef> blacklist;
for (Project p : projects) {
if (p.isExecutionRoot()) {
logger.debug("Calling REST client for blacklist with {}...", p.getKey().asProjectRef());
blacklist = state.getVersionTranslator().findBlacklisted(p.getKey().asProjectRef());
if (blacklist.size() > 0) {
String suffix = PropertiesUtils.getSuffix(session);
String bVersion = blacklist.get(0).getVersionString();
String pVersion = p.getVersion();
logger.debug("REST Client returned for blacklist {} ", blacklist);
if (isEmpty(suffix)) {
logger.warn("No version suffix found ; unable to verify community blacklisting.");
} else if (blacklist.size() == 1 && !bVersion.contains(suffix)) {
if (pVersion.contains(suffix)) {
pVersion = pVersion.substring(0, pVersion.indexOf(suffix) - 1);
}
if (pVersion.equals(bVersion)) {
throw new ManipulationException("community artifact '" + blacklist.get(0) + "' has been blacklisted. Unable to build project version " + p.getVersion());
}
}
// Found part of the current project to store in Versioning State
Set<String> versions = versionStates.get(p.getKey().asProjectRef());
if (versions == null) {
versions = new HashSet<>();
versionStates.put(p.getKey().asProjectRef(), versions);
}
for (ProjectVersionRef b : blacklist) {
versions.add(b.getVersionString());
}
}
break;
}
}
return versionStates;
}
Aggregations