Author: dennisl Date: Fri May 29 12:55:17 2015 New Revision: 1682450 URL: http://svn.apache.org/r1682450 Log: [MPMD-205] Javascript violations won't fail the build, closes apache/maven-plugins#46 Submitted by: Andreas Dangel Reviewed by: Dennis Lundberg
Added: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/ (with props) maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/invoker.properties maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/pom.xml maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/src/ (with props) maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/src/main/ (with props) maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/src/main/javascript/ (with props) maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/src/main/javascript/PmdJsCheck.js maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/verify.groovy Modified: 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/PmdReport.java maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-cpd-exclusions-configuration-plugin-config.xml maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failandwarnonpriority-plugin-config.xml maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failonpriority-plugin-config.xml maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-pmd-exclusions-configuration-plugin-config.xml Added: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/invoker.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/invoker.properties?rev=1682450&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/invoker.properties (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/invoker.properties Fri May 29 12:55:17 2015 @@ -0,0 +1,19 @@ +# 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. + +invoker.goals = clean verify +invoker.buildResult = failure Added: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/pom.xml?rev=1682450&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/pom.xml (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/pom.xml Fri May 29 12:55:17 2015 @@ -0,0 +1,82 @@ +<?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-205-pmd-js-check</artifactId> + <version>1.0-SNAPSHOT</version> + + <description> + Verify that check fails the build if language is javascript + </description> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <version>1.9.1</version> + <executions> + <execution> + <id>add-javascript-source</id> + <goals><goal>add-source</goal></goals> + <configuration> + <sources> + <source>src/main/javascript</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-pmd-plugin</artifactId> + <version>@project.version@</version> + <configuration> + <language>javascript</language> + <rulesets> + <ruleset>ecmascript-basic</ruleset> + <ruleset>ecmascript-braces</ruleset> + <ruleset>ecmascript-unnecessary</ruleset> + </rulesets> + <includes> + <include>**/*.js</include> + </includes> + <printFailingErrors>true</printFailingErrors> + </configuration> + <executions> + <execution> + <phase>verify</phase> + <goals> + <goal>check</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> Added: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/src/main/javascript/PmdJsCheck.js URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/src/main/javascript/PmdJsCheck.js?rev=1682450&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/src/main/javascript/PmdJsCheck.js (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/src/main/javascript/PmdJsCheck.js Fri May 29 12:55:17 2015 @@ -0,0 +1,25 @@ +/* +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. +*/ + +(function() { + + var i = 1; // this semicolon should have been a comma + j = 2; // that's why "j" is now a global variable + +})(); \ No newline at end of file Added: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/verify.groovy URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/verify.groovy?rev=1682450&view=auto ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/verify.groovy (added) +++ maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-205-pmd-js-check/verify.groovy Fri May 29 12:55:17 2015 @@ -0,0 +1,23 @@ +/* + * 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() + +assert buildLog.getText().contains("[INFO] PMD Failure: PmdJsCheck.js:23 Rule:GlobalVariable Priority:1 Avoid using global variables."); 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=1682450&r1=1682449&r2=1682450&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 Fri May 29 12:55:17 2015 @@ -106,62 +106,62 @@ public abstract class AbstractPmdViolati return; } - if ( "java".equals( language ) - || "jsp".equals( language ) - || aggregate ) + if ( "pom".equals( project.getPackaging() ) && !aggregate ) { - if ( !StringUtils.isEmpty( excludeFromFailureFile ) ) - { - loadExcludeFromFailuresData( excludeFromFailureFile ); - } - final File outputFile = new File( targetDirectory, filename ); + return; + } - if ( outputFile.exists() ) - { - try - { - final ViolationDetails<D> violations = getViolations( outputFile, failurePriority ); + if ( !StringUtils.isEmpty( excludeFromFailureFile ) ) + { + loadExcludeFromFailuresData( excludeFromFailureFile ); + } + final File outputFile = new File( targetDirectory, filename ); - final List<D> failures = violations.getFailureDetails(); - final List<D> warnings = violations.getWarningDetails(); + if ( outputFile.exists() ) + { + try + { + final ViolationDetails<D> violations = getViolations( outputFile, failurePriority ); - if ( verbose ) - { - printErrors( failures, warnings ); - } + final List<D> failures = violations.getFailureDetails(); + final List<D> warnings = violations.getWarningDetails(); - final int failureCount = failures.size(); - final int warningCount = warnings.size(); + if ( verbose ) + { + printErrors( failures, warnings ); + } - final String message = getMessage( failureCount, warningCount, key, outputFile ); + final int failureCount = failures.size(); + final int warningCount = warnings.size(); - getLog().debug( "PMD failureCount: " + failureCount + ", warningCount: " + warningCount ); + final String message = getMessage( failureCount, warningCount, key, outputFile ); - if ( failureCount > 0 && isFailOnViolation() ) - { - throw new MojoFailureException( message ); - } + getLog().debug( "PMD failureCount: " + failureCount + ", warningCount: " + warningCount ); - this.getLog().info( message ); - } - catch ( final IOException e ) - { - throw new MojoExecutionException( - "Unable to read PMD results xml: " + outputFile.getAbsolutePath(), - e ); - } - catch ( final XmlPullParserException e ) + if ( failureCount > 0 && isFailOnViolation() ) { - throw new MojoExecutionException( - "Unable to read PMD results xml: " + outputFile.getAbsolutePath(), - e ); + throw new MojoFailureException( message ); } + + this.getLog().info( message ); + } + catch ( final IOException e ) + { + throw new MojoExecutionException( + "Unable to read PMD results xml: " + outputFile.getAbsolutePath(), + e ); } - else + catch ( final XmlPullParserException e ) { - throw new MojoFailureException( "Unable to perform check, " + "unable to find " + outputFile ); + throw new MojoExecutionException( + "Unable to read PMD results xml: " + outputFile.getAbsolutePath(), + e ); } } + else + { + throw new MojoFailureException( "Unable to perform check, " + "unable to find " + outputFile ); + } } protected abstract void loadExcludeFromFailuresData( String excludeFromFailureFile ) Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java?rev=1682450&r1=1682449&r2=1682450&view=diff ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java (original) +++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java Fri May 29 12:55:17 2015 @@ -82,16 +82,16 @@ public class PmdReport * The target JDK to analyze based on. Should match the target used in the compiler plugin. Valid values are * currently <code>1.3</code>, <code>1.4</code>, <code>1.5</code>, <code>1.6</code>, <code>1.7</code> and * <code>1.8</code>. + * <p> + * <b>Note:</b> this parameter is only used if the language parameter is set to <code>java</code>. + * </p> */ @Parameter( property = "targetJdk", defaultValue = "${maven.compiler.target}" ) private String targetJdk; /** - * The programming language to be analyzed by PMD. Valid values are currently <code>java</code> and - * <code>ecmascript</code> or <code>javascript</code>. - * <p> - * <b>Note:</b> if the parameter targetJdk is given, then this language parameter will be ignored. - * </p> + * The programming language to be analyzed by PMD. Valid values are currently <code>java</code>, + * <code>javascript</code> and <code>jsp</code>. * * @since 3.0 */ @@ -537,7 +537,7 @@ public class PmdReport PMDConfiguration configuration = new PMDConfiguration(); LanguageVersion languageVersion = null; - if ( null != targetJdk ) + if ( ( "java".equals( language ) || null == language ) && null != targetJdk ) { languageVersion = LanguageRegistry.findLanguageVersionByTerseName( "java " + targetJdk ); if ( languageVersion == null ) Modified: maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-cpd-exclusions-configuration-plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-cpd-exclusions-configuration-plugin-config.xml?rev=1682450&r1=1682449&r2=1682450&view=diff ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-cpd-exclusions-configuration-plugin-config.xml (original) +++ maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-cpd-exclusions-configuration-plugin-config.xml Fri May 29 12:55:17 2015 @@ -35,7 +35,7 @@ under the License. <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <configuration> - <!-- project implementation="org.apache.maven.plugin.pmd.stubs.DefaultConfigurationMavenProjectStub"/--> + <project implementation="org.apache.maven.plugin.pmd.stubs.DefaultConfigurationMavenProjectStub"/> <targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory> <failOnViolation>true</failOnViolation> <verbose>false</verbose> Modified: maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failandwarnonpriority-plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failandwarnonpriority-plugin-config.xml?rev=1682450&r1=1682449&r2=1682450&view=diff ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failandwarnonpriority-plugin-config.xml (original) +++ maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failandwarnonpriority-plugin-config.xml Fri May 29 12:55:17 2015 @@ -33,6 +33,7 @@ under the License. <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <configuration> + <project implementation="org.apache.maven.plugin.pmd.stubs.DefaultConfigurationMavenProjectStub"/> <targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory> <failOnViolation>true</failOnViolation> <failurePriority>3</failurePriority> Modified: maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failonpriority-plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failonpriority-plugin-config.xml?rev=1682450&r1=1682449&r2=1682450&view=diff ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failonpriority-plugin-config.xml (original) +++ maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failonpriority-plugin-config.xml Fri May 29 12:55:17 2015 @@ -33,7 +33,7 @@ under the License. <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <configuration> - <!-- project implementation="org.apache.maven.plugin.pmd.stubs.DefaultConfigurationMavenProjectStub"/--> + <project implementation="org.apache.maven.plugin.pmd.stubs.DefaultConfigurationMavenProjectStub"/> <targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory> <failOnViolation>true</failOnViolation> <failurePriority>1</failurePriority> Modified: maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml?rev=1682450&r1=1682449&r2=1682450&view=diff ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml (original) +++ maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml Fri May 29 12:55:17 2015 @@ -33,7 +33,7 @@ under the License. <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <configuration> - <!-- project implementation="org.apache.maven.plugin.pmd.stubs.DefaultConfigurationMavenProjectStub"/--> + <project implementation="org.apache.maven.plugin.pmd.stubs.DefaultConfigurationMavenProjectStub"/> <targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory> <failOnViolation>false</failOnViolation> <verbose>false</verbose> Modified: maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-pmd-exclusions-configuration-plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-pmd-exclusions-configuration-plugin-config.xml?rev=1682450&r1=1682449&r2=1682450&view=diff ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-pmd-exclusions-configuration-plugin-config.xml (original) +++ maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-pmd-exclusions-configuration-plugin-config.xml Fri May 29 12:55:17 2015 @@ -33,7 +33,7 @@ under the License. <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <configuration> - <!-- project implementation="org.apache.maven.plugin.pmd.stubs.DefaultConfigurationMavenProjectStub"/--> + <project implementation="org.apache.maven.plugin.pmd.stubs.DefaultConfigurationMavenProjectStub"/> <targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory> <failOnViolation>true</failOnViolation> <failurePriority>3</failurePriority>