RulesetsFactoryUtils xref

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

AltStyle によって変換されたページ (->オリジナル) /