public static Version parseMavenVersion ( String version ) { if ( Strings . isNullOrEmpty ( version ) ) { return new Version ( 0 , 0 , 0 ) ; } // Detect the snapshot final boolean isSnapshot ; final String coreVersion ; Matcher matcher = Artifact . VERSION_FILE_PATTERN . matcher ( version ) ; if ( matcher . matches ( ) ) { coreVersion = matcher . group ( 1 ) ; isSnapshot = true ; } else { matcher = SNAPSHOT_VERSION_PATTERN . matcher ( version ) ; if ( matcher . matches ( ) ) { coreVersion = matcher . group ( 1 ) ; isSnapshot = true ; } else { coreVersion = version ; isSnapshot = false ; } } // Parse the numbers final String [ ] parts = coreVersion . split ( "[.]" ) ; //$NON-NLS-1$ final int [ ] numbers = new int [ ] { 0 , 0 , 0 } ; int i = 0 ; while ( i < numbers . length && i < parts . length ) { try { numbers [ i ] = Integer . parseInt ( parts [ i ] ) ; ++ i ; } catch ( Exception exception ) { // Force the exit of the loop since a number cannot be find. i = numbers . length ; } } // Reply if ( isSnapshot ) { return new Version ( numbers [ 0 ] , numbers [ 1 ] , numbers [ 2 ] , SNAPSHOT_QUALIFIER ) ; } return new Version ( numbers [ 0 ] , numbers [ 1 ] , numbers [ 2 ] ) ; }
Maven version parser .