1 package org.apache.maven.plugin.pmd; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.util.ArrayList; 23 import java.util.HashSet; 24 import java.util.List; 25 26 import net.sourceforge.pmd.Report; 27 import net.sourceforge.pmd.ReportListener; 28 import net.sourceforge.pmd.RuleViolation; 29 import net.sourceforge.pmd.stat.Metric; 30 31 /** 32 * Handle events from PMD and collect violations. 33 */ 34 public class PmdReportListener 35 implements ReportListener 36 { 37 private HashSet<RuleViolation> violations = new HashSet<RuleViolation>(); 38 39 // private List<Metric> metrics = new ArrayList<Metric>(); 40 41 /** 42 * {@inheritDoc} 43 */ 44 public void ruleViolationAdded( RuleViolation ruleViolation ) 45 { 46 violations.add( ruleViolation ); 47 } 48 49 public List<RuleViolation> getViolations() 50 { 51 return new ArrayList<RuleViolation>( violations ); 52 } 53 54 public boolean hasViolations() 55 { 56 return !violations.isEmpty(); 57 } 58 59 /** 60 * Create a new single report with all violations for further rendering into other formats than HTML. 61 */ 62 public Report asReport() 63 { 64 Report report = new Report(); 65 for ( RuleViolation v : violations ) 66 { 67 report.addRuleViolation( v ); 68 } 69 return report; 70 } 71 72 /** 73 * {@inheritDoc} 74 */ 75 public void metricAdded( Metric metric ) 76 { 77 // if ( metric.getCount() != 0 ) 78 // { 79 // // Skip metrics which have no data 80 // metrics.add( metric ); 81 // } 82 } 83 }