Search in sources :

Example 1 with PomManipulator

use of org.eclipse.tycho.versions.manipulation.PomManipulator in project tycho by eclipse.

the class VersionsEngine method apply.

public void apply() throws IOException {
    VersionChangesDescriptor versionChangeContext = new VersionChangesDescriptor(originalVersionChanges, new DefaultVersionRangeUpdateStrategy(updateVersionRangeMatchingBounds));
    // collecting secondary changes
    boolean newChanges = true;
    while (newChanges) {
        newChanges = false;
        for (ProjectMetadata project : projects) {
            for (MetadataManipulator manipulator : manipulators) {
                newChanges |= manipulator.addMoreChanges(project, versionChangeContext);
            }
        }
    }
    // validate version changes can be implemented
    List<String> errors = new ArrayList<>();
    for (ProjectMetadata project : projects) {
        for (MetadataManipulator manipulator : manipulators) {
            Collection<String> error = manipulator.validateChanges(project, versionChangeContext);
            if (error != null) {
                errors.addAll(error);
            }
        }
    }
    if (!errors.isEmpty()) {
        throw new IllegalVersionChangeException(errors);
    }
    // make changes to the metadata
    for (ProjectMetadata project : projects) {
        logger.info("Making changes in " + project.getBasedir().getAbsolutePath());
        PomFile pom = project.getMetadata(PomFile.class);
        // TODO property changes should be added as a new type of change in VersionChangeDescriptors
        for (PropertyChange propertyChange : propertyChanges) {
            if (pom == propertyChange.pom) {
                ((PomManipulator) pomManipulator).applyPropertyChange(pom, propertyChange.propertyName, propertyChange.propertyValue);
            }
        }
        // apply changes
        for (MetadataManipulator manipulator : manipulators) {
            manipulator.applyChanges(project, versionChangeContext);
        }
    }
    // write changes to the disk
    for (ProjectMetadata project : projects) {
        for (MetadataManipulator manipulator : manipulators) {
            manipulator.writeMetadata(project);
        }
    }
}
Also used : PomManipulator(org.eclipse.tycho.versions.manipulation.PomManipulator) ArrayList(java.util.ArrayList) PomFile(org.eclipse.tycho.versions.pom.PomFile)

Aggregations

ArrayList (java.util.ArrayList)1 PomManipulator (org.eclipse.tycho.versions.manipulation.PomManipulator)1 PomFile (org.eclipse.tycho.versions.pom.PomFile)1