Author: olamy Date: Mon Feb 4 20:53:36 2013 New Revision: 1442347 URL: http://svn.apache.org/viewvc?rev=1442347&view=rev Log: format code
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/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/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=1442347&r1=1442346&r2=1442347&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 Mon Feb 4 20:53:36 2013 @@ -75,21 +75,25 @@ public abstract class AbstractPmdViolati */ @Parameter( property = "pmd.verbose", defaultValue = "false" ) private boolean verbose; - - /** + + /** * Print details of errors that cause build failure + * + * @since 3.0 */ - @Parameter( property = "pmd.printFailingErrors", defaultValue = "false" ) + @Parameter(property = "pmd.printFailingErrors", defaultValue = "false") private boolean printFailingErrors; /** * File that lists classes and rules to be excluded from failures * For PMD, this is a properties file * For CPD, this is a text file that contains comma-separated lists of classes that are allowed to duplicate + * + * @since 3.0 */ - @Parameter( property = "pmd.excludeFromFailureFile", defaultValue = "" ) + @Parameter(property = "pmd.excludeFromFailureFile", defaultValue = "") private String excludeFromFailureFile; - + /** * The project to analyze. */ @@ -106,8 +110,9 @@ public abstract class AbstractPmdViolati if ( "java".equals( language ) || aggregate ) { - if (!StringUtils.isEmpty(excludeFromFailureFile)) { - loadExcludeFromFailuresData(excludeFromFailureFile); + if ( !StringUtils.isEmpty( excludeFromFailureFile ) ) + { + loadExcludeFromFailuresData( excludeFromFailureFile ); } final File outputFile = new File( targetDirectory, filename ); @@ -160,13 +165,14 @@ public abstract class AbstractPmdViolati } } - protected abstract void loadExcludeFromFailuresData(String excludeFromFailureFile) throws MojoExecutionException; - + protected abstract void loadExcludeFromFailuresData( String excludeFromFailureFile ) + throws MojoExecutionException; + /** * Method for collecting the violations found by the PMD tool * - * @param xpp the xml parser object - * @param tagName the element that will be checked + * @param analysisFile + * @param failurePriority * @return an int that specifies the number of violations found * @throws XmlPullParserException * @throws IOException @@ -182,11 +188,12 @@ public abstract class AbstractPmdViolati for ( final D violation : violations ) { final int priority = getPriority( violation ); - if ( priority <= failurePriority && !isExcludedFromFailure(violation)) + if ( priority <= failurePriority && !isExcludedFromFailure( violation ) ) { failures.add( violation ); - if (printFailingErrors) { - printError(violation, "Failure"); + if ( printFailingErrors ) + { + printError( violation, "Failure" ); } } else @@ -203,8 +210,8 @@ public abstract class AbstractPmdViolati protected abstract int getPriority( D errorDetail ); - protected abstract boolean isExcludedFromFailure(D errorDetail); - + protected abstract boolean isExcludedFromFailure( D errorDetail ); + protected abstract ViolationDetails<D> newViolationDetailsInstance(); /** @@ -274,7 +281,7 @@ public abstract class AbstractPmdViolati * Gets the attributes and text for the violation tag and puts them in a * HashMap * - * @param xpp + * @param analisysFile * @throws XmlPullParserException * @throws IOException */ 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=1442347&r1=1442346&r2=1442347&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 Mon Feb 4 20:53:36 2013 @@ -59,8 +59,8 @@ public class CpdViolationCheckMojo @Parameter( property = "cpd.skip", defaultValue = "false" ) private boolean skip; - private final List<Set<String>> exclusionList = new ArrayList<Set<String>>(); - + private final List<Set<String>> exclusionList = new ArrayList<Set<String>>(); + /** * Whether to fail the build if the validation check fails. * @@ -118,73 +118,95 @@ public class CpdViolationCheckMojo return details.getDuplications(); } - @Override - protected boolean isExcludedFromFailure(final Duplication errorDetail) { + @Override + protected boolean isExcludedFromFailure( final Duplication errorDetail ) + { final Set<String> uniquePaths = new HashSet<String>(); - for (final CpdFile cpdFile : errorDetail.getFiles()) { - uniquePaths.add(cpdFile.getPath()); + for ( final CpdFile cpdFile : errorDetail.getFiles() ) + { + uniquePaths.add( cpdFile.getPath() ); } - for (final Set<String> singleExclusionGroup : exclusionList) { - if (uniquePaths.size() == singleExclusionGroup.size() && duplicationExcludedByGroup(uniquePaths, singleExclusionGroup)) { + for ( final Set<String> singleExclusionGroup : exclusionList ) + { + if ( uniquePaths.size() == singleExclusionGroup.size() && duplicationExcludedByGroup( uniquePaths, + singleExclusionGroup ) ) + { return true; } } return false; } - - private boolean duplicationExcludedByGroup(final Set<String> uniquePaths, final Set<String> singleExclusionGroup) { - for (final String path : uniquePaths) { - if (!fileExcludedByGroup(path, singleExclusionGroup)) { + + private boolean duplicationExcludedByGroup( final Set<String> uniquePaths, final Set<String> singleExclusionGroup ) + { + for ( final String path : uniquePaths ) + { + if ( !fileExcludedByGroup( path, singleExclusionGroup ) ) + { return false; } } return true; } - private boolean fileExcludedByGroup(final String path, final Set<String> singleExclusionGroup) { - final String formattedPath = path.replace('\\', '.').replace('/', '.'); - for (final String className : singleExclusionGroup) { - if (formattedPath.contains(className)) { + private boolean fileExcludedByGroup( final String path, final Set<String> singleExclusionGroup ) + { + final String formattedPath = path.replace( '\\', '.' ).replace( '/', '.' ); + for ( final String className : singleExclusionGroup ) + { + if ( formattedPath.contains( className ) ) + { return true; } } return false; } - + @Override - protected void loadExcludeFromFailuresData(final String excludeFromFailureFile) throws MojoExecutionException { + protected void loadExcludeFromFailuresData( final String excludeFromFailureFile ) + throws MojoExecutionException + { LineNumberReader reader = null; - try { - reader = new LineNumberReader(new FileReader(excludeFromFailureFile)); + try + { + reader = new LineNumberReader( new FileReader( excludeFromFailureFile ) ); String line = null; - while ((line = reader.readLine()) != null) { - exclusionList.add(createSetFromExclusionLine(line)); + while ( ( line = reader.readLine() ) != null ) + { + exclusionList.add( createSetFromExclusionLine( line ) ); } } - catch (final IOException e) { - throw new MojoExecutionException("Cannot load file " + excludeFromFailureFile, e); + catch ( final IOException e ) + { + throw new MojoExecutionException( "Cannot load file " + excludeFromFailureFile, e ); } - finally { - if (reader != null) { - try { + finally + { + if ( reader != null ) + { + try + { reader.close(); } - catch (final IOException e) { - getLog().warn("Cannot close file " + excludeFromFailureFile, e); + catch ( final IOException e ) + { + getLog().warn( "Cannot close file " + excludeFromFailureFile, e ); } } } - + } - private Set<String> createSetFromExclusionLine(final String line) { + private Set<String> createSetFromExclusionLine( final String line ) + { final Set<String> result = new HashSet<String>(); - for(final String className : line.split(",")) { - result.add(className.trim()); + for ( final String className : line.split( "," ) ) + { + result.add( className.trim() ); } return result; } - + @Override protected int getPriority( Duplication errorDetail ) { 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=1442347&r1=1442346&r2=1442347&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 Mon Feb 4 20:53:36 2013 @@ -71,8 +71,8 @@ public class PmdViolationCheckMojo @Parameter( property = "pmd.skip", defaultValue = "false" ) private boolean skip; - private final Map<String, Set<String>> excludeFromFailureClasses = new HashMap<String, Set<String>>(); - + private final Map<String, Set<String>> excludeFromFailureClasses = new HashMap<String, Set<String>>(); + /** * {@inheritDoc} */ @@ -85,45 +85,55 @@ public class PmdViolationCheckMojo } } - @Override - protected void loadExcludeFromFailuresData(final String excludeFromFailureFile) throws MojoExecutionException { + @Override + protected void loadExcludeFromFailuresData( final String excludeFromFailureFile ) + throws MojoExecutionException + { final Properties props = new Properties(); - try { - props.load(new FileReader(excludeFromFailureFile)); + try + { + props.load( new FileReader( excludeFromFailureFile ) ); } - catch (final IOException e) { - throw new MojoExecutionException("Cannot load properties file " + excludeFromFailureFile, e); + catch ( final IOException e ) + { + throw new MojoExecutionException( "Cannot load properties file " + excludeFromFailureFile, e ); } - for (final Entry<Object, Object> propEntry : props.entrySet()) { + for ( final Entry<Object, Object> propEntry : props.entrySet() ) + { final Set<String> excludedRuleSet = new HashSet<String>(); final String className = propEntry.getKey().toString(); - final String[] excludedRules = propEntry.getValue().toString().split(","); - for (final String excludedRule : excludedRules) { - excludedRuleSet.add(excludedRule.trim()); + final String[] excludedRules = propEntry.getValue().toString().split( "," ); + for ( final String excludedRule : excludedRules ) + { + excludedRuleSet.add( excludedRule.trim() ); } - excludeFromFailureClasses.put(className, excludedRuleSet); + excludeFromFailureClasses.put( className, excludedRuleSet ); } } - + @Override - protected boolean isExcludedFromFailure(final Violation errorDetail) { - final String className = extractClassName(errorDetail); - final Set<String> excludedRuleSet = excludeFromFailureClasses.get(className); - return excludedRuleSet != null && excludedRuleSet.contains(errorDetail.getRule()); - } - - private String extractClassName(final Violation errorDetail) { - //for some reason, some violations don't contain the package name, so we have to guess the full class name - if (errorDetail.getViolationPackage() != null && errorDetail.getViolationClass() != null) { + protected boolean isExcludedFromFailure( final Violation errorDetail ) + { + final String className = extractClassName( errorDetail ); + final Set<String> excludedRuleSet = excludeFromFailureClasses.get( className ); + return excludedRuleSet != null && excludedRuleSet.contains( errorDetail.getRule() ); + } + + private String extractClassName( final Violation errorDetail ) + { + //for some reason, some violations don't contain the package name, so we have to guess the full class name + if ( errorDetail.getViolationPackage() != null && errorDetail.getViolationClass() != null ) + { return errorDetail.getViolationPackage() + "." + errorDetail.getViolationClass(); } - else { + else + { final String fileName = errorDetail.getFileName(); - final int javaIdx = fileName.indexOf("\\java\\"); - return fileName.substring(javaIdx >= 0 ? javaIdx + 6 : 0, fileName.length() - 5).replace('\\', '.'); + final int javaIdx = fileName.indexOf( "\\java\\" ); + return fileName.substring( javaIdx >= 0 ? javaIdx + 6 : 0, fileName.length() - 5 ).replace( '\\', '.' ); } } - + /** * {@inheritDoc} */