public String generateFragment ( ) { if ( ! DownloadSettings . usePostBack ( ) ) { return "" ; } if ( neverUpdate ) return "" ; if ( doesNotSupportPostMessage ( ) ) return "" ; StringBuilder buf = new StringBuilder ( ) ; if ( Jenkins . getInstance ( ) . hasPermission ( Jenkins . READ ) ) { long now = System . currentTimeMillis ( ) ; for ( Downloadable d : Downloadable . all ( ) ) { if ( d . getDue ( ) < now && d . lastAttempt + TimeUnit . SECONDS . toMillis ( 10 ) < now ) { buf . append ( "<script>" ) . append ( "Behaviour.addLoadEvent(function() {" ) . append ( " downloadService.download(" ) . append ( QuotedStringTokenizer . quote ( d . getId ( ) ) ) . append ( ' ' ) . append ( QuotedStringTokenizer . quote ( mapHttps ( d . getUrl ( ) ) ) ) . append ( ' ' ) . append ( "{version:" + QuotedStringTokenizer . quote ( Jenkins . VERSION ) + ' ' ) . append ( ' ' ) . append ( QuotedStringTokenizer . quote ( Stapler . getCurrentRequest ( ) . getContextPath ( ) + ' ' + getUrl ( ) + "/byId/" + d . getId ( ) + "/postBack" ) ) . append ( ' ' ) . append ( "null);" ) . append ( "});" ) . append ( "</script>" ) ; d . lastAttempt = now ; } } } return buf . toString ( ) ; }
Builds up an HTML fragment that starts all the download jobs .