private void reduceResults ( final List < AnalysisResultFuture > results , final Map < ComponentJob , AnalyzerResult > resultMap , final List < AnalysisResultReductionException > reductionErrors ) { if ( _hasRun . get ( ) ) { // already reduced return ; } _hasRun . set ( true ) ; for ( AnalysisResultFuture result : results ) { if ( result . isErrornous ( ) ) { logger . error ( "Encountered errorneous slave result. Result reduction will stop. Result={}" , result ) ; final List < Throwable > errors = result . getErrors ( ) ; if ( ! errors . isEmpty ( ) ) { final Throwable firstError = errors . get ( 0 ) ; logger . error ( "Encountered error before reducing results (showing stack trace of invoking the reducer): " + firstError . getMessage ( ) , new Throwable ( ) ) ; _analysisListener . errorUknown ( _masterJob , firstError ) ; } // error occurred! return ; } } final Collection < AnalyzerJob > analyzerJobs = _masterJob . getAnalyzerJobs ( ) ; for ( AnalyzerJob masterAnalyzerJob : analyzerJobs ) { final Collection < AnalyzerResult > slaveResults = new ArrayList < AnalyzerResult > ( ) ; logger . info ( "Reducing {} slave results for component: {}" , results . size ( ) , masterAnalyzerJob ) ; for ( AnalysisResultFuture result : results ) { final Map < ComponentJob , AnalyzerResult > slaveResultMap = result . getResultMap ( ) ; final List < AnalyzerJob > slaveAnalyzerJobs = CollectionUtils2 . filterOnClass ( slaveResultMap . keySet ( ) , AnalyzerJob . class ) ; final AnalyzerJobHelper analyzerJobHelper = new AnalyzerJobHelper ( slaveAnalyzerJobs ) ; final AnalyzerJob slaveAnalyzerJob = analyzerJobHelper . getAnalyzerJob ( masterAnalyzerJob ) ; if ( slaveAnalyzerJob == null ) { throw new IllegalStateException ( "Could not resolve slave component matching [" + masterAnalyzerJob + "] in slave result: " + result ) ; } final AnalyzerResult analyzerResult = result . getResult ( slaveAnalyzerJob ) ; slaveResults . add ( analyzerResult ) ; } reduce ( masterAnalyzerJob , slaveResults , resultMap , reductionErrors ) ; } }
Reduces all the analyzer results of an analysis