forked from phoedos/pmd
updated cougaar system properties rule
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@302 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -875,7 +875,9 @@ void Literal() :
|
||||
|
|
||||
<CHARACTER_LITERAL>
|
||||
|
|
||||
<STRING_LITERAL>
|
||||
{ String stringValue = ""; Token t = null;}
|
||||
t=<STRING_LITERAL>
|
||||
{ stringValue=t.image;} {jjtThis.setImage(stringValue);}
|
||||
|
|
||||
BooleanLiteral()
|
||||
|
|
||||
|
@ -2,4 +2,4 @@
|
||||
set MAIN=net.sourceforge.pmd.PMD
|
||||
set TEST_FILE=c:\\data\\pmd\\pmd\\test-data\\%1%.java
|
||||
|
||||
java %MAIN% %TEST_FILE% xml rulesets\basic.xml
|
||||
java %MAIN% %TEST_FILE% xml rulesets\cougaar.xml
|
||||
|
@ -22,4 +22,8 @@ public class SystemPropsRuleTest extends RuleTst {
|
||||
assertEquals(new SystemPropsRule(), ((RuleViolation)report.iterator().next()).getRule());
|
||||
}
|
||||
|
||||
public void testProps2() throws Throwable {
|
||||
Report report = process("ContainsSystemGetProps2.java", new SystemPropsRule());
|
||||
assertTrue(report.isEmpty());
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class PMD {
|
||||
InputStreamReader reader = new InputStreamReader(fileContents);
|
||||
JavaParser parser = new JavaParser(reader);
|
||||
ASTCompilationUnit c = parser.CompilationUnit();
|
||||
//c.dump("");
|
||||
c.dump("");
|
||||
List acus = new ArrayList();
|
||||
acus.add(c);
|
||||
ruleSet.apply(acus, ctx);
|
||||
|
@ -3120,7 +3120,12 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java
|
||||
jj_consume_token(CHARACTER_LITERAL);
|
||||
break;
|
||||
case STRING_LITERAL:
|
||||
jj_consume_token(STRING_LITERAL);
|
||||
String stringValue = ""; Token t = null;
|
||||
t = jj_consume_token(STRING_LITERAL);
|
||||
stringValue=t.image;
|
||||
jjtree.closeNodeScope(jjtn000, true);
|
||||
jjtc000 = false;
|
||||
jjtn000.setImage(stringValue);
|
||||
break;
|
||||
case FALSE:
|
||||
case TRUE:
|
||||
@ -6676,6 +6681,14 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_381() {
|
||||
if (jj_scan_token(COLON)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
if (jj_3R_60()) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3_5() {
|
||||
Token xsp;
|
||||
xsp = jj_scanpos;
|
||||
@ -6688,14 +6701,6 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_381() {
|
||||
if (jj_scan_token(COLON)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
if (jj_3R_60()) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_304() {
|
||||
if (jj_scan_token(FINAL)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
@ -6878,6 +6883,20 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_227() {
|
||||
if (jj_scan_token(ASSERT)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
if (jj_3R_60()) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
Token xsp;
|
||||
xsp = jj_scanpos;
|
||||
if (jj_3R_381()) jj_scanpos = xsp;
|
||||
else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
if (jj_scan_token(SEMICOLON)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_302() {
|
||||
if (jj_scan_token(STATIC)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
@ -6910,20 +6929,6 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_227() {
|
||||
if (jj_scan_token(ASSERT)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
if (jj_3R_60()) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
Token xsp;
|
||||
xsp = jj_scanpos;
|
||||
if (jj_3R_381()) jj_scanpos = xsp;
|
||||
else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
if (jj_scan_token(SEMICOLON)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_67() {
|
||||
if (jj_scan_token(PUBLIC)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
@ -6962,12 +6967,6 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_66() {
|
||||
if (jj_scan_token(FINAL)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_380() {
|
||||
if (jj_scan_token(FINALLY)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
@ -6990,6 +6989,12 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_66() {
|
||||
if (jj_scan_token(FINAL)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_175() {
|
||||
if (jj_scan_token(CLASS)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
@ -7923,20 +7928,14 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_155() {
|
||||
if (jj_3R_158()) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_169() {
|
||||
if (jj_3R_177()) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_168() {
|
||||
if (jj_scan_token(STRING_LITERAL)) return true;
|
||||
final private boolean jj_3R_155() {
|
||||
if (jj_3R_158()) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
return false;
|
||||
}
|
||||
@ -7947,6 +7946,12 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_168() {
|
||||
if (jj_scan_token(STRING_LITERAL)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
final private boolean jj_3R_166() {
|
||||
if (jj_scan_token(FLOATING_POINT_LITERAL)) return true;
|
||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Generated By:JJTree: Do not edit this line. /home/dpeugh/projects/pmd/src/net/sourceforge/pmd/ast/JavaParserTreeConstants.java */
|
||||
/* Generated By:JJTree: Do not edit this line. C:/data/pmd/pmd/src/net/sourceforge/pmd/ast\JavaParserTreeConstants.java */
|
||||
|
||||
package net.sourceforge.pmd.ast;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Generated By:JJTree: Do not edit this line. /home/dpeugh/projects/pmd/src/net/sourceforge/pmd/ast/JavaParserVisitor.java */
|
||||
/* Generated By:JJTree: Do not edit this line. C:/data/pmd/pmd/src/net/sourceforge/pmd/ast\JavaParserVisitor.java */
|
||||
|
||||
package net.sourceforge.pmd.ast;
|
||||
|
||||
|
@ -3,17 +3,33 @@ package org.cougaar.util.pmd;
|
||||
import net.sourceforge.pmd.ast.ASTName;
|
||||
import net.sourceforge.pmd.ast.JavaParserVisitorAdapter;
|
||||
import net.sourceforge.pmd.ast.SimpleNode;
|
||||
import net.sourceforge.pmd.ast.ASTLiteral;
|
||||
import net.sourceforge.pmd.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class SystemPropsRule extends AbstractRule implements Rule {
|
||||
|
||||
private boolean inGetPropsCtx;
|
||||
|
||||
public Object visit(ASTName node, Object data){
|
||||
RuleContext ctx = (RuleContext)data;
|
||||
if (node.getImage() != null && (node.getImage().startsWith("System.getProperty") || node.getImage().startsWith("System.setProperty") || node.getImage().startsWith("System.getProperties"))) {
|
||||
if (node.getImage() != null && node.getImage().startsWith("System.setProperty") || node.getImage().startsWith("System.getProperties")) {
|
||||
RuleContext ctx = (RuleContext)data;
|
||||
ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine()));
|
||||
return super.visit(node,data);
|
||||
}
|
||||
if (node.getImage() != null && (node.getImage().startsWith("System.getProperty"))) {
|
||||
inGetPropsCtx = true;
|
||||
}
|
||||
return super.visit(node,data);
|
||||
}
|
||||
|
||||
public Object visit(ASTLiteral node, Object data) {
|
||||
if (inGetPropsCtx && (node.getImage() != null) && (!node.getImage().startsWith("\"org.cougaar"))) {
|
||||
RuleContext ctx = (RuleContext)data;
|
||||
ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine()));
|
||||
}
|
||||
inGetPropsCtx = false;
|
||||
return super.visit(node,data);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
public class ContainsSystemGetProps {
|
||||
public ContainsSystemGetProps() {
|
||||
System.getProperty("Rule violation");
|
||||
public void foo() {
|
||||
System.getProperty("this.is.not.allowed");
|
||||
System.getProperties();
|
||||
System.setProperty("Another rule violation", "foo");
|
||||
System.setProperty("set.a.system.property", "value");
|
||||
}
|
||||
}
|
||||
|
5
pmd/test-data/ContainsSystemGetProps2.java
Normal file
5
pmd/test-data/ContainsSystemGetProps2.java
Normal file
@ -0,0 +1,5 @@
|
||||
public class ContainsSystemGetProps2 {
|
||||
public void foo() {
|
||||
System.getProperty("org.cougaar.its.ok");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user