本文整理汇总了Java中net.sourceforge.pmd.PMD类的典型用法代码示例。如果您正苦于以下问题:Java PMD类的具体用法?Java PMD怎么用?Java PMD使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PMD类属于net.sourceforge.pmd包,在下文中一共展示了PMD类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: check
import net.sourceforge.pmd.PMD; //导入依赖的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: test
import net.sourceforge.pmd.PMD; //导入依赖的package包/类
@Test
public void test() throws IOException, InterruptedException {
String fileString = "C:\\Users\\KYJ\\eclipse\\jee-neon\\workspace\\sos-server\\src\\main\\java\\com\\samsung\\sds\\sos\\server\\util\\ValueUtil.java";
File javaFile = new File(fileString);
String ruleSetFile = /*"java-basic";*/new File("rulesets/java/basic.xml").getAbsolutePath();
File resultXml = new File("result.xml");
String pmdReportFileName = resultXml.getAbsolutePath();
System.out.println(javaFile.getAbsolutePath());
System.out.println(pmdReportFileName);
// String[] args = new String[] { "-d ", javaFile.getAbsolutePath(), "-f", "xml", "-R", ruleSetFile, "-r", pmdReportFileName , "-version" , "1.8", "-language", "java" , "-debug" };
String string = FileUtils.readFileToString(javaFile, Charset.forName("UTF-8"));
// System.out.println(string);
String[] args = new String[] { "-sourceText ", string, "-f", "xml", /*"-R", ruleSetFile, */"-r", pmdReportFileName, "-version",
"1.8", "-language", "java", "-P", "driver=jdbc.oracle,url=10.20.2.2,id=ccc,password=ccc" };
PMD.main(args);
Assert.assertTrue(true);
// Thread.sleep(1000L);
// System.out.println(Files.toString(resultXml, Charset.forName("UTF-8")));
// System.out.println(Files.readLines(resultXml, Charset.forName("UTF-8")));
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:26,代码来源:PMDTest.java
示例3: testDir
import net.sourceforge.pmd.PMD; //导入依赖的package包/类
@Test
public void testDir() throws IOException, InterruptedException {
String relativePath = "src\\main\\java\\net\\sourceforge\\pmd";
String fileString = new File(relativePath).getAbsolutePath();
// File javaFile = new File(fileString);
String ruleSetFile = /*"java-basic";*/new File("rulesets/java/basic.xml").getAbsolutePath();
File resultXml = new File("result.xml");
String pmdReportFileName = resultXml.getAbsolutePath();
System.out.println(fileString);
System.out.println(pmdReportFileName);
// String[] args = new String[] { "-d ", javaFile.getAbsolutePath(), "-f", "xml", "-R", ruleSetFile, "-r", pmdReportFileName , "-version" , "1.8", "-language", "java" , "-debug" };
// String string = Files.toString(javaFile, Charset.forName("UTF-8"));
// System.out.println(string);
String[] args = new String[] { "-d", fileString, "-f", "xml", "-R", ruleSetFile, "-r", pmdReportFileName, "-version", "1.8",
"-language", "java", "-P", "driver=jdbc.oracle,url=10.20.2.2,id=ccc,password=ccc", "-debug" };
PMD.main(args);
// Thread.sleep(1000L);
// System.out.println(Files.toString(resultXml, Charset.forName("UTF-8")));
// System.out.println(Files.readLines(resultXml, Charset.forName("UTF-8")));
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:25,代码来源:PMDTest.java
示例4: start
import net.sourceforge.pmd.PMD; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void start() throws IOException {
String encoding = getProperty(ENCODING);
if (encoding.equalsIgnoreCase("utf-8")) {
useUTF8 = true;
}
Writer writer = getWriter();
StringBuilder buf = new StringBuilder(500);
buf.append("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>").append(PMD.EOL);
createVersionAttr(buf);
createTimestampAttr(buf);
// FIXME: elapsed time not available until the end of the processing
// buf.append(createTimeElapsedAttr(report));
buf.append('>').append(PMD.EOL);
writer.write(buf.toString());
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:21,代码来源:DatabaseXmlRenderer.java
示例5: header
import net.sourceforge.pmd.PMD; //导入依赖的package包/类
private String header() {
StringBuffer sb = new StringBuffer();
sb.append("<html><head><title>PMD</title></head>");
sb.append("<style type=\"text/css\">");
sb.append("<!--" + PMD.EOL);
sb.append("body { background-color: white; font-family:verdana, arial, helvetica, geneva; font-size: 16px; font-style: italic; color: black; }" + PMD.EOL);
sb.append(".title { font-family: verdana, arial, helvetica,geneva; font-size: 12px; font-weight:bold; color: white; }" + PMD.EOL);
sb.append(".body { font-family: verdana, arial, helvetica, geneva; font-size: 12px; font-weight:plain; color: black; }" + PMD.EOL);
sb.append("#TableHeader { background-color: #003366; }" + PMD.EOL);
sb.append("#RowColor1 { background-color: #eeeeee; }" + PMD.EOL);
sb.append("#RowColor2 { background-color: white; }" + PMD.EOL);
sb.append("-->");
sb.append("</style>");
sb.append("<body><center>");
return sb.toString();
}
开发者ID:cdk,项目名称:cdk-build-util,代码行数:17,代码来源:SummaryVBHTMLRenderer.java
示例6: test_ruleset_properties
import net.sourceforge.pmd.PMD; //导入依赖的package包/类
@Test
public void test_ruleset_properties() throws IOException, InterruptedException {
String preffix = "C:/Users/KYJ/.git/Gargoyle/pmd.core/";
String suffix = "src/main/java/org/ky/pmd/core/App.java";
File javaFile = new File(preffix + suffix);
String ruleSetFile = readProperteis();/*"java-basic";*/ //new File("rulesets/java/rulesets.properties").getAbsolutePath();
File resultXml = new File("result.xml");
String pmdReportFileName = resultXml.getAbsolutePath();
System.out.println(javaFile.getAbsolutePath());
System.out.println(pmdReportFileName);
// String[] args = new String[] { "-d ", javaFile.getAbsolutePath(), "-f", "xml", "-R", ruleSetFile, "-r", pmdReportFileName , "-version" , "1.8", "-language", "java" , "-debug" };
String string = FileUtils.readFileToString(javaFile, Charset.forName("UTF-8"));
// System.out.println(string);
String[] args = new String[] { "-sourceText ", string, "-f", "xml", "-R", ruleSetFile, "-r", pmdReportFileName, "-version", "1.8",
"-language", "java", "-P", "driver=jdbc.oracle,url=10.20.2.2,id=ccc,password=ccc", "-verbose" };
PMD.main(args);
String xmlformastString = FileUtils.readFileToString(new File("result.xml"), Charset.forName("UTF-8"));
System.out.println(xmlformastString);
Assert.assertTrue(true);
// Thread.sleep(1000L);
// System.out.println(Files.toString(resultXml, Charset.forName("UTF-8")));
// System.out.println(Files.readLines(resultXml, Charset.forName("UTF-8")));
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:32,代码来源:PMDTest.java
示例7: createKids
import net.sourceforge.pmd.PMD; //导入依赖的package包/类
private void createKids() {
String message = ((ParseException) item).getMessage();
String[] lines = StringUtil.substringsOf(message, PMD.EOL);
kids = new ExceptionNode[lines.length];
for (int i = 0; i < lines.length; i++) {
kids[i] = new ExceptionNode(lines[i]);
}
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:11,代码来源:DesignerFx.java
示例8: getListCellRendererComponent
import net.sourceforge.pmd.PMD; //导入依赖的package包/类
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
String text;
if (value instanceof Node) {
Node node = (Node) value;
StringBuffer sb = new StringBuffer();
String name = node.getClass().getName().substring(node.getClass().getName().lastIndexOf('.') + 1);
if (Proxy.isProxyClass(value.getClass())) {
name = value.toString();
}
sb.append(name).append(" at line ").append(node.getBeginLine()).append(" column ").append(node.getBeginColumn())
.append(PMD.EOL);
text = sb.toString();
} else {
text = value.toString();
}
setText(text);
return this;
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:28,代码来源:DesignerFx.java
示例9: end
import net.sourceforge.pmd.PMD; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void end() throws IOException {
Writer writer = getWriter();
StringBuilder buf = new StringBuilder(500);
// errors
for (Report.ProcessingError pe : errors) {
buf.setLength(0);
buf.append("<error ").append("filename=\"");
StringUtil.appendXmlEscaped(buf, pe.getFile(), useUTF8);
buf.append("\" msg=\"");
StringUtil.appendXmlEscaped(buf, pe.getMsg(), useUTF8);
buf.append("\"/>").append(PMD.EOL);
writer.write(buf.toString());
}
// suppressed violations
if (showSuppressedViolations) {
for (Report.SuppressedViolation s : suppressed) {
buf.setLength(0);
buf.append("<suppressedviolation ").append("filename=\"");
StringUtil.appendXmlEscaped(buf, s.getRuleViolation().getFilename(), useUTF8);
buf.append("\" suppressiontype=\"");
StringUtil.appendXmlEscaped(buf, s.suppressedByNOPMD() ? "nopmd" : "annotation", useUTF8);
buf.append("\" msg=\"");
StringUtil.appendXmlEscaped(buf, s.getRuleViolation().getDescription(), useUTF8);
buf.append("\" usermsg=\"");
StringUtil.appendXmlEscaped(buf, s.getUserMessage() == null ? "" : s.getUserMessage(), useUTF8);
buf.append("\"/>").append(PMD.EOL);
writer.write(buf.toString());
}
}
writer.write("</pmd>" + PMD.EOL);
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:38,代码来源:DatabaseXmlRenderer.java
示例10: create
import net.sourceforge.pmd.PMD; //导入依赖的package包/类
public static PmdBasedClassLoader create(Collection<URL> additionalUrls) {
ClassLoader pmdClassLoader = PMD.class.getClassLoader();
return new PmdBasedClassLoader(
additionalUrls
.stream()
.toArray(URL[]::new),
pmdClassLoader
);
}
开发者ID:giancosta86,项目名称:EasyPmd,代码行数:11,代码来源:PmdBasedClassLoader.java
示例11: doPMD
import net.sourceforge.pmd.PMD; //导入依赖的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
示例12: validateOne
import net.sourceforge.pmd.PMD; //导入依赖的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
示例13: appendLn
import net.sourceforge.pmd.PMD; //导入依赖的package包/类
private static void appendLn(StringBuilder sb, String text) {
sb.append(text).append(PMD.EOL);
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:4,代码来源:CreateXMLRulePanelFx.java
示例14: processFiles
import net.sourceforge.pmd.PMD; //导入依赖的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
示例15: renderFileViolations
import net.sourceforge.pmd.PMD; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void renderFileViolations(Iterator<RuleViolation> violations) throws IOException {
Writer writer = getWriter();
StringBuilder buf = new StringBuilder(500);
String filename = null;
// rule violations
while (violations.hasNext()) {
buf.setLength(0);
RuleViolation rv = violations.next();
if (!rv.getFilename().equals(filename)) { // New File
if (filename != null) {// Not first file ?
buf.append("</file>").append(PMD.EOL);
}
filename = rv.getFilename();
buf.append("<file name=\"");
StringUtil.appendXmlEscaped(buf, filename, useUTF8);
buf.append("\">").append(PMD.EOL);
}
buf.append("<violation beginline=\"").append(rv.getBeginLine());
buf.append("\" endline=\"").append(rv.getEndLine());
buf.append("\" begincolumn=\"").append(rv.getBeginColumn());
buf.append("\" endcolumn=\"").append(rv.getEndColumn());
buf.append("\" rule=\"");
StringUtil.appendXmlEscaped(buf, rv.getRule().getName(), useUTF8);
buf.append("\" ruleset=\"");
StringUtil.appendXmlEscaped(buf, rv.getRule().getRuleSetName(), useUTF8);
buf.append('"');
maybeAdd("package", rv.getPackageName(), buf);
maybeAdd("class", rv.getClassName(), buf);
maybeAdd("method", rv.getMethodName(), buf);
maybeAdd("variable", rv.getVariableName(), buf);
maybeAdd("externalInfoUrl", rv.getRule().getExternalInfoUrl(), buf);
buf.append(" priority=\"");
buf.append(rv.getRule().getPriority().getPriority());
buf.append("\">").append(PMD.EOL);
StringUtil.appendXmlEscaped(buf, rv.getDescription(), useUTF8);
buf.append(PMD.EOL);
buf.append("</violation>");
buf.append(PMD.EOL);
writer.write(buf.toString());
}
if (filename != null) { // Not first file ?
writer.write("</file>");
writer.write(PMD.EOL);
}
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:53,代码来源:DatabaseXmlRenderer.java
示例16: createVersionAttr
import net.sourceforge.pmd.PMD; //导入依赖的package包/类
private void createVersionAttr(StringBuilder buffer) {
buffer.append("<pmd version=\"").append(PMD.VERSION).append('"');
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:4,代码来源:DatabaseXmlRenderer.java
示例17: EasyPmdPanel
import net.sourceforge.pmd.PMD; //导入依赖的package包/类
EasyPmdPanel() {
pluginInfoService = Injector.lookup(ProductInfoService.class);
optionsService = Injector.lookup(OptionsService.class);
scanMessagesCache = Injector.lookup(ScanMessagesCache.class);
initComponents();
pathFilteringScrollPane.getVerticalScrollBar().setUnitIncrement(300);
dialogService = Injector.lookup(DialogService.class);
optionsFactory = Injector.lookup(OptionsFactory.class);
minimumPriorityCombo.setModel(new RulePriorityComboBoxModel());
profileComboActionListener = (ActionEvent e) -> {
if (refillingProfileCombo) {
return;
}
String selectedProfileName = (String) profileCombo.getSelectedItem();
String oldProfileName = EasyPmdPanel.this.activeProfileName;
EasyPmdPanel.this.activeProfileName = selectedProfileName;
updateOptionsControls(oldProfileName);
};
ImageIcon pluginIcon = new ImageIcon(getClass().getResource("/info/gianlucacosta/easypmd/mainIcon128.png"));
pluginIconPicture.setIcon(pluginIcon);
pluginIconPicture.setText("");
pluginTitleLabel.setText(
String.format("%s %s",
pluginInfoService.getName(),
pluginInfoService.getVersion()
)
);
pmdVersionLabel.setText(
String.format("PMD version %s", PMD.VERSION)
);
}
开发者ID:giancosta86,项目名称:EasyPmd,代码行数:44,代码来源:EasyPmdPanel.java
注:本文中的net.sourceforge.pmd.PMD类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论