View Javadoc

    1   package net.sourceforge.pmd;
    2
    3   import java.util.logging.Level;
    4   import java.util.logging.Logger;
    5
    6   import net.sourceforge.pmd.benchmark.Benchmark;
    7   import net.sourceforge.pmd.benchmark.Benchmarker;
    8
    9   public final class RulesetsFactoryUtils {
    10
    11  	private static final Logger LOG = Logger.getLogger(RulesetsFactoryUtils.class.getName());
    12
    13  	private RulesetsFactoryUtils() {}
    14
    15  	public static RuleSets getRuleSets(String rulesets, RuleSetFactory factory, long loadRuleStart) {
    16  		RuleSets ruleSets = null;
    17
    18  		try {
    19  			ruleSets = factory.createRuleSets(rulesets);
    20  			factory.setWarnDeprecated(false);
    21  			printRuleNamesInDebug(ruleSets);
    22  			long endLoadRules = System.nanoTime();
    23  			Benchmarker.mark(Benchmark.LoadRules, endLoadRules - loadRuleStart, 0);
    24  		} catch (RuleSetNotFoundException rsnfe) {
    25  			LOG.log(Level.SEVERE, "Ruleset not found", rsnfe);
    26  			throw new IllegalArgumentException(rsnfe);
    27  		}
    28  		return ruleSets;
    29  	}
    30
    31  	public static RuleSetFactory getRulesetFactory(PMDConfiguration configuration) {
    32  		RuleSetFactory ruleSetFactory = new RuleSetFactory();
    33  		ruleSetFactory.setMinimumPriority(configuration.getMinimumPriority());
    34  		ruleSetFactory.setWarnDeprecated(true);
    35  		return ruleSetFactory;
    36  	}
    37
    38  	/**
    39  	 * If in debug modus, print the names of the rules.
    40  	 *
    41  	 * @param rulesets     the RuleSets to print
    42  	 */
    43  	private static void printRuleNamesInDebug(RuleSets rulesets) {
    44  		if (LOG.isLoggable(Level.FINER)) {
    45  			for (Rule r : rulesets.getAllRules()) {
    46  				LOG.finer("Loaded rule " + r.getName());
    47  			}
    48  		}
    49  	}
    50  }