use of org.commonjava.maven.ext.core.state.RepoReportingState in project pom-manipulation-ext by release-engineering.
the class RepoAndReportingRemovalManipulator method applyChanges.
/**
* Apply the reporting and repository removal changes to the list of {@link Project}'s given.
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final RepoReportingState state = session.getState(RepoReportingState.class);
if (!session.isEnabled() || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return Collections.emptySet();
}
final Set<Project> changed = new HashSet<>();
Settings backupSettings = new Settings();
Profile backupProfile = new Profile();
backupProfile.setId("removed-by-pme");
backupSettings.addActiveProfile("removed-by-pme");
for (final Project project : projects) {
final String ga = ga(project);
logger.debug("Applying changes to: " + ga);
final Model model = project.getModel();
Iterator<Repository> it = model.getRepositories().iterator();
while (it.hasNext()) {
Repository repository = it.next();
if (removeRepository(state, repository)) {
backupProfile.addRepository(repository);
it.remove();
changed.add(project);
}
}
it = model.getPluginRepositories().iterator();
while (it.hasNext()) {
Repository repository = it.next();
if (removeRepository(state, repository)) {
backupProfile.addPluginRepository(repository);
it.remove();
changed.add(project);
}
}
if (model.getReporting() != null) {
backupProfile.setReporting(model.getReporting());
model.setReporting(null);
changed.add(project);
}
// remove repositories in the profiles as well
final List<Profile> profiles = ProfileUtils.getProfiles(session, model);
for (final Profile profile : profiles) {
Profile repoProfile = new Profile();
repoProfile.setId(profile.getId());
it = profile.getRepositories().iterator();
while (it.hasNext()) {
Repository repository = it.next();
if (removeRepository(state, repository)) {
repoProfile.addRepository(repository);
it.remove();
changed.add(project);
}
}
it = profile.getPluginRepositories().iterator();
while (it.hasNext()) {
Repository repository = it.next();
if (removeRepository(state, repository)) {
repoProfile.addPluginRepository(repository);
it.remove();
changed.add(project);
}
}
if (profile.getReporting() != null) {
repoProfile.setReporting(profile.getReporting());
profile.setReporting(null);
changed.add(project);
}
if (!repoProfile.getRepositories().isEmpty() || !repoProfile.getPluginRepositories().isEmpty() || repoProfile.getReporting() != null) {
backupSettings.addProfile(SettingsUtils.convertToSettingsProfile(repoProfile));
}
}
}
// create new settings file with the removed repositories and reporting
if (!backupProfile.getRepositories().isEmpty() || !backupProfile.getPluginRepositories().isEmpty() || backupProfile.getReporting() != null) {
backupSettings.addProfile(SettingsUtils.convertToSettingsProfile(backupProfile));
String settingsFilePath = state.getRemovalBackupSettings();
if (!isEmpty(settingsFilePath)) {
File settingsFile;
if (settingsFilePath.equals("settings.xml")) {
String topDir = session.getTargetDir().getParentFile().getPath();
settingsFile = new File(topDir, settingsFilePath);
} else {
settingsFile = new File(settingsFilePath);
}
settingsWriter.update(backupSettings, settingsFile);
}
}
return changed;
}
use of org.commonjava.maven.ext.core.state.RepoReportingState in project pom-manipulation-ext by release-engineering.
the class RepoAndReportingRemovalManipulator method init.
/**
* Initialize the {@link RepoReportingState} state holder in the {@link ManipulationSession}. This state holder detects
* version-change configuration from the Maven user properties (-D properties from the CLI) and makes it available for
* later.
*/
@Override
public void init(final ManipulationSession session) {
this.session = session;
session.setState(new RepoReportingState(session.getUserProperties()));
}
Aggregations