@Test public void testFixJDKVersion() { assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.0_11" ) ).isEqualTo( "1.5.0-11" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.1" ) ).isEqualTo( "1.5.1" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.2-1.b11" ) ).isEqualTo( "1.5.2-1" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.3_11" ) ).isEqualTo( "1.5.3-11" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.4.5_11" ) ).isEqualTo( "1.5.4-5" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.5.6_11.2" ) ).isEqualTo( "1.5.5-6" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1-5-0-11" ) ).isEqualTo( "1.5.0-11" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1-_5-_0-_11" ) ).isEqualTo( "1.5.0-11" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1_5_0_11" ) ).isEqualTo( "1.5.0-11" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.0-07" ) ).isEqualTo( "1.5.0-7" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.0-b7" ) ).isEqualTo( "1.5.0-7" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.0-;7" ) ).isEqualTo( "1.5.0-7" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1.6.0-dp" ) ).isEqualTo( "1.6.0" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1.6.0-dp2" ) ).isEqualTo( "1.6.0-2" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "1.8.0_73" ) ).isEqualTo( "1.8.0-73" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "9" ) ).isEqualTo( "9" ); assertThat( RequireJavaVersion.normalizeJDKVersion( "17" ) ).isEqualTo( "17" ); }
public static String normalizeJDKVersion( String theJdkVersion ) { theJdkVersion = theJdkVersion.replaceAll( "_|-", "." ); String tokenArray[] = StringUtils.split( theJdkVersion, "." ); List<String> tokens = Arrays.asList( tokenArray ); StringBuilder buffer = new StringBuilder( theJdkVersion.length() ); Iterator<String> iter = tokens.iterator(); for ( int i = 0; i < tokens.size() && i < 4; i++ ) { String section = iter.next(); section = section.replaceAll( "[^0-9]", "" ); if ( StringUtils.isNotEmpty( section ) ) { buffer.append( Integer.parseInt( section ) ); if ( i != 2 ) { buffer.append( '.' ); } else { buffer.append( '-' ); } } } String version = buffer.toString(); version = StringUtils.stripEnd( version, "-" ); return StringUtils.stripEnd( version, "." ); }
RequireJavaVersion extends AbstractVersionEnforcer { public static String normalizeJDKVersion( String theJdkVersion ) { theJdkVersion = theJdkVersion.replaceAll( "_|-", "." ); String tokenArray[] = StringUtils.split( theJdkVersion, "." ); List<String> tokens = Arrays.asList( tokenArray ); StringBuilder buffer = new StringBuilder( theJdkVersion.length() ); Iterator<String> iter = tokens.iterator(); for ( int i = 0; i < tokens.size() && i < 4; i++ ) { String section = iter.next(); section = section.replaceAll( "[^0-9]", "" ); if ( StringUtils.isNotEmpty( section ) ) { buffer.append( Integer.parseInt( section ) ); if ( i != 2 ) { buffer.append( '.' ); } else { buffer.append( '-' ); } } } String version = buffer.toString(); version = StringUtils.stripEnd( version, "-" ); return StringUtils.stripEnd( version, "." ); } }
RequireJavaVersion extends AbstractVersionEnforcer { public static String normalizeJDKVersion( String theJdkVersion ) { theJdkVersion = theJdkVersion.replaceAll( "_|-", "." ); String tokenArray[] = StringUtils.split( theJdkVersion, "." ); List<String> tokens = Arrays.asList( tokenArray ); StringBuilder buffer = new StringBuilder( theJdkVersion.length() ); Iterator<String> iter = tokens.iterator(); for ( int i = 0; i < tokens.size() && i < 4; i++ ) { String section = iter.next(); section = section.replaceAll( "[^0-9]", "" ); if ( StringUtils.isNotEmpty( section ) ) { buffer.append( Integer.parseInt( section ) ); if ( i != 2 ) { buffer.append( '.' ); } else { buffer.append( '-' ); } } } String version = buffer.toString(); version = StringUtils.stripEnd( version, "-" ); return StringUtils.stripEnd( version, "." ); }  }
RequireJavaVersion extends AbstractVersionEnforcer { public static String normalizeJDKVersion( String theJdkVersion ) { theJdkVersion = theJdkVersion.replaceAll( "_|-", "." ); String tokenArray[] = StringUtils.split( theJdkVersion, "." ); List<String> tokens = Arrays.asList( tokenArray ); StringBuilder buffer = new StringBuilder( theJdkVersion.length() ); Iterator<String> iter = tokens.iterator(); for ( int i = 0; i < tokens.size() && i < 4; i++ ) { String section = iter.next(); section = section.replaceAll( "[^0-9]", "" ); if ( StringUtils.isNotEmpty( section ) ) { buffer.append( Integer.parseInt( section ) ); if ( i != 2 ) { buffer.append( '.' ); } else { buffer.append( '-' ); } } } String version = buffer.toString(); version = StringUtils.stripEnd( version, "-" ); return StringUtils.stripEnd( version, "." ); }  @Override void execute( EnforcerRuleHelper helper ); static String normalizeJDKVersion( String theJdkVersion ); }
RequireJavaVersion extends AbstractVersionEnforcer { public static String normalizeJDKVersion( String theJdkVersion ) { theJdkVersion = theJdkVersion.replaceAll( "_|-", "." ); String tokenArray[] = StringUtils.split( theJdkVersion, "." ); List<String> tokens = Arrays.asList( tokenArray ); StringBuilder buffer = new StringBuilder( theJdkVersion.length() ); Iterator<String> iter = tokens.iterator(); for ( int i = 0; i < tokens.size() && i < 4; i++ ) { String section = iter.next(); section = section.replaceAll( "[^0-9]", "" ); if ( StringUtils.isNotEmpty( section ) ) { buffer.append( Integer.parseInt( section ) ); if ( i != 2 ) { buffer.append( '.' ); } else { buffer.append( '-' ); } } } String version = buffer.toString(); version = StringUtils.stripEnd( version, "-" ); return StringUtils.stripEnd( version, "." ); }  @Override void execute( EnforcerRuleHelper helper ); static String normalizeJDKVersion( String theJdkVersion );  }