Author: rfscholte Date: Wed Jan 18 20:59:15 2012 New Revision: 1233066 URL: http://svn.apache.org/viewvc?rev=1233066&view=rev Log: Fix MPMD-138: Use modello to generate models to read pmd and cpd files
Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/invoker.properties maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/pom.xml maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/config/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/config/pmd/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/config/pmd/latin-1.xml maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/config/pmd/utf-8.xml maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/java/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/java/test/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/java/test/MyClass.java maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/pom.xml maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/rulesets/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/rulesets/basic.xml maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/src/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/src/main/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/src/main/java/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/src/main/java/test/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/src/main/java/test/MyClass.java maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/pom.xml maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/java/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/java/test/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/java/test/MyClass.java maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/java/test/sub/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/java/test/sub/MyClass.java maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/pom.xml maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/MyClass.java maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/OtherClass.java maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/sub/ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/sub/MyClass.java maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/pom.xml maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/verify.groovy maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ViolationDetails.java maven/plugins/trunk/maven-pmd-plugin/src/main/mdo/ maven/plugins/trunk/maven-pmd-plugin/src/main/mdo/cpd.mdo maven/plugins/trunk/maven-pmd-plugin/src/main/mdo/pmd.mdo Modified: maven/plugins/trunk/maven-pmd-plugin/pom.xml maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java Modified: maven/plugins/trunk/maven-pmd-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/pom.xml?rev=1233066&r1=1233065&r2=1233066&view=diff ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/pom.xml (original) +++ maven/plugins/trunk/maven-pmd-plugin/pom.xml Wed Jan 18 20:59:15 2012 @@ -68,6 +68,33 @@ under the License. <sitePluginVersion>3.0</sitePluginVersion> </properties> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.modello</groupId> + <artifactId>modello-maven-plugin</artifactId> + <version>1.4.1</version> + <configuration> + <useJava5>true</useJava5> + <models> + <model>src/main/mdo/pmd.mdo</model> + <model>src/main/mdo/cpd.mdo</model> + </models> + <version>1.0</version> + </configuration> + <executions> + <execution> + <phase>generate-sources</phase> + <goals> + <goal>java</goal> + <goal>xpp3-reader</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + <dependencies> <!-- maven --> <dependency> @@ -124,7 +151,7 @@ under the License. <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> - <version>2.0.5</version> + <version>2.1</version> </dependency> <!-- pmd --> Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/invoker.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/invoker.properties?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/invoker.properties (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/invoker.properties Wed Jan 18 20:59:15 2012 @@ -0,0 +1 @@ +invoker.goals = clean verify \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/pom.xml?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/pom.xml (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/pom.xml Wed Jan 18 20:59:15 2012 @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<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> + + <parent> + <groupId>org.apache.maven.plugin.pmd.its</groupId> + <artifactId>mpmd-138-parent</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>mpmd-138-mod-1</artifactId> + + <name>Module 1</name> + + <properties> + <project.reporting.outputEncoding>ISO-8859-1</project.reporting.outputEncoding> + </properties> + +</project> \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/config/pmd/latin-1.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/config/pmd/latin-1.xml?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/config/pmd/latin-1.xml (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/config/pmd/latin-1.xml Wed Jan 18 20:59:15 2012 @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<ruleset name="Custom ruleset" + 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> + This ruleset is encoded with ISO-8859-1 to check proper encoding handling. + </description> + <rule ref="rulesets/basic.xml/UnnecessaryReturn" message="LATIN-1-CHARS: ÄÖÜäöüß¼½¾¤"/> + <!-- note: ¼½¾¤ = 0xBC 0xBD 0xBE 0xA4 don't exist any more in Latin 15, replaced by OE oe Y" and euro --> +</ruleset> Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/config/pmd/utf-8.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/config/pmd/utf-8.xml?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/config/pmd/utf-8.xml (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/config/pmd/utf-8.xml Wed Jan 18 20:59:15 2012 @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ruleset name="Custom ruleset" + 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> + This ruleset is encoded with UTF-8 to check proper encoding handling. + </description> + <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop" message="UTF-8-CHARS: ÃÃÃäöüü½¾¤"/> +</ruleset> Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/java/test/MyClass.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/java/test/MyClass.java?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/java/test/MyClass.java (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-1/src/main/java/test/MyClass.java Wed Jan 18 20:59:15 2012 @@ -0,0 +1,12 @@ +package test; + +public class MyClass +{ + + public static void main( String[] args ) + { + ; + return; + } + +} Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/pom.xml?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/pom.xml (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/pom.xml Wed Jan 18 20:59:15 2012 @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<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> + + <parent> + <groupId>org.apache.maven.plugin.pmd.its</groupId> + <artifactId>mpmd-138-parent</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>mpmd-138-mod-2</artifactId> + + <name>Module 2</name> + +</project> \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/rulesets/basic.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/rulesets/basic.xml?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/rulesets/basic.xml (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/rulesets/basic.xml Wed Jan 18 20:59:15 2012 @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ruleset name="Custom ruleset" + 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> + The relative path of this ruleset matches the built-in ruleset "basic". + </description> + <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop" message="TEST: LOCAL-FILE-RULESET"/> +</ruleset> Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/src/main/java/test/MyClass.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/src/main/java/test/MyClass.java?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/src/main/java/test/MyClass.java (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-2/src/main/java/test/MyClass.java Wed Jan 18 20:59:15 2012 @@ -0,0 +1,12 @@ +package test; + +public class MyClass +{ + + public static void main( String[] args ) + { + ; + return; + } + +} Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/pom.xml?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/pom.xml (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/pom.xml Wed Jan 18 20:59:15 2012 @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<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> + + <parent> + <groupId>org.apache.maven.plugin.pmd.its</groupId> + <artifactId>mpmd-138-parent</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>mpmd-138-mod-3</artifactId> + + <name>Module 3</name> + + <description>Test 3 classes with copy-paste block</description> + +</project> \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/java/test/MyClass.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/java/test/MyClass.java?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/java/test/MyClass.java (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/java/test/MyClass.java Wed Jan 18 20:59:15 2012 @@ -0,0 +1,39 @@ +package test; + +public class MyClass +{ + + + /** + * + * @param args + */ + public static void main( String[] args ) + { + int nullArgs = 0; + int emptyArgs = 0; + int notEmptyArgs = 0; + for ( int i = 0; i < args.length; i++ ) + { + if( args[i] == null ) + { + nullArgs++; + System.out.println( "arg[" + i + "] is null, weird" ); + } + else if( args[i] == "" ) + { + emptyArgs++; + System.out.println( "arg[" + i + "] is empty" ); + } + else + { + notEmptyArgs++; + System.out.println( "arg[" + i + "] is not empty" ); + } + System.out.print( "Number of null args: " + nullArgs ); + System.out.print( "Number of empty args: " + emptyArgs ); + System.out.print( "Number of not empty args: " + notEmptyArgs ); + } + } + +} Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/java/test/sub/MyClass.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/java/test/sub/MyClass.java?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/java/test/sub/MyClass.java (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-3/src/main/java/test/sub/MyClass.java Wed Jan 18 20:59:15 2012 @@ -0,0 +1,40 @@ +package test.sub; + +public class MyClass +{ + + + + + /** + * + * @param args + */ + public static void main( String[] args ) + { + int nullArgs = 0; + int emptyArgs = 0; + int notEmptyArgs = 0; + for ( int i = 0; i < args.length; i++ ) + { + if( args[i] == null ) + { + nullArgs++; + System.out.println( "arg[" + i + "] is null, weird" ); + } + else if( args[i] == "" ) + { + emptyArgs++; + System.out.println( "arg[" + i + "] is empty" ); + } + else + { + notEmptyArgs++; + System.out.println( "arg[" + i + "] is not empty" ); + } + System.out.print( "Number of null args: " + nullArgs ); + System.out.print( "Number of empty args: " + emptyArgs ); + System.out.print( "Number of not empty args: " + notEmptyArgs ); + } + } +} \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/pom.xml?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/pom.xml (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/pom.xml Wed Jan 18 20:59:15 2012 @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<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> + + <parent> + <groupId>org.apache.maven.plugin.pmd.its</groupId> + <artifactId>mpmd-138-parent</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>mpmd-138-mod-4</artifactId> + + <name>Module 4</name> + + <description>Test 3 classes with copy-paste block</description> + +</project> \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/MyClass.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/MyClass.java?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/MyClass.java (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/MyClass.java Wed Jan 18 20:59:15 2012 @@ -0,0 +1,37 @@ +package test; + +public class MyClass +{ + + /** + * + * @param args + */ + public static void main( String[] args ) + { + int nullArgs = 0; + int emptyArgs = 0; + int notEmptyArgs = 0; + for ( int i = 0; i < args.length; i++ ) + { + if( args[i] == null ) + { + nullArgs++; + System.out.println( "arg[" + i + "] is null, weird" ); + } + else if( args[i] == "" ) + { + emptyArgs++; + System.out.println( "arg[" + i + "] is empty" ); + } + else + { + notEmptyArgs++; + System.out.println( "arg[" + i + "] is not empty" ); + } + System.out.print( "Number of null args: " + nullArgs ); + System.out.print( "Number of empty args: " + emptyArgs ); + System.out.print( "Number of not empty args: " + notEmptyArgs ); + } + } +} \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/OtherClass.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/OtherClass.java?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/OtherClass.java (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/OtherClass.java Wed Jan 18 20:59:15 2012 @@ -0,0 +1,40 @@ +package test; + +public class OtherClass +{ + + + + + /** + * + * @param args + */ + public static void main( String[] args ) + { + int nullArgs = 0; + int emptyArgs = 0; + int notEmptyArgs = 0; + for ( int i = 0; i < args.length; i++ ) + { + if( args[i] == null ) + { + nullArgs++; + System.out.println( "arg[" + i + "] is null, weird" ); + } + else if( args[i] == "" ) + { + emptyArgs++; + System.out.println( "arg[" + i + "] is empty" ); + } + else + { + notEmptyArgs++; + System.out.println( "arg[" + i + "] is not empty" ); + } + System.out.print( "Number of null args: " + nullArgs ); + System.out.print( "Number of empty args: " + emptyArgs ); + System.out.print( "Number of not empty args: " + notEmptyArgs ); + } + } +} \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/sub/MyClass.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/sub/MyClass.java?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/sub/MyClass.java (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/mod-4/src/main/java/test/sub/MyClass.java Wed Jan 18 20:59:15 2012 @@ -0,0 +1,36 @@ +package test.sub; + +public class MyClass +{ + /** + * + * @param args + */ + public static void main( String[] args ) + { + int nullArgs = 0; + int emptyArgs = 0; + int notEmptyArgs = 0; + for ( int i = 0; i < args.length; i++ ) + { + if( args[i] == null ) + { + nullArgs++; + System.out.println( "arg[" + i + "] is null, weird" ); + } + else if( args[i] == "" ) + { + emptyArgs++; + System.out.println( "arg[" + i + "] is empty" ); + } + else + { + notEmptyArgs++; + System.out.println( "arg[" + i + "] is not empty" ); + } + System.out.print( "Number of null args: " + nullArgs ); + System.out.print( "Number of empty args: " + emptyArgs ); + System.out.print( "Number of not empty args: " + notEmptyArgs ); + } + } +} \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/pom.xml?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/pom.xml (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/pom.xml Wed Jan 18 20:59:15 2012 @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<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>org.apache.maven.plugin.pmd.its</groupId> + <artifactId>mpmd-138-parent</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <name>Parent</name> + <description> + Test proper report generation in a multi-module build. + </description> + + <modules> + <module>mod-1</module> + <module>mod-2</module> + <module>mod-3</module> + <module>mod-4</module> + </modules> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <build> + <plugins> + <plugin> + <artifactId>maven-pmd-plugin</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <goals> + <goal>check</goal> + <goal>cpd-check</goal> + </goals> + </execution> + </executions> + <configuration> + <verbose>true</verbose> + <minimumTokens>25</minimumTokens> + <failOnViolation>false</failOnViolation> <!-- force execution of both goals, will be checked with verify-script --> + </configuration> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/verify.groovy URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/verify.groovy?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/verify.groovy (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-138/verify.groovy Wed Jan 18 20:59:15 2012 @@ -0,0 +1,37 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.exists() + +// Module 1 +assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:8 Rule:EmptyStatementNotInLoop Priority:3 An empty statement (semicolon) not part of a loop.') +assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:9 Rule:UnnecessaryReturn Priority:3 Avoid unnecessary return statements.') +assert 1 == buildLog.getText().count('[INFO] You have 2 PMD violations. For more details see:') + +// Module 2 +assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:8 Rule:EmptyStatementNotInLoop Priority:3 TEST: LOCAL-FILE-RULESET.') +assert 1 == buildLog.getText().count('[INFO] You have 1 PMD violation. For more details see:') + +// Module 3 +assert 1 == buildLog.getText().count('[INFO] You have 1 CPD duplication. For more details see:') + +// Module 4 +assert 1 == buildLog.getText().count('[INFO] You have 2 CPD duplications. For more details see:') \ No newline at end of file Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java?rev=1233066&r1=1233065&r2=1233066&view=diff ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java (original) +++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java Wed Jan 18 20:59:15 2012 @@ -23,19 +23,13 @@ import java.io.File; import java.io.IOException; import java.io.Reader; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.ReaderFactory; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.xml.pull.MXParser; -import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** @@ -44,13 +38,9 @@ import org.codehaus.plexus.util.xml.pull * @author <a href="mailto:br...@apache.org">Brett Porter</a> * @version $Id$ */ -public abstract class AbstractPmdViolationCheckMojo +public abstract class AbstractPmdViolationCheckMojo<D> extends AbstractMojo { - private static final Boolean FAILURES_KEY = Boolean.TRUE; - - private static final Boolean WARNINGS_KEY = Boolean.FALSE; - /** * The location of the XML report to check, as generated by the PMD report. * @@ -117,14 +107,10 @@ public abstract class AbstractPmdViolati Reader reader = null; try { - XmlPullParser xpp = new MXParser(); - reader = ReaderFactory.newXmlReader( outputFile ); - xpp.setInput( reader ); - - Map<Boolean, List<Map<String, String>>> violations = getViolations( xpp, tagName, failurePriority ); + ViolationDetails<D> violations = getViolations( outputFile, failurePriority ); - List<Map<String, String>> failures = violations.get( FAILURES_KEY ); - List<Map<String, String>> warnings = violations.get( WARNINGS_KEY ); + List<D> failures = violations.getFailureDetails(); + List<D> warnings = violations.getWarningDetails(); if ( verbose ) { @@ -178,86 +164,36 @@ public abstract class AbstractPmdViolati * @throws XmlPullParserException * @throws IOException */ - private Map<Boolean, List<Map<String, String>>> getViolations( XmlPullParser xpp, String tagName, int failurePriority ) + private ViolationDetails<D> getViolations( File analysisFile, int failurePriority ) throws XmlPullParserException, IOException { - int eventType = xpp.getEventType(); - - List<Map<String, String>> failures = new ArrayList<Map<String, String>>(); - List<Map<String, String>> warnings = new ArrayList<Map<String, String>>(); - - String fullpath = null; + List<D> failures = new ArrayList<D>(); + List<D> warnings = new ArrayList<D>(); - while ( eventType != XmlPullParser.END_DOCUMENT ) + List<D> violations = getErrorDetails( analysisFile ); + + for( D violation : violations ) { - if ( eventType == XmlPullParser.START_TAG && "file".equals( xpp.getName() ) ) + int priority = getPriority( violation ); + if ( priority <= failurePriority ) { - fullpath = xpp.getAttributeValue( "", "name" ); + failures.add( violation ); } - if ( eventType == XmlPullParser.START_TAG && tagName.equals( xpp.getName() ) ) - { - Map<String, String> details = getErrorDetails( xpp ); - - if ( fullpath != null ) - { - details.put( "filename", getFilename( fullpath, details.get( "package" ) ) ); - } - - try - { - int priority = Integer.parseInt( details.get( "priority" ) ); - if ( priority <= failurePriority ) - { - failures.add( details ); - } - else - { - warnings.add( details ); - } - } - catch ( NumberFormatException e ) - { - // I don't know what priority this is. Treat it like a - // failure - failures.add( details ); - } - catch ( NullPointerException e ) - { - // I don't know what priority this is. Treat it like a - // failure - failures.add( details ); - } - - } - - eventType = xpp.next(); - } - - Map<Boolean, List<Map<String, String>>> map = new HashMap<Boolean, List<Map<String, String>>>( 2 ); - map.put( FAILURES_KEY, failures ); - map.put( WARNINGS_KEY, warnings ); - return map; - } - - private String getFilename( String fullpath, String pkg ) - { - int index = fullpath.lastIndexOf( File.separatorChar ); - - while ( StringUtils.isNotEmpty( pkg ) ) - { - index = fullpath.substring( 0, index ).lastIndexOf( File.separatorChar ); - - int dot = pkg.indexOf( '.' ); - - if ( dot < 0 ) + else { - break; + warnings.add( violation ); } - pkg = pkg.substring( dot + 1 ); } - - return fullpath.substring( index + 1 ); + + ViolationDetails<D> details = newViolationDetailsInstance(); + details.setFailureDetails( failures ); + details.setWarningDetails( warnings ); + return details; } + + protected abstract int getPriority( D errorDetail ); + + protected abstract ViolationDetails<D> newViolationDetailsInstance(); /** * Prints the warnings and failures @@ -267,14 +203,14 @@ public abstract class AbstractPmdViolati * @param warnings * list of warnings */ - protected void printErrors( List<Map<String, String>> failures, List<Map<String, String>> warnings ) + protected void printErrors( List<D> failures, List<D> warnings ) { - for ( Map<String, String> warning : warnings ) + for ( D warning : warnings ) { printError( warning, "Warning" ); } - for ( Map<String, String> failure : failures ) + for ( D failure : failures ) { printError( failure, "Failure" ); } @@ -322,7 +258,7 @@ public abstract class AbstractPmdViolati * * @param item */ - protected abstract void printError( Map<String, String> item, String severity ); + protected abstract void printError( D item, String severity ); /** * Gets the attributes and text for the violation tag and puts them in a @@ -332,6 +268,6 @@ public abstract class AbstractPmdViolati * @throws XmlPullParserException * @throws IOException */ - protected abstract Map<String, String> getErrorDetails( XmlPullParser xpp ) + protected abstract List<D> getErrorDetails( File analisysFile ) throws XmlPullParserException, IOException; } \ No newline at end of file Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java?rev=1233066&r1=1233065&r2=1233066&view=diff ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java (original) +++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java Wed Jan 18 20:59:15 2012 @@ -19,13 +19,17 @@ package org.apache.maven.plugin.pmd; * under the License. */ +import java.io.File; +import java.io.FileReader; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; +import java.util.List; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.codehaus.plexus.util.xml.pull.XmlPullParser; +import org.apache.maven.plugin.pmd.model.CpdErrorDetail; +import org.apache.maven.plugin.pmd.model.CpdFile; +import org.apache.maven.plugin.pmd.model.Duplication; +import org.apache.maven.plugin.pmd.model.io.xpp3.CpdXpp3Reader; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** @@ -39,7 +43,7 @@ import org.codehaus.plexus.util.xml.pull * @threadSafe */ public class CpdViolationCheckMojo - extends AbstractPmdViolationCheckMojo + extends AbstractPmdViolationCheckMojo<Duplication> { /** @@ -61,9 +65,9 @@ public class CpdViolationCheckMojo } /** {@inheritDoc} */ - protected void printError( Map item, String severity ) + protected void printError( Duplication item, String severity ) { - String lines = (String) item.get( "lines" ); + int lines = item.getLines(); StringBuffer buff = new StringBuffer( 100 ); @@ -71,68 +75,38 @@ public class CpdViolationCheckMojo buff.append( lines ).append( " lines of duplicated code at locations:" ); this.getLog().info( buff.toString() ); - buff.setLength( 0 ); - buff.append( " " ); - Map file = (Map) item.get( "file" ); - buff.append( file.get( "path" ) ); - buff.append( " line " ).append( file.get( "line" ) ); - this.getLog().info( buff.toString() ); - - buff.setLength( 0 ); - buff.append( " " ); - file = (Map) item.get( "file1" ); - buff.append( file.get( "path" ) ); - buff.append( " line " ).append( file.get( "line" ) ); - this.getLog().info( buff.toString() ); + + for( CpdFile file : item.getFiles() ) + { + buff.setLength( 0 ); + buff.append( " " ); + buff.append( file.getPath() ); + buff.append( " line " ).append( file.getLine() ); + this.getLog().info( buff.toString() ); + } - Map codefrag = (Map) item.get( "codefragment" ); - String codefragstr = (String) codefrag.get( "text" ); this.getLog().debug( "CPD " + severity + ": Code Fragment " ); - this.getLog().debug( codefragstr ); + this.getLog().debug( item.getCodefragment() ); } /** {@inheritDoc} */ - protected Map getErrorDetails( XmlPullParser xpp ) + protected List<Duplication> getErrorDetails( File cpdFile ) throws XmlPullParserException, IOException { - int index = 0; - int attributeCount = 0; - HashMap msgs = new HashMap(); - - attributeCount = xpp.getAttributeCount(); - while ( index < attributeCount ) - { - msgs.put( xpp.getAttributeName( index ), xpp.getAttributeValue( index ) ); - - index++; - } - - int tp = xpp.next(); - while ( tp != XmlPullParser.END_TAG ) - { - // get the tag's text - switch ( tp ) - { - case XmlPullParser.TEXT: - msgs.put( "text", xpp.getText().trim() ); - break; - case XmlPullParser.START_TAG: - String nm = xpp.getName(); - if ( msgs.containsKey( nm ) ) - { - int cnt = 1; - while ( msgs.containsKey( nm + cnt ) ) - { - ++cnt; - } - nm = nm + cnt; - } - msgs.put( nm, getErrorDetails( xpp ) ); - break; - default: - } - tp = xpp.next(); - } - return msgs; + CpdXpp3Reader reader = new CpdXpp3Reader(); + CpdErrorDetail details = reader.read( new FileReader( cpdFile ), false ); + return details.getDuplications(); + } + + @Override + protected int getPriority( Duplication errorDetail ) + { + return 0; + } + + @Override + protected ViolationDetails<Duplication> newViolationDetailsInstance() + { + return new ViolationDetails<Duplication>(); } -} +} \ No newline at end of file Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java?rev=1233066&r1=1233065&r2=1233066&view=diff ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java (original) +++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java Wed Jan 18 20:59:15 2012 @@ -19,12 +19,19 @@ package org.apache.maven.plugin.pmd; * under the License. */ +import java.io.File; +import java.io.FileReader; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.pmd.model.PmdErrorDetail; +import org.apache.maven.plugin.pmd.model.PmdFile; +import org.apache.maven.plugin.pmd.model.Violation; +import org.apache.maven.plugin.pmd.model.io.xpp3.PmdXpp3Reader; +import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -39,7 +46,7 @@ import org.codehaus.plexus.util.xml.pull * @threadSafe */ public class PmdViolationCheckMojo - extends AbstractPmdViolationCheckMojo + extends AbstractPmdViolationCheckMojo<Violation> { /** * What priority level to fail the build on. Failures at or above this level @@ -71,55 +78,83 @@ public class PmdViolationCheckMojo } /** {@inheritDoc} */ - protected void printError( Map<String, String> item, String severity ) + protected void printError( Violation item, String severity ) { StringBuffer buff = new StringBuffer( 100 ); buff.append( "PMD " + severity + ": " ); - if ( item.containsKey( "class" ) ) + if ( item.getViolationClass() != null ) { - if ( item.containsKey( "package" ) ) + if ( item.getViolationPackage() != null ) { - buff.append( item.get( "package" ) ); + buff.append( item.getViolationPackage() ); buff.append( "." ); } - buff.append( item.get( "class" ) ); + buff.append( item.getViolationClass() ); } else { - buff.append( item.get( "filename" ) ); + buff.append( item.getFileName() ); } buff.append( ":" ); - buff.append( item.get( "beginline" ) ); - buff.append( " Rule:" ).append( item.get( "rule" ) ); - buff.append( " Priority:" ).append( item.get( "priority" ) ); - buff.append( " " ).append( item.get( "text" ) ).append( "." ); + buff.append( item.getBeginline() ); + buff.append( " Rule:" ).append( item.getRule() ); + buff.append( " Priority:" ).append( item.getPriority() ); + buff.append( " " ).append( item.getText() ).append( "." ); this.getLog().info( buff.toString() ); } - - /** {@inheritDoc} */ - protected Map<String, String> getErrorDetails( XmlPullParser xpp ) + + @Override + protected List<Violation> getErrorDetails( File pmdFile ) throws XmlPullParserException, IOException { - int index = 0; - int attributeCount = 0; - Map<String, String> msgs = new HashMap<String, String>(); + PmdXpp3Reader reader = new PmdXpp3Reader(); + PmdErrorDetail details = reader.read( new FileReader( pmdFile ), false ); - attributeCount = xpp.getAttributeCount(); - while ( index < attributeCount ) + List<Violation> violations = new ArrayList<Violation>(); + for( PmdFile file : details.getFiles() ) { - - msgs.put( xpp.getAttributeName( index ), xpp.getAttributeValue( index ) ); - - index++; + String fullPath = file.getName(); + + for ( Violation violation : file.getViolations() ) + { + violation.setFileName( getFilename( fullPath, violation.getViolationPackage() ) ); + violations.add( violation ); + } } + return violations; + } + + @Override + protected int getPriority( Violation errorDetail ) + { + return errorDetail.getPriority(); + } + + @Override + protected ViolationDetails<Violation> newViolationDetailsInstance() + { + return new ViolationDetails<Violation>(); + } + + private String getFilename( String fullpath, String pkg ) + { + int index = fullpath.lastIndexOf( File.separatorChar ); - // get the tag's text - if ( xpp.next() == XmlPullParser.TEXT ) + while ( StringUtils.isNotEmpty( pkg ) ) { - msgs.put( "text", xpp.getText().trim() ); + index = fullpath.substring( 0, index ).lastIndexOf( File.separatorChar ); + + int dot = pkg.indexOf( '.' ); + + if ( dot < 0 ) + { + break; + } + pkg = pkg.substring( dot + 1 ); } - return msgs; + + return fullpath.substring( index + 1 ); } } \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ViolationDetails.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ViolationDetails.java?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ViolationDetails.java (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ViolationDetails.java Wed Jan 18 20:59:15 2012 @@ -0,0 +1,69 @@ +package org.apache.maven.plugin.pmd; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.ArrayList; +import java.util.List; + +/** + * Collector of warnings and failures. + * + * @author Robert Scholte + * @param <D> + * @since 2.7 + */ +public class ViolationDetails<D> +{ + private List<D> warningDetails = new ArrayList<D>(); + + private List<D> failureDetails = new ArrayList<D>(); + + /** + * @return the warningDetails, never {@code null} + */ + public List<D> getWarningDetails() + { + return warningDetails; + } + + /** + * @param warningDetails the warningDetails to set + */ + public void setWarningDetails( List<D> warningDetails ) + { + this.warningDetails = warningDetails; + } + + /** + * @return the failureDetails, never {@code null} + */ + public List<D> getFailureDetails() + { + return failureDetails; + } + + /** + * @param failureDetails the failureDetails to set + */ + public void setFailureDetails( List<D> failureDetails ) + { + this.failureDetails = failureDetails; + } +} \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/main/mdo/cpd.mdo URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/mdo/cpd.mdo?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/main/mdo/cpd.mdo (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/main/mdo/cpd.mdo Wed Jan 18 20:59:15 2012 @@ -0,0 +1,70 @@ +<model xmlns="http://modello.codehaus.org/MODELLO/1.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://modello.codehaus.org/MODELLO/1.4.0 http://modello.codehaus.org/xsd/modello-1.4.0.xsd"> + + <!-- Source: http://www.jcoderz.org/fawkez/browser/trunk/src/xml/schema/cpd.xsd --> + + <name>Cpd</name> + + <defaults> + <default> + <key>package</key> + <value>org.apache.maven.plugin.pmd.model</value> + </default> + </defaults> + <versionDefinition> + <type>namespace</type> + <value>1.0+</value> + </versionDefinition> + + <classes> + <class xml.tagName="pmd-cpd" rootElement="true"> + <name>CpdErrorDetail</name> + <fields> + <field> + <name>duplications</name> + <association xml.tagName="duplication" xml.itemsStyle="flat"> + <type>Duplication</type> + <multiplicity>*</multiplicity> + </association> + </field> + </fields> + </class> + <class> + <name>Duplication</name> + <fields> + <field xml.attribute="true"> + <name>lines</name> + <type>int</type> + </field> + <field xml.attribute="true"> + <name>tokens</name> + <type>int</type> + </field> + <field xml.tagName="file"> + <name>files</name> + <association xml.tagName="file" xml.itemsStyle="flat"> + <type>CpdFile</type> + <multiplicity>*</multiplicity> + </association> + </field> + <field> + <name>codefragment</name> + <type>String</type> + </field> + </fields> + </class> + <class xml.tagName="file"> + <name>CpdFile</name> + <fields> + <field xml.attribute="true"> + <name>line</name> + <type>int</type> + </field> + <field xml.attribute="true"> + <name>path</name> + <type>String</type> + </field> + </fields> + </class> + </classes> +</model> \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/main/mdo/pmd.mdo URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/mdo/pmd.mdo?rev=1233066&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/main/mdo/pmd.mdo (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/main/mdo/pmd.mdo Wed Jan 18 20:59:15 2012 @@ -0,0 +1,109 @@ +<model xmlns="http://modello.codehaus.org/MODELLO/1.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://modello.codehaus.org/MODELLO/1.4.0 http://modello.codehaus.org/xsd/modello-1.4.0.xsd"> + + <!-- Source: http://www.jcoderz.org/fawkez/browser/trunk/src/xml/schema/pmd.xsd --> + + <name>Pmd</name> + + <defaults> + <default> + <key>package</key> + <value>org.apache.maven.plugin.pmd.model</value> + </default> + </defaults> + <versionDefinition> + <type>namespace</type> + <value>1.0+</value> + </versionDefinition> + + <classes> + <class rootElement="true" xml.tagName="pmd"> + <name>PmdErrorDetail</name> + <fields> + <field> + <name>files</name> + <association xml.tagName="file" xml.itemsStyle="flat"> + <type>PmdFile</type> + <multiplicity>*</multiplicity> + </association> + </field> + <!-- + <field> + <name>errors</name> + <association xml.tagName="error" xml.itemsStyle="flat"> + <type>PmdError</type> + <multiplicity>*</multiplicity> + </association> + </field> + --> + </fields> + </class> + <class> + <name>PmdFile</name> + <fields> + <field xml.attribute="true"> + <name>name</name> + <type>String</type> + </field> + <field> + <name>violations</name> + <association xml.tagName="violation" xml.itemsStyle="flat"> + <type>Violation</type> + <multiplicity>*</multiplicity> + </association> + </field> + </fields> + </class> + <class> + <name>Violation</name> + <fields> + <field xml.attribute="true"> + <name>beginline</name> + <type>int</type> + </field> + <field xml.tagName="class" xml.attribute="true"> + <name>violationClass</name> + <type>String</type> + </field> + <field xml.tagName="package" xml.attribute="true"> + <name>violationPackage</name> + <type>String</type> + </field> + <field xml.attribute="true"> + <name>rule</name> + <type>String</type> + </field> + <field xml.attribute="true"> + <name>priority</name> + <type>int</type> + </field> + <field xml.content="true"> + <name>text</name> + <type>String</type> + </field> + </fields> + <codeSegments> + <codeSegment> + <code> + <![CDATA[ + private String fileName; + + public void setFileName( String fileName ) + { + this.fileName = fileName; + } + + public String getFileName() + { + return fileName; + } + ]]> + </code> + </codeSegment> + </codeSegments> + </class> + </classes> + + + +</model> \ No newline at end of file