@ Override public Run < ? , ? > resolve ( Job < ? , ? > job ) { File f = getPermalinkFile ( job ) ; Run < ? , ? > b = null ; try { String target = readSymlink ( f ) ; if ( target != null ) { int n = Integer . parseInt ( Util . getFileName ( target ) ) ; if ( n == RESOLVES_TO_NONE ) return null ; b = job . getBuildByNumber ( n ) ; if ( b != null && apply ( b ) ) return b ; // found it (in the most efficient way possible) // the cache is stale. start the search if ( b == null ) b = job . getNearestOldBuild ( n ) ; } } catch ( InterruptedException e ) { LOGGER . log ( Level . WARNING , "Failed to read permalink cache:" + f , e ) ; // if we fail to read the cache, fall back to the re-computation } catch ( NumberFormatException e ) { LOGGER . log ( Level . WARNING , "Failed to parse the build number in the permalink cache:" + f , e ) ; // if we fail to read the cache, fall back to the re-computation } catch ( IOException e ) { // this happens when the symlink doesn't exist // (and it cannot be distinguished from the case when the actual I/O error happened } if ( b == null ) { // no cache b = job . getLastBuild ( ) ; } // start from the build 'b' and locate the build that matches the criteria going back in time b = find ( b ) ; updateCache ( job , b ) ; return b ; }
Resolves the permalink by using the cache if possible .