View Javadoc

    1   /**
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package net.sourceforge.pmd.processor;
    5
    6   import java.io.IOException;
    7   import java.util.List;
    8
    9   import net.sourceforge.pmd.PMDConfiguration;
    10  import net.sourceforge.pmd.Report;
    11  import net.sourceforge.pmd.RuleSetFactory;
    12  import net.sourceforge.pmd.RuleSetNotFoundException;
    13  import net.sourceforge.pmd.RuleSets;
    14  import net.sourceforge.pmd.benchmark.Benchmark;
    15  import net.sourceforge.pmd.benchmark.Benchmarker;
    16  import net.sourceforge.pmd.renderers.Renderer;
    17  import net.sourceforge.pmd.util.datasource.DataSource;
    18
    19  /**
    20   * @author Romain Pelisse <belaran@gmail.com>
    21   *
    22   */
    23  public abstract class AbstractPMDProcessor {
    24
    25  	protected final PMDConfiguration configuration;
    26
    27  	public AbstractPMDProcessor(PMDConfiguration configuration) {
    28  		this.configuration = configuration;
    29  	}
    30
    31  	public void renderReports(final List<Renderer> renderers, final Report report) {
    32
    33  		long start = System.nanoTime();
    34
    35  		try {
    36  			for (Renderer r : renderers) {
    37  				r.renderFileReport(report);
    38  			}
    39  			long end = System.nanoTime();
    40  			Benchmarker.mark(Benchmark.Reporting, end - start, 1);
    41  		} catch (IOException ioe) {
    42
    43  		}
    44  	}
    45
    46  	protected String filenameFrom(DataSource dataSource) {
    47  		return dataSource.getNiceFileName(
    48  			 configuration.isReportShortNames(),
    49  			 configuration.getInputPaths()
    50  			 );
    51  	}
    52
    53  	protected RuleSets createRuleSets(RuleSetFactory factory) {
    54
    55  		try {
    56  			return factory.createRuleSets(configuration.getRuleSets());
    57  		} catch (RuleSetNotFoundException rsnfe) {
    58  			// should not happen: parent already created a ruleset
    59  			return null;
    60  		}
    61  	}
    62
    63  }