Coverage Report - org.owasp.dependencycheck.analyzer.AnalyzerService
 
Classes in this File Line Coverage Branch Coverage Complexity
AnalyzerService
100%
7/7
100%
2/2
1.333
 
 1  
 /*
 2  
  * This file is part of dependency-check-core.
 3  
  *
 4  
  * Dependency-check-core is free software: you can redistribute it and/or modify it
 5  
  * under the terms of the GNU General Public License as published by the Free
 6  
  * Software Foundation, either version 3 of the License, or (at your option) any
 7  
  * later version.
 8  
  *
 9  
  * Dependency-check-core is distributed in the hope that it will be useful, but
 10  
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 12  
  * details.
 13  
  *
 14  
  * You should have received a copy of the GNU General Public License along with
 15  
  * dependency-check-core. If not, see http://www.gnu.org/licenses/.
 16  
  *
 17  
  * Copyright (c) 2012 Jeremy Long. All Rights Reserved.
 18  
  */
 19  
 package org.owasp.dependencycheck.analyzer;
 20  
 
 21  
 import java.util.Iterator;
 22  
 import java.util.ServiceLoader;
 23  
 
 24  
 /**
 25  
  *
 26  
  * @author Jeremy Long (jeremy.long@owasp.org)
 27  
  */
 28  
 public final class AnalyzerService {
 29  
 
 30  
     /**
 31  
      * The analyzer service singleton.
 32  
      */
 33  
     private static AnalyzerService service;
 34  
     /**
 35  
      * The service loader for analyzers.
 36  
      */
 37  
     private final ServiceLoader<Analyzer> loader;
 38  
 
 39  
     /**
 40  
      * Creates a new instance of AnalyzerService.
 41  
      */
 42  1
     private AnalyzerService() {
 43  1
         loader = ServiceLoader.load(Analyzer.class);
 44  1
     }
 45  
 
 46  
     /**
 47  
      * Retrieve the singleton instance of AnalyzerService.
 48  
      *
 49  
      * @return a singleton AnalyzerService.
 50  
      */
 51  
     public static synchronized AnalyzerService getInstance() {
 52  7
         if (service == null) {
 53  1
             service = new AnalyzerService();
 54  
         }
 55  7
         return service;
 56  
     }
 57  
 
 58  
     /**
 59  
      * Returns an Iterator for all instances of the Analyzer interface.
 60  
      *
 61  
      * @return an iterator of Analyzers.
 62  
      */
 63  
     public Iterator<Analyzer> getAnalyzers() {
 64  7
         return loader.iterator();
 65  
     }
 66  
 }