Search in sources :

Example 1 with ProjectVersionEnforcingState

use of org.commonjava.maven.ext.core.state.ProjectVersionEnforcingState in project pom-manipulation-ext by release-engineering.

the class ProjectVersionEnforcingManipulator method applyChanges.

/**
 * For each project in the current build set, reset the version if using project.version
 */
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
    final ProjectVersionEnforcingState state = session.getState(ProjectVersionEnforcingState.class);
    if (!session.isEnabled() || !session.anyStateEnabled(State.activeByDefault) || state == null || !state.isEnabled()) {
        logger.debug("Project version enforcement is disabled.");
        return Collections.emptySet();
    }
    final Set<Project> changed = new HashSet<>();
    for (final Project project : projects) {
        final Model model = project.getModel();
        if (model.getPackaging().equals("pom")) {
            enforceProjectVersion(project, model.getDependencies(), changed);
            if (model.getDependencyManagement() != null) {
                enforceProjectVersion(project, model.getDependencyManagement().getDependencies(), changed);
            }
            final List<Profile> profiles = ProfileUtils.getProfiles(session, model);
            if (profiles != null) {
                for (final Profile profile : profiles) {
                    enforceProjectVersion(project, profile.getDependencies(), changed);
                    if (profile.getDependencyManagement() != null) {
                        enforceProjectVersion(project, profile.getDependencyManagement().getDependencies(), changed);
                    }
                }
            }
        }
    }
    if (!changed.isEmpty()) {
        logger.warn("Using ${project.version} in pom files may lead to unexpected errors with inheritance.");
    }
    return changed;
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) ProjectVersionEnforcingState(org.commonjava.maven.ext.core.state.ProjectVersionEnforcingState) Model(org.apache.maven.model.Model) Profile(org.apache.maven.model.Profile) HashSet(java.util.HashSet)

Example 2 with ProjectVersionEnforcingState

use of org.commonjava.maven.ext.core.state.ProjectVersionEnforcingState in project pom-manipulation-ext by release-engineering.

the class ProjectVersionEnforcingManipulator method init.

/**
 * Sets the mode based on user properties and defaults.
 * @see ProjectVersionEnforcingState
 */
@Override
public void init(final ManipulationSession session) {
    this.session = session;
    session.setState(new ProjectVersionEnforcingState(session.getUserProperties()));
}
Also used : ProjectVersionEnforcingState(org.commonjava.maven.ext.core.state.ProjectVersionEnforcingState)

Aggregations

ProjectVersionEnforcingState (org.commonjava.maven.ext.core.state.ProjectVersionEnforcingState)2 HashSet (java.util.HashSet)1 Model (org.apache.maven.model.Model)1 Profile (org.apache.maven.model.Profile)1 Project (org.commonjava.maven.ext.common.model.Project)1