• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Renderer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.sourceforge.pmd.renderers.Renderer的典型用法代码示例。如果您正苦于以下问题:Java Renderer类的具体用法?Java Renderer怎么用?Java Renderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Renderer类属于net.sourceforge.pmd.renderers包,在下文中一共展示了Renderer类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: check

import net.sourceforge.pmd.renderers.Renderer; //导入依赖的package包/类
/**
 * Execute PMD validation for SourceClass, if the class fail,
 * then a MemoryCompilerException is thrown with the violations
 *
 * @param sourceClass the input source class
 * @throws MemoryCompilerException throws a memory compiler exception
 */
public void check(SourceClass sourceClass) {

    List<DataSource> dataSources = Arrays.asList(new StringDataSource(sourceClass.getSourceCode()));
    RuleContext ruleContext = new RuleContext();
    StringBuilder violationReport = new StringBuilder();
    PMD.processFiles(configuration, ruleSetFactory, dataSources, ruleContext, Collections.<Renderer> emptyList());
    if(!ruleContext.getReport().isEmpty()) {
        violationReport.append(PMD_VALIDATION_FAILED);
        Iterator<RuleViolation> violations = ruleContext.getReport().iterator();
        while (violations.hasNext()) {
            RuleViolation ruleViolation = violations.next();
            if(!ruleViolation.getClassName().trim().equals("")) {
                violationReport.append(ruleViolation.getClassName());
                violationReport.append(DOTDOT);
                violationReport.append(ruleViolation.getBeginLine());
                violationReport.append(DOTDOT);
            }
            violationReport.append(ruleViolation.getDescription());
            violationReport.append(BRK_LINE);
        }
        throw new MemoryCompilerException(violationReport.toString(), MessageStatus.PMD_ERROR);
    }

}
 
开发者ID:schmittjoaopedro,项目名称:mcc,代码行数:32,代码来源:MemoryPMDValidator.java


示例2: processFiles

import net.sourceforge.pmd.renderers.Renderer; //导入依赖的package包/类
/**
 * Run PMD on a list of files using multiple threads - if more than one is available
 *
 * @param configuration
 *            Configuration
 * @param ruleSetFactory
 *            RuleSetFactory
 * @param files
 *            List<DataSource>
 * @param ctx
 *            RuleContext
 * @param renderers
 *            List<Renderer>
 */
public void processFiles(final GargoylePMDConfiguration configuration, final RuleSetFactory ruleSetFactory,
		final List<DataSource> files, final RuleContext ctx, final List<Renderer> renderers) {

	sortFiles(configuration, files);

	/*
	 * Check if multithreaded support is available. ExecutorService can also
	 * be disabled if threadCount is not positive, e.g. using the
	 * "-threads 0" command line option.
	 */
	//			if (SystemUtils.MT_SUPPORTED && configuration.getThreads() > 0) {
	//				MultiThreadProcessor multiThreadProcessor = new MultiThreadProcessor(configuration);
	//				multiThreadProcessor.processFiles(ruleSetFactory, files, ctx, renderers);
	//			} else {
	pmdGargoyleThreadProcessor = new PMDGargoyleThreadProcessor(configuration);
	pmdGargoyleThreadProcessor.processFiles(ruleSetFactory, files, ctx, renderers);
	//			}

	if (configuration.getClassLoader() instanceof ClasspathClassLoader) {
		IOUtil.tryCloseClassLoader(configuration.getClassLoader());
	}
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:37,代码来源:DoPMD.java


示例3: createPmdConfig

import net.sourceforge.pmd.renderers.Renderer; //导入依赖的package包/类
private PMDConfiguration createPmdConfig(final PmdRenderer renderer) {
    final PMDConfiguration pmdConfig = new PMDConfiguration() {
        @Override
        public Renderer createRenderer() {
            for (final PmdRuleset ruleset : rulesets.values()) {
                ruleset.apply(this);
            }
            return renderer;
        }
    };
    final StringBuilder inputs = new StringBuilder();
    for (final AnalyzerConfig.Path source : config.getSourcePaths()) {
        inputs.append(',').append(source.getPath());
    }
    pmdConfig.setInputPaths(inputs.substring(1));
    pmdConfig.setRuleSets(ruleSetNames());
    pmdConfig.setThreads(0);
    return pmdConfig;
}
 
开发者ID:nidi3,项目名称:code-assert,代码行数:20,代码来源:PmdAnalyzer.java


示例4: createRenderer

import net.sourceforge.pmd.renderers.Renderer; //导入依赖的package包/类
public Renderer createRenderer() {
    if (reportFormat.equals("xml")) {
        return new XMLRenderer();
    } else if (reportFormat.equals("ideaj")) {
        return new IDEAJRenderer(args);
    } else if (reportFormat.equals("papari")) {
        return new PapariTextRenderer();
    } else if (reportFormat.equals("text")) {
        return new TextRenderer();
    } else if (reportFormat.equals("emacs")) {
        return new EmacsRenderer();
    } else if (reportFormat.equals("csv")) {
        return new CSVRenderer();
    } else if (reportFormat.equals("html")) {
        return new HTMLRenderer();
    }
    if (reportFormat.equals("summaryhtml")) {
        return new SummaryHTMLRenderer();
    }
    if (reportFormat.equals("vbhtml")) {
        return new VBHTMLRenderer();
    }
    if (!reportFormat.equals("")) {
        try {
            return (Renderer)Class.forName(reportFormat).newInstance();
        } catch (Exception e) {
            throw new IllegalArgumentException("Can't find the custom format " + reportFormat + ": " + e.getClass().getName());
        }
    }

    throw new IllegalArgumentException("Can't create report with format of " + reportFormat);
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:33,代码来源:CommandLineOptions.java


示例5: createRenderer

import net.sourceforge.pmd.renderers.Renderer; //导入依赖的package包/类
/**
 * Create a Renderer instance based upon the configured reporting options. If withReportWriter then we'll configure it with a writer for the reportFile specified.
 *
 * @param withReportWriter
 *            whether to configure a writer or not
 * @return A Renderer instance.
 */
public Renderer createRenderer(boolean withReportWriter) {
	Renderer renderer = RendererFactory.createRenderer(reportFormat, reportProperties);
	renderer.setShowSuppressedViolations(showSuppressedViolations);
	if (withReportWriter) {
		renderer.setWriter(IOUtil.createWriter(reportFile));
	}
	return renderer;
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:16,代码来源:GargoylePMDConfiguration.java


示例6: doPMD

import net.sourceforge.pmd.renderers.Renderer; //导入依赖的package包/类
/**
 * PMD has terrible design of process configuration. You must use report file with it. I paste this method here and
 * improve it.
 *
 * @throws IllegalArgumentException
 *             if the configuration is not correct
 */
private void doPMD(@NotNull PMDConfiguration configuration) throws IllegalArgumentException {
    // Load the RuleSets
    RuleSetFactory ruleSetFactory = RulesetsFactoryUtils.getRulesetFactory(configuration, new ResourceLoader());

    RuleSets ruleSets = RulesetsFactoryUtils.getRuleSets(configuration.getRuleSets(), ruleSetFactory);
    // this is just double check - we don't get null here
    // instead IllegalArgumentException/RuntimeException is thrown if configuration is wrong
    if (ruleSets == null) {
        return;
    }

    Set<Language> languages = getApplicableLanguages(configuration, ruleSets);
    // this throws RuntimeException when modified file does not exist in workspace
    List<DataSource> files = PMD.getApplicableFiles(configuration, languages);

    long reportStart = System.nanoTime();
    try {
        renderer = configuration.createRenderer();
        List<Renderer> renderers = new LinkedList<>();
        renderers.add(renderer);
        renderer.start();

        Benchmarker.mark(Benchmark.Reporting, System.nanoTime() - reportStart, 0);

        RuleContext ctx = new RuleContext();

        PMD.processFiles(configuration, ruleSetFactory, files, ctx, renderers);

        reportStart = System.nanoTime();
        renderer.end();
    } catch (IOException e) {
        log.error("PMD analysis error", e);
    } finally {
        Benchmarker.mark(Benchmark.Reporting, System.nanoTime() - reportStart, 0);
    }
}
 
开发者ID:TouK,项目名称:sputnik,代码行数:44,代码来源:PmdProcessor.java


示例7: doPMD

import net.sourceforge.pmd.renderers.Renderer; //导入依赖的package包/类
public static Report doPMD(List<DataSource> javaFilesUnderTest, AbstractJavaRule ruleUnderTest) {

        RuleSetFactory factory = new SimpleRuleSetFactory(ruleUnderTest);
        RuleContext context = new RuleContext();

        PMDConfiguration config = new PMDConfiguration();
        config.setInputPaths("."); // overridden by file list
        config.setClassLoader(PMDTestHelper.class.getClassLoader());
        config.setThreads(1);
        config.setRuleSets("aludratest.xml");

        List<Report> fileReports = new ArrayList<Report>();

        PMD.processFiles(config, factory, javaFilesUnderTest, context,
                Collections.<Renderer> singletonList(new GetReportRenderer(fileReports)));

        // combine multiple reports to one
        Report aggregate = new Report();
        for (Report r : fileReports) {
            Iterator<RuleViolation> iter = r.iterator();
            while (iter.hasNext()) {
                aggregate.addRuleViolation(iter.next());
            }
            Iterator<ProcessingError> iter2 = r.errors();
            while (iter2.hasNext()) {
                aggregate.addError(iter2.next());
            }
        }

        return aggregate;
    }
 
开发者ID:AludraTest,项目名称:aludratest,代码行数:32,代码来源:PMDTestHelper.java


示例8: validateOne

import net.sourceforge.pmd.renderers.Renderer; //导入依赖的package包/类
/**
 * Performs validation of one file.
 * @param source Input source file
 */
private void validateOne(final DataSource source) {
    final RuleSetFactory factory = new RuleSetFactory();
    // @checkstyle MagicNumber (1 line)
    factory.setMinimumPriority(RulePriority.valueOf(5));
    PMD.processFiles(
        this.config,
        factory,
        new LinkedList<>(Collections.singleton(source)),
        this.context,
        Collections.<Renderer>emptyList()
    );
}
 
开发者ID:teamed,项目名称:qulice,代码行数:17,代码来源:SourceValidator.java


示例9: main

import net.sourceforge.pmd.renderers.Renderer; //导入依赖的package包/类
public static void main(String[] args) {
    CommandLineOptions opts = new CommandLineOptions(args);

    List files;
    if (opts.containsCommaSeparatedFileList()) {
        files = collectFromCommaDelimitedString(opts.getInputFileName());
    } else {
        files = collectFilesFromOneName(opts.getInputFileName());
    }

    PMD pmd;
    if (opts.jdk13()) {
        pmd = new PMD(new TargetJDK1_3());
    } else {
        pmd = new PMD();
    }

    RuleContext ctx = new RuleContext();
    ctx.setReport(new Report());

    try {
        RuleSetFactory ruleSetFactory = new RuleSetFactory();
        RuleSet rules = ruleSetFactory.createRuleSet(opts.getRulesets());
        for (Iterator i = files.iterator(); i.hasNext();) {
            File file = (File) i.next();
            ctx.setSourceCodeFilename(glomName(opts.shortNamesEnabled(), opts.getInputFileName(), file));
            try {
                pmd.processFile(new FileInputStream(file), opts.getEncoding(), rules, ctx);
            } catch (PMDException pmde) {
                if (opts.debugEnabled()) {
                    pmde.getReason().printStackTrace();
                }
                ctx.getReport().addError(new Report.ProcessingError(pmde.getMessage(), glomName(opts.shortNamesEnabled(), opts.getInputFileName(), file)));
            }
        }
    } catch (FileNotFoundException fnfe) {
        System.out.println(opts.usage());
        fnfe.printStackTrace();
    } catch (RuleSetNotFoundException rsnfe) {
        System.out.println(opts.usage());
        rsnfe.printStackTrace();
    }

    try {
        Renderer r = opts.createRenderer();
        System.out.println(r.render(ctx.getReport()));
    } catch (Exception e) {
        System.out.println(e.getMessage());
        System.out.println(opts.usage());
        if (opts.debugEnabled()) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:55,代码来源:PMD.java


示例10: processFiles

import net.sourceforge.pmd.renderers.Renderer; //导入依赖的package包/类
public void processFiles(RuleSetFactory ruleSetFactory, List<DataSource> files, RuleContext ctx, List<Renderer> renderers) {

		// single threaded execution

		RuleSets rs = createRuleSets(ruleSetFactory);
		SourceCodeProcessor processor = new SourceCodeProcessor(configuration);

		for (DataSource dataSource : files) {
			String niceFileName = filenameFrom(dataSource);

			Report report = PMD.setupReport(rs, ctx, niceFileName);
			// overtake the listener
			//bug fix 2016-10-05 by kyj. 결과가 중복되서 출력됨.
			//			report.addSynchronizedListeners(ctx.getReport().getSynchronizedListeners());
			//	        ctx.setReport(report);
			//	        ctx.setSourceCodeFilename(niceFileName);

			//			if (LOG.isLoggable(Level.FINE)) {
			//				LOG.fine("Processing " + ctx.getSourceCodeFilename());
			//			}
			rs.start(ctx);

			for (Renderer r : renderers) {
				r.startFileAnalysis(dataSource);
			}

			try {
				InputStream stream = new BufferedInputStream(dataSource.getInputStream());
				//				ctx.setLanguageVersion(null);
				processor.processSourceCode(stream, rs, ctx);
			} catch (PMDException pmde) {

				//				LOGGER.error(ValueUtil.toString(pmde));
				//				if (LOG.isLoggable(Level.FINE)) {
				//					LOG.log(Level.FINE, "Error while processing file: " + niceFileName, pmde.getCause());
				//				}

				report.addError(new Report.ProcessingError(pmde.getMessage(), niceFileName));
			} catch (IOException ioe) {
				//				LOGGER.error(ValueUtil.toString(ioe));
				// unexpected exception: log and stop executor service
				addError(report, "Unable to read source file", ioe, niceFileName);
			} catch (RuntimeException re) {
				//				LOGGER.error(ValueUtil.toString(re));
				// unexpected exception: log and stop executor service
				addError(report, "RuntimeException while processing file", re, niceFileName);
			} catch (Exception e) {
				LOGGER.error(ValueUtil.toString(e));
			}

			rs.end(ctx);

			super.renderReports(renderers, ctx.getReport());
		}
	}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:56,代码来源:PMDGargoyleThreadProcessor.java



注:本文中的net.sourceforge.pmd.renderers.Renderer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Serialization类代码示例发布时间:2022-05-23
下一篇:
Java BidirectionalMap类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap