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;
}
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;
}
Aggregations