public static String [ ] extractNameVersionType ( String url ) { Matcher m = ARTIFACT_MATCHER . matcher ( url ) ; if ( ! m . matches ( ) ) { return new String [ ] { url . split ( "\\." ) [ 0 ] , DEFAULT_VERSION } ; } else { //CHECKSTYLE:OFF StringBuilder v = new StringBuilder ( ) ; String d1 = m . group ( 1 ) ; String d2 = m . group ( 2 ) ; String d3 = m . group ( 3 ) ; String d4 = m . group ( 4 ) ; String d5 = m . group ( 5 ) ; String d6 = m . group ( 6 ) ; if ( d2 != null ) { v . append ( d2 ) ; if ( d3 != null ) { v . append ( ' ' ) ; v . append ( d3 ) ; if ( d4 != null ) { v . append ( ' ' ) ; v . append ( d4 ) ; if ( d5 != null ) { v . append ( "." ) ; cleanupModifier ( v , d5 ) ; } } else if ( d5 != null ) { v . append ( ".0." ) ; cleanupModifier ( v , d5 ) ; } } else if ( d5 != null ) { v . append ( ".0.0." ) ; cleanupModifier ( v , d5 ) ; } } //CHECKSTYLE:ON return new String [ ] { d1 , v . toString ( ) , d6 } ; } }
Heuristic to compute the name and version of a file given it s name on disk