Ver Fonte

assira.rules

Ranides Atterwim há 11 anos atrás
pai
commit
a1d955f4d3

+ 3 - 1
.gitignore

@@ -1,2 +1,4 @@
 /assira/target/
-/assira.asm/target/
+/assira.asm/target/
+/assira.rules/target/
+/assira.rules.test/target/

+ 38 - 0
assira.rules.test/pom.xml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	
+	<groupId>net.ranides</groupId>
+	<artifactId>assira.rules.test</artifactId>
+	<version>1.0-SNAPSHOT</version>
+	<packaging>jar</packaging>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<maven.compiler.source>1.7</maven.compiler.source>
+		<maven.compiler.target>1.7</maven.compiler.target>
+	</properties>
+	
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-pmd-plugin</artifactId>
+				<version>3.4</version>
+				<configuration>
+					<rulesets>
+						<ruleset>rulesets/java/ranides.test.xml</ruleset>
+					</rulesets>
+				</configuration>
+				<dependencies>
+					<dependency>
+						<groupId>net.ranides</groupId>
+						<artifactId>assira.rules</artifactId>
+						<version>1.0-SNAPSHOT</version>
+					</dependency>
+				</dependencies>
+			</plugin>
+		</plugins>
+	</build>
+	
+</project>

+ 25 - 0
assira.rules.test/src/main/java/net/ranides/assira/rules/test/ECB.java

@@ -0,0 +1,25 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package net.ranides.assira.rules.test;
+
+/**
+ *
+ * @author msieron
+ */
+public class ECB {
+	
+	public static void main(String[] args) {
+		try {
+			if(true);
+			
+			if(true) { }
+			
+			System.out.println("Hello world");
+		} catch(RuntimeException ex) {
+		}
+	}
+	
+}

+ 20 - 0
assira.rules/pom.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>net.ranides</groupId>
+    <artifactId>assira.rules</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+    <dependencies>
+        <dependency>
+            <groupId>net.sourceforge.pmd</groupId>
+            <artifactId>pmd-java</artifactId>
+            <version>5.3.3</version>
+        </dependency>
+    </dependencies>
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.compiler.source>1.7</maven.compiler.source>
+        <maven.compiler.target>1.7</maven.compiler.target>
+    </properties>
+</project>

+ 44 - 0
assira.rules/src/main/java/net/ranides/assira/rules/ClassSize.java

@@ -0,0 +1,44 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package net.ranides.assira.rules;
+
+import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
+import net.sourceforge.pmd.lang.java.ast.JavaNode;
+import net.sourceforge.pmd.lang.java.rule.AbstractStatisticalJavaRule;
+import net.sourceforge.pmd.lang.java.rule.codesize.ExcessiveClassLengthRule;
+import net.sourceforge.pmd.lang.java.rule.design.ExcessiveLengthRule;
+import static net.sourceforge.pmd.lang.rule.stat.StatisticalRule.MINIMUM_DESCRIPTOR;
+import net.sourceforge.pmd.stat.DataPoint;
+
+/**
+ *
+ * @author msieron
+ */
+public class ClassSize extends AbstractStatisticalJavaRule {
+	
+
+	private final Class<?> nodeClass;
+
+    public ClassSize() {
+		super();
+		this.nodeClass = ASTClassOrInterfaceDeclaration.class;
+		setProperty(MINIMUM_DESCRIPTOR, 1000d);
+    }
+
+    @Override
+    public Object visit(final JavaNode node, final Object data) {
+		if (nodeClass.isInstance(node)) {
+			final DataPoint point = new DataPoint();
+			point.setNode(node);
+			point.setScore(1.0 * (node.getEndLine() - node.getBeginLine()));
+			point.setMessage(getMessage());
+			addDataPoint(point);
+		}
+
+		return node.childrenAccept(this, data);
+    }
+	
+}

+ 30 - 0
assira.rules/src/main/resources/rulesets/java/ranides.test.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<ruleset name="net.ranides.assira.standard"
+    xmlns="http://pmd.sf.net/ruleset/1.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
+    xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
+
+    <description>TEST</description>
+
+    <!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>-->
+	
+	<rule
+		name="TST-EC"
+		ref="rulesets/basic.xml/EmptyCatchBlock"
+		message="TEST: Must handle exceptions">
+		<priority>2</priority>
+	</rule>
+	
+	<!--
+	<rule
+		ref="rulesets/java/basic.xml/EmptyCatchBlock"
+		message="TEST: Must handle exceptions">
+		<priority>2</priority>
+	</rule>
+	
+	<rule ref="rulesets/basic.xml/EmptyIfStmt"/>
+	-->
+
+</ruleset>

+ 8 - 0
assira/pom.xml

@@ -10,6 +10,14 @@
     <artifactId>assira</artifactId>
     <version>2.0.0</version>
     <packaging>jar</packaging>
+	
+	<repositories>
+        <repository>
+            <id>ranides.net</id>
+            <name>ranides.net</name>
+            <url>http://maven.ranides.net</url>
+        </repository>
+    </repositories>
     
     <dependencies>
         <dependency>