Search in sources :

Example 11 with VersioningState

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

the class PropertiesUtils method checkStrictValue.

/**
 * Check the version change is valid in strict mode.
 *
 * @param session the manipulation session
 * @param oldValue the original version
 * @param newValue the new version
 * @return true if the version can be changed to the new version
 */
public static boolean checkStrictValue(ManipulationSession session, String oldValue, String newValue) {
    if (oldValue == null || newValue == null) {
        return false;
    } else if (oldValue.equals(newValue)) {
        // The old version and new version matches. So technically it can be changed (even if its a bit pointless).
        return true;
    }
    final CommonState cState = session.getState(CommonState.class);
    final VersioningState vState = session.getState(VersioningState.class);
    final boolean ignoreSuffix = cState.getStrictIgnoreSuffix();
    // New value might be e.g. 3.1-rebuild-1 or 3.1.0.rebuild-1 (i.e. it *might* be OSGi compliant).
    String newVersion = newValue;
    String suffix = getSuffix(session);
    String v = oldValue;
    if (!vState.preserveSnapshot()) {
        v = Version.removeSnapshot(v);
    }
    String osgiVersion = Version.getOsgiVersion(v);
    if (isNotEmpty(suffix)) {
        // the oldValue actually contains the suffix process it.
        if (ignoreSuffix && oldValue.contains(suffix)) {
            HashSet<String> s = new HashSet<>();
            s.add(oldValue);
            s.add(newValue);
            String x = String.valueOf(Version.findHighestMatchingBuildNumber(v, s));
            // matching.
            if (newValue.endsWith(x)) {
                String oldValueCache = oldValue;
                oldValue = oldValue.substring(0, oldValue.indexOf(suffix) - 1);
                v = oldValue;
                osgiVersion = Version.getOsgiVersion(v);
                logger.debug("Updating version to {} and for oldValue {} with newValue {} ", v, oldValueCache, newValue);
            } else {
                logger.warn("strictIgnoreSuffix set but unable to align from {} to {}", oldValue, newValue);
            }
        }
        // to work out the OSGi version.
        if (!Version.hasQualifier(v)) {
            v = Version.appendQualifierSuffix(v, suffix);
            osgiVersion = Version.getOsgiVersion(v);
            osgiVersion = osgiVersion.substring(0, osgiVersion.indexOf(suffix) - 1);
        }
        if (newValue.contains(suffix)) {
            newVersion = newValue.substring(0, newValue.indexOf(suffix) - 1);
        }
    }
    logger.debug("Comparing original version {} and OSGi variant {} with new version {} and suffix removed {} ", oldValue, osgiVersion, newValue, newVersion);
    // We compare both an OSGi'ied oldVersion and the non-OSGi version against the possible new version (which has
    // had its suffix stripped) in order to check whether its a valid change.
    boolean result = false;
    if (oldValue.equals(newVersion) || osgiVersion.equals(newVersion)) {
        result = true;
    }
    return result;
}
Also used : CommonState(org.commonjava.maven.ext.core.state.CommonState) VersioningState(org.commonjava.maven.ext.core.state.VersioningState) HashSet(java.util.HashSet)

Example 12 with VersioningState

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

the class PropertiesUtils method getSuffix.

/**
 * Retrieve any configured rebuild suffix.
 * @param session Current ManipulationSession
 * @return string suffix.
 */
public static String getSuffix(ManipulationSession session) {
    final VersioningState versioningState = session.getState(VersioningState.class);
    String suffix = null;
    if (versioningState.getIncrementalSerialSuffix() != null && !versioningState.getIncrementalSerialSuffix().isEmpty()) {
        suffix = versioningState.getIncrementalSerialSuffix();
    } else if (versioningState.getSuffix() != null && !versioningState.getSuffix().isEmpty()) {
        suffix = versioningState.getSuffix().substring(0, versioningState.getSuffix().lastIndexOf('-'));
    }
    return suffix;
}
Also used : VersioningState(org.commonjava.maven.ext.core.state.VersioningState)

Aggregations

VersioningState (org.commonjava.maven.ext.core.state.VersioningState)12 HashSet (java.util.HashSet)4 Project (org.commonjava.maven.ext.common.model.Project)4 HashMap (java.util.HashMap)3 CommonState (org.commonjava.maven.ext.core.state.CommonState)3 Properties (java.util.Properties)2 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)2 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)2 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)2 MavenSession (org.apache.maven.execution.MavenSession)2 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)2 PlexusContainer (org.codehaus.plexus.PlexusContainer)2 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)2 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)2 DependencyState (org.commonjava.maven.ext.core.state.DependencyState)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1