@Test public void testCheckStrictValue() throws Exception { ManipulationSession session = createUpdateSession(); assertFalse( PropertiesUtils.checkStrictValue( session, null, "1.0" ) ); assertFalse( PropertiesUtils.checkStrictValue( session, "1.0", null ) ); assertFalse( PropertiesUtils.checkStrictValue( session, "1.0.0.Final", "1.0.0.redhat-1" ) ); assertTrue( PropertiesUtils.checkStrictValue( session, "1.0.0", "1.0.0.redhat-1" ) ); assertTrue( PropertiesUtils.checkStrictValue( session, "1.0.0-SNAPSHOT", "1.0.0.redhat-1" ) ); assertFalse( PropertiesUtils.checkStrictValue( session, "1.0.Final-SNAPSHOT", "1.0.0.redhat-1" ) ); assertTrue( PropertiesUtils.checkStrictValue( session, "1.0-SNAPSHOT", "1.0.0.redhat-1" ) ); }
public static boolean checkStrictValue( ManipulationSession session, String oldValue, String newValue ) { if ( oldValue == null || newValue == null ) { return false; } else if ( oldValue.equals( newValue ) ) { return true; } final CommonState cState = session.getState( CommonState.class ); final VersioningState vState = session.getState( VersioningState.class ); final boolean ignoreSuffix = cState.isStrictIgnoreSuffix(); final Set<String> oldValueOptions = buildOldValueSet( vState, oldValue ); boolean result = false; if ( vState.getAllSuffixes().isEmpty() ) { logger.warn( "No version suffixes found ; unable to determine strict mapping" ); } loop: for ( String origValue : oldValueOptions ) { for ( String suffix : vState.getAllSuffixes() ) { String v = origValue; if ( !vState.isPreserveSnapshot() ) { v = Version.removeSnapshot( v ); } String osgiVersion = Version.getOsgiVersion( v ); String newVersion = newValue; if ( isNotEmpty( suffix ) ) { if ( ignoreSuffix && origValue.contains( suffix ) ) { HashSet<String> s = new HashSet<>(); s.add( origValue ); s.add( newValue ); String x = String.valueOf( Version.findHighestMatchingBuildNumber( v, s ) ); if ( newValue.endsWith( x ) ) { String oldValueCache = origValue; origValue = origValue.substring( 0, origValue.indexOf( suffix ) - 1 ); v = origValue; osgiVersion = Version.getOsgiVersion( v ); logger.debug( "Updating version to {} and for oldValue {} with newValue {} ", v, oldValueCache, newValue ); } else if ( origValue.endsWith( x ) ) { logger.warn( "strictValueChecking with strictIgnoreSuffix found older value ({}) was newer ({}) ", origValue, newValue ); } else { logger.warn( "strictIgnoreSuffix set but unable to align from {} to {}", origValue, newValue ); } } 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 ); } } boolean success = ( origValue.equals( newVersion ) || osgiVersion.equals( newVersion ) ); logger.debug( "When validating original {} / new value {} comparing {} to {} and OSGi variant {} to {} (utilising suffix {}) is {}", origValue, newValue, origValue, newVersion, osgiVersion, newVersion, suffix, success ? "allowed" : "not allowed" ); if ( success ) { result = true; break loop; } } } return result; }
PropertiesUtils { public static boolean checkStrictValue( ManipulationSession session, String oldValue, String newValue ) { if ( oldValue == null || newValue == null ) { return false; } else if ( oldValue.equals( newValue ) ) { return true; } final CommonState cState = session.getState( CommonState.class ); final VersioningState vState = session.getState( VersioningState.class ); final boolean ignoreSuffix = cState.isStrictIgnoreSuffix(); final Set<String> oldValueOptions = buildOldValueSet( vState, oldValue ); boolean result = false; if ( vState.getAllSuffixes().isEmpty() ) { logger.warn( "No version suffixes found ; unable to determine strict mapping" ); } loop: for ( String origValue : oldValueOptions ) { for ( String suffix : vState.getAllSuffixes() ) { String v = origValue; if ( !vState.isPreserveSnapshot() ) { v = Version.removeSnapshot( v ); } String osgiVersion = Version.getOsgiVersion( v ); String newVersion = newValue; if ( isNotEmpty( suffix ) ) { if ( ignoreSuffix && origValue.contains( suffix ) ) { HashSet<String> s = new HashSet<>(); s.add( origValue ); s.add( newValue ); String x = String.valueOf( Version.findHighestMatchingBuildNumber( v, s ) ); if ( newValue.endsWith( x ) ) { String oldValueCache = origValue; origValue = origValue.substring( 0, origValue.indexOf( suffix ) - 1 ); v = origValue; osgiVersion = Version.getOsgiVersion( v ); logger.debug( "Updating version to {} and for oldValue {} with newValue {} ", v, oldValueCache, newValue ); } else if ( origValue.endsWith( x ) ) { logger.warn( "strictValueChecking with strictIgnoreSuffix found older value ({}) was newer ({}) ", origValue, newValue ); } else { logger.warn( "strictIgnoreSuffix set but unable to align from {} to {}", origValue, newValue ); } } 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 ); } } boolean success = ( origValue.equals( newVersion ) || osgiVersion.equals( newVersion ) ); logger.debug( "When validating original {} / new value {} comparing {} to {} and OSGi variant {} to {} (utilising suffix {}) is {}", origValue, newValue, origValue, newVersion, osgiVersion, newVersion, suffix, success ? "allowed" : "not allowed" ); if ( success ) { result = true; break loop; } } } return result; } }
PropertiesUtils { public static boolean checkStrictValue( ManipulationSession session, String oldValue, String newValue ) { if ( oldValue == null || newValue == null ) { return false; } else if ( oldValue.equals( newValue ) ) { return true; } final CommonState cState = session.getState( CommonState.class ); final VersioningState vState = session.getState( VersioningState.class ); final boolean ignoreSuffix = cState.isStrictIgnoreSuffix(); final Set<String> oldValueOptions = buildOldValueSet( vState, oldValue ); boolean result = false; if ( vState.getAllSuffixes().isEmpty() ) { logger.warn( "No version suffixes found ; unable to determine strict mapping" ); } loop: for ( String origValue : oldValueOptions ) { for ( String suffix : vState.getAllSuffixes() ) { String v = origValue; if ( !vState.isPreserveSnapshot() ) { v = Version.removeSnapshot( v ); } String osgiVersion = Version.getOsgiVersion( v ); String newVersion = newValue; if ( isNotEmpty( suffix ) ) { if ( ignoreSuffix && origValue.contains( suffix ) ) { HashSet<String> s = new HashSet<>(); s.add( origValue ); s.add( newValue ); String x = String.valueOf( Version.findHighestMatchingBuildNumber( v, s ) ); if ( newValue.endsWith( x ) ) { String oldValueCache = origValue; origValue = origValue.substring( 0, origValue.indexOf( suffix ) - 1 ); v = origValue; osgiVersion = Version.getOsgiVersion( v ); logger.debug( "Updating version to {} and for oldValue {} with newValue {} ", v, oldValueCache, newValue ); } else if ( origValue.endsWith( x ) ) { logger.warn( "strictValueChecking with strictIgnoreSuffix found older value ({}) was newer ({}) ", origValue, newValue ); } else { logger.warn( "strictIgnoreSuffix set but unable to align from {} to {}", origValue, newValue ); } } 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 ); } } boolean success = ( origValue.equals( newVersion ) || osgiVersion.equals( newVersion ) ); logger.debug( "When validating original {} / new value {} comparing {} to {} and OSGi variant {} to {} (utilising suffix {}) is {}", origValue, newValue, origValue, newVersion, osgiVersion, newVersion, suffix, success ? "allowed" : "not allowed" ); if ( success ) { result = true; break loop; } } } return result; } private  PropertiesUtils(); }
PropertiesUtils { public static boolean checkStrictValue( ManipulationSession session, String oldValue, String newValue ) { if ( oldValue == null || newValue == null ) { return false; } else if ( oldValue.equals( newValue ) ) { return true; } final CommonState cState = session.getState( CommonState.class ); final VersioningState vState = session.getState( VersioningState.class ); final boolean ignoreSuffix = cState.isStrictIgnoreSuffix(); final Set<String> oldValueOptions = buildOldValueSet( vState, oldValue ); boolean result = false; if ( vState.getAllSuffixes().isEmpty() ) { logger.warn( "No version suffixes found ; unable to determine strict mapping" ); } loop: for ( String origValue : oldValueOptions ) { for ( String suffix : vState.getAllSuffixes() ) { String v = origValue; if ( !vState.isPreserveSnapshot() ) { v = Version.removeSnapshot( v ); } String osgiVersion = Version.getOsgiVersion( v ); String newVersion = newValue; if ( isNotEmpty( suffix ) ) { if ( ignoreSuffix && origValue.contains( suffix ) ) { HashSet<String> s = new HashSet<>(); s.add( origValue ); s.add( newValue ); String x = String.valueOf( Version.findHighestMatchingBuildNumber( v, s ) ); if ( newValue.endsWith( x ) ) { String oldValueCache = origValue; origValue = origValue.substring( 0, origValue.indexOf( suffix ) - 1 ); v = origValue; osgiVersion = Version.getOsgiVersion( v ); logger.debug( "Updating version to {} and for oldValue {} with newValue {} ", v, oldValueCache, newValue ); } else if ( origValue.endsWith( x ) ) { logger.warn( "strictValueChecking with strictIgnoreSuffix found older value ({}) was newer ({}) ", origValue, newValue ); } else { logger.warn( "strictIgnoreSuffix set but unable to align from {} to {}", origValue, newValue ); } } 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 ); } } boolean success = ( origValue.equals( newVersion ) || osgiVersion.equals( newVersion ) ); logger.debug( "When validating original {} / new value {} comparing {} to {} and OSGi variant {} to {} (utilising suffix {}) is {}", origValue, newValue, origValue, newVersion, osgiVersion, newVersion, suffix, success ? "allowed" : "not allowed" ); if ( success ) { result = true; break loop; } } } return result; } private  PropertiesUtils(); static Map<String, String> getPropertiesByPrefix( final Properties properties, final String prefix ); static PropertyUpdate updateProperties( ManipulationSession session, Project project, boolean ignoreStrict,
                                                   String key, String newValue ); static String getSuffix( ManipulationSession session ); static boolean checkStrictValue( ManipulationSession session, String oldValue, String newValue ); static boolean cacheProperty( Project project, CommonState state, Map<Project, Map<String, PropertyMapper>> versionPropertyUpdateMap,
                                         String oldVersion, String newVersion, Object originalType, boolean force ); static String extractPropertyName( String version ); static void verifyPropertyMapping( CommonState cState, Project project, Map<Project, Map<String, PropertyMapper>> versionPropertyMap,
                                              ProjectVersionRef pvr, String version ); static void handleConfigPrecedence( Properties userProperties, Properties config ); }
PropertiesUtils { public static boolean checkStrictValue( ManipulationSession session, String oldValue, String newValue ) { if ( oldValue == null || newValue == null ) { return false; } else if ( oldValue.equals( newValue ) ) { return true; } final CommonState cState = session.getState( CommonState.class ); final VersioningState vState = session.getState( VersioningState.class ); final boolean ignoreSuffix = cState.isStrictIgnoreSuffix(); final Set<String> oldValueOptions = buildOldValueSet( vState, oldValue ); boolean result = false; if ( vState.getAllSuffixes().isEmpty() ) { logger.warn( "No version suffixes found ; unable to determine strict mapping" ); } loop: for ( String origValue : oldValueOptions ) { for ( String suffix : vState.getAllSuffixes() ) { String v = origValue; if ( !vState.isPreserveSnapshot() ) { v = Version.removeSnapshot( v ); } String osgiVersion = Version.getOsgiVersion( v ); String newVersion = newValue; if ( isNotEmpty( suffix ) ) { if ( ignoreSuffix && origValue.contains( suffix ) ) { HashSet<String> s = new HashSet<>(); s.add( origValue ); s.add( newValue ); String x = String.valueOf( Version.findHighestMatchingBuildNumber( v, s ) ); if ( newValue.endsWith( x ) ) { String oldValueCache = origValue; origValue = origValue.substring( 0, origValue.indexOf( suffix ) - 1 ); v = origValue; osgiVersion = Version.getOsgiVersion( v ); logger.debug( "Updating version to {} and for oldValue {} with newValue {} ", v, oldValueCache, newValue ); } else if ( origValue.endsWith( x ) ) { logger.warn( "strictValueChecking with strictIgnoreSuffix found older value ({}) was newer ({}) ", origValue, newValue ); } else { logger.warn( "strictIgnoreSuffix set but unable to align from {} to {}", origValue, newValue ); } } 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 ); } } boolean success = ( origValue.equals( newVersion ) || osgiVersion.equals( newVersion ) ); logger.debug( "When validating original {} / new value {} comparing {} to {} and OSGi variant {} to {} (utilising suffix {}) is {}", origValue, newValue, origValue, newVersion, osgiVersion, newVersion, suffix, success ? "allowed" : "not allowed" ); if ( success ) { result = true; break loop; } } } return result; } private  PropertiesUtils(); static Map<String, String> getPropertiesByPrefix( final Properties properties, final String prefix ); static PropertyUpdate updateProperties( ManipulationSession session, Project project, boolean ignoreStrict,
                                                   String key, String newValue ); static String getSuffix( ManipulationSession session ); static boolean checkStrictValue( ManipulationSession session, String oldValue, String newValue ); static boolean cacheProperty( Project project, CommonState state, Map<Project, Map<String, PropertyMapper>> versionPropertyUpdateMap,
                                         String oldVersion, String newVersion, Object originalType, boolean force ); static String extractPropertyName( String version ); static void verifyPropertyMapping( CommonState cState, Project project, Map<Project, Map<String, PropertyMapper>> versionPropertyMap,
                                              ProjectVersionRef pvr, String version ); static void handleConfigPrecedence( Properties userProperties, Properties config );  }