@Test public void testFindHighestMatchingBuildNumber_Fuse() { String version = "2.10.0-000164.fuse-000001-redhat"; final Set<String> versionSet = new HashSet<>(); versionSet.add( "2.10.0.redhat-000022" ); versionSet.add( "2.10.0.000164-fuse-000001-redhat-2" ); versionSet.add( "2.10.0.fuse-000022-redhat-2" ); versionSet.add( "2.10.0.fuse-000022-redhat-1" ); assertThat( Version.findHighestMatchingBuildNumber( version, versionSet ), equalTo( 2 ) ); versionSet.clear(); }
public static int findHighestMatchingBuildNumber(String version, Set<String> versionSet ) { int highestBuildNum = 0; String osgiVersion = getOsgiVersion( version ); String qualifier = getQualifier( osgiVersion ); Matcher qualifierMatcher = qualifierPattern.matcher( qualifier ); if ( qualifierMatcher.matches() ) { qualifier = removeLeadingDelimiter( qualifierMatcher.group( 1 ) ); } StringBuilder versionPatternBuf = new StringBuilder(); versionPatternBuf.append( '(' ) .append( Pattern.quote( getMMM( version ) ) ).append('(').append( DELIMITER_REGEX ).append("0)*") .append( ")?" ) .append( DELIMITER_REGEX ); if ( !isEmpty( qualifier ) ) { versionPatternBuf.append( Pattern.quote( qualifier ) ); versionPatternBuf.append( DELIMITER_REGEX ); } versionPatternBuf.append( "(\\d+)" ); String candidatePatternStr = versionPatternBuf.toString(); logger.debug( "Using pattern: '{}' to find compatible versions from metadata.", candidatePatternStr ); final Pattern candidateSuffixPattern = Pattern.compile( candidatePatternStr ); for ( final String compareVersion : versionSet ) { final Matcher candidateSuffixMatcher = candidateSuffixPattern.matcher( compareVersion ); if ( candidateSuffixMatcher.matches() ) { String buildNumberStr = candidateSuffixMatcher.group( 3 ); int compareBuildNum = Integer.parseInt( buildNumberStr ); if ( compareBuildNum > highestBuildNum ) { highestBuildNum = compareBuildNum; } } } logger.debug ("Found highest matching build number {} from set {} ", highestBuildNum, versionSet); return highestBuildNum; }
Version { public static int findHighestMatchingBuildNumber(String version, Set<String> versionSet ) { int highestBuildNum = 0; String osgiVersion = getOsgiVersion( version ); String qualifier = getQualifier( osgiVersion ); Matcher qualifierMatcher = qualifierPattern.matcher( qualifier ); if ( qualifierMatcher.matches() ) { qualifier = removeLeadingDelimiter( qualifierMatcher.group( 1 ) ); } StringBuilder versionPatternBuf = new StringBuilder(); versionPatternBuf.append( '(' ) .append( Pattern.quote( getMMM( version ) ) ).append('(').append( DELIMITER_REGEX ).append("0)*") .append( ")?" ) .append( DELIMITER_REGEX ); if ( !isEmpty( qualifier ) ) { versionPatternBuf.append( Pattern.quote( qualifier ) ); versionPatternBuf.append( DELIMITER_REGEX ); } versionPatternBuf.append( "(\\d+)" ); String candidatePatternStr = versionPatternBuf.toString(); logger.debug( "Using pattern: '{}' to find compatible versions from metadata.", candidatePatternStr ); final Pattern candidateSuffixPattern = Pattern.compile( candidatePatternStr ); for ( final String compareVersion : versionSet ) { final Matcher candidateSuffixMatcher = candidateSuffixPattern.matcher( compareVersion ); if ( candidateSuffixMatcher.matches() ) { String buildNumberStr = candidateSuffixMatcher.group( 3 ); int compareBuildNum = Integer.parseInt( buildNumberStr ); if ( compareBuildNum > highestBuildNum ) { highestBuildNum = compareBuildNum; } } } logger.debug ("Found highest matching build number {} from set {} ", highestBuildNum, versionSet); return highestBuildNum; } }
Version { public static int findHighestMatchingBuildNumber(String version, Set<String> versionSet ) { int highestBuildNum = 0; String osgiVersion = getOsgiVersion( version ); String qualifier = getQualifier( osgiVersion ); Matcher qualifierMatcher = qualifierPattern.matcher( qualifier ); if ( qualifierMatcher.matches() ) { qualifier = removeLeadingDelimiter( qualifierMatcher.group( 1 ) ); } StringBuilder versionPatternBuf = new StringBuilder(); versionPatternBuf.append( '(' ) .append( Pattern.quote( getMMM( version ) ) ).append('(').append( DELIMITER_REGEX ).append("0)*") .append( ")?" ) .append( DELIMITER_REGEX ); if ( !isEmpty( qualifier ) ) { versionPatternBuf.append( Pattern.quote( qualifier ) ); versionPatternBuf.append( DELIMITER_REGEX ); } versionPatternBuf.append( "(\\d+)" ); String candidatePatternStr = versionPatternBuf.toString(); logger.debug( "Using pattern: '{}' to find compatible versions from metadata.", candidatePatternStr ); final Pattern candidateSuffixPattern = Pattern.compile( candidatePatternStr ); for ( final String compareVersion : versionSet ) { final Matcher candidateSuffixMatcher = candidateSuffixPattern.matcher( compareVersion ); if ( candidateSuffixMatcher.matches() ) { String buildNumberStr = candidateSuffixMatcher.group( 3 ); int compareBuildNum = Integer.parseInt( buildNumberStr ); if ( compareBuildNum > highestBuildNum ) { highestBuildNum = compareBuildNum; } } } logger.debug ("Found highest matching build number {} from set {} ", highestBuildNum, versionSet); return highestBuildNum; } private  Version(); }
Version { public static int findHighestMatchingBuildNumber(String version, Set<String> versionSet ) { int highestBuildNum = 0; String osgiVersion = getOsgiVersion( version ); String qualifier = getQualifier( osgiVersion ); Matcher qualifierMatcher = qualifierPattern.matcher( qualifier ); if ( qualifierMatcher.matches() ) { qualifier = removeLeadingDelimiter( qualifierMatcher.group( 1 ) ); } StringBuilder versionPatternBuf = new StringBuilder(); versionPatternBuf.append( '(' ) .append( Pattern.quote( getMMM( version ) ) ).append('(').append( DELIMITER_REGEX ).append("0)*") .append( ")?" ) .append( DELIMITER_REGEX ); if ( !isEmpty( qualifier ) ) { versionPatternBuf.append( Pattern.quote( qualifier ) ); versionPatternBuf.append( DELIMITER_REGEX ); } versionPatternBuf.append( "(\\d+)" ); String candidatePatternStr = versionPatternBuf.toString(); logger.debug( "Using pattern: '{}' to find compatible versions from metadata.", candidatePatternStr ); final Pattern candidateSuffixPattern = Pattern.compile( candidatePatternStr ); for ( final String compareVersion : versionSet ) { final Matcher candidateSuffixMatcher = candidateSuffixPattern.matcher( compareVersion ); if ( candidateSuffixMatcher.matches() ) { String buildNumberStr = candidateSuffixMatcher.group( 3 ); int compareBuildNum = Integer.parseInt( buildNumberStr ); if ( compareBuildNum > highestBuildNum ) { highestBuildNum = compareBuildNum; } } } logger.debug ("Found highest matching build number {} from set {} ", highestBuildNum, versionSet); return highestBuildNum; } private  Version(); static String getBuildNumber(String version); static int getBuildNumberPadding( int incrementalSerialSuffixPadding, Set<String> versions ); static String getMMM(String version); static String getOsgiVersion(String version); static String getQualifier(String version); static String getQualifierBase(String version); static String getQualifierWithDelim(String version); static String getSnapshot( String version ); static String getSnapshotWithDelim( String version ); static boolean hasBuildNumber( String version ); static boolean hasQualifier( String version ); static boolean isEmpty( String string ); static boolean isSnapshot( String version ); static boolean isValidOSGi(String version); static String removeBuildNumber( String version ); static String removeSnapshot( String version ); static String appendQualifierSuffix( final String version, final String suffix ); static String setBuildNumber( String version, String buildNumber ); static String setSnapshot( String version, boolean snapshot ); static int findHighestMatchingBuildNumber(String version, Set<String> versionSet ); static int getIntegerBuildNumber( String version ); }
Version { public static int findHighestMatchingBuildNumber(String version, Set<String> versionSet ) { int highestBuildNum = 0; String osgiVersion = getOsgiVersion( version ); String qualifier = getQualifier( osgiVersion ); Matcher qualifierMatcher = qualifierPattern.matcher( qualifier ); if ( qualifierMatcher.matches() ) { qualifier = removeLeadingDelimiter( qualifierMatcher.group( 1 ) ); } StringBuilder versionPatternBuf = new StringBuilder(); versionPatternBuf.append( '(' ) .append( Pattern.quote( getMMM( version ) ) ).append('(').append( DELIMITER_REGEX ).append("0)*") .append( ")?" ) .append( DELIMITER_REGEX ); if ( !isEmpty( qualifier ) ) { versionPatternBuf.append( Pattern.quote( qualifier ) ); versionPatternBuf.append( DELIMITER_REGEX ); } versionPatternBuf.append( "(\\d+)" ); String candidatePatternStr = versionPatternBuf.toString(); logger.debug( "Using pattern: '{}' to find compatible versions from metadata.", candidatePatternStr ); final Pattern candidateSuffixPattern = Pattern.compile( candidatePatternStr ); for ( final String compareVersion : versionSet ) { final Matcher candidateSuffixMatcher = candidateSuffixPattern.matcher( compareVersion ); if ( candidateSuffixMatcher.matches() ) { String buildNumberStr = candidateSuffixMatcher.group( 3 ); int compareBuildNum = Integer.parseInt( buildNumberStr ); if ( compareBuildNum > highestBuildNum ) { highestBuildNum = compareBuildNum; } } } logger.debug ("Found highest matching build number {} from set {} ", highestBuildNum, versionSet); return highestBuildNum; } private  Version(); static String getBuildNumber(String version); static int getBuildNumberPadding( int incrementalSerialSuffixPadding, Set<String> versions ); static String getMMM(String version); static String getOsgiVersion(String version); static String getQualifier(String version); static String getQualifierBase(String version); static String getQualifierWithDelim(String version); static String getSnapshot( String version ); static String getSnapshotWithDelim( String version ); static boolean hasBuildNumber( String version ); static boolean hasQualifier( String version ); static boolean isEmpty( String string ); static boolean isSnapshot( String version ); static boolean isValidOSGi(String version); static String removeBuildNumber( String version ); static String removeSnapshot( String version ); static String appendQualifierSuffix( final String version, final String suffix ); static String setBuildNumber( String version, String buildNumber ); static String setSnapshot( String version, boolean snapshot ); static int findHighestMatchingBuildNumber(String version, Set<String> versionSet ); static int getIntegerBuildNumber( String version ); static final String PROJECT_VERSION; }