+++ /dev/null
--Djava.awt.headless=true
\ No newline at end of file
+++ /dev/null
-# These tests fail in Eclipse. Until they are fixed, let's ignore them
-
-.*PmdExecutorTest
+++ /dev/null
-<?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>
- <parent>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar</artifactId>
- <version>3.4-SNAPSHOT</version>
- <relativePath>../..</relativePath>
- </parent>
- <groupId>org.codehaus.sonar.plugins</groupId>
- <artifactId>sonar-pmd-plugin</artifactId>
- <packaging>sonar-plugin</packaging>
- <name>Sonar :: Plugins :: PMD</name>
- <description>PMD is a tool that looks for potential problems like possible bugs, dead code, suboptimal code, overcomplicated expressions or duplicate code.</description>
-
- <properties>
- <pmd.version>4.3</pmd.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-java-api</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-plugin-api</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>pmd</groupId>
- <artifactId>pmd</artifactId>
- <version>${pmd.version}</version>
- <exclusions>
- <exclusion>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </exclusion>
- <exclusion>
- <!-- optimization for JAR size -->
- <groupId>ant</groupId>
- <artifactId>ant</artifactId>
- </exclusion>
- <exclusion>
- <groupId>xom</groupId>
- <artifactId>xom</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <!-- TODO http://jira.codehaus.org/browse/SONAR-2011
- We need following dependency, otherwise we will receive
- java.lang.NoClassDefFoundError: org/apache/maven/project/MavenProject
- during call mock(org.sonar.api.resources.Project.class)
- -->
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-project</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-testing-harness</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.codehaus.sonar.plugins</groupId>
- <artifactId>sonar-l10n-en-plugin</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <resources>
- <resource>
- <directory>src/main/resources</directory>
- <filtering>true</filtering>
- </resource>
- </resources>
-
- <testResources>
- <testResource>
- <directory>${basedir}/src/main/resources</directory>
- </testResource>
- <testResource>
- <directory>${basedir}/src/test/resources</directory>
- </testResource>
- </testResources>
-
- <plugins>
- <plugin>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-packaging-maven-plugin</artifactId>
- <configuration>
- <pluginKey>pmd</pluginKey>
- <pluginName>PMD</pluginName>
- <pluginDescription><![CDATA[Analyze Java code with <a href="http://pmd.sourceforge.net/">PMD</a> ${pmd.version}.]]></pluginDescription>
- <pluginClass>org.sonar.plugins.pmd.PmdPlugin</pluginClass>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <executions>
- <execution>
- <id>enforce-plugin-size</id>
- <goals>
- <goal>enforce</goal>
- </goals>
- <phase>verify</phase>
- <configuration>
- <rules>
- <requireFilesSize>
- <maxsize>1600000</maxsize>
- <minsize>1400000</minsize>
- <files>
- <file>${project.build.directory}/${project.build.finalName}.jar</file>
- </files>
- </requireFilesSize>
- </rules>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.renderers.Renderer;
-import net.sourceforge.pmd.renderers.XMLRenderer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.BatchExtension;
-import org.sonar.api.Property;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.ProjectFileSystem;
-import org.sonar.api.utils.SonarException;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.StringWriter;
-
-@org.sonar.api.Properties({
- @Property(
- key = PmdConfiguration.PROPERTY_GENERATE_XML,
- defaultValue = "false",
- name = "Generate XML Report",
- project = false,
- global = false
- )
-})
-public class PmdConfiguration implements BatchExtension {
- private static final Logger LOG = LoggerFactory.getLogger(PmdConfiguration.class);
-
- public static final String PROPERTY_GENERATE_XML = "sonar.pmd.generateXml";
- public static final String PMD_RESULT_XML = "pmd-result.xml";
-
- private final ProjectFileSystem projectFileSystem;
- private final Settings settings;
-
- public PmdConfiguration(ProjectFileSystem projectFileSystem, Settings settings) {
- this.projectFileSystem = projectFileSystem;
- this.settings = settings;
- }
-
- public File getTargetXMLReport() {
- if (settings.getBoolean(PROPERTY_GENERATE_XML)) {
- return projectFileSystem.resolvePath(PMD_RESULT_XML);
- }
- return null;
- }
-
- public File dumpXmlRuleSet(String repositoryKey, String rulesXml) {
- try {
- File configurationFile = projectFileSystem.writeToWorkingDirectory(rulesXml, repositoryKey + ".xml");
-
- LOG.info("PMD configuration: " + configurationFile.getAbsolutePath());
-
- return configurationFile;
- } catch (IOException e) {
- throw new SonarException("Fail to save the PMD configuration", e);
- }
- }
-
- public File dumpXmlReport(Report report) {
- if (!settings.getBoolean(PROPERTY_GENERATE_XML)) {
- return null;
- }
-
- try {
- String reportAsString = reportToString(report);
-
- File reportFile = projectFileSystem.writeToWorkingDirectory(reportAsString, PMD_RESULT_XML);
-
- LOG.info("PMD output report: " + reportFile.getAbsolutePath());
-
- return reportFile;
- } catch (IOException e) {
- throw new SonarException("Fail to save the PMD report", e);
- }
- }
-
- private static String reportToString(Report report) throws IOException {
- StringWriter output = new StringWriter();
-
- Renderer xmlRenderer = new XMLRenderer();
- xmlRenderer.setWriter(output);
- xmlRenderer.start();
- xmlRenderer.renderFileReport(report);
- xmlRenderer.end();
-
- return output.toString();
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import org.sonar.api.CoreProperties;
-
-public final class PmdConstants {
- public static final String REPOSITORY_KEY = CoreProperties.PMD_PLUGIN;
- public static final String REPOSITORY_NAME = "PMD";
- public static final String TEST_REPOSITORY_KEY = "pmd-unit-tests";
- public static final String TEST_REPOSITORY_NAME = "PMD Unit Tests";
- public static final String PLUGIN_NAME = "PMD";
- public static final String PLUGIN_KEY = CoreProperties.PMD_PLUGIN;
- public static final String XPATH_CLASS = "net.sourceforge.pmd.rules.XPathRule";
- public static final String XPATH_EXPRESSION_PARAM = "xpath";
- public static final String XPATH_MESSAGE_PARAM = "message";
-
- private PmdConstants() {
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.io.Closeables;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.RuleContext;
-import net.sourceforge.pmd.RuleSet;
-import net.sourceforge.pmd.RuleSetFactory;
-import net.sourceforge.pmd.RuleSets;
-import org.sonar.api.BatchExtension;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.InputFile;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.ProjectFileSystem;
-import org.sonar.api.utils.TimeProfiler;
-import org.sonar.java.api.JavaUtils;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-import java.util.List;
-
-public class PmdExecutor implements BatchExtension {
- private final Project project;
- private final ProjectFileSystem projectFileSystem;
- private final RulesProfile rulesProfile;
- private final PmdProfileExporter pmdProfileExporter;
- private final PmdConfiguration pmdConfiguration;
-
- public PmdExecutor(Project project, ProjectFileSystem projectFileSystem, RulesProfile rulesProfile, PmdProfileExporter pmdProfileExporter, PmdConfiguration pmdConfiguration) {
- this.project = project;
- this.projectFileSystem = projectFileSystem;
- this.rulesProfile = rulesProfile;
- this.pmdProfileExporter = pmdProfileExporter;
- this.pmdConfiguration = pmdConfiguration;
- }
-
- public Report execute() {
- TimeProfiler profiler = new TimeProfiler().start("Execute PMD " + PmdVersion.getVersion());
-
- ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-
- return executePmd();
- } finally {
- Thread.currentThread().setContextClassLoader(initialClassLoader);
- profiler.stop();
- }
- }
-
- private Report executePmd() {
- Report report = new Report();
-
- RuleContext context = new RuleContext();
- context.setReport(report);
-
- PmdTemplate pmdFactory = createPmdTemplate();
- executeRules(pmdFactory, context, projectFileSystem.mainFiles(Java.KEY), PmdConstants.REPOSITORY_KEY);
- executeRules(pmdFactory, context, projectFileSystem.testFiles(Java.KEY), PmdConstants.TEST_REPOSITORY_KEY);
-
- pmdConfiguration.dumpXmlReport(report);
-
- return report;
- }
-
- public void executeRules(PmdTemplate pmdFactory, RuleContext ruleContext, List<InputFile> files, String repositoryKey) {
- if (files.isEmpty()) {
- return; // Nothing to analyse
- }
-
- RuleSets rulesets = createRulesets(repositoryKey);
- if (rulesets.getAllRules().isEmpty()) {
- return; // No rule
- }
-
- Charset encoding = projectFileSystem.getSourceCharset();
-
- for (InputFile file : files) {
- pmdFactory.process(file, encoding, rulesets, ruleContext);
- }
- }
-
- private RuleSets createRulesets(String repositoryKey) {
- String rulesXml = pmdProfileExporter.exportProfile(repositoryKey, rulesProfile);
-
- pmdConfiguration.dumpXmlRuleSet(repositoryKey, rulesXml);
-
- return new RuleSets(readRuleSet(rulesXml));
- }
-
- private static RuleSet readRuleSet(String rulesXml) {
- InputStream rulesInput = null;
- try {
- rulesInput = new ByteArrayInputStream(rulesXml.getBytes());
-
- return new RuleSetFactory().createRuleSet(rulesInput);
- } finally {
- Closeables.closeQuietly(rulesInput);
- }
- }
-
- @VisibleForTesting
- PmdTemplate createPmdTemplate() {
- return new PmdTemplate(JavaUtils.getSourceVersion(project));
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import com.google.common.collect.BiMap;
-import com.google.common.collect.EnumHashBiMap;
-import org.sonar.api.rules.RulePriority;
-
-import static com.google.common.collect.ImmutableMap.of;
-
-public final class PmdLevelUtils {
- private static final BiMap<RulePriority, String> LEVELS_PER_PRIORITY = EnumHashBiMap.create(of(
- RulePriority.BLOCKER, "1",
- RulePriority.CRITICAL, "2",
- RulePriority.MAJOR, "3",
- RulePriority.MINOR, "4",
- RulePriority.INFO, "5"));
-
- private PmdLevelUtils() {
- // only static methods
- }
-
- public static RulePriority fromLevel(String level) {
- return LEVELS_PER_PRIORITY.inverse().get(level);
- }
-
- public static String toLevel(RulePriority priority) {
- return LEVELS_PER_PRIORITY.get(priority);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import com.google.common.collect.ImmutableList;
-import org.sonar.api.Extension;
-import org.sonar.api.SonarPlugin;
-
-import java.util.List;
-
-public class PmdPlugin extends SonarPlugin {
- public List<Class<? extends Extension>> getExtensions() {
- return ImmutableList.of(
- PmdSensor.class,
- PmdConfiguration.class,
- PmdExecutor.class,
- PmdRuleRepository.class,
- PmdUnitTestsRuleRepository.class,
- PmdProfileExporter.class,
- PmdProfileImporter.class,
- SonarWayProfile.class,
- SonarWayWithFindbugsProfile.class,
- SunConventionsProfile.class,
- PmdViolationToRuleViolation.class);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.jdom.CDATA;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.output.Format;
-import org.jdom.output.XMLOutputter;
-import org.sonar.api.profiles.ProfileExporter;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Java;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.ActiveRuleParam;
-import org.sonar.api.utils.SonarException;
-import org.sonar.plugins.pmd.xml.PmdProperty;
-import org.sonar.plugins.pmd.xml.PmdRule;
-import org.sonar.plugins.pmd.xml.PmdRuleset;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.List;
-
-public class PmdProfileExporter extends ProfileExporter {
- public PmdProfileExporter() {
- super(PmdConstants.REPOSITORY_KEY, PmdConstants.PLUGIN_NAME);
- setSupportedLanguages(Java.KEY);
- setMimeType("application/xml");
- }
-
- @Override
- public void exportProfile(RulesProfile profile, Writer writer) {
- try {
- String xmlModules = exportProfile(PmdConstants.REPOSITORY_KEY, profile);
- writer.append(xmlModules);
- } catch (IOException e) {
- throw new SonarException("Fail to export the profile " + profile, e);
- }
- }
-
- public String exportProfile(String repositoryKey, RulesProfile profile) {
- PmdRuleset tree = createPmdRuleset(repositoryKey, profile.getActiveRulesByRepository(repositoryKey), profile.getName());
- return exportPmdRulesetToXml(tree);
- }
-
- private PmdRuleset createPmdRuleset(String repositoryKey, List<ActiveRule> activeRules, String profileName) {
- PmdRuleset ruleset = new PmdRuleset(profileName);
- for (ActiveRule activeRule : activeRules) {
- if (activeRule.getRule().getRepositoryKey().equals(repositoryKey)) {
- String configKey = activeRule.getRule().getConfigKey();
- PmdRule rule = new PmdRule(configKey, PmdLevelUtils.toLevel(activeRule.getSeverity()));
- if ((activeRule.getActiveRuleParams() != null) && !activeRule.getActiveRuleParams().isEmpty()) {
- List<PmdProperty> properties = new ArrayList<PmdProperty>();
- for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
- properties.add(new PmdProperty(activeRuleParam.getRuleParam().getKey(), activeRuleParam.getValue()));
- }
- rule.setProperties(properties);
- }
- ruleset.addRule(rule);
- processXPathRule(activeRule.getRuleKey(), rule);
- }
- }
- return ruleset;
- }
-
- @VisibleForTesting
- void processXPathRule(String sonarRuleKey, PmdRule rule) {
- if (PmdConstants.XPATH_CLASS.equals(rule.getRef())) {
- rule.setRef(null);
- PmdProperty xpathMessage = rule.getProperty(PmdConstants.XPATH_MESSAGE_PARAM);
- if (xpathMessage == null) {
- throw new SonarException("Property '" + PmdConstants.XPATH_MESSAGE_PARAM + "' should be set for PMD rule " + sonarRuleKey);
- }
- rule.setMessage(xpathMessage.getValue());
- rule.removeProperty(PmdConstants.XPATH_MESSAGE_PARAM);
- PmdProperty xpathExp = rule.getProperty(PmdConstants.XPATH_EXPRESSION_PARAM);
- if (xpathExp == null) {
- throw new SonarException("Property '" + PmdConstants.XPATH_EXPRESSION_PARAM + "' should be set for PMD rule " + sonarRuleKey);
- }
- xpathExp.setCdataValue(xpathExp.getValue());
- rule.setClazz(PmdConstants.XPATH_CLASS);
- rule.setName(sonarRuleKey);
- }
- }
-
- private String exportPmdRulesetToXml(PmdRuleset pmdRuleset) {
- Element eltRuleset = new Element("ruleset");
- for (PmdRule pmdRule : pmdRuleset.getPmdRules()) {
- Element eltRule = new Element("rule");
- addAttribute(eltRule, "ref", pmdRule.getRef());
- addAttribute(eltRule, "class", pmdRule.getClazz());
- addAttribute(eltRule, "message", pmdRule.getMessage());
- addAttribute(eltRule, "name", pmdRule.getName());
- addChild(eltRule, "priority", pmdRule.getPriority());
- if (pmdRule.hasProperties()) {
- Element eltProperties = new Element("properties");
- eltRule.addContent(eltProperties);
- for (PmdProperty prop : pmdRule.getProperties()) {
- Element eltProperty = new Element("property");
- eltProperty.setAttribute("name", prop.getName());
- if (prop.isCdataValue()) {
- Element eltValue = new Element("value");
- eltValue.addContent(new CDATA(prop.getCdataValue()));
- eltProperty.addContent(eltValue);
- } else {
- eltProperty.setAttribute("value", prop.getValue());
- }
- eltProperties.addContent(eltProperty);
- }
- }
- eltRuleset.addContent(eltRule);
- }
- XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat());
- StringWriter xml = new StringWriter();
- try {
- serializer.output(new Document(eltRuleset), xml);
- } catch (IOException e) {
- throw new SonarException("A exception occured while generating the PMD configuration file.", e);
- }
- return xml.toString();
- }
-
- private void addChild(Element elt, String name, String text) {
- if (text != null) {
- elt.addContent(new Element(name).setText(text));
- }
- }
-
- private void addAttribute(Element elt, String name, String value) {
- if (value != null) {
- elt.setAttribute(name, value);
- }
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.Namespace;
-import org.jdom.input.SAXBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.profiles.ProfileImporter;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Java;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.RuleQuery;
-import org.sonar.api.utils.ValidationMessages;
-import org.sonar.plugins.pmd.xml.PmdProperty;
-import org.sonar.plugins.pmd.xml.PmdRule;
-import org.sonar.plugins.pmd.xml.PmdRuleset;
-
-import javax.annotation.Nullable;
-
-import java.io.Reader;
-import java.util.List;
-
-public class PmdProfileImporter extends ProfileImporter {
-
- private final RuleFinder ruleFinder;
- private static final Logger LOG = LoggerFactory.getLogger(PmdProfileImporter.class);
-
- public PmdProfileImporter(RuleFinder ruleFinder) {
- super(PmdConstants.REPOSITORY_KEY, PmdConstants.PLUGIN_NAME);
- setSupportedLanguages(Java.KEY);
- this.ruleFinder = ruleFinder;
- }
-
- @Override
- public RulesProfile importProfile(Reader pmdConfigurationFile, ValidationMessages messages) {
- PmdRuleset pmdRuleset = parsePmdRuleset(pmdConfigurationFile, messages);
- return createRuleProfile(pmdRuleset, messages);
- }
-
- protected RulesProfile createRuleProfile(PmdRuleset pmdRuleset, ValidationMessages messages) {
- RulesProfile profile = RulesProfile.create();
- for (PmdRule pmdRule : pmdRuleset.getPmdRules()) {
- if (PmdConstants.XPATH_CLASS.equals(pmdRule.getClazz())) {
- messages.addWarningText("PMD XPath rule '" + pmdRule.getName()
- + "' can't be imported automatically. The rule must be created manually through the Sonar web interface.");
- continue;
- }
- if (pmdRule.getRef() == null) {
- messages.addWarningText("A PMD rule without 'ref' attribute can't be imported. see '" + pmdRule.getClazz() + "'");
- continue;
- }
- Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PmdConstants.REPOSITORY_KEY).withConfigKey(pmdRule.getRef()));
- if (rule != null) {
- ActiveRule activeRule = profile.activateRule(rule, PmdLevelUtils.fromLevel(pmdRule.getPriority()));
- if (pmdRule.getProperties() != null) {
- for (PmdProperty prop : pmdRule.getProperties()) {
- if (rule.getParam(prop.getName()) == null) {
- messages.addWarningText("The property '" + prop.getName() + "' is not supported in the pmd rule: " + pmdRule.getRef());
- continue;
- }
- activeRule.setParameter(prop.getName(), prop.getValue());
- }
- }
- } else {
- messages.addWarningText("Unable to import unknown PMD rule '" + pmdRule.getRef() + "'");
- }
- }
- return profile;
- }
-
- protected PmdRuleset parsePmdRuleset(Reader pmdConfigurationFile, ValidationMessages messages) {
- try {
- SAXBuilder parser = new SAXBuilder();
- Document dom = parser.build(pmdConfigurationFile);
- Element eltResultset = dom.getRootElement();
- Namespace namespace = eltResultset.getNamespace();
- PmdRuleset pmdResultset = new PmdRuleset();
- for (Element eltRule : getChildren(eltResultset, "rule", namespace)) {
- PmdRule pmdRule = new PmdRule(eltRule.getAttributeValue("ref"));
- pmdRule.setClazz(eltRule.getAttributeValue("class"));
- pmdRule.setName(eltRule.getAttributeValue("name"));
- pmdRule.setMessage(eltRule.getAttributeValue("message"));
- parsePmdPriority(eltRule, pmdRule, namespace);
- parsePmdProperties(eltRule, pmdRule, namespace);
- pmdResultset.addRule(pmdRule);
- }
- return pmdResultset;
- } catch (Exception e) {
- String errorMessage = "The PMD configuration file is not valid";
- messages.addErrorText(errorMessage + " : " + e.getMessage());
- LOG.error(errorMessage, e);
- return new PmdRuleset();
- }
- }
-
- private List<Element> getChildren(Element parent, String childName, @Nullable Namespace namespace) {
- if (namespace == null) {
- return parent.getChildren(childName);
- } else {
- return parent.getChildren(childName, namespace);
- }
- }
-
- private void parsePmdProperties(Element eltRule, PmdRule pmdRule, @Nullable Namespace namespace) {
- for (Element eltProperties : getChildren(eltRule, "properties", namespace)) {
- for (Element eltProperty : getChildren(eltProperties, "property", namespace)) {
- pmdRule.addProperty(new PmdProperty(eltProperty.getAttributeValue("name"), eltProperty.getAttributeValue("value")));
- }
- }
- }
-
- private void parsePmdPriority(Element eltRule, PmdRule pmdRule, @Nullable Namespace namespace) {
- for (Element eltPriority : getChildren(eltRule, "priority", namespace)) {
- pmdRule.setPriority(eltPriority.getValue());
- }
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import com.google.common.collect.Lists;
-import org.sonar.api.platform.ServerFileSystem;
-import org.sonar.api.resources.Java;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleRepository;
-import org.sonar.api.rules.XMLRuleParser;
-
-import java.io.File;
-import java.util.List;
-
-public final class PmdRuleRepository extends RuleRepository {
- private final ServerFileSystem fileSystem;
- private final XMLRuleParser xmlRuleParser;
-
- public PmdRuleRepository(ServerFileSystem fileSystem, XMLRuleParser xmlRuleParser) {
- super(PmdConstants.REPOSITORY_KEY, Java.KEY);
- setName(PmdConstants.REPOSITORY_NAME);
- this.fileSystem = fileSystem;
- this.xmlRuleParser = xmlRuleParser;
- }
-
- @Override
- public List<Rule> createRules() {
- List<Rule> rules = Lists.newArrayList();
- rules.addAll(xmlRuleParser.parse(getClass().getResourceAsStream("/org/sonar/plugins/pmd/rules.xml")));
- for (File userExtensionXml : fileSystem.getExtensions(PmdConstants.REPOSITORY_KEY, "xml")) {
- rules.addAll(xmlRuleParser.parse(userExtensionXml));
- }
- return rules;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import net.sourceforge.pmd.IRuleViolation;
-import net.sourceforge.pmd.Report;
-import org.sonar.api.batch.Sensor;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.Project;
-import org.sonar.api.rules.Violation;
-import org.sonar.api.utils.XmlParserException;
-
-import java.util.Iterator;
-
-public class PmdSensor implements Sensor {
- private final RulesProfile profile;
- private final PmdExecutor executor;
- private final PmdViolationToRuleViolation pmdViolationToRuleViolation;
-
- public PmdSensor(RulesProfile profile, PmdExecutor executor, PmdViolationToRuleViolation pmdViolationToRuleViolation) {
- this.profile = profile;
- this.executor = executor;
- this.pmdViolationToRuleViolation = pmdViolationToRuleViolation;
- }
-
- public boolean shouldExecuteOnProject(Project project) {
- return (!project.getFileSystem().mainFiles(Java.KEY).isEmpty() && !profile.getActiveRulesByRepository(PmdConstants.REPOSITORY_KEY).isEmpty())
- || (!project.getFileSystem().testFiles(Java.KEY).isEmpty() && !profile.getActiveRulesByRepository(PmdConstants.TEST_REPOSITORY_KEY).isEmpty());
- }
-
- public void analyse(Project project, SensorContext context) {
- try {
- Report report = executor.execute();
- reportViolations(report.iterator(), context);
- } catch (Exception e) {
- throw new XmlParserException(e);
- }
- }
-
- private void reportViolations(Iterator<IRuleViolation> violations, SensorContext context) {
- while (violations.hasNext()) {
- IRuleViolation pmdViolation = violations.next();
-
- Violation violation = pmdViolationToRuleViolation.toViolation(pmdViolation, context);
- if (null != violation) {
- context.saveViolation(violation);
- }
- }
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName();
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Functions;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.io.Closeables;
-import net.sourceforge.pmd.PMD;
-import net.sourceforge.pmd.PMDException;
-import net.sourceforge.pmd.RuleContext;
-import net.sourceforge.pmd.RuleSets;
-import net.sourceforge.pmd.SourceType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.resources.InputFile;
-import org.sonar.api.utils.SonarException;
-
-import java.io.File;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-import java.util.Map;
-
-public class PmdTemplate {
- private static final Logger LOG = LoggerFactory.getLogger(PmdTemplate.class);
-
- private static final Map<String, String> JAVA_VERSIONS = ImmutableMap.of(
- "1.1", "1.3",
- "1.2", "1.3",
- "5", "1.5",
- "6", "1.6");
-
- private final PMD pmd;
-
- public PmdTemplate(String javaVersion) {
- this(new PMD());
- setJavaVersion(pmd, javaVersion);
- }
-
- @VisibleForTesting
- PmdTemplate(PMD pmd) {
- this.pmd = pmd;
- }
-
- public void process(InputFile inputFile, Charset encoding, RuleSets rulesets, RuleContext ruleContext) {
- File file = inputFile.getFile();
- ruleContext.setSourceCodeFilename(file.getAbsolutePath());
-
- InputStream inputStream = null;
- try {
- inputStream = inputFile.getInputStream();
-
- pmd.processFile(inputStream, encoding.displayName(), rulesets, ruleContext);
- } catch (PMDException e) {
- LOG.error("Fail to execute PMD. Following file is ignored: " + file, e.getCause());
- } catch (Exception e) {
- LOG.error("Fail to execute PMD. Following file is ignored: " + file, e);
- } finally {
- Closeables.closeQuietly(inputStream);
- }
- }
-
- @VisibleForTesting
- static void setJavaVersion(PMD pmd, String javaVersion) {
- String version = normalize(javaVersion);
- SourceType sourceType = SourceType.getSourceTypeForId("java " + version);
- if (sourceType == null) {
- throw new SonarException("Unsupported Java version for PMD: " + version);
- }
-
- LOG.info("Java version: " + version);
- pmd.setJavaVersion(sourceType);
- }
-
- private static String normalize(String version) {
- return Functions.forMap(JAVA_VERSIONS, version).apply(version);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import org.sonar.api.resources.Java;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleRepository;
-import org.sonar.api.rules.XMLRuleParser;
-
-import java.io.InputStream;
-import java.util.List;
-
-public final class PmdUnitTestsRuleRepository extends RuleRepository {
- private final XMLRuleParser xmlRuleParser;
-
- public PmdUnitTestsRuleRepository(XMLRuleParser xmlRuleParser) {
- super(PmdConstants.TEST_REPOSITORY_KEY, Java.KEY);
- setName(PmdConstants.TEST_REPOSITORY_NAME);
- this.xmlRuleParser = xmlRuleParser;
- }
-
- @Override
- public List<Rule> createRules() {
- InputStream input = getClass().getResourceAsStream("/org/sonar/plugins/pmd/rules-unit-tests.xml");
- return xmlRuleParser.parse(input);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import com.google.common.io.Closeables;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-public final class PmdVersion {
- private static final String PROPERTIES_PATH = "/org/sonar/plugins/pmd/pmd-plugin.properties";
-
- private PmdVersion() {
- // Static utility class
- }
-
- public static String getVersion() {
- Properties properties = new Properties();
-
- InputStream input = null;
- try {
- input = PmdVersion.class.getResourceAsStream(PROPERTIES_PATH);
- properties.load(input);
- } catch (IOException e) {
- LoggerFactory.getLogger(PmdVersion.class).warn("Can not load the PMD version from the file " + PROPERTIES_PATH);
- } finally {
- Closeables.closeQuietly(input);
- }
-
- return properties.getProperty("pmd.version", "");
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import net.sourceforge.pmd.IRuleViolation;
-import org.sonar.api.BatchExtension;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.resources.JavaFile;
-import org.sonar.api.resources.ProjectFileSystem;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.Violation;
-
-import java.io.File;
-import java.util.List;
-
-public class PmdViolationToRuleViolation implements BatchExtension {
- private final ProjectFileSystem projectFileSystem;
- private final RuleFinder ruleFinder;
-
- public PmdViolationToRuleViolation(ProjectFileSystem projectFileSystem, RuleFinder ruleFinder) {
- this.projectFileSystem = projectFileSystem;
- this.ruleFinder = ruleFinder;
- }
-
- public Violation toViolation(IRuleViolation pmdViolation, SensorContext context) {
- Resource resource = findResourceFor(pmdViolation);
- if (context.getResource(resource) == null) {
- return null; // Save violations only for existing resources
- }
-
- Rule rule = findRuleFor(pmdViolation);
- if (rule == null) {
- return null; // Save violations only for enabled rules
- }
-
- int lineId = pmdViolation.getBeginLine();
- String message = pmdViolation.getDescription();
-
- return Violation.create(rule, resource).setLineId(lineId).setMessage(message);
- }
-
- private Resource findResourceFor(IRuleViolation violation) {
- List<File> allSources = ImmutableList.copyOf(Iterables.concat(projectFileSystem.getSourceDirs(), projectFileSystem.getTestDirs()));
-
- return JavaFile.fromAbsolutePath(violation.getFilename(), allSources, true);
- }
-
- private Rule findRuleFor(IRuleViolation violation) {
- String ruleKey = violation.getRule().getName();
- Rule rule = ruleFinder.findByKey(PmdConstants.REPOSITORY_KEY, ruleKey);
- if (rule != null) {
- return rule;
- }
- return ruleFinder.findByKey(PmdConstants.TEST_REPOSITORY_KEY, ruleKey);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import com.google.common.io.Closeables;
-import org.sonar.api.profiles.ProfileDefinition;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Java;
-import org.sonar.api.utils.ValidationMessages;
-
-import java.io.InputStreamReader;
-import java.io.Reader;
-
-public final class SonarWayProfile extends ProfileDefinition {
- private final PmdProfileImporter importer;
-
- public SonarWayProfile(PmdProfileImporter importer) {
- this.importer = importer;
- }
-
- @Override
- public RulesProfile createProfile(ValidationMessages validation) {
- Reader config = null;
- try {
- config = new InputStreamReader(this.getClass().getResourceAsStream("/org/sonar/plugins/pmd/profile-sonar-way.xml"));
-
- RulesProfile profile = importer.importProfile(config, validation);
- profile.setLanguage(Java.KEY);
- profile.setName(RulesProfile.SONAR_WAY_NAME);
-
- return profile;
- } finally {
- Closeables.closeQuietly(config);
- }
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import org.sonar.api.profiles.ProfileDefinition;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Java;
-import org.sonar.api.utils.ValidationMessages;
-
-public class SonarWayWithFindbugsProfile extends ProfileDefinition {
- private final SonarWayProfile sonarWay;
-
- public SonarWayWithFindbugsProfile(SonarWayProfile sonarWay) {
- this.sonarWay = sonarWay;
- }
-
- @Override
- public RulesProfile createProfile(ValidationMessages validation) {
- RulesProfile profile = sonarWay.createProfile(validation);
-
- profile.setName(RulesProfile.SONAR_WAY_FINDBUGS_NAME);
- profile.setLanguage(Java.KEY);
-
- return profile;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import com.google.common.io.Closeables;
-import org.sonar.api.profiles.ProfileDefinition;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Java;
-import org.sonar.api.utils.ValidationMessages;
-
-import java.io.InputStreamReader;
-import java.io.Reader;
-
-public final class SunConventionsProfile extends ProfileDefinition {
- private final PmdProfileImporter importer;
-
- public SunConventionsProfile(PmdProfileImporter importer) {
- this.importer = importer;
- }
-
- @Override
- public RulesProfile createProfile(ValidationMessages validation) {
- Reader config = null;
- try {
- config = new InputStreamReader(this.getClass().getResourceAsStream("/org/sonar/plugins/pmd/profile-sun-conventions.xml"));
-
- RulesProfile profile = importer.importProfile(config, validation);
- profile.setLanguage(Java.KEY);
- profile.setName(RulesProfile.SUN_CONVENTIONS_NAME);
-
- return profile;
- } finally {
- Closeables.closeQuietly(config);
- }
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.plugins.pmd;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd.xml;
-
-public class PmdProperty {
-
- private String name;
-
- private String value;
-
- private String cdataValue;
-
- public PmdProperty(String name, String value) {
- this.name = name;
- this.value = value;
- }
-
- public String getName() {
- return name;
- }
-
- public String getValue() {
- return value;
- }
-
- public String getCdataValue() {
- return cdataValue;
- }
-
- public boolean isCdataValue(){
- return cdataValue != null;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public void setCdataValue(String cdataValue) {
- this.cdataValue = cdataValue;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd.xml;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class PmdRule {
-
- private String ref;
-
- private String priority;
-
- private String name;
-
- private String message;
-
- private List<PmdProperty> properties = new ArrayList<PmdProperty>();
-
- private String clazz;
-
- public PmdRule(String ref) {
- this(ref, null);
- }
-
- public PmdRule(String ref, String priority) {
- this.ref = ref;
- this.priority = priority;
- }
-
- public String getRef() {
- return ref;
- }
-
- public void setProperties(List<PmdProperty> properties) {
- this.properties = properties;
- }
-
- public List<PmdProperty> getProperties() {
- return properties;
- }
-
- public PmdProperty getProperty(String propertyName) {
- for (PmdProperty prop : properties) {
- if (propertyName.equals(prop.getName())) {
- return prop;
- }
- }
- return null;
- }
-
- public int compareTo(String o) {
- return o.compareTo(ref);
- }
-
- public String getPriority() {
- return priority;
- }
-
- public void setPriority(String priority) {
- this.priority = priority;
- }
-
- public void addProperty(PmdProperty property) {
- if (properties == null) {
- properties = new ArrayList<PmdProperty>();
- }
- properties.add(property);
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setClazz(String clazz) {
- this.clazz = clazz;
- }
-
- public String getClazz() {
- return clazz;
- }
-
- public void setRef(String ref) {
- this.ref = ref;
- }
-
- public void removeProperty(String propertyName) {
- PmdProperty prop = getProperty(propertyName);
- properties.remove(prop);
- }
-
- public boolean hasProperties() {
- return properties != null && !properties.isEmpty();
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd.xml;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class PmdRuleset {
-
- private String description;
-
- private List<PmdRule> rules = new ArrayList<PmdRule>();
-
- public PmdRuleset() {
- }
-
- public PmdRuleset(String description) {
- this.description = description;
- }
-
- public List<PmdRule> getPmdRules() {
- return rules;
- }
-
- public void setRules(List<PmdRule> rules) {
- this.rules = rules;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public void addRule(PmdRule rule) {
- rules.add(rule);
- }
-
-}
+++ /dev/null
-rule.pmd.StringInstantiation.name=String Instantiation
-rule.pmd.RemoteInterfaceNamingConvention.name=Remote Interface Naming Convention
-rule.pmd.InefficientEmptyStringCheck.name=Inefficient Empty String Check
-rule.pmd.DoubleCheckedLocking.name=Double checked locking
-rule.pmd.EmptyStaticInitializer.name=Empty Static Initializer
-rule.pmd.DoNotThrowExceptionInFinally.name=Strict Exception - Do not throw exception in finally
-rule.pmd.SignatureDeclareThrowsException.name=Signature Declare Throws Exception
-rule.pmd.UseEqualsToCompareStrings.name=Use Equals To Compare Strings
-rule.pmd.VariableNamingConventions.name=Naming - Variable naming conventions
-rule.pmd.VariableNamingConventions.param.memberSuffix=A suffix for member variables
-rule.pmd.VariableNamingConventions.param.memberPrefix=A prefix for member variables
-rule.pmd.VariableNamingConventions.param.staticSuffix=A suffix for static variables
-rule.pmd.VariableNamingConventions.param.staticPrefix=A prefix for static variables
-rule.pmd.PositionLiteralsFirstInComparisons.name=Position Literals First In Comparisons
-rule.pmd.ConfusingTernary.name=Confusing Ternary
-rule.pmd.ShortMethodName.name=Naming - Short method name
-rule.pmd.UncommentedEmptyConstructor.name=Uncommented Empty Constructor
-rule.pmd.UncommentedEmptyConstructor.param.ignoreExplicitConstructorInvocation=Ignore explicit constructor invocation when deciding whether constructor is empty or not. Default is false.
-rule.pmd.UnusedFormalParameter.name=Unused formal parameter
-rule.pmd.ExcessiveParameterList.name=Excessive Parameter List
-rule.pmd.ExcessiveParameterList.param.minimum=The parameter count reporting threshold. Default is 10.
-rule.pmd.OnlyOneReturn.name=Only One Return
-rule.pmd.UseStringBufferForStringAppends.name=Use String Buffer For String Appends
-rule.pmd.BooleanInversion.name=Boolean Inversion
-rule.pmd.AvoidDollarSigns.name=Naming - Avoid dollar signs
-rule.pmd.AvoidUsingShortType.name=Avoid Using Short Type
-rule.pmd.NonCaseLabelInSwitchStatement.name=Non Case Label In Switch Statement
-rule.pmd.CyclomaticComplexity.name=Code size - cyclomatic complexity
-rule.pmd.CyclomaticComplexity.param.showMethodsComplexity=Indicate if method average violation should be added to the report. Default is true.
-rule.pmd.CyclomaticComplexity.param.showClassesComplexity=Indicate if class average violation should be added to the report. Default is true.
-rule.pmd.CyclomaticComplexity.param.reportLevel=The Cyclomatic Complexity reporting threshold. Default is 10.
-rule.pmd.AvoidEnumAsIdentifier.name=Avoid Enum As Identifier
-rule.pmd.AvoidFieldNameMatchingMethodName.name=Naming - Avoid field name matching method name
-rule.pmd.InstantiationToGetClass.name=Instantiation To Get Class
-rule.pmd.SuspiciousHashcodeMethodName.name=Naming - Suspicious Hashcode method name
-rule.pmd.MDBAndSessionBeanNamingConvention.name=Message Driven Bean And Session Bean Naming Convention
-rule.pmd.UselessOperationOnImmutable.name=Useless Operation On Immutable
-rule.pmd.ReturnEmptyArrayRatherThanNull.name=Return empty array rather than null
-rule.pmd.LongInstantiation.name=Java5 migration - Long instantiation
-rule.pmd.ExcessiveImports.name=Coupling - excessive imports
-rule.pmd.ExcessiveImports.param.minimum=The import count reporting threshold. Default is 30.
-rule.pmd.StringBufferInstantiationWithChar.name=String Buffer Instantiation With Char
-rule.pmd.StringToString.name=String To String
-rule.pmd.MissingSerialVersionUID.name=Missing Serial Version UID
-rule.pmd.UnconditionalIfStatement.name=Unconditional If Statement
-rule.pmd.AvoidArrayLoops.name=Avoid Array Loops
-rule.pmd.ShortVariable.name=Short Variable
-rule.pmd.UnusedLocalVariable.name=Unused local variable
-rule.pmd.SuspiciousConstantFieldName.name=Naming - Suspicious constant field name
-rule.pmd.UseArrayListInsteadOfVector.name=Use Array List Instead Of Vector
-rule.pmd.CallSuperLast.name=Android - call super last
-rule.pmd.SimplifyBooleanExpressions.name=Avoid unnecessary comparisons in boolean expressions
-rule.pmd.FinalizeOnlyCallsSuperFinalize.name=Finalize Only Calls Super Finalize
-rule.pmd.ImmutableField.name=Immutable Field
-rule.pmd.BooleanInstantiation.name=Boolean Instantiation
-rule.pmd.StaticEJBFieldShouldBeFinal.name=Static EJB Field Should Be Final
-rule.pmd.AvoidFieldNameMatchingTypeName.name=Naming - Avoid field name matching type name
-rule.pmd.OverrideBothEqualsAndHashcode.name=Override both equals and hashcode
-rule.pmd.BrokenNullCheck.name=Broken Null Check
-rule.pmd.NPathComplexity.name=NPath complexity
-rule.pmd.NPathComplexity.param.minimum=The npath reporting threshold. Default is 200.
-rule.pmd.CouplingBetweenObjects.name=Coupling between objects
-rule.pmd.CouplingBetweenObjects.param.threshold=The unique type reporting threshold. Default is 20.
-rule.pmd.IntegerInstantiation.name=Integer Instantiation
-rule.pmd.DoNotCallGarbageCollectionExplicitly.name=Do not call garbage collection explicitly
-rule.pmd.BeanMembersShouldSerialize.name=Bean Members Should Serialize
-rule.pmd.BeanMembersShouldSerialize.param.prefix=A variable prefix to skip, i.e., m_
-rule.pmd.IdempotentOperations.name=Idempotent Operations
-rule.pmd.NcssTypeCount.name=Ncss Type Count
-rule.pmd.NcssTypeCount.param.minimum=The type NCSS count reporting threshold. Default is 1500.
-rule.pmd.AvoidThrowingRawExceptionTypes.name=Avoid Throwing Raw Exception Types
-rule.pmd.ImportFromSamePackage.name=Import From Same Package
-rule.pmd.UnnecessaryLocalBeforeReturn.name=Unnecessary Local Before Return
-rule.pmd.IfElseStmtsMustUseBraces.name=If Else Stmts Must Use Braces
-rule.pmd.ForLoopsMustUseBraces.name=For Loops Must Use Braces
-rule.pmd.UseIndexOfChar.name=Use Index Of Char
-rule.pmd.EmptyMethodInAbstractClassShouldBeAbstract.name=Empty Method In Abstract Class Should Be Abstract
-rule.pmd.LongVariable.name=Long Variable
-rule.pmd.LongVariable.param.minimum=The variable length reporting threshold. Default is 17.
-rule.pmd.MissingBreakInSwitch.name=Missing Break In Switch
-rule.pmd.UnnecessaryParentheses.name=Unnecessary parentheses
-rule.pmd.MisleadingVariableName.name=Naming - Misleading variable name
-rule.pmd.AbstractClassWithoutAnyMethod.name=Abstract class without any methods
-rule.pmd.DoNotCallSystemExit.name=Do Not Call System Exit
-rule.pmd.AvoidThrowingNullPointerException.name=Avoid Throwing Null Pointer Exception
-rule.pmd.EmptySynchronizedBlock.name=Empty Synchronized Block
-rule.pmd.SwitchStmtsShouldHaveDefault.name=Switch statements should have default
-rule.pmd.UseNotifyAllInsteadOfNotify.name=Use Notify All Instead Of Notify
-rule.pmd.UnusedPrivateMethod.name=Unused private method
-rule.pmd.MoreThanOneLogger.name=More Than One Logger
-rule.pmd.EmptyTryBlock.name=Empty Try Block
-rule.pmd.AvoidDeeplyNestedIfStmts.name=Avoid Deeply Nested If Stmts
-rule.pmd.AvoidDeeplyNestedIfStmts.param.problemDepth=The if statement depth reporting threshold. Default is 3.
-rule.pmd.LocalHomeNamingConvention.name=Local Home Naming Convention
-rule.pmd.AvoidUsingNativeCode.name=Avoid Using Native Code
-rule.pmd.LooseCoupling.name=Loose coupling
-rule.pmd.FinalizeOverloaded.name=Finalize Overloaded
-rule.pmd.AvoidThreadGroup.name=Avoid Thread Group
-rule.pmd.UnnecessaryConstructor.name=Unnecessary constructor
-rule.pmd.LocalVariableCouldBeFinal.name=Local variable could be final
-rule.pmd.MethodArgumentCouldBeFinal.name=Method Argument Could Be Final
-rule.pmd.AvoidAssertAsIdentifier.name=Avoid Assert As Identifier
-rule.pmd.SuspiciousOctalEscape.name=Suspicious Octal Escape
-rule.pmd.ByteInstantiation.name=Java5 migration - Byte instantiation
-rule.pmd.AvoidConstantsInterface.name=Avoid Constants Interface
-rule.pmd.LocalInterfaceSessionNamingConvention.name=Local Interface Session Naming Convention
-rule.pmd.CloneMethodMustImplementCloneable.name=Clone method must implement Cloneable
-rule.pmd.MethodWithSameNameAsEnclosingClass.name=Naming - Method with same name as enclosing class
-rule.pmd.ConsecutiveLiteralAppends.name=Consecutive Literal Appends
-rule.pmd.ConsecutiveLiteralAppends.param.threshold=The report threshold. Default is 1.
-rule.pmd.CallSuperInConstructor.name=Call Super In Constructor
-rule.pmd.SimplifyConditional.name=Simplify Conditional
-rule.pmd.InefficientStringBuffering.name=Inefficient String Buffering
-rule.pmd.EmptyStatementNotInLoop.name=Empty Statement Not In Loop
-rule.pmd.AvoidSynchronizedAtMethodLevel.name=Avoid Synchronized At Method Level
-rule.pmd.NcssMethodCount.name=Ncss Method Count
-rule.pmd.NcssMethodCount.param.minimum=The method NCSS count reporting threshold. Default is 100.
-rule.pmd.AbstractClassWithoutAbstractMethod.name=Abstract Class Without Abstract Method
-rule.pmd.AbstractNaming.name=Abstract naming
-rule.pmd.DoNotExtendJavaLangError.name=Do Not Extend Java Lang Error
-rule.pmd.NoPackage.name=No package
-rule.pmd.ExcessiveMethodLength.name=Excessive Method Length
-rule.pmd.ExcessiveMethodLength.param.minimum=The method size reporting threshold. Default is 100.
-rule.pmd.SwitchDensity.name=Switch Density
-rule.pmd.SwitchDensity.param.minimum=The switch statement ratio reporting threshold. Default is 10.
-rule.pmd.UseLocaleWithCaseConversions.name=Use Locale With Case Conversions
-rule.pmd.DuplicateImports.name=Duplicate Imports
-rule.pmd.ProperLogger.name=Proper Logger
-rule.pmd.ProperLogger.param.staticLoggerName=Default is LOG
-rule.pmd.PreserveStackTrace.name=Preserve Stack Trace
-rule.pmd.FinalizeDoesNotCallSuperFinalize.name=Finalize Does Not Call Super Finalize
-rule.pmd.DontImportSun.name=Dont Import Sun
-rule.pmd.ReplaceVectorWithList.name=Replace Vector With List
-rule.pmd.ClassNamingConventions.name=Naming - Class naming conventions
-rule.pmd.UncommentedEmptyMethod.name=Uncommented Empty Method
-rule.pmd.AvoidAccessibilityAlteration.name=Avoid Accessibility Alteration
-rule.pmd.IfStmtsMustUseBraces.name=If Stmts Must Use Braces
-rule.pmd.AvoidReassigningParameters.name=Avoid Reassigning Parameters
-rule.pmd.OptimizableToArrayCall.name=Optimizable To Array Call
-rule.pmd.FinalizeShouldBeProtected.name=Finalize Should Be Protected
-rule.pmd.AddEmptyString.name=Add Empty String
-rule.pmd.EmptyFinallyBlock.name=Empty Finally Block
-rule.pmd.EqualsNull.name=Equals Null
-rule.pmd.SuspiciousEqualsMethodName.name=Naming - Suspicious equals method name
-rule.pmd.UnnecessaryWrapperObjectCreation.name=Unnecessary Wrapper Object Creation
-rule.pmd.AvoidStringBufferField.name=Avoid StringBuffer field
-rule.pmd.SimplifyBooleanReturns.name=Simplify boolean returns
-rule.pmd.DefaultLabelNotLastInSwitchStmt.name=Default label not last in switch statement
-rule.pmd.AvoidUsingOctalValues.name=Avoid Using Octal Values
-rule.pmd.AvoidCallingFinalize.name=Avoid Calling Finalize
-rule.pmd.ExcessiveClassLength.name=Excessive Class Length
-rule.pmd.ExcessiveClassLength.param.minimum=The class size reporting threshold. Default is 1000.
-rule.pmd.FinalFieldCouldBeStatic.name=Final Field Could Be Static
-rule.pmd.AvoidRethrowingException.name=Avoid Rethrowing Exception
-rule.pmd.AvoidUsingHardCodedIP.name=Avoid Using Hard Coded IP
-rule.pmd.AvoidUsingHardCodedIP.param.pattern=Regular Expression. Default is ^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$
-rule.pmd.ProtectLogD.name=Android - Protect LOGD
-rule.pmd.ProtectLogV.name=Android - Protect LOGV
-rule.pmd.MethodNamingConventions.name=Naming - Method naming conventions
-rule.pmd.NonStaticInitializer.name=Non Static Initializer
-rule.pmd.AvoidProtectedFieldInFinalClass.name=Avoid Protected Field In Final Class
-rule.pmd.CompareObjectsWithEquals.name=Compare Objects With Equals
-rule.pmd.SystemPrintln.name=System Println
-rule.pmd.XPathRule.name=XPath rule template
-rule.pmd.XPathRule.param.message=Message to display when a violation occurs.
-rule.pmd.XPathRule.param.xpath=XPath expressions.
-rule.pmd.DontImportJavaLang.name=Dont Import Java Lang
-rule.pmd.TooManyMethods.name=Too many methods
-rule.pmd.TooManyMethods.param.maxmethods=The method count reporting threshold. Default is 10.
-rule.pmd.CloneThrowsCloneNotSupportedException.name=Clone Throws Clone Not Supported Exception
-rule.pmd.EmptyCatchBlock.name=Empty Catch Block
-rule.pmd.EmptyCatchBlock.param.allowCommentedBlocks=Empty blocks containing comments will be skipped. Default is false.
-rule.pmd.CollapsibleIfStatements.name=Collapsible If Statements
-rule.pmd.ForLoopShouldBeWhileLoop.name=For Loop Should Be While Loop
-rule.pmd.UseCorrectExceptionLogging.name=Use Correct Exception Logging
-rule.pmd.ReplaceEnumerationWithIterator.name=Replace Enumeration With Iterator
-rule.pmd.EmptyWhileStmt.name=Empty While Stmt
-rule.pmd.ReplaceHashtableWithMap.name=Replace Hashtable With Map
-rule.pmd.AvoidMultipleUnaryOperators.name=Avoid Multiple Unary Operators
-rule.pmd.UselessOverridingMethod.name=Useless Overriding Method
-rule.pmd.UselessOverridingMethod.param.ignoreAnnotations=Ignore annotations. Default is false.
-rule.pmd.SimpleDateFormatNeedsLocale.name=Simple Date Format Needs Locale
-rule.pmd.UnnecessaryFinalModifier.name=Unnecessary Final Modifier
-rule.pmd.CallSuperFirst.name=Android - call super first
-rule.pmd.UseArraysAsList.name=Use Arrays As List
-rule.pmd.CloseResource.name=Close Resource
-rule.pmd.CloseResource.param.closeTargets=Methods which may close this resource. Default is 'close'.
-rule.pmd.CloseResource.param.types=Resources to check. Default value is 'Connection,Statement,ResultSet',
-rule.pmd.EmptySwitchStatements.name=Empty Switch Statements
-rule.pmd.AccessorClassGeneration.name=Accessor Class Generation
-rule.pmd.PackageCase.name=Package case
-rule.pmd.TooFewBranchesForASwitchStatement.name=Too few branches for a switch statement
-rule.pmd.TooFewBranchesForASwitchStatement.param.minimumNumberCaseForASwitch=Minimum number of branches for a switch. Default is 3.
-rule.pmd.TooManyStaticImports.name=Too Many Static Imports
-rule.pmd.TooManyStaticImports.param.maximumStaticImports=All static imports can be disallowed by setting this to 0. Default is 4.
-rule.pmd.EmptyIfStmt.name=Empty If Stmt
-rule.pmd.DataflowAnomalyAnalysis.name=Dataflow Anomaly Analysis
-rule.pmd.DataflowAnomalyAnalysis.param.maxviolations=The maximum number of violations per class. Default is 100.
-rule.pmd.DataflowAnomalyAnalysis.param.maxpaths=The maximum number of checked paths per method. A lower value will increase the performance of the rule but may decrease the number of found anomalies. Default is 1000.
-rule.pmd.NonThreadSafeSingleton.name=Non Thread Safe Singleton
-rule.pmd.NonThreadSafeSingleton.param.checkNonStaticFields=Do not set this to true and checkNonStaticMethods to false. Default is false.
-rule.pmd.NonThreadSafeSingleton.param.checkNonStaticMethods=Do not set this to false and checkNonStaticFields to true. Default is true.
-rule.pmd.WhileLoopsMustUseBraces.name=While Loops Must Use Braces
-rule.pmd.UnusedModifier.name=Unused Modifier
-rule.pmd.ClassCastExceptionWithToArray.name=Class Cast Exception With To Array
-rule.pmd.EmptyInitializer.name=Basic - Empty Initializer
-rule.pmd.DoNotUseThreads.name=Do Not Use Threads
-rule.pmd.InsufficientStringBufferDeclaration.name=Insufficient String Buffer Declaration
-rule.pmd.AvoidUsingVolatile.name=Avoid Using Volatile
-rule.pmd.UseStringBufferLength.name=Use String Buffer Length
-rule.pmd.AvoidInstantiatingObjectsInLoops.name=Avoid instantiating objects in loops
-rule.pmd.UnsynchronizedStaticDateFormatter.name=Unsynchronized Static Date Formatter
-rule.pmd.MissingStaticMethodInNonInstantiatableClass.name=Missing Static Method In Non Instantiatable Class
-rule.pmd.EmptyFinalizer.name=Empty Finalizer
-rule.pmd.ShortInstantiation.name=Java5 migration - Short instantiation
-rule.pmd.ConstructorCallsOverridableMethod.name=Constructor Calls Overridable Method
-rule.pmd.DefaultPackage.name=Default Package
-rule.pmd.NcssConstructorCount.name=Ncss Constructor Count
-rule.pmd.NcssConstructorCount.param.minimum=The constructor NCSS count reporting threshold. Default is 100.
-rule.pmd.AvoidCatchingThrowable.name=Avoid Catching Throwable
-rule.pmd.AvoidDecimalLiteralsInBigDecimalConstructor.name=Avoid Decimal Literals In Big Decimal Constructor
-rule.pmd.AvoidDuplicateLiterals.name=Avoid Duplicate Literals
-rule.pmd.AvoidDuplicateLiterals.param.separator=Separator used in the exceptionlist. Default is ,
-rule.pmd.AvoidDuplicateLiterals.param.skipAnnotations=Skip literals within Annotations. Default is false.
-rule.pmd.AvoidDuplicateLiterals.param.exceptionfile=File containing strings to skip (one string per line), only used if exceptionlist is not set.
-rule.pmd.AvoidDuplicateLiterals.param.threshold=The number of duplicate literals reporting threshold. Default is 4.
-rule.pmd.AvoidDuplicateLiterals.param.exceptionlist=Strings in that list are skipped.
-rule.pmd.ExcessivePublicCount.name=Excessive Public Count
-rule.pmd.ExcessivePublicCount.param.minimum=The public item reporting threshold. Default is 45.
-rule.pmd.ClassWithOnlyPrivateConstructorsShouldBeFinal.name=Class with only private constructors should be final
-rule.pmd.NullAssignment.name=Null Assignment
-rule.pmd.MisplacedNullCheck.name=Misplaced Null Check
-rule.pmd.SingularField.name=Singular Field
-rule.pmd.UnusedImports.name=Unused imports
-rule.pmd.UselessStringValueOf.name=Useless String Value Of
-rule.pmd.UnusedNullCheckInEquals.name=Unused Null Check In Equals
-rule.pmd.AvoidCatchingNPE.name=Avoid Catching NPE
-rule.pmd.DontNestJsfInJstlIteration.name=Dont Nest Jsf In Jstl Iteration
-rule.pmd.CheckResultSet.name=Check ResultSet
-rule.pmd.ReturnFromFinallyBlock.name=Return From Finally Block
-rule.pmd.UseProperClassLoader.name=Use Proper Class Loader
-rule.pmd.UseSingleton.name=Use Singleton
-rule.pmd.ProperCloneImplementation.name=Proper clone implementation
-rule.pmd.UseCollectionIsEmpty.name=Use Collection Is Empty
-rule.pmd.AvoidThrowingNewInstanceOfSameException.name=Strict Exception - Avoid throwing new instance of same exception
-rule.pmd.SimplifyStartsWith.name=Simplify Starts With
-rule.pmd.AvoidFinalLocalVariable.name=Avoid Final Local Variable
-rule.pmd.TooManyFields.name=Too Many Fields
-rule.pmd.TooManyFields.param.maxfields=The field count reporting threshold. Default is 15.
-rule.pmd.MethodReturnsInternalArray.name=Security - Method returns internal array
-rule.pmd.AvoidInstanceofChecksInCatchClause.name=Avoid Instanceof Checks In Catch Clause
-rule.pmd.LoggerIsNotStaticFinal.name=Logger Is Not Static Final
-rule.pmd.BigIntegerInstantiation.name=Big Integer Instantiation
-rule.pmd.AssignmentInOperand.name=Assignment In Operand
-rule.pmd.BadComparison.name=Bad Comparison
-rule.pmd.UnnecessaryReturn.name=Unnecessary Return
-rule.pmd.AssignmentToNonFinalStatic.name=Assignment To Non Final Static
-rule.pmd.UnnecessaryConversionTemporary.name=Unnecessary Conversion Temporary
-rule.pmd.JumbledIncrementer.name=Jumbled Incrementer
-rule.pmd.BooleanGetMethodName.name=Boolean Get Method Name
-rule.pmd.BooleanGetMethodName.param.checkParameterizedMethods=Check parameterized methods. Default is false.
-rule.pmd.AvoidPrintStackTrace.name=Avoid Print Stack Trace
-rule.pmd.RemoteSessionInterfaceNamingConvention.name=Remote Session Interface Naming Convention
-rule.pmd.UnnecessaryCaseChange.name=Unnecessary Case Change
-rule.pmd.ArrayIsStoredDirectly.name=Security - Array is stored directly
-rule.pmd.ExceptionAsFlowControl.name=Exception As Flow Control
-rule.pmd.UnusedPrivateField.name=Unused Private Field
-rule.pmd.AtLeastOneConstructor.name=At Least One Constructor
-rule.pmd.AppendCharacterWithChar.name=Append Character With Char
-rule.pmd.GenericsNaming.name=Generics Naming
-rule.pmd.AvoidCatchingGenericException.name=Avoid Catching Generic Exception
-rule.pmd.AvoidLosingExceptionInformation.name=Avoid Losing Exception Information
-rule.pmd.AvoidLiteralsInIfCondition.name=Avoid Literals In If Condition
-rule.pmd.UseConcurrentHashMap.name=Use ConcurrentHashMap
-rule.pmd.DoNotHardCodeSDCard.name=Android - Do Not Hard Code SD Card
-rule.pmd.DontCallThreadRun.name=Dont Call Thread Run
-rule.pmd.GuardDebugLogging.name=Guard Debug Logging
-rule.pmd-unit-tests.JUnitStaticSuite.name=JUnit static suite
-rule.pmd-unit-tests.JUnitSpelling.name= JUnit spelling
-rule.pmd-unit-tests.JUnitAssertionsShouldIncludeMessage.name=JUnit assertions should include a message
-rule.pmd-unit-tests.JUnitTestsShouldIncludeAssert.name=JUnit tests should include an assert
-rule.pmd-unit-tests.TestClassWithoutTestCases.name=Test class without test cases (JUnit 3.x only)
-rule.pmd-unit-tests.UnnecessaryBooleanAssertion.name=Unnecessary boolean assertion
-rule.pmd-unit-tests.UseAssertEqualsInsteadOfAssertTrue.name=Use assertEquals instead of assertTrue
-rule.pmd-unit-tests.UseAssertSameInsteadOfAssertTrue.name=Use assertSame instead of assertTrue
-rule.pmd-unit-tests.UseAssertNullInsteadOfAssertTrue.name=Use assertNull instead of assertTrue
-rule.pmd-unit-tests.SimplifyBooleanAssertion.name=Simplify boolean assertion
+++ /dev/null
-JUnit assertions should include a message - i.e., use the three argument version of assertEquals(), not the two argument version.
-<pre>
-public class Foo extends TestCase {
- public void testSomething() {
- assertEquals("foo", "bar"); // violation, should be assertEquals("Foo does not equals bar", "foo", "bar");
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Some JUnit framework methods are easy to misspell.
-<pre>
-import junit.framework.*;
-
-public class Foo extends TestCase {
- public void setup() {} // violation, should be setUp()
- public void TearDown() {} // violation, should be tearDown()
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-The suite() method in a JUnit test needs to be both public and static.
-<pre>
-import junit.framework.*;
-
-public class Foo extends TestCase {
- public void suite() {} // violation, should be static
- private static void suite() {} // violation, should be public
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-JUnit tests should include at least one assertion. This makes the tests more robust, and using assert with messages provide the developer a clearer idea of what the test does.
-<pre>
-public class Foo extends TestCase {
- public void testSomething() {
- Bar b = findBar();
- b.work();
- // violation, we could use assertNotNull("bar not found", b);
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Avoid negation in an assertTrue or assertFalse test. For example, rephrase: assertTrue(!expr); as: assertFalse(expr);
-<pre>
-public class SimpleTest extends TestCase {
- public void testX() {
- assertTrue("not empty", !r.isEmpty()); // violation, replace with assertFalse("not empty", r.isEmpty())
- assertFalse(!r.isEmpty()); // violation, replace with assertTrue("empty", r.isEmpty())
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Test classes end with the suffix Test. Having a non-test class with that name is not a good practice, since most people will assume it is a test case. Test classes have test methods named testXXX.
-Beware: This rule doesn't support JUnit 4.x's @Test annotation.
-<pre>
-public class CarTest { // violation, consider changing the name of the class if it is not a test
- // consider adding test methods if it is a test
- public static void main(String[] args) {
- // do something
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-A JUnit test assertion with a boolean literal is unnecessary since it always will eval to the same thing. Consider using flow control (in case of assertTrue(false) or similar) or simply removing statements like assertTrue(true) and assertFalse(false). If you just want a test to halt, use the fail method.
-<pre>
-public class SimpleTest extends TestCase {
- public void testX() {
- assertTrue(true); // violation
- }
-}</pre>
\ No newline at end of file
+++ /dev/null
-This rule detects JUnit assertions in object equality. These assertions should be made by more specific methods, like assertEquals.
-<pre>
-public class FooTest extends TestCase {
- void testCode() {
- Object a, b;
-
- assertTrue(a.equals(b)); // violation
- assertEquals("a should equals b", a, b); // good usage
- }
-}</pre>
\ No newline at end of file
+++ /dev/null
-This rule detects JUnit assertions in object references equality. These assertions should be made by more specific methods, like assertNull, assertNotNull.
-<pre>
-public class FooTest extends TestCase {
- void testCode() {
- Object a = doSomething();
-
- assertTrue(a==null); // violation
- assertNull(a); // good usage
- assertTrue(a != null); // violation
- assertNotNull(a); // good usage
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-This rule detects JUnit assertions in object references equality. These assertions should be made by more specific methods, like assertSame, assertNotSame.
-<pre>
-public class FooTest extends TestCase {
- void testCode() {
- Object a, b;
-
- assertTrue(a==b); // violation
- assertSame(a, b); // good usage
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-The abstract class does not contain any abstract methods. An abstract class suggests an incomplete implementation, which is to be completed by subclasses implementing the abstract methods. If the class is intended to be used as a base class only (not to be instantiated direcly) a protected constructor can be provided prevent direct instantiation.
\ No newline at end of file
+++ /dev/null
-If the abstract class does not provides any methods, it may be just a data container that is not to be instantiated. In this case, it's probably better to use a private or a protected constructor in order to prevent instantiation than make the class misleadingly abstract. Example :
-<pre>
-public class abstract Example {
- String field;
- int otherField;
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Abstract classes should be named 'AbstractXXX'. Example :
- <pre>
-public abstract class Foo { // should be AbstractFoo
-}
- </pre>
\ No newline at end of file
+++ /dev/null
-Instantiation by way of private constructors from outside of the constructor's class often causes the generation of an accessor. A factory method, or non-privitization of the constructor can eliminate this situation. The generated class file is actually an interface. It gives the accessing class the ability to invoke a new hidden package scope constructor that takes the interface as a supplementary parameter. This turns a private constructor effectively into one with package scope, and is challenging to discern.
\ No newline at end of file
+++ /dev/null
-Finds empty string literals which are being added. This is an inefficient way to convert any type to a String.
\ No newline at end of file
+++ /dev/null
-Avoid concatenating characters as strings in StringBuffer.append.
\ No newline at end of file
+++ /dev/null
-Constructors and methods receiving arrays should clone objects and store the copy. This prevents that future changes from the user affect the internal functionality.
\ No newline at end of file
+++ /dev/null
-Avoid assignments in operands; this can make code more complicated and harder to read.
\ No newline at end of file
+++ /dev/null
-Identifies a possible unsafe usage of a static field.
\ No newline at end of file
+++ /dev/null
-Each class should declare at least one constructor.
\ No newline at end of file
+++ /dev/null
-Methods such as getDeclaredConstructors(), getDeclaredConstructor(Class[]) and setAccessible(), as the interface PrivilegedAction, allow to alter, at runtime, the visilibilty of variable, classes, or methods, even if they are private. Obviously, no one should do so, as such behavior is against everything encapsulation principal stands for.
\ No newline at end of file
+++ /dev/null
-Instead of copying data between two arrays, use System.arrayCopy method
\ No newline at end of file
+++ /dev/null
-Finds all places 'assert' is used as an identifier is used.
\ No newline at end of file
+++ /dev/null
-Object.finalize() is called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
\ No newline at end of file
+++ /dev/null
-Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block.
+++ /dev/null
-Code should never throw NPE under normal circumstances. A catch block may hide the original error, causing other more subtle errors in its wake.
\ No newline at end of file
+++ /dev/null
-This is dangerous because it casts too wide a net; it can catch things like OutOfMemoryError.
\ No newline at end of file
+++ /dev/null
-An interface should be used only to model a behaviour of a class: using an interface as a container of constants is a poor usage pattern.
\ No newline at end of file
+++ /dev/null
-One might assume that new BigDecimal(.1) is exactly equal to .1, but it is actually equal to .1000000000000000055511151231257827021181583404541015625. This is so because .1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the long value that is being passed in to the constructor is not exactly equal to .1, appearances notwithstanding. The (String) constructor, on the other hand, is perfectly predictable: 'new BigDecimal(.1)' is exactly equal to .1, as one would expect. Therefore, it is generally recommended that the (String) constructor be used in preference to this one.
\ No newline at end of file
+++ /dev/null
-Deeply nested if..then statements are hard to read.
\ No newline at end of file
+++ /dev/null
-Avoid using dollar signs in variable/method/class/interface names.
\ No newline at end of file
+++ /dev/null
-Code containing duplicate String literals can usually be improved by declaring the String as a constant field. Example :
-<pre>
-public class Foo {
- private void bar() {
- buz("Howdy");
- buz("Howdy");
- buz("Howdy");
- buz("Howdy");
- }
- private void buz(String x) {}
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Finds all places 'enum' is used as an identifier is used.
\ No newline at end of file
+++ /dev/null
-It is somewhat confusing to have a field name with the same name as a method. While this is totally legal, having information (field) and actions (method) is not clear naming. Example :
-<pre>
-public class Foo {
- Object bar;
- // bar is data or an action or both?
- void bar() {
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-It is somewhat confusing to have a field name matching the declaring class name. This probably means that type and or field names could be more precise. Example :
-<pre>
-public class Foo extends Bar {
- // There's probably a better name for foo
- int foo;
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Avoid using final local variables, turn them into fields. Example :
-<pre>
-public class MyClass {
- public void foo() {
- final String finalLocalVariable;
- }
-}
- </pre>
\ No newline at end of file
+++ /dev/null
-Each caught exception type should be handled in its own catch clause.
\ No newline at end of file
+++ /dev/null
-Detects when a new object is created inside a loop
\ No newline at end of file
+++ /dev/null
-Avoid using hard coded literals in conditional statements, declare those as static variables or private members.
+++ /dev/null
-Statements in a catch block that invoke accessors on the exception without using the information only add to code size. Either remove the invocation, or use the return result.
+++ /dev/null
-Using multiple unary operators may be a bug, and/or is confusing. Check the usage is not a bug, or consider simplifying the expression. Example :
-<pre>
-// These are typo bugs, or at best needlessly complex and confusing:
-int i = - -1;
-int j = + - +1;
-int z = ~~2;
-boolean b = !!true;
-boolean c = !!!true;
-
-// These are better:
-int i = 1;
-int j = -1;
-int z = 2;
-boolean b = true;
-boolean c = false;
-
-// And these just make your brain hurt:
-int i = ~-2;
-int j = -~7;
-</pre>
\ No newline at end of file
+++ /dev/null
-Avoid printStackTrace(); use a logger call instead.
\ No newline at end of file
+++ /dev/null
-Do not use protected fields in final classes since they cannot be subclassed. Clarify your intent by using private or package access modifiers instead.
\ No newline at end of file
+++ /dev/null
-Reassigning values to parameters is a questionable practice. Use a temporary local variable instead.
\ No newline at end of file
+++ /dev/null
-Catch blocks that merely rethrow a caught exception only add to code size and runtime complexity.
\ No newline at end of file
+++ /dev/null
-StringBuffers can grow quite a lot, and so may become a source of memory leak (if the owning class has a long life time). Example :
-<pre>
-class Foo {
- private StringBuffer memoryLeak;
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Method level synchronization can backfire when new code is added to the method. Block-level synchronization helps to ensure that only the code that needs synchronization gets it.
\ No newline at end of file
+++ /dev/null
-Avoid using ThreadGroup; although it is intended to be used in a threaded environment it contains methods that are not thread safe.
\ No newline at end of file
+++ /dev/null
-Catch blocks that merely rethrow a caught exception wrapped inside a new instance of the same type only add to code size and runtime complexity. Example :
-<pre>
-public class Foo {
- void bar() {
- try {
- // do something
- } catch (SomeException se) {
- // harmless comment
- throw new SomeException(se);
- }
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Avoid throwing a NullPointerException - it's confusing because most people will assume that the virtual machine threw it. Consider using an IllegalArgumentException instead; this will be clearly seen as a programmer-initiated exception.
\ No newline at end of file
+++ /dev/null
-Avoid throwing certain exception types. Rather than throw a raw RuntimeException, Throwable, Exception, or Error, use a subclassed exception or error instead.
\ No newline at end of file
+++ /dev/null
-An application with hard coded IP may become impossible to deploy in some case. It never hurts to externalize IP adresses.
\ No newline at end of file
+++ /dev/null
-As JVM and Java language offer already many help in creating application, it should be very rare to have to rely on non-java code. Even though, it is rare to actually have to use Java Native Interface (JNI). As the use of JNI make application less portable, and harder to maintain, it is not recommended.
\ No newline at end of file
+++ /dev/null
-Integer literals should not start with zero. Zero means that the rest of literal will be interpreted as an octal value.
\ No newline at end of file
+++ /dev/null
-Java uses the short type to reduce memory usage, not to optimize calculation. On the contrary, the jvm does not has an arithmetic capabilities with the type short. So, the P-code must convert the short into int, then do the proper caculation and then again, convert int to short. So, use of the "short" type may have a great effect on memory usage.
\ No newline at end of file
+++ /dev/null
-Use of the keyword "volatile" is general used to fine tune a Java application, and therefore, requires a good expertise of the Java Memory Model. Morover, its range of action is somewhat misknown. Therefore, the volatile keyword should not be used for maintenance purpose and portability.
\ No newline at end of file
+++ /dev/null
-Avoid equality comparisons with Double.NaN - these are likely to be logic errors.
\ No newline at end of file
+++ /dev/null
-If a class is a bean, or is referenced by a bean directly or indirectly it needs to be serializable. Member variables need to be marked as transient, static, or have accessor methods in the class. Marking variables as transient is the safest and easiest modification. Accessor methods should follow the Java naming conventions, i.e.if you have a variable foo, you should provide getFoo and setFoo methods.
\ No newline at end of file
+++ /dev/null
-Don't create instances of already existing BigInteger (BigInteger.ZERO, BigInteger.ONE) and for 1.5 on, BigInteger.TEN and BigDecimal (BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN)
\ No newline at end of file
+++ /dev/null
-Looks for methods named "getX()" with "boolean" as the return type. The convention is to name these methods "isX()".
\ No newline at end of file
+++ /dev/null
-Avoid instantiating Boolean objects; you can reference Boolean.TRUE, Boolean.FALSE, or call Boolean.valueOf() instead.
\ No newline at end of file
+++ /dev/null
-Use bitwise inversion to invert boolean values - it's the fastest way to do this. See http://www.javaspecialists.co.za/archive/newsletter.do?issue=042&locale=en_US for specific details
\ No newline at end of file
+++ /dev/null
-The null check is broken since it will throw a Nullpointer itself. The reason is that a method is called on the object when it is null. It is likely that you used || instead of && or vice versa.
\ No newline at end of file
+++ /dev/null
-In JDK 1.5, calling new Byte() causes memory allocation. Byte.valueOf() is more memory friendly. Example :
-<pre>
-public class Foo {
-private Byte i = new Byte(0); // change to Byte i =
-Byte.valueOf(0);
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Super should be called at the start of the method. Example :
-<pre>
-public class DummyActivity extends Activity {
- public void onCreate(Bundle bundle) {
- // missing call to super.onCreate(bundle)
- foo();
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-It is a good practice to call super() in a constructor. If super() is not called but another constructor (such as an overloaded constructor) is called, this rule will not report it.
\ No newline at end of file
+++ /dev/null
-Super should be called at the end of the method. Example :
-<pre>
-public class DummyActivity extends Activity {
- public void onPause() {
- foo();
- // missing call to super.onPause()
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Always check the return of one of the navigation method (next,previous,first,last) of a ResultSet. Indeed, if the value return is "false", the developer should deal with it !
\ No newline at end of file
+++ /dev/null
-if you need to get an array of a class from your Collection, you should pass an array of the desidered class as the parameter of the toArray method. Otherwise you will get a ClassCastException.
\ No newline at end of file
+++ /dev/null
-Class names should always begin with an upper case character.
\ No newline at end of file
+++ /dev/null
-A class with only private constructors should be final, unless the private constructor is called by a inner class. Example :
- <pre>
-public class Foo { //Should be final
- private Foo() { }
-}
- </pre>
\ No newline at end of file
+++ /dev/null
-The method clone() should only be implemented if the class implements the Cloneable interface with the exception of a final method that only throws CloneNotSupportedException. This version uses PMD's type resolution facilities, and can detect if the class implements or extends a Cloneable class
\ No newline at end of file
+++ /dev/null
-The method clone() should throw a CloneNotSupportedException.
\ No newline at end of file
+++ /dev/null
-Ensure that resources (like Connection, Statement, and ResultSet objects) are always closed after use. It does this by looking for code patterned like :
-<pre>
-Connection c = openConnection();
-try {
- // do stuff, and maybe catch something
-} finally {
- c.close();
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Sometimes two 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.
\ No newline at end of file
+++ /dev/null
-Use equals() to compare object references; avoid comparing them with ==.
\ No newline at end of file
+++ /dev/null
-In an if expression with an else clause, avoid negation in the test. For example, rephrase: if (x != y) diff(); else same(); as: if (x == y) same(); else diff(); Most if (x != y) cases without an else are often return cases, so consistent use of this rule makes the code easier to read. Also, this resolves trivial ordering problems, such as does the error case go first? or does the common case go first?.
\ No newline at end of file
+++ /dev/null
-Consecutively calling StringBuffer.append with String literals
\ No newline at end of file
+++ /dev/null
-Calling overridable methods during construction poses a risk of invoking methods on an incompletely constructed object
- and can be difficult to discern. It may leave the sub-class unable to construct its superclass or forced to replicate
- the construction process completely within itself, losing the ability to call super().
- If the default constructor contains a call to an overridable method, the subclass may be completely uninstantiable.
- Note that this includes method calls throughout the control flow graph - i.e., if a constructor Foo() calls
- a private method bar() that calls a public method buz(), this denotes a problem.
- <br/>Example :
-<pre>
-public class SeniorClass {
- public SeniorClass(){
- toString(); //may throw NullPointerException if overridden
- }
- public String toString(){
- return "IAmSeniorClass";
- }
-}
-public class JuniorClass extends SeniorClass {
- private String name;
- public JuniorClass(){
- super(); //Automatic call leads to NullPointerException
- name = "JuniorClass";
- }
- public String toString(){
- return name.toUpperCase();
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-This rule counts unique attributes, local variables and return types within an object. A number higher than specified threshold can indicate a high degree of coupling.
\ No newline at end of file
+++ /dev/null
-Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
\ No newline at end of file
+++ /dev/null
-The dataflow analysis tracks local definitions, undefinitions and references to variables on different paths on the data flow. From those informations there can be found various problems. 1. UR - Anomaly: There is a reference to a variable that was not defined before. This is a bug and leads to an error. 2. DU - Anomaly: A recently defined variable is undefined. These anomalies may appear in normal source text. 3. DD - Anomaly: A recently defined variable is redefined. This is ominous but don't have to be a bug.
\ No newline at end of file
+++ /dev/null
-Switch statements should have a default label. Example :
- <pre>
-public class Foo {
- void bar(int a) {
- switch (a) {
- case 1: // do something
- break;
- default: // the default case should be last, by convention
- break;
- case 2:
- break;
- }
- }
-}
- </pre>
\ No newline at end of file
+++ /dev/null
-Use explicit scoping instead of the default package private level.
\ No newline at end of file
+++ /dev/null
-Calls to System.gc(), Runtime.getRuntime().gc(), and System.runFinalization() are not advised. Code should have the same behavior whether the garbage collection is disabled using the option -Xdisableexplicitgc or not. Moreover, "modern" jvms do a very good job handling garbage collections. If memory usage issues unrelated to memory leaks develop within an application, it should be dealt with JVM options rather than within the code itself. Example :
-<pre>
- public class GCCall
-{
- public GCCall()
- {
- // Explicit gc call !
- System.gc();
- }
- public void doSomething()
- {
- // Explicit gc call !
- Runtime.getRuntime().gc();
- }
-
- public explicitGCcall() { // Explicit gc call ! System.gc(); }
-
- public void doSomething() { // Explicit gc call ! Runtime.getRuntime().gc(); }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Web applications should not call System.exit(), since only the web container or the application server should stop the JVM.
\ No newline at end of file
+++ /dev/null
-Errors are system exceptions. Do not extend them.
\ No newline at end of file
+++ /dev/null
-Use Environment.getExternalStorageDirectory() instead of "/sdcard".
+++ /dev/null
-Throwing exception in a finally block is confusing. It may mask exception or a defect of the code, it also render code cleanup uninstable. Example :
-<pre>
-public class Foo
-{
- public void bar()
- {
- try {
- // Here do some stuff
- }
- catch( Exception e) {
- // Handling the issue
- }
- finally
- {
- // is this really a good idea ?
- throw new Exception();
- }
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-The J2EE specification explicitly forbid use of threads.
\ No newline at end of file
+++ /dev/null
-Explicitly calling Thread.run() method will execute in the caller's thread of control. Instead, call Thread.start() for the intended behavior.
+++ /dev/null
-Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3).
\ No newline at end of file
+++ /dev/null
-Avoid importing anything from the 'sun.*' packages. These packages are not portable and are likely to change.
\ No newline at end of file
+++ /dev/null
-Do not nest JSF component custom actions inside a custom action that iterates over its body.
\ No newline at end of file
+++ /dev/null
-Partially created objects can be returned by the Double Checked Locking pattern when used in Java. An optimizing JRE may assign a reference to the baz variable before it creates the object the reference is intended to point to. <a href="http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html">More details</a>. Example :
-<pre>
-public class Foo {
- Object baz;
- Object bar() {
- if(baz == null) { //baz may be non-null yet not fully created
- synchronized(this){
- if(baz == null){
- baz = new Object();
- }
- }
- }
- return baz;
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Avoid duplicate import statements.
\ No newline at end of file
+++ /dev/null
-Empty Catch Block finds instances where an exception is caught, but nothing is done. In most circumstances, this swallows an exception which should either be acted on or reported.
\ No newline at end of file
+++ /dev/null
-If the finalize() method is empty, then it does not need to exist.
\ No newline at end of file
+++ /dev/null
-Avoid empty finally blocks - these can be deleted.
\ No newline at end of file
+++ /dev/null
-Empty If Statement finds instances where a condition is checked but nothing is done about it.
\ No newline at end of file
+++ /dev/null
-An empty initializer was found. Example :
-<pre>
-public class Foo {
-
- static {} // Why ?
-
- {} // Again, why ?
-
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-An empty method in an abstract class should be abstract instead, as developer may rely on this empty implementation rather than code the appropriate one.
- <pre>
-public abstract class ShouldBeAbstract
-{
- public Object couldBeAbstract()
- {
- // Should be abstract method ?
- return null;
- }
-
- public void couldBeAbstract()
- {
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-An empty statement (aka a semicolon by itself) that is not used as the sole body of a for loop or while loop is probably a bug. It could also be a double semicolon, which is useless and should be removed.
\ No newline at end of file
+++ /dev/null
-An empty static initializer was found.
\ No newline at end of file
+++ /dev/null
-Avoid empty switch statements.
\ No newline at end of file
+++ /dev/null
-Avoid empty synchronized blocks - they're useless.
\ No newline at end of file
+++ /dev/null
-Avoid empty try blocks - what's the point?
\ No newline at end of file
+++ /dev/null
-Empty While Statement finds all instances where a while statement does nothing. If it is a timing loop, then you should use Thread.sleep() for it; if it's a while loop that does a lot in the exit expression, rewrite it to make it clearer.
\ No newline at end of file
+++ /dev/null
-Inexperienced programmers sometimes confuse comparison concepts and use equals() to compare to null.
\ No newline at end of file
+++ /dev/null
-Using Exceptions as flow control leads to GOTOish code and obscures true exceptions when debugging.
\ No newline at end of file
+++ /dev/null
-Long Class files are indications that the class may be trying to do too much. Try to break it down, and reduce the size to something manageable.
\ No newline at end of file
+++ /dev/null
-A high number of imports can indicate a high degree of coupling within an object. Rule counts the number of unique imports and reports a violation if the count is above the user defined threshold.
\ No newline at end of file
+++ /dev/null
-Violations of this rule usually indicate that the method is doing too much. Try to reduce the method size by creating helper methods and removing any copy/pasted code.
\ No newline at end of file
+++ /dev/null
-Long parameter lists can indicate that a new object should be created to wrap the numerous parameters. Basically, try to group the parameters together.
\ No newline at end of file
+++ /dev/null
-A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it.
\ No newline at end of file
+++ /dev/null
-If a final field is assigned to a compile-time constant, it could be made static, thus saving overhead in each object at runtime.
\ No newline at end of file
+++ /dev/null
-If the finalize() is implemented, its last action should be to call super.finalize.
\ No newline at end of file
+++ /dev/null
-If the finalize() is implemented, it should do something besides just calling super.finalize().
\ No newline at end of file
+++ /dev/null
-Methods named finalize() should not have parameters. It is confusing and probably a bug to overload finalize(). It will not be called by the VM.
\ No newline at end of file
+++ /dev/null
-If you override finalize(), make it protected. If you make it public, other classes may call it.
\ No newline at end of file
+++ /dev/null
-Some for loops can be simplified to while loops - this makes them more concise.
\ No newline at end of file
+++ /dev/null
-Avoid using 'for' statements without using curly braces, like <code>for (int i=0; i<42;i++) foo();</code>
\ No newline at end of file
+++ /dev/null
-Generics names should be a one letter long and upper case.
+++ /dev/null
-When log messages are composed by concatenating strings, the whole section should be guarded by a isDebugEnabled() check to avoid performance and memory issues.
+++ /dev/null
-Avoid idempotent operations - they are have no effect. Example : <br/><code>int x = 2;<br/> x = x;</code>
\ No newline at end of file
+++ /dev/null
-Avoid using if..else statements without using curly braces.
\ No newline at end of file
+++ /dev/null
-Avoid using if statements without using curly braces.
\ No newline at end of file
+++ /dev/null
-Identifies private fields whose values never change once they are initialized either in the declaration of the field or by a constructor. This aids in converting existing classes to immutable classes.
\ No newline at end of file
+++ /dev/null
-No need to import a type that lives in the same package.
\ No newline at end of file
+++ /dev/null
-String.trim().length() is an inefficient way to check if a String is really empty, as it creates a new String object just to check its size. Consider creating a static function that loops through a string, checking Character.isWhitespace() on each character and returning false if a non-whitespace character is found.
\ No newline at end of file
+++ /dev/null
-Avoid concatenating non literals in a StringBuffer constructor or append().
\ No newline at end of file
+++ /dev/null
-Avoid instantiating an object just to call getClass() on it; use the .class public member instead. Example : replace <code>Class c = new String().getClass();</code> with <code>Class c = String.class;</code>
\ No newline at end of file
+++ /dev/null
-Failing to pre-size a StringBuffer properly could cause it to re-size many times during runtime. This rule checks the characters that are actually passed into StringBuffer.append(), but represents a best guess worst case scenario. An empty StringBuffer constructor initializes the object to 16 characters. This default is assumed if the length of the constructor can not be determined.
\ No newline at end of file
+++ /dev/null
-In JDK 1.5, calling new Integer() causes memory allocation. Integer.valueOf() is more memory friendly.
\ No newline at end of file
+++ /dev/null
-Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended.
- <br>Example :
- <pre>
-public class JumbledIncrementerRule1 {
- public void foo() {
- for (int i = 0; i < 10; i++) {
- for (int k = 0; k < 20; i++) {
- System.out.println("Hello");
- }
- }
- }
-}</pre>
\ No newline at end of file
+++ /dev/null
-The Local Home interface of a Session EJB should be suffixed by "LocalHome".
\ No newline at end of file
+++ /dev/null
-The Local Interface of a Session EJB should be suffixed by "Local".
\ No newline at end of file
+++ /dev/null
-A local variable assigned only once can be declared final. Example :
- <pre>
-public class Bar {
- public void foo () {
- String a = "a"; //if a will not be assigned again it is better to do this:
- final String b = "b";
- }
-}
- </pre>
\ No newline at end of file
+++ /dev/null
-In most cases, the Logger can be declared static and final.
\ No newline at end of file
+++ /dev/null
-In JDK 1.5, calling new Long() causes memory allocation. Long.valueOf() is more memory friendly. Example :
- <pre>
-public class Foo {
-private Long i = new Long(0); // change to Long i =
-Long.valueOf(0);
-}
- </pre>
\ No newline at end of file
+++ /dev/null
-Detects when a field, formal or local variable is declared with a long name.
\ No newline at end of file
+++ /dev/null
-Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead
\ No newline at end of file
+++ /dev/null
-The EJB Specification state that any MessageDrivenBean or SessionBean should be suffixed by Bean.
\ No newline at end of file
+++ /dev/null
-A method argument that is never assigned can be declared final.
\ No newline at end of file
+++ /dev/null
-Method names should always begin with a lower case character, and should not contain underscores. Example :
-<pre>
-public class Foo {
- public void fooStuff() {
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Exposing internal arrays directly allows the user to modify some code that could be critical. It is safer to return a copy of the array.
\ No newline at end of file
+++ /dev/null
-Non-constructor methods should not have the same name as the enclosing class. Example :
-<pre>
-public class MyClass {
- // this is bad because it is a method
- public void MyClass() {}
- // this is OK because it is a constructor
- public MyClass() {}
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Detects when a non-field has a name starting with 'm_'. This usually indicates a field and thus is confusing. Example :
-<pre>
-public class Foo {
- private int m_foo; // OK
- public void bar(String m_baz) { // Bad
- int m_boz = 42; // Bad
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-The null check here is misplaced. if the variable is null you'll get a NullPointerException.
- Either the check is useless (the variable will never be null) or it's incorrect.
- <br>Example :
- <pre>
-if (object1!=null && object2.equals(object1)) {
- ...
-}
- </pre>
\ No newline at end of file
+++ /dev/null
-A switch statement without an enclosed break statement may be a bug.
\ No newline at end of file
+++ /dev/null
-Classes that are serializable should provide a serialVersionUID field.
\ No newline at end of file
+++ /dev/null
-A class that has private constructors and does not have any static methods or fields cannot be used.
\ No newline at end of file
+++ /dev/null
-Normally only one logger is used in each class.
\ No newline at end of file
+++ /dev/null
-The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity. Example :
-<pre>
-public class Foo {
- void bar() {
- // lots of complicated code
- }
- }
-</pre>
\ No newline at end of file
+++ /dev/null
-This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines of code for a given constructor. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.
\ No newline at end of file
+++ /dev/null
-This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines of code for a given method. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.
\ No newline at end of file
+++ /dev/null
-This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines of code for a given type. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.
\ No newline at end of file
+++ /dev/null
-Detects when a class or interface does not have a package definition. Example :
- <pre>
-// no package declaration
-public class ClassInDefaultPackage {
-}
- </pre>
\ No newline at end of file
+++ /dev/null
-A non-case label (e.g. a named break/continue label) was present in a switch statement. This legal, but confusing. It is easy to mix up the case labels and the non-case labels.
\ No newline at end of file
+++ /dev/null
-A nonstatic initializer block will be called any time a constructor is invoked (just prior to invoking the constructor). While this is a valid language construct, it is rarely used and is confusing. Example :<br/><code>public class MyClass {<br/>// this block gets run before any call to a constructor {<br/>System.out.println("I am about to construct myself");<br/>}<br/>}</code>
\ No newline at end of file
+++ /dev/null
-Non-thread safe singletons can result in bad state changes. Eliminate static singletons if possible by instantiating the object directly. Static singletons are usually not needed as only a single instance exists anyway. Other possible fixes are to synchronize the entire method or to use an initialize-on-demand holder class (do not use the double-check idiom). See Effective Java, item 48.
\ No newline at end of file
+++ /dev/null
-Assigning a null to a variable (outside of its declaration) is usually bad form. Some times, the assignment is an indication that the programmer doesn't completely understand what is going on in the code. NOTE: This sort of assignment may in rare cases be useful to encourage garbage collection. If that's what you're using it for, by all means, disregard this rule :-)
\ No newline at end of file
+++ /dev/null
-A method should have only one exit point, and that should be the last statement in the method.
\ No newline at end of file
+++ /dev/null
-A call to Collection.toArray can use the Collection's size vs an empty Array of the desired type.
\ No newline at end of file
+++ /dev/null
-Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass. Example :
-<pre>
-// this is bad
-public class Bar {
- public boolean equals(Object o) {
- // do some comparison
- }
-}
-
-// and so is this
-public class Baz {
- public int hashCode() {
- // return some hash value
- }
-}
-
-// this is OK
-public class Foo {
- public boolean equals(Object other) {
- // do some comparison
- }
- public int hashCode() {
- // return some hash value
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Detects when a package definition contains upper case characters. Example :
-<pre>
-package com.MyCompany; // <- should be lower case name
-public class SomeClass {
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Position literals first in String comparisons - that way if the String is null you won't get a NullPointerException, it'll just return false.
\ No newline at end of file
+++ /dev/null
-Throwing a new exception from a catch block without passing the original exception into the new Exception will cause the true stack trace to be lost, and can make it difficult to debug effectively.
\ No newline at end of file
+++ /dev/null
-Object clone() should be implemented with super.clone(). Example :
- <pre>
-class Foo{
- public Object clone(){
- return new Foo(); // This is bad
- }
-}
- </pre>
\ No newline at end of file
+++ /dev/null
-Logger should normally be defined private static final and have the correct class. Private final Log log; is also allowed for rare cases when loggers need to be passed around, but the logger needs to be passed into the constructor.
\ No newline at end of file
+++ /dev/null
-Log.d calls should be protected by checking Config.LOGD first. Example :
-<pre>
-public class DummyActivity extends Activity {
- public void foo() {
- Log.d("TAG", "msg1"); // Bad
-
- bar();
-
- if (Config.LOGD) Log.d("TAG", "msg1"); // Good
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Log.v calls should be protected by checking Config.LOGV first. Example :
-<pre>
-public class DummyActivity extends Activity {
- public void foo() {
- Log.v("TAG", "msg1"); // Bad
- bar();
- if (Config.LOGV) Log.v("TAG", "msg1"); // Good
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Remote Interface of a Session EJB should NOT be suffixed.
\ No newline at end of file
+++ /dev/null
-Remote Home interface of a Session EJB should be suffixed by "Home".
\ No newline at end of file
+++ /dev/null
-Consider replacing this Enumeration with the newer java.util.Iterator
\ No newline at end of file
+++ /dev/null
-Consider replacing this Hashtable with the newer java.util.Map
\ No newline at end of file
+++ /dev/null
-Consider replacing Vector usages with the newer java.util.ArrayList if expensive threadsafe operation is not required.
\ No newline at end of file
+++ /dev/null
-For any method that returns an array, it's a better behavior to return an empty array rather than a null reference. Example :
-<pre>
-public class Example
-{
- // Not a good idea...
- public int []badBehavior()
- {
- // ...
- return null;
- }
-
- // Good behavior
- public String[] bonnePratique()
- {
- //...
- return new String[0];
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Avoid returning from a finally block - this can discard exceptions.
\ No newline at end of file
+++ /dev/null
-In JDK 1.5, calling new Short() causes memory allocation. Short.valueOf() is more memory friendly. Example :
- <pre>
-public class Foo {
-private Short i = new Short(0); // change to Short i =
-Short.valueOf(0);
-}
- </pre>
\ No newline at end of file
+++ /dev/null
-Detects when very short method names are used. Example :
-<pre>
-public class ShortMethod {
- public void a( int i ) { // Violation
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Detects when a field, local, or parameter has a very short name.
\ No newline at end of file
+++ /dev/null
-It is unclear which exceptions that can be thrown from the methods. It might be difficult to document and understand the vague interfaces. Use either a class derived from RuntimeException or a checked exception.
\ No newline at end of file
+++ /dev/null
-Be sure to specify a Locale when creating a new instance of SimpleDateFormat.
\ No newline at end of file
+++ /dev/null
-Avoid unnecessary comparisons in boolean expressions - this complicates simple code. Example :
-<pre>
-public class Bar {
- // can be simplified to
- // bar = isFoo();
- private boolean bar = (isFoo() == true);
-
- public isFoo() { return false;}
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Avoid unnecessary if..then..else statements when returning a boolean. Example :
-<pre>
-public class Foo {
- private int bar =2;
- public boolean isBarEqualsTo(int x) {
- // this bit of code
- if (bar == x) {
- return true;
- } else {
- return false;
- }
- // can be replaced with a simple
- // return bar == x;
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-No need to check for null before an instanceof; the instanceof keyword returns false when given a null argument.
\ No newline at end of file
+++ /dev/null
-Since it passes in a literal of length 1, this call to String.startsWith can be rewritten using String.charAt(0) to save some time.
\ No newline at end of file
+++ /dev/null
-A field that's only used by one method could perhaps be replaced by a local variable.
\ No newline at end of file
+++ /dev/null
-According to the J2EE specification (p.494), an EJB should not have any static fields with write access. However, static read only fields are allowed. This ensures proper behavior especially when instances are distributed by the container on several JREs.
\ No newline at end of file
+++ /dev/null
-StringBuffer sb = new StringBuffer('c'); The char will be converted into int to intialize StringBuffer size.
\ No newline at end of file
+++ /dev/null
-Avoid instantiating String objects; this is usually unnecessary.
\ No newline at end of file
+++ /dev/null
-Avoid calling toString() on String objects; this is unnecessary.
\ No newline at end of file
+++ /dev/null
-A field name is all in uppercase characters, which in Sun's Java naming conventions indicate a constant. However, the field is not final. Example :
-<pre>
-public class Foo {
- // this is bad, since someone could accidentally
- // do PI = 2.71828; which is actualy e
- // final double PI = 3.16; is ok
- double PI = 3.16;
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-The method name and parameter number are suspiciously close to equals(Object), which may mean you are intending to override the equals(Object) method. Example :
-<pre>
-public class Foo {
- public int equals(Object o) {
- // oops, this probably was supposed to be boolean equals
- }
- public boolean equals(String s) {
- // oops, this probably was supposed to be equals(Object)
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-The method name and return type are suspiciously close to hashCode(), which may mean you are intending to override the hashCode() method. Example :
-<pre>
-public class Foo {
- public int hashcode() {
- // oops, this probably was supposed to be hashCode
- }
-}</pre>
\ No newline at end of file
+++ /dev/null
-A suspicious octal escape sequence was found inside a String literal. The Java language specification (section 3.10.6) says an octal escape sequence inside a literal String shall consist of a backslash followed by: OctalDigit | OctalDigit OctalDigit | ZeroToThree OctalDigit OctalDigit Any octal escape sequence followed by non-octal digits can be confusing, e.g. "\038" is interpreted as the octal escape sequence "\03" followed by the literal character 8.
\ No newline at end of file
+++ /dev/null
-A high ratio of statements to labels in a switch statement implies that the switch statement is doing too much work. Consider moving the statements into new methods, or creating subclasses based on the switch variable.
\ No newline at end of file
+++ /dev/null
-Switch statements should have a default label. Example :
-<pre>
-public class Foo {
- public void bar() {
- int x = 2;
- switch (x) {
- case 2: int j = 8;
- }
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-System.(out|err).print is used, consider using a logger.
\ No newline at end of file
+++ /dev/null
-Swith are designed complex branches, and allow branches to share treatement. Using a switch for only a few branches is ill advised, as switches are not as easy to understand as if. In this case, it's most likely is a good idea to use a if statement instead, at least to increase code readability. Example :
-<pre>
-// With a minimumNumberCaseForASwitch of 3
-public class Foo {
- public void bar() {
- switch (condition) {
- case ONE:
- instruction;
- break;
- default:
- break; // not enough for a 'switch' stmt,
- // a simple 'if' stmt would have been more appropriate
- }
- }
-}
-</pre>
\ No newline at end of file
+++ /dev/null
-Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.
\ No newline at end of file
+++ /dev/null
-A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
\ No newline at end of file
+++ /dev/null
-If you overuse the static import feature, it can make your program unreadable and unmaintainable, polluting its namespace with all the static members you import. Readers of your code (including you, a few months after you wrote it) will not know which class a static member comes from (Sun 1.5 Language Guide).
\ No newline at end of file
+++ /dev/null
-Uncommented Empty Constructor finds instances where a constructor does not contain statements, but there is no comment. By explicitly commenting empty constructors it is easier to distinguish between intentional (commented) and unintentional empty constructors.
\ No newline at end of file
+++ /dev/null
-Uncommented Empty Method finds instances where a method does not contain statements, but there is no comment. By explicitly commenting empty methods it is easier to distinguish between intentional (commented) and unintentional empty methods.
\ No newline at end of file
+++ /dev/null
-Do not use if statements that are always true or always false.
\ No newline at end of file
+++ /dev/null
-Using equalsIgnoreCase() is faster than using toUpperCase/toLowerCase().equals()
\ No newline at end of file
+++ /dev/null
-This rule detects when a constructor is not necessary; i.e., when there's only one constructor, it's public, has an empty body, and takes no arguments.
\ No newline at end of file
+++ /dev/null
-Avoid unnecessary temporaries when converting primitives to Strings
\ No newline at end of file
+++ /dev/null
-When a class has the final modifier, all the methods are automatically final.
\ No newline at end of file
+++ /dev/null
-Avoid unnecessarily creating local variables
\ No newline at end of file
+++ /dev/null
-Sometimes expressions are wrapped in unnecessary parentheses, making them look like a function call. Example :
-<pre>
-public class Foo {
- boolean bar() {
- return (true);
- }
-}
- </pre>
\ No newline at end of file
+++ /dev/null
-Avoid unnecessary return statements
\ No newline at end of file
+++ /dev/null
-Parsing method should be called directy instead.
\ No newline at end of file
+++ /dev/null
-SimpleDateFormat is not synchronized. Sun recomends separate format instances for each thread. If multiple threads must access a static formatter, the formatter must be synchronized either on method or block level.
\ No newline at end of file
+++ /dev/null
-Avoid passing parameters to methods or constructors and then not using those parameters.
\ No newline at end of file
+++ /dev/null
-Avoid unused import statements. Example :
- <pre>
-// this is bad
-import java.io.File;
-public class Foo {}
- </pre>
\ No newline at end of file
+++ /dev/null
-Detects when a local variable is declared and/or assigned, but not used.
\ No newline at end of file
+++ /dev/null
-Fields in interfaces are automatically public static final, and methods are public abstract. Classes or interfaces nested in an interface are automatically public and static (all nested interfaces are automatically static). For historical reasons, modifiers which are implied by the context are accepted by the compiler, but are superfluous.
\ No newline at end of file
+++ /dev/null
-After checking an object reference for null, you should invoke equals() on that object rather than passing it to another object's equals() method.
\ No newline at end of file
+++ /dev/null
-Detects when a private field is declared and/or assigned a value, but not used.
\ No newline at end of file
+++ /dev/null
-Unused Private Method detects when a private method is declared but is unused. This PMD rule should be switched off and replaced by its equivalent from Squid that is more effective : it generates less false-positives and detects more dead code.
\ No newline at end of file
+++ /dev/null
-ArrayList is a much better Collection implementation than Vector.
\ No newline at end of file
+++ /dev/null
-The class java.util.Arrays has a asList method that should be use when you want to create a new List from an array of objects. It is faster than executing a loop to cpy all the elements of the array one by one
\ No newline at end of file
+++ /dev/null
-The isEmpty() method on java.util.Collection is provided to see if a collection has any elements. Comparing the value of size() to 0 merely duplicates existing behavior.
\ No newline at end of file
+++ /dev/null
-Since Java5 brought a new implementation of the Map interface, specially designed for concurrent application.
+++ /dev/null
-To make sure the full stacktrace is printed out, use the logging statement with 2 arguments: a String and a Throwable.
\ No newline at end of file
+++ /dev/null
-Using "==" or "!=" to compare strings only works if intern version is used on both sides.
\ No newline at end of file
+++ /dev/null
-Use String.indexOf(char) when checking for the index of a single character; it executes faster.
\ No newline at end of file
+++ /dev/null
-When doing a String.toLowerCase()/toUpperCase() call, use a Locale. This avoids problems with certain locales, i.e. Turkish.
\ No newline at end of file
+++ /dev/null
-Thread.notify() awakens a thread monitoring the object. If more than one thread is monitoring, then only one is chosen. The thread chosen is arbitrary; thus it's usually safer to call notifyAll() instead.
\ No newline at end of file
+++ /dev/null
-In J2EE getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead.
\ No newline at end of file
+++ /dev/null
-If you have a class that has nothing but static methods, consider making it a Singleton. Note that this doesn't apply to abstract classes, since their subclasses may well include non-static methods. Also, if you want this class to be a Singleton, remember to add a private constructor to prevent instantiation.
\ No newline at end of file
+++ /dev/null
-Finds usages of += for appending strings.
\ No newline at end of file
+++ /dev/null
-Use StringBuffer.length() to determine StringBuffer length rather than using StringBuffer.toString().equals() or StringBuffer.toString().length() ==.
\ No newline at end of file
+++ /dev/null
-An operation on an Immutable object (BigDecimal or BigInteger) won't change the object itself. The result of the operation is a new object. Therefore, ignoring the operation result is an error.
\ No newline at end of file
+++ /dev/null
-The overriding method merely calls the same method defined in a superclass
\ No newline at end of file
+++ /dev/null
-No need to call String.valueOf to append to a string; just use the valueOf() argument directly.
\ No newline at end of file
+++ /dev/null
-A variable naming conventions rule - customize this to your liking. Currently, it checks for final variables that should be fully capitalized and non-final variables that should not include underscores.
\ No newline at end of file
+++ /dev/null
-Avoid using 'while' statements without using curly braces.
\ No newline at end of file
+++ /dev/null
-PMD provides a very handy method for creating new rules by writing an XPath query. When the XPath query finds a match, a violation is created.
-Let's take a simple example: assume we have a Factory class that must be always declared final.
-We'd like to report a violation each time a declaration of Factory is not declared final. Consider the following class:
-<pre>
-public class a {
- Factory f1;
-
- void myMethod() {
- Factory f2;
- int a;
- }
-}
-</pre>
-The following expression does the magic we need:
-<pre>
-//VariableDeclarator
- [../Type/ReferenceType/ClassOrInterfaceType
- [@Image = 'Factory'] and ..[@Final='false']]
-</pre>
-See the <a href="http://pmd.sourceforge.net/xpathruletutorial.html" target="_blank">XPath rule tutorial</a> for more information.
+++ /dev/null
-pmd.version=${pmd.version}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<ruleset xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xmlns="http://pmd.sf.net/ruleset/1.0.0" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd" name="Sonar rules set" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <description>Sonar PMD rules generated configuration</description>
- <rule ref="rulesets/basic.xml/UnusedNullCheckInEquals" />
- <rule ref="rulesets/strings.xml/StringInstantiation" />
- <rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod" />
- <rule ref="rulesets/strictexception.xml/AvoidCatchingNPE" />
- <rule ref="rulesets/strictexception.xml/AvoidRethrowingException" />
- <rule ref="rulesets/migrating.xml/ReplaceEnumerationWithIterator" />
- <rule ref="rulesets/optimizations.xml/AvoidArrayLoops" />
- <rule ref="rulesets/unusedcode.xml/UnusedFormalParameter" />
- <rule ref="rulesets/basic.xml/EmptySwitchStatements" />
- <rule ref="rulesets/basic.xml/ClassCastExceptionWithToArray" />
- <rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException" />
- <rule ref="rulesets/unusedcode.xml/UnusedPrivateField" />
- <rule ref="rulesets/design.xml/CompareObjectsWithEquals" />
- <rule ref="rulesets/strings.xml/UseIndexOfChar" />
- <rule ref="rulesets/basic.xml/BigIntegerInstantiation" />
- <rule ref="rulesets/design.xml/FinalFieldCouldBeStatic" />
- <rule ref="rulesets/braces.xml/IfStmtsMustUseBraces" />
- <rule ref="rulesets/naming.xml/SuspiciousEqualsMethodName" />
- <rule ref="rulesets/design.xml/InstantiationToGetClass" />
- <rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName" />
- <rule ref="rulesets/coupling.xml/LooseCoupling" />
- <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable" />
- <rule ref="rulesets/strings.xml/UnnecessaryCaseChange" />
- <rule ref="rulesets/basic.xml/EmptySynchronizedBlock" />
- <rule ref="rulesets/design.xml/SingularField" />
- <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod" />
- <rule ref="rulesets/design.xml/CloseResource" />
- <rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable" />
- <rule ref="rulesets/basic.xml/EmptyWhileStmt" />
- <rule ref="rulesets/basic.xml/CollapsibleIfStatements" />
- <rule ref="rulesets/basic.xml/UselessOperationOnImmutable" />
- <rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable" />
- <rule ref="rulesets/basic.xml/UselessOverridingMethod" />
- <rule ref="rulesets/controversial.xml/UnusedModifier" />
- <rule ref="rulesets/design.xml/PreserveStackTrace" />
- <rule ref="rulesets/optimizations.xml/UseArraysAsList" />
- <rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes" />
- <rule ref="rulesets/basic.xml/EmptyIfStmt" />
- <rule ref="rulesets/design.xml/EqualsNull" />
- <rule ref="rulesets/basic.xml/BrokenNullCheck" />
- <rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging" />
- <rule ref="rulesets/strings.xml/InefficientStringBuffering" />
- <rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly" />
- <rule ref="rulesets/finalizers.xml/FinalizeOverloaded" />
- <rule ref="rulesets/naming.xml/ClassNamingConventions" />
- <rule ref="rulesets/controversial.xml/DontImportSun" />
- <rule ref="rulesets/imports.xml/DontImportJavaLang" />
- <rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass" />
- <rule ref="rulesets/strings.xml/StringBufferInstantiationWithChar" />
- <rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector" />
- <rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces" />
- <rule ref="rulesets/strings.xml/StringToString" />
- <rule ref="rulesets/design.xml/SimplifyConditional" />
- <rule ref="rulesets/migrating.xml/ReplaceVectorWithList" />
- <rule ref="rulesets/codesize.xml/NcssMethodCount">
- <properties>
- <property value="50" name="minimum"/>
- </properties>
- </rule>
- <rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace" />
- <rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass" />
- <rule ref="rulesets/naming.xml/SuspiciousConstantFieldName" />
- <rule ref="rulesets/codesize.xml/NcssTypeCount">
- <properties>
- <property value="800" name="minimum"/>
- </properties>
- </rule>
- <rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause" />
- <rule ref="rulesets/basic.xml/EmptyFinallyBlock" />
- <rule ref="rulesets/migrating.xml/IntegerInstantiation" />
- <rule ref="rulesets/naming.xml/AvoidDollarSigns" />
- <rule ref="rulesets/migrating.xml/AvoidAssertAsIdentifier" />
- <rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn" />
- <rule ref="rulesets/finalizers.xml/AvoidCallingFinalize" />
- <rule ref="rulesets/basic.xml/BooleanInstantiation" />
- <rule ref="rulesets/basic.xml/UnconditionalIfStatement" />
- <rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException" />
- <rule ref="rulesets/migrating.xml/ReplaceHashtableWithMap" />
- <rule ref="rulesets/basic.xml/AvoidDecimalLiteralsInBigDecimalConstructor" />
- <rule ref="rulesets/braces.xml/ForLoopsMustUseBraces" />
- <rule ref="rulesets/basic.xml/EmptyTryBlock" />
- <rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException" />
- <rule ref="rulesets/finalizers.xml/EmptyFinalizer" />
- <rule ref="rulesets/design.xml/IdempotentOperations" />
- <rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl" />
- <rule ref="rulesets/basic.xml/EmptyStaticInitializer" />
- <rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize" />
- <rule ref="rulesets/strings.xml/UseStringBufferLength" />
- <rule ref="rulesets/migrating.xml/AvoidEnumAsIdentifier" />
- <rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces" />
- <rule ref="rulesets/logging-java.xml/SystemPrintln" />
- <rule ref="rulesets/strings.xml/UselessStringValueOf" />
- <rule ref="rulesets/strings.xml/AvoidDuplicateLiterals" />
-</ruleset>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<ruleset xmlns="http://pmd.sf.net/ruleset/1.0.0" 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" name="Sonar rules set" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <description>Generated by Sonar</description>
- <rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray" />
- <rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly" />
-</ruleset>
+++ /dev/null
-<rules>
- <rule key="JUnitStaticSuite">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/junit.xml/JUnitStaticSuite]]></configKey>
- </rule>
- <rule key="JUnitSpelling">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/junit.xml/JUnitSpelling]]></configKey>
- </rule>
- <rule key="JUnitAssertionsShouldIncludeMessage">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage]]></configKey>
- </rule>
- <rule key="JUnitTestsShouldIncludeAssert">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/junit.xml/JUnitTestsShouldIncludeAssert]]></configKey>
- </rule>
- <rule key="TestClassWithoutTestCases">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/junit.xml/TestClassWithoutTestCases]]></configKey>
- </rule>
- <rule key="UnnecessaryBooleanAssertion">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/junit.xml/UnnecessaryBooleanAssertion]]></configKey>
- </rule>
- <rule key="UseAssertEqualsInsteadOfAssertTrue">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue]]></configKey>
- </rule>
- <rule key="UseAssertSameInsteadOfAssertTrue">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue]]></configKey>
- </rule>
- <rule key="UseAssertNullInsteadOfAssertTrue">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/junit.xml/UseAssertNullInsteadOfAssertTrue]]></configKey>
- </rule>
- <rule key="SimplifyBooleanAssertion">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/junit.xml/SimplifyBooleanAssertion]]></configKey>
- </rule>
-</rules>
+++ /dev/null
-<rules>
-
- <rule key="DontCallThreadRun">
- <priority>MAJOR</priority>
- <configKey>rulesets/basic.xml/DontCallThreadRun</configKey>
- </rule>
-
- <rule key="GuardDebugLogging">
- <priority>MAJOR</priority>
- <configKey>rulesets/logging-jakarta-commons.xml/GuardDebugLogging</configKey>
- </rule>
-
- <rule key="GenericsNaming">
- <priority>MAJOR</priority>
- <configKey>rulesets/naming.xml/GenericsNaming</configKey>
- </rule>
-
- <rule key="AvoidCatchingGenericException">
- <priority>MAJOR</priority>
- <configKey>rulesets/strictexception.xml/AvoidCatchingGenericException</configKey>
- </rule>
-
- <rule key="AvoidLosingExceptionInformation">
- <priority>MAJOR</priority>
- <configKey>rulesets/strictexception.xml/AvoidLosingExceptionInformation</configKey>
- </rule>
-
- <rule key="AvoidLiteralsInIfCondition">
- <priority>MAJOR</priority>
- <configKey>rulesets/controversial.xml/AvoidLiteralsInIfCondition</configKey>
- </rule>
-
- <rule key="UseConcurrentHashMap">
- <priority>MAJOR</priority>
- <configKey>rulesets/controversial.xml/UseConcurrentHashMap</configKey>
- </rule>
-
- <rule key="DoNotHardCodeSDCard">
- <priority>MAJOR</priority>
- <configKey>rulesets/android.xml/DoNotHardCodeSDCard</configKey>
- </rule>
-
- <rule key="AvoidThrowingNewInstanceOfSameException">
- <priority>MAJOR</priority>
- <configKey>rulesets/strictexception.xml/AvoidThrowingNewInstanceOfSameException</configKey>
- </rule>
-
- <rule key="CallSuperFirst">
- <priority>MAJOR</priority>
- <configKey>rulesets/android.xml/CallSuperFirst</configKey>
- </rule>
-
- <rule key="CallSuperLast">
- <priority>MAJOR</priority>
- <configKey>rulesets/android.xml/CallSuperLast</configKey>
- </rule>
-
- <rule key="ProtectLogD">
- <priority>MAJOR</priority>
- <configKey>rulesets/android.xml/ProtectLogD</configKey>
- </rule>
-
- <rule key="ProtectLogV">
- <priority>MAJOR</priority>
- <configKey>rulesets/android.xml/ProtectLogV</configKey>
- </rule>
-
- <rule key="EmptyInitializer">
- <priority>MAJOR</priority>
- <configKey>rulesets/basic.xml/EmptyInitializer</configKey>
- </rule>
-
- <rule key="CyclomaticComplexity">
- <priority>MAJOR</priority>
- <configKey>rulesets/codesize.xml/CyclomaticComplexity</configKey>
- <param key="reportLevel" type="INTEGER">
- </param>
- <param key="showClassesComplexity" type="BOOLEAN">
- </param>
- <param key="showMethodsComplexity" type="BOOLEAN">
- </param>
- </rule>
-
- <rule key="AvoidStringBufferField">
- <priority>MAJOR</priority>
- <configKey>rulesets/strings.xml/AvoidStringBufferField</configKey>
- </rule>
-
- <rule key="DoNotThrowExceptionInFinally">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strictexception.xml/DoNotThrowExceptionInFinally]]></configKey>
- </rule>
-
- <rule key="TooManyMethods">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/codesize.xml/TooManyMethods]]></configKey>
- <param key="maxmethods" type="INTEGER">
- </param>
- </rule>
-
- <rule key="ReturnEmptyArrayRatherThanNull">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/design.xml/ReturnEmptyArrayRatherThanNull]]></configKey>
- </rule>
-
- <rule key="TooFewBranchesForASwitchStatement">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/design.xml/TooFewBranchesForASwitchStatement]]></configKey>
- <param key="minimumNumberCaseForASwitch" type="INTEGER">
- </param>
- </rule>
-
- <rule key="AbstractClassWithoutAnyMethod">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/AbstractClassWithoutAnyMethod]]></configKey>
- </rule>
-
- <rule key="DoNotCallGarbageCollectionExplicitly">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/controversial.xml/DoNotCallGarbageCollectionExplicitly]]></configKey>
- </rule>
-
- <rule key="AvoidMultipleUnaryOperators">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/AvoidMultipleUnaryOperators]]></configKey>
- </rule>
-
- <rule key="DoubleCheckedLocking">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/DoubleCheckedLocking]]></configKey>
- </rule>
-
- <rule key="NPathComplexity">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/codesize.xml/NPathComplexity]]></configKey>
- <param key="minimum" type="INTEGER">
- </param>
- </rule>
-
- <rule key="SimplifyBooleanReturns">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/design.xml/SimplifyBooleanReturns]]></configKey>
- </rule>
-
- <rule key="SimplifyBooleanExpressions">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/SimplifyBooleanExpressions]]></configKey>
- </rule>
-
- <rule key="SwitchStmtsShouldHaveDefault">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/SwitchStmtsShouldHaveDefault]]></configKey>
- </rule>
-
- <rule key="DefaultLabelNotLastInSwitchStmt">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/DefaultLabelNotLastInSwitchStmt]]></configKey>
- </rule>
-
- <rule key="ClassWithOnlyPrivateConstructorsShouldBeFinal">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/ClassWithOnlyPrivateConstructorsShouldBeFinal]]></configKey>
- </rule>
-
- <rule key="AvoidFinalLocalVariable">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/AvoidFinalLocalVariable]]></configKey>
- </rule>
-
- <rule key="UnnecessaryParentheses">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/UnnecessaryParentheses]]></configKey>
- </rule>
-
- <rule key="OverrideBothEqualsAndHashcode">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/basic.xml/OverrideBothEqualsAndHashcode]]></configKey>
- </rule>
-
- <rule key="UnusedImports">
- <priority>INFO</priority>
- <configKey><![CDATA[rulesets/imports.xml/UnusedImports]]></configKey>
- </rule>
-
- <rule key="LocalVariableCouldBeFinal">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/optimizations.xml/LocalVariableCouldBeFinal]]></configKey>
- </rule>
-
- <rule key="AbstractNaming">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/AbstractNaming]]></configKey>
- </rule>
-
- <rule key="NoPackage">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/NoPackage]]></configKey>
- </rule>
-
- <rule key="PackageCase">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/PackageCase]]></configKey>
- </rule>
-
- <rule key="ByteInstantiation">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/migrating.xml/ByteInstantiation]]></configKey>
- </rule>
-
- <rule key="ShortInstantiation">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/migrating.xml/ShortInstantiation]]></configKey>
- </rule>
-
- <rule key="LongInstantiation">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/migrating.xml/LongInstantiation]]></configKey>
- </rule>
-
- <rule key="ProperCloneImplementation">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/clone.xml/ProperCloneImplementation]]></configKey>
- </rule>
-
- <rule key="EmptyFinalizer">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/finalizers.xml/EmptyFinalizer]]></configKey>
- </rule>
-
- <rule key="FinalizeOnlyCallsSuperFinalize">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize]]></configKey>
- </rule>
-
- <rule key="FinalizeOverloaded">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/finalizers.xml/FinalizeOverloaded]]></configKey>
- </rule>
-
- <rule key="FinalizeDoesNotCallSuperFinalize">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize]]></configKey>
- </rule>
-
- <rule key="FinalizeShouldBeProtected">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/finalizers.xml/FinalizeShouldBeProtected]]></configKey>
- </rule>
-
- <rule key="AvoidCallingFinalize">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/finalizers.xml/AvoidCallingFinalize]]></configKey>
- </rule>
-
- <rule key="DontNestJsfInJstlIteration">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic-jsf.xml/DontNestJsfInJstlIteration]]></configKey>
- </rule>
-
- <rule key="UnusedPrivateField">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/unusedcode.xml/UnusedPrivateField]]></configKey>
- </rule>
-
- <rule key="UnusedLocalVariable">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/unusedcode.xml/UnusedLocalVariable]]></configKey>
- </rule>
-
- <rule key="UnusedPrivateMethod">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/unusedcode.xml/UnusedPrivateMethod]]></configKey>
- </rule>
-
- <rule key="UnusedFormalParameter">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/unusedcode.xml/UnusedFormalParameter]]></configKey>
- </rule>
-
- <rule key="UnnecessaryConstructor">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/UnnecessaryConstructor]]></configKey>
- </rule>
-
- <rule key="NullAssignment">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/NullAssignment]]></configKey>
- </rule>
-
- <rule key="OnlyOneReturn">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/OnlyOneReturn]]></configKey>
- </rule>
-
- <rule key="UnusedModifier">
- <priority>INFO</priority>
- <configKey><![CDATA[rulesets/controversial.xml/UnusedModifier]]></configKey>
- </rule>
-
- <rule key="AssignmentInOperand">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/AssignmentInOperand]]></configKey>
- </rule>
-
- <rule key="AtLeastOneConstructor">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/AtLeastOneConstructor]]></configKey>
- </rule>
-
- <rule key="DontImportSun">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/DontImportSun]]></configKey>
- </rule>
-
- <rule key="SuspiciousOctalEscape">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/SuspiciousOctalEscape]]></configKey>
- </rule>
-
- <rule key="CallSuperInConstructor">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/CallSuperInConstructor]]></configKey>
- </rule>
-
- <rule key="SingularField">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/design.xml/SingularField]]></configKey>
- </rule>
-
- <rule key="DefaultPackage">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/DefaultPackage]]></configKey>
- </rule>
-
- <rule key="BooleanInversion">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/BooleanInversion]]></configKey>
- </rule>
-
- <rule key="DataflowAnomalyAnalysis">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/DataflowAnomalyAnalysis]]></configKey>
- <param key="maxviolations" type="INTEGER">
- </param>
- <param key="maxpaths" type="INTEGER">
- </param>
- </rule>
-
- <rule key="CouplingBetweenObjects">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/coupling.xml/CouplingBetweenObjects]]></configKey>
- <param key="threshold" type="INTEGER">
- </param>
- </rule>
-
- <rule key="ExcessiveImports">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/coupling.xml/ExcessiveImports]]></configKey>
- <param key="minimum" type="INTEGER">
- </param>
- </rule>
-
- <rule key="LooseCoupling">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/coupling.xml/LooseCoupling]]></configKey>
- </rule>
-
- <rule key="MethodArgumentCouldBeFinal">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/optimizations.xml/MethodArgumentCouldBeFinal]]></configKey>
- </rule>
-
- <rule key="AvoidInstantiatingObjectsInLoops">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops]]></configKey>
- </rule>
-
- <rule key="UseArrayListInsteadOfVector">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/optimizations.xml/UseArrayListInsteadOfVector]]></configKey>
- </rule>
-
- <rule key="SimplifyStartsWith">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/optimizations.xml/SimplifyStartsWith]]></configKey>
- </rule>
-
- <rule key="UseStringBufferForStringAppends">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/optimizations.xml/UseStringBufferForStringAppends]]></configKey>
- </rule>
-
- <rule key="UseArraysAsList">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/optimizations.xml/UseArraysAsList]]></configKey>
- </rule>
-
- <rule key="AvoidArrayLoops">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/optimizations.xml/AvoidArrayLoops]]></configKey>
- </rule>
-
- <rule key="UnnecessaryWrapperObjectCreation">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/optimizations.xml/UnnecessaryWrapperObjectCreation]]></configKey>
- </rule>
-
- <rule key="UseProperClassLoader">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/j2ee.xml/UseProperClassLoader]]></configKey>
- </rule>
-
- <rule key="EmptyCatchBlock">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/basic.xml/EmptyCatchBlock]]></configKey>
- <param key="allowCommentedBlocks" type="BOOLEAN">
- </param>
- </rule>
-
- <rule key="EmptyIfStmt">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/basic.xml/EmptyIfStmt]]></configKey>
- </rule>
-
- <rule key="EmptyWhileStmt">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/basic.xml/EmptyWhileStmt]]></configKey>
- </rule>
-
- <rule key="EmptyTryBlock">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/EmptyTryBlock]]></configKey>
- </rule>
-
- <rule key="EmptyFinallyBlock">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/basic.xml/EmptyFinallyBlock]]></configKey>
- </rule>
-
- <rule key="EmptySwitchStatements">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/EmptySwitchStatements]]></configKey>
- </rule>
-
- <rule key="JumbledIncrementer">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/JumbledIncrementer]]></configKey>
- </rule>
-
- <rule key="ForLoopShouldBeWhileLoop">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/ForLoopShouldBeWhileLoop]]></configKey>
- </rule>
-
- <rule key="UnnecessaryConversionTemporary">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/UnnecessaryConversionTemporary]]></configKey>
- </rule>
-
- <rule key="ReturnFromFinallyBlock">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/ReturnFromFinallyBlock]]></configKey>
- </rule>
-
- <rule key="EmptySynchronizedBlock">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/basic.xml/EmptySynchronizedBlock]]></configKey>
- </rule>
-
- <rule key="UnnecessaryReturn">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/UnnecessaryReturn]]></configKey>
- </rule>
-
- <rule key="EmptyStaticInitializer">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/EmptyStaticInitializer]]></configKey>
- </rule>
-
- <rule key="UnconditionalIfStatement">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/basic.xml/UnconditionalIfStatement]]></configKey>
- </rule>
-
- <rule key="EmptyStatementNotInLoop">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/EmptyStatementNotInLoop]]></configKey>
- </rule>
-
- <rule key="BooleanInstantiation">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/BooleanInstantiation]]></configKey>
- </rule>
-
- <rule key="UnnecessaryFinalModifier">
- <priority>INFO</priority>
- <configKey><![CDATA[rulesets/basic.xml/UnnecessaryFinalModifier]]></configKey>
- </rule>
-
- <rule key="CollapsibleIfStatements">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/CollapsibleIfStatements]]></configKey>
- </rule>
-
- <rule key="UselessOverridingMethod">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/UselessOverridingMethod]]></configKey>
- <param key="ignoreAnnotations" type="BOOLEAN">
- </param>
- </rule>
-
- <rule key="ClassCastExceptionWithToArray">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/ClassCastExceptionWithToArray]]></configKey>
- </rule>
-
- <rule key="AvoidDecimalLiteralsInBigDecimalConstructor">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/AvoidDecimalLiteralsInBigDecimalConstructor]]></configKey>
- </rule>
-
- <rule key="UselessOperationOnImmutable">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/basic.xml/UselessOperationOnImmutable]]></configKey>
- </rule>
-
- <rule key="MisplacedNullCheck">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/basic.xml/MisplacedNullCheck]]></configKey>
- </rule>
-
- <rule key="UnusedNullCheckInEquals">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/UnusedNullCheckInEquals]]></configKey>
- </rule>
-
- <rule key="AvoidThreadGroup">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/basic.xml/AvoidThreadGroup]]></configKey>
- </rule>
-
- <rule key="BrokenNullCheck">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/basic.xml/BrokenNullCheck]]></configKey>
- </rule>
-
- <rule key="BigIntegerInstantiation">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/BigIntegerInstantiation]]></configKey>
- </rule>
-
- <rule key="AvoidUsingOctalValues">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/AvoidUsingOctalValues]]></configKey>
- </rule>
-
- <rule key="UseSingleton">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/UseSingleton]]></configKey>
- </rule>
-
- <rule key="AvoidDeeplyNestedIfStmts">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/AvoidDeeplyNestedIfStmts]]></configKey>
- <param key="problemDepth" type="INTEGER">
- </param>
- </rule>
-
- <rule key="AvoidReassigningParameters">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/AvoidReassigningParameters]]></configKey>
- </rule>
-
- <rule key="SwitchDensity">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/SwitchDensity]]></configKey>
- <param key="minimum" type="INTEGER">
- </param>
- </rule>
-
- <rule key="ConstructorCallsOverridableMethod">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/ConstructorCallsOverridableMethod]]></configKey>
- </rule>
-
- <rule key="AccessorClassGeneration">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/AccessorClassGeneration]]></configKey>
- </rule>
-
- <rule key="FinalFieldCouldBeStatic">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/design.xml/FinalFieldCouldBeStatic]]></configKey>
- </rule>
-
- <rule key="CloseResource">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/CloseResource]]></configKey>
- <param key="types" type="STRING">
- </param>
- <param key="closeTargets" type="STRING">
- </param>
- </rule>
-
- <rule key="NonStaticInitializer">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/NonStaticInitializer]]></configKey>
- </rule>
-
- <rule key="NonCaseLabelInSwitchStatement">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/NonCaseLabelInSwitchStatement]]></configKey>
- </rule>
-
- <rule key="OptimizableToArrayCall">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/OptimizableToArrayCall]]></configKey>
- </rule>
-
- <rule key="BadComparison">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/BadComparison]]></configKey>
- </rule>
-
- <rule key="EqualsNull">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/design.xml/EqualsNull]]></configKey>
- </rule>
-
- <rule key="ConfusingTernary">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/ConfusingTernary]]></configKey>
- </rule>
-
- <rule key="InstantiationToGetClass">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/InstantiationToGetClass]]></configKey>
- </rule>
-
- <rule key="IdempotentOperations">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/IdempotentOperations]]></configKey>
- </rule>
-
- <rule key="SimpleDateFormatNeedsLocale">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/SimpleDateFormatNeedsLocale]]></configKey>
- </rule>
-
- <rule key="ImmutableField">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/ImmutableField]]></configKey>
- </rule>
-
- <rule key="UseLocaleWithCaseConversions">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/UseLocaleWithCaseConversions]]></configKey>
- </rule>
-
- <rule key="AvoidProtectedFieldInFinalClass">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/AvoidProtectedFieldInFinalClass]]></configKey>
- </rule>
-
- <rule key="AssignmentToNonFinalStatic">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/AssignmentToNonFinalStatic]]></configKey>
- </rule>
-
- <rule key="MissingStaticMethodInNonInstantiatableClass">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass]]></configKey>
- </rule>
-
- <rule key="AvoidSynchronizedAtMethodLevel">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/AvoidSynchronizedAtMethodLevel]]></configKey>
- </rule>
-
- <rule key="MissingBreakInSwitch">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/design.xml/MissingBreakInSwitch]]></configKey>
- </rule>
-
- <rule key="UseNotifyAllInsteadOfNotify">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/UseNotifyAllInsteadOfNotify]]></configKey>
- </rule>
-
- <rule key="AvoidInstanceofChecksInCatchClause">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/design.xml/AvoidInstanceofChecksInCatchClause]]></configKey>
- </rule>
-
- <rule key="AbstractClassWithoutAbstractMethod">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/AbstractClassWithoutAbstractMethod]]></configKey>
- </rule>
-
- <rule key="SimplifyConditional">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/SimplifyConditional]]></configKey>
- </rule>
-
- <rule key="CompareObjectsWithEquals">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/CompareObjectsWithEquals]]></configKey>
- </rule>
-
- <rule key="PositionLiteralsFirstInComparisons">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/PositionLiteralsFirstInComparisons]]></configKey>
- </rule>
-
- <rule key="UnnecessaryLocalBeforeReturn">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/UnnecessaryLocalBeforeReturn]]></configKey>
- </rule>
-
- <rule key="NonThreadSafeSingleton">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/NonThreadSafeSingleton]]></configKey>
- <param key="checkNonStaticMethods" type="BOOLEAN">
- </param>
- <param key="checkNonStaticFields" type="BOOLEAN">
- </param>
- </rule>
-
- <rule key="UncommentedEmptyMethod">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/UncommentedEmptyMethod]]></configKey>
- </rule>
-
- <rule key="UncommentedEmptyConstructor">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/UncommentedEmptyConstructor]]></configKey>
- <param key="ignoreExplicitConstructorInvocation" type="BOOLEAN">
- </param>
- </rule>
-
- <rule key="AvoidConstantsInterface">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/AvoidConstantsInterface]]></configKey>
- </rule>
-
- <rule key="UnsynchronizedStaticDateFormatter">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/UnsynchronizedStaticDateFormatter]]></configKey>
- </rule>
-
- <rule key="PreserveStackTrace">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/PreserveStackTrace]]></configKey>
- </rule>
-
- <rule key="UseCollectionIsEmpty">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/design.xml/UseCollectionIsEmpty]]></configKey>
- </rule>
-
- <rule key="MethodReturnsInternalArray">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/sunsecure.xml/MethodReturnsInternalArray]]></configKey>
- </rule>
-
- <rule key="ArrayIsStoredDirectly">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/sunsecure.xml/ArrayIsStoredDirectly]]></configKey>
- </rule>
-
- <rule key="AvoidCatchingThrowable">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/strictexception.xml/AvoidCatchingThrowable]]></configKey>
- </rule>
-
- <rule key="SignatureDeclareThrowsException">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strictexception.xml/SignatureDeclareThrowsException]]></configKey>
- </rule>
-
- <rule key="ExceptionAsFlowControl">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strictexception.xml/ExceptionAsFlowControl]]></configKey>
- </rule>
-
- <rule key="AvoidCatchingNPE">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strictexception.xml/AvoidCatchingNPE]]></configKey>
- </rule>
-
- <rule key="AvoidThrowingRawExceptionTypes">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes]]></configKey>
- </rule>
-
- <rule key="AvoidThrowingNullPointerException">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strictexception.xml/AvoidThrowingNullPointerException]]></configKey>
- </rule>
-
- <rule key="AvoidRethrowingException">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strictexception.xml/AvoidRethrowingException]]></configKey>
- </rule>
-
- <rule key="BeanMembersShouldSerialize">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/javabeans.xml/BeanMembersShouldSerialize]]></configKey>
- <param key="prefix" type="STRING">
- </param>
- </rule>
-
- <rule key="MissingSerialVersionUID">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/javabeans.xml/MissingSerialVersionUID]]></configKey>
- </rule>
-
- <rule key="CloneMethodMustImplementCloneable">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/clone.xml/CloneMethodMustImplementCloneable]]></configKey>
- </rule>
-
- <rule key="AvoidDuplicateLiterals">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/AvoidDuplicateLiterals]]></configKey>
- <param key="threshold" type="INTEGER">
- </param>
- <param key="skipAnnotations" type="BOOLEAN">
- </param>
- <param key="exceptionlist" type="STRING">
- </param>
- <param key="separator" type="STRING">
- </param>
- <param key="exceptionfile" type="STRING">
- </param>
- </rule>
-
- <rule key="StringInstantiation">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/StringInstantiation]]></configKey>
- </rule>
-
- <rule key="StringToString">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/StringToString]]></configKey>
- </rule>
-
- <rule key="InefficientStringBuffering">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/InefficientStringBuffering]]></configKey>
- </rule>
-
- <rule key="UnnecessaryCaseChange">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/UnnecessaryCaseChange]]></configKey>
- </rule>
-
- <rule key="UseStringBufferLength">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/UseStringBufferLength]]></configKey>
- </rule>
-
- <rule key="AppendCharacterWithChar">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/AppendCharacterWithChar]]></configKey>
- </rule>
-
- <rule key="ConsecutiveLiteralAppends">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/ConsecutiveLiteralAppends]]></configKey>
- <param key="threshold" type="INTEGER">
- </param>
- </rule>
-
- <rule key="UseIndexOfChar">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/UseIndexOfChar]]></configKey>
- </rule>
-
- <rule key="InefficientEmptyStringCheck">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/InefficientEmptyStringCheck]]></configKey>
- </rule>
-
- <rule key="InsufficientStringBufferDeclaration">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/InsufficientStringBufferDeclaration]]></configKey>
- </rule>
-
- <rule key="UselessStringValueOf">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/UselessStringValueOf]]></configKey>
- </rule>
-
- <rule key="StringBufferInstantiationWithChar">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/StringBufferInstantiationWithChar]]></configKey>
- </rule>
-
- <rule key="ExcessiveMethodLength">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/codesize.xml/ExcessiveMethodLength]]></configKey>
- <param key="minimum" type="INTEGER">
- </param>
- </rule>
-
- <rule key="ExcessiveParameterList">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/codesize.xml/ExcessiveParameterList]]></configKey>
- <param key="minimum" type="INTEGER">
- </param>
- </rule>
-
- <rule key="ExcessiveClassLength">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/codesize.xml/ExcessiveClassLength]]></configKey>
- <param key="minimum" type="INTEGER">
- </param>
- </rule>
-
- <rule key="ExcessivePublicCount">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/codesize.xml/ExcessivePublicCount]]></configKey>
- <param key="minimum" type="INTEGER">
- </param>
- </rule>
-
- <rule key="TooManyFields">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/codesize.xml/TooManyFields]]></configKey>
- <param key="maxfields" type="INTEGER">
- </param>
- </rule>
-
- <rule key="NcssMethodCount">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/codesize.xml/NcssMethodCount]]></configKey>
- <param key="minimum" type="INTEGER">
- </param>
- </rule>
-
- <rule key="NcssTypeCount">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/codesize.xml/NcssTypeCount]]></configKey>
- <param key="minimum" type="INTEGER">
- </param>
- </rule>
-
- <rule key="NcssConstructorCount">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/codesize.xml/NcssConstructorCount]]></configKey>
- <param key="minimum" type="INTEGER">
- </param>
- </rule>
-
- <rule key="DuplicateImports">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/imports.xml/DuplicateImports]]></configKey>
- </rule>
-
- <rule key="DontImportJavaLang">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/imports.xml/DontImportJavaLang]]></configKey>
- </rule>
-
- <rule key="ImportFromSamePackage">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/imports.xml/ImportFromSamePackage]]></configKey>
- </rule>
-
- <rule key="CloneThrowsCloneNotSupportedException">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/clone.xml/CloneThrowsCloneNotSupportedException]]></configKey>
- </rule>
-
- <rule key="UseCorrectExceptionLogging">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging]]></configKey>
- </rule>
-
- <rule key="ProperLogger">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/logging-jakarta-commons.xml/ProperLogger]]></configKey>
- <param key="staticLoggerName" type="STRING">
- </param>
- </rule>
-
- <rule key="ShortVariable">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/ShortVariable]]></configKey>
- </rule>
-
- <rule key="LongVariable">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/LongVariable]]></configKey>
- <param key="minimum" type="INTEGER">
- </param>
- </rule>
-
- <rule key="ShortMethodName">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/ShortMethodName]]></configKey>
- </rule>
-
- <rule key="VariableNamingConventions">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/VariableNamingConventions]]></configKey>
- <param key="staticPrefix" type="STRING">
- </param>
- <param key="staticSuffix" type="STRING">
- </param>
- <param key="memberPrefix" type="STRING">
- </param>
- <param key="memberSuffix" type="STRING">
- </param>
- </rule>
-
- <rule key="MethodNamingConventions">
- <priority>MAJOR</priority>
- <configKey>rulesets/naming.xml/MethodNamingConventions</configKey>
- </rule>
-
- <rule key="ClassNamingConventions">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/ClassNamingConventions]]></configKey>
- </rule>
-
- <rule key="AvoidDollarSigns">
- <priority>MINOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/AvoidDollarSigns]]></configKey>
- </rule>
-
- <rule key="MethodWithSameNameAsEnclosingClass">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/MethodWithSameNameAsEnclosingClass]]></configKey>
- </rule>
-
- <rule key="SuspiciousHashcodeMethodName">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/SuspiciousHashcodeMethodName]]></configKey>
- </rule>
-
- <rule key="SuspiciousConstantFieldName">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/SuspiciousConstantFieldName]]></configKey>
- </rule>
-
- <rule key="SuspiciousEqualsMethodName">
- <priority>CRITICAL</priority>
- <configKey><![CDATA[rulesets/naming.xml/SuspiciousEqualsMethodName]]></configKey>
- </rule>
-
- <rule key="AvoidFieldNameMatchingTypeName">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/AvoidFieldNameMatchingTypeName]]></configKey>
- </rule>
-
- <rule key="AvoidFieldNameMatchingMethodName">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/AvoidFieldNameMatchingMethodName]]></configKey>
- </rule>
-
- <rule key="MisleadingVariableName">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/MisleadingVariableName]]></configKey>
- </rule>
-
- <rule key="ReplaceVectorWithList">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/migrating.xml/ReplaceVectorWithList]]></configKey>
- </rule>
-
- <rule key="ReplaceHashtableWithMap">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/migrating.xml/ReplaceHashtableWithMap]]></configKey>
- </rule>
-
- <rule key="ReplaceEnumerationWithIterator">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/migrating.xml/ReplaceEnumerationWithIterator]]></configKey>
- </rule>
-
- <rule key="AvoidEnumAsIdentifier">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/migrating.xml/AvoidEnumAsIdentifier]]></configKey>
- </rule>
-
- <rule key="AvoidAssertAsIdentifier">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/migrating.xml/AvoidAssertAsIdentifier]]></configKey>
- </rule>
-
- <rule key="IntegerInstantiation">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/migrating.xml/IntegerInstantiation]]></configKey>
- </rule>
-
- <rule key="MoreThanOneLogger">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/logging-java.xml/MoreThanOneLogger]]></configKey>
- </rule>
-
- <rule key="LoggerIsNotStaticFinal">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/logging-java.xml/LoggerIsNotStaticFinal]]></configKey>
- </rule>
-
- <rule key="SystemPrintln">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/logging-java.xml/SystemPrintln]]></configKey>
- </rule>
-
- <rule key="AvoidPrintStackTrace">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/logging-java.xml/AvoidPrintStackTrace]]></configKey>
- </rule>
-
- <rule key="IfStmtsMustUseBraces">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/braces.xml/IfStmtsMustUseBraces]]></configKey>
- </rule>
-
- <rule key="WhileLoopsMustUseBraces">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/braces.xml/WhileLoopsMustUseBraces]]></configKey>
- </rule>
-
- <rule key="IfElseStmtsMustUseBraces">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/braces.xml/IfElseStmtsMustUseBraces]]></configKey>
- </rule>
-
- <rule key="ForLoopsMustUseBraces">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/braces.xml/ForLoopsMustUseBraces]]></configKey>
- </rule>
-
- <rule key="AvoidUsingHardCodedIP">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/AvoidUsingHardCodedIP]]></configKey>
- <param key="pattern" type="REGULAR_EXPRESSION">
- </param>
- </rule>
-
- <rule key="CheckResultSet">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/basic.xml/CheckResultSet]]></configKey>
- </rule>
-
- <rule key="AvoidUsingShortType">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/AvoidUsingShortType]]></configKey>
- </rule>
-
- <rule key="AvoidUsingVolatile">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/AvoidUsingVolatile]]></configKey>
- </rule>
-
- <rule key="AvoidUsingNativeCode">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/AvoidUsingNativeCode]]></configKey>
- </rule>
-
- <rule key="AvoidAccessibilityAlteration">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/controversial.xml/AvoidAccessibilityAlteration]]></configKey>
- </rule>
-
- <rule key="EmptyMethodInAbstractClassShouldBeAbstract">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/design.xml/EmptyMethodInAbstractClassShouldBeAbstract]]></configKey>
- </rule>
-
- <rule key="TooManyStaticImports">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/imports.xml/TooManyStaticImports]]></configKey>
- <param key="maximumStaticImports" type="INTEGER">
- </param>
- </rule>
-
- <rule key="DoNotCallSystemExit">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/j2ee.xml/DoNotCallSystemExit]]></configKey>
- </rule>
-
- <rule key="StaticEJBFieldShouldBeFinal">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/j2ee.xml/StaticEJBFieldShouldBeFinal]]></configKey>
- </rule>
-
- <rule key="DoNotUseThreads">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/j2ee.xml/DoNotUseThreads]]></configKey>
- </rule>
-
- <rule key="MDBAndSessionBeanNamingConvention">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/j2ee.xml/MDBAndSessionBeanNamingConvention]]></configKey>
- </rule>
-
- <rule key="RemoteSessionInterfaceNamingConvention">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/j2ee.xml/RemoteSessionInterfaceNamingConvention]]></configKey>
- </rule>
-
- <rule key="LocalInterfaceSessionNamingConvention">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/j2ee.xml/LocalInterfaceSessionNamingConvention]]></configKey>
- </rule>
-
- <rule key="LocalHomeNamingConvention">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/j2ee.xml/LocalHomeNamingConvention]]></configKey>
- </rule>
-
- <rule key="RemoteInterfaceNamingConvention">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/j2ee.xml/RemoteInterfaceNamingConvention]]></configKey>
- </rule>
-
- <rule key="UseEqualsToCompareStrings">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strings.xml/UseEqualsToCompareStrings]]></configKey>
- </rule>
-
- <rule key="DoNotExtendJavaLangError">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/strictexception.xml/DoNotExtendJavaLangError]]></configKey>
- </rule>
-
- <rule key="AddEmptyString">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/optimizations.xml/AddEmptyString]]></configKey>
- </rule>
-
- <rule key="BooleanGetMethodName">
- <priority>MAJOR</priority>
- <configKey><![CDATA[rulesets/naming.xml/BooleanGetMethodName]]></configKey>
- <param key="checkParameterizedMethods" type="BOOLEAN">
- </param>
- </rule>
-
- <rule key="XPathRule">
- <priority>MAJOR</priority>
- <configKey><![CDATA[net.sourceforge.pmd.rules.XPathRule]]></configKey>
- <cardinality>MULTIPLE</cardinality>
- <param key="xpath" type="TEXT">
- </param>
- <param key="message" type="STRING">
- </param>
- </rule>
-
-</rules>
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import net.sourceforge.pmd.Report;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.ProjectFileSystem;
-import org.sonar.api.utils.SonarException;
-
-import java.io.File;
-import java.io.IOException;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.matches;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-public class PmdConfigurationTest {
- PmdConfiguration configuration;
-
- Settings settings = new Settings();
- ProjectFileSystem fs = mock(ProjectFileSystem.class);
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- @Before
- public void setUpPmdConfiguration() {
- configuration = new PmdConfiguration(fs, settings);
- }
-
- @Test
- public void should_return_default_target_xml_report_when_property_is_not_set() {
- File targetXMLReport = configuration.getTargetXMLReport();
-
- assertThat(targetXMLReport).isNull();
- }
-
- @Test
- public void should_set_target_xml_report() {
- when(fs.resolvePath("pmd-result.xml")).thenReturn(new File("/workingDir/pmd-result.xml"));
-
- settings.setProperty(PmdConfiguration.PROPERTY_GENERATE_XML, true);
- File targetXMLReport = configuration.getTargetXMLReport();
-
- assertThat(targetXMLReport).isEqualTo(new File("/workingDir/pmd-result.xml"));
- }
-
- @Test
- public void should_dump_xml_rule_set() throws IOException {
- when(fs.writeToWorkingDirectory("<rules>", "pmd.xml")).thenReturn(new File("/workingDir/pmd.xml"));
-
- File rulesFile = configuration.dumpXmlRuleSet("pmd", "<rules>");
-
- assertThat(rulesFile).isEqualTo(new File("/workingDir/pmd.xml"));
- }
-
- @Test
- public void should_fail_to_dump_xml_rule_set() throws IOException {
- when(fs.writeToWorkingDirectory("<xml>", "pmd.xml")).thenThrow(new IOException("BUG"));
-
- expectedException.expect(SonarException.class);
- expectedException.expectMessage("Fail to save the PMD configuration");
-
- configuration.dumpXmlRuleSet("pmd", "<xml>");
- }
-
- @Test
- public void should_dump_xml_report() throws IOException {
- when(fs.writeToWorkingDirectory(matches("(?s).*<pmd.*>.*</pmd>"), eq("pmd-result.xml"))).thenReturn(new File("/workingDir/pmd-result.xml"));
-
- settings.setProperty(PmdConfiguration.PROPERTY_GENERATE_XML, true);
- File reportFile = configuration.dumpXmlReport(new Report());
-
- assertThat(reportFile).isEqualTo(new File("/workingDir/pmd-result.xml"));
- }
-
- @Test
- public void should_ignore_xml_report_when_property_is_not_set() {
- File reportFile = configuration.dumpXmlReport(new Report());
-
- assertThat(reportFile).isNull();
- verifyZeroInteractions(fs);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import com.google.common.base.Charsets;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.RuleContext;
-import net.sourceforge.pmd.RuleSets;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.InputFile;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.ProjectFileSystem;
-import org.sonar.test.TestUtils;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.Collections;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-public class PmdExecutorTest {
- PmdExecutor pmdExecutor;
-
- Project project = mock(Project.class);
- ProjectFileSystem projectFileSystem = mock(ProjectFileSystem.class);
- RulesProfile rulesProfile = mock(RulesProfile.class);
- PmdProfileExporter pmdProfileExporter = mock(PmdProfileExporter.class);
- PmdConfiguration pmdConfiguration = mock(PmdConfiguration.class);
- PmdTemplate pmdTemplate = mock(PmdTemplate.class);
-
- @Before
- public void setUpPmdExecutor() {
- pmdExecutor = Mockito.spy(new PmdExecutor(project, projectFileSystem, rulesProfile, pmdProfileExporter, pmdConfiguration));
-
- doReturn(pmdTemplate).when(pmdExecutor).createPmdTemplate();
- }
-
- @Test
- public void should_execute_pmd_on_source_files_and_test_files() {
- InputFile srcFile = file("src/Class.java");
- InputFile tstFile = file("test/ClassTest.java");
- when(pmdProfileExporter.exportProfile(PmdConstants.REPOSITORY_KEY, rulesProfile)).thenReturn(TestUtils.getResourceContent("/org/sonar/plugins/pmd/simple.xml"));
- when(pmdProfileExporter.exportProfile(PmdConstants.TEST_REPOSITORY_KEY, rulesProfile)).thenReturn(TestUtils.getResourceContent("/org/sonar/plugins/pmd/junit.xml"));
- when(projectFileSystem.getSourceCharset()).thenReturn(Charsets.UTF_8);
- when(projectFileSystem.mainFiles(Java.KEY)).thenReturn(Arrays.asList(srcFile));
- when(projectFileSystem.testFiles(Java.KEY)).thenReturn(Arrays.asList(tstFile));
-
- Report report = pmdExecutor.execute();
-
- verify(pmdTemplate).process(eq(srcFile), eq(Charsets.UTF_8), any(RuleSets.class), any(RuleContext.class));
- verify(pmdTemplate).process(eq(tstFile), eq(Charsets.UTF_8), any(RuleSets.class), any(RuleContext.class));
- assertThat(report).isNotNull();
- }
-
- @Test
- public void should_dump_configuration_as_xml() {
- when(pmdProfileExporter.exportProfile(PmdConstants.REPOSITORY_KEY, rulesProfile)).thenReturn(TestUtils.getResourceContent("/org/sonar/plugins/pmd/simple.xml"));
- when(pmdProfileExporter.exportProfile(PmdConstants.TEST_REPOSITORY_KEY, rulesProfile)).thenReturn(TestUtils.getResourceContent("/org/sonar/plugins/pmd/junit.xml"));
-
- Report report = pmdExecutor.execute();
-
- verify(pmdConfiguration).dumpXmlReport(report);
- }
-
- @Test
- public void should_dump_ruleset_as_xml() {
- InputFile srcFile = file("src/Class.java");
- InputFile tstFile = file("test/ClassTest.java");
- when(pmdProfileExporter.exportProfile(PmdConstants.REPOSITORY_KEY, rulesProfile)).thenReturn(TestUtils.getResourceContent("/org/sonar/plugins/pmd/simple.xml"));
- when(pmdProfileExporter.exportProfile(PmdConstants.TEST_REPOSITORY_KEY, rulesProfile)).thenReturn(TestUtils.getResourceContent("/org/sonar/plugins/pmd/junit.xml"));
- when(projectFileSystem.mainFiles(Java.KEY)).thenReturn(Arrays.asList(srcFile));
- when(projectFileSystem.testFiles(Java.KEY)).thenReturn(Arrays.asList(tstFile));
-
- pmdExecutor.execute();
-
- verify(pmdConfiguration).dumpXmlRuleSet(PmdConstants.REPOSITORY_KEY, TestUtils.getResourceContent("/org/sonar/plugins/pmd/simple.xml"));
- verify(pmdConfiguration).dumpXmlRuleSet(PmdConstants.TEST_REPOSITORY_KEY, TestUtils.getResourceContent("/org/sonar/plugins/pmd/junit.xml"));
- }
-
- @Test
- public void should_ignore_empty_test_dir() {
- InputFile srcFile = file("src/Class.java");
- doReturn(pmdTemplate).when(pmdExecutor).createPmdTemplate();
- when(pmdProfileExporter.exportProfile(PmdConstants.REPOSITORY_KEY, rulesProfile)).thenReturn(TestUtils.getResourceContent("/org/sonar/plugins/pmd/simple.xml"));
- when(projectFileSystem.getSourceCharset()).thenReturn(Charsets.UTF_8);
- when(projectFileSystem.mainFiles(Java.KEY)).thenReturn(Arrays.asList(srcFile));
- when(projectFileSystem.testFiles(Java.KEY)).thenReturn(Collections.<InputFile> emptyList());
-
- pmdExecutor.execute();
-
- verify(pmdTemplate).process(eq(srcFile), eq(Charsets.UTF_8), any(RuleSets.class), any(RuleContext.class));
- verifyNoMoreInteractions(pmdTemplate);
- }
-
- static InputFile file(String path) {
- InputFile inputFile = mock(InputFile.class);
- when(inputFile.getFile()).thenReturn(new File(path));
- return inputFile;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import org.junit.Test;
-import org.sonar.api.rules.RulePriority;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class PmdLevelUtilsTest {
- @Test
- public void should_get_priority_from_level() {
- assertThat(PmdLevelUtils.fromLevel("1")).isSameAs(RulePriority.BLOCKER);
- assertThat(PmdLevelUtils.fromLevel("2")).isSameAs(RulePriority.CRITICAL);
- assertThat(PmdLevelUtils.fromLevel("3")).isSameAs(RulePriority.MAJOR);
- assertThat(PmdLevelUtils.fromLevel("4")).isSameAs(RulePriority.MINOR);
- assertThat(PmdLevelUtils.fromLevel("5")).isSameAs(RulePriority.INFO);
- assertThat(PmdLevelUtils.fromLevel("?")).isNull();
- assertThat(PmdLevelUtils.fromLevel(null)).isNull();
- }
-
- @Test
- public void should_get_level_from_priority() {
- assertThat(PmdLevelUtils.toLevel(RulePriority.BLOCKER)).isEqualTo("1");
- assertThat(PmdLevelUtils.toLevel(RulePriority.CRITICAL)).isEqualTo("2");
- assertThat(PmdLevelUtils.toLevel(RulePriority.MAJOR)).isEqualTo("3");
- assertThat(PmdLevelUtils.toLevel(RulePriority.MINOR)).isEqualTo("4");
- assertThat(PmdLevelUtils.toLevel(RulePriority.INFO)).isEqualTo("5");
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import org.junit.Test;
-import org.sonar.api.Extension;
-
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class PmdPluginTest {
- PmdPlugin plugin = new PmdPlugin();
-
- @Test
- public void should_contain_both_rule_repositories() {
- List<Class<? extends Extension>> extensions = plugin.getExtensions();
-
- assertThat(extensions).contains(PmdRuleRepository.class, PmdUnitTestsRuleRepository.class);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.sonar.api.platform.ServerFileSystem;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.RuleQuery;
-import org.sonar.api.rules.XMLRuleParser;
-import org.sonar.api.utils.SonarException;
-import org.sonar.api.utils.ValidationMessages;
-import org.sonar.plugins.pmd.xml.PmdProperty;
-import org.sonar.plugins.pmd.xml.PmdRule;
-import org.sonar.test.TestUtils;
-
-import java.io.StringReader;
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.test.MoreConditions.equalsIgnoreEOL;
-
-public class PmdProfileExporterTest {
- PmdProfileExporter exporter = new PmdProfileExporter();
-
- @Test
- public void should_export_pmd_profile() {
- String importedXml = TestUtils.getResourceContent("/org/sonar/plugins/pmd/export_simple.xml");
-
- String exportedXml = exporter.exportProfile(PmdConstants.REPOSITORY_KEY, importProfile(importedXml));
-
- assertThat(exportedXml).satisfies(equalsIgnoreEOL(importedXml));
- }
-
- @Test
- public void should_export_empty_configuration_as_xml() {
- String exportedXml = exporter.exportProfile(PmdConstants.REPOSITORY_KEY, RulesProfile.create());
-
- assertThat(exportedXml).satisfies(equalsIgnoreEOL("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ruleset />"));
- }
-
- @Test
- public void should_export_xPath_rule() {
- Rule rule = Rule.create(PmdConstants.REPOSITORY_KEY, "MyOwnRule", "This is my own xpath rule.")
- .setConfigKey(PmdConstants.XPATH_CLASS)
- .setRepositoryKey(PmdConstants.REPOSITORY_KEY);
- rule.createParameter(PmdConstants.XPATH_EXPRESSION_PARAM);
- rule.createParameter(PmdConstants.XPATH_MESSAGE_PARAM);
-
- RulesProfile profile = RulesProfile.create();
- ActiveRule xpath = profile.activateRule(rule, null);
- xpath.setParameter(PmdConstants.XPATH_EXPRESSION_PARAM, "//FieldDeclaration");
- xpath.setParameter(PmdConstants.XPATH_MESSAGE_PARAM, "This is bad");
-
- String exportedXml = exporter.exportProfile(PmdConstants.REPOSITORY_KEY, profile);
-
- assertThat(exportedXml).satisfies(equalsIgnoreEOL(TestUtils.getResourceContent("/org/sonar/plugins/pmd/export_xpath_rules.xml")));
- }
-
- @Test(expected = SonarException.class)
- public void should_fail_if_message_not_provided_for_xPath_rule() {
- PmdRule rule = new PmdRule(PmdConstants.XPATH_CLASS);
-
- rule.addProperty(new PmdProperty(PmdConstants.XPATH_EXPRESSION_PARAM, "xpathExpression"));
- rule.setName("MyOwnRule");
-
- exporter.processXPathRule("xpathKey", rule);
- }
-
- @Test
- public void should_process_xPath_rule() {
- PmdRule rule = new PmdRule(PmdConstants.XPATH_CLASS);
- rule.setName("MyOwnRule");
- rule.addProperty(new PmdProperty(PmdConstants.XPATH_EXPRESSION_PARAM, "xpathExpression"));
- rule.addProperty(new PmdProperty(PmdConstants.XPATH_MESSAGE_PARAM, "message"));
-
- exporter.processXPathRule("xpathKey", rule);
-
- assertThat(rule.getMessage()).isEqualTo("message");
- assertThat(rule.getRef()).isNull();
- assertThat(rule.getClazz()).isEqualTo(PmdConstants.XPATH_CLASS);
- assertThat(rule.getProperty(PmdConstants.XPATH_MESSAGE_PARAM)).isNull();
- assertThat(rule.getName()).isEqualTo("xpathKey");
- assertThat(rule.getProperty(PmdConstants.XPATH_EXPRESSION_PARAM).getValue()).isEqualTo("xpathExpression");
- }
-
- @Test(expected = SonarException.class)
- public void should_fail_if_xPath_not_provided() {
- PmdRule rule = new PmdRule(PmdConstants.XPATH_CLASS);
- rule.setName("MyOwnRule");
- rule.addProperty(new PmdProperty(PmdConstants.XPATH_MESSAGE_PARAM, "This is bad"));
-
- exporter.processXPathRule("xpathKey", rule);
- }
-
- static RulesProfile importProfile(String configuration) {
- PmdRuleRepository pmdRuleRepository = new PmdRuleRepository(mock(ServerFileSystem.class), new XMLRuleParser());
- RuleFinder ruleFinder = createRuleFinder(pmdRuleRepository.createRules());
- PmdProfileImporter importer = new PmdProfileImporter(ruleFinder);
-
- return importer.importProfile(new StringReader(configuration), ValidationMessages.create());
- }
-
- static RuleFinder createRuleFinder(final List<Rule> rules) {
- RuleFinder ruleFinder = mock(RuleFinder.class);
- when(ruleFinder.find(any(RuleQuery.class))).then(new Answer<Rule>() {
- public Rule answer(InvocationOnMock invocation) {
- RuleQuery query = (RuleQuery) invocation.getArguments()[0];
- for (Rule rule : rules) {
- if (query.getConfigKey().equals(rule.getConfigKey())) {
- return rule.setRepositoryKey(PmdConstants.REPOSITORY_KEY);
- }
- }
- return null;
- }
- });
- return ruleFinder;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.RulePriority;
-import org.sonar.api.rules.RuleQuery;
-import org.sonar.api.utils.ValidationMessages;
-import org.sonar.plugins.pmd.xml.PmdRuleset;
-import org.sonar.test.TestUtils;
-
-import java.io.Reader;
-import java.io.StringReader;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class PmdProfileImporterTest {
- PmdProfileImporter importer;
- ValidationMessages messages;
-
- @Before
- public void setUpImporter() {
- messages = ValidationMessages.create();
- importer = new PmdProfileImporter(createRuleFinder());
- }
-
- @Test
- public void should_import_pmd_ruleset() {
- Reader reader = read("/org/sonar/plugins/pmd/simple.xml");
-
- PmdRuleset pmdRuleset = importer.parsePmdRuleset(reader, messages);
-
- assertThat(pmdRuleset.getPmdRules()).hasSize(3);
- }
-
- @Test
- public void should_import_simple_profile() {
- Reader reader = read("/org/sonar/plugins/pmd/simple.xml");
-
- RulesProfile profile = importer.importProfile(reader, messages);
-
- assertThat(profile.getActiveRules()).hasSize(3);
- assertThat(profile.getActiveRuleByConfigKey("pmd", "rulesets/coupling.xml/ExcessiveImports")).isNotNull();
- assertThat(profile.getActiveRuleByConfigKey("pmd", "rulesets/design.xml/UseNotifyAllInsteadOfNotify")).isNotNull();
- assertThat(messages.hasErrors()).isFalse();
- }
-
- @Test
- public void should_import_profile_with_xpath_rule() {
- Reader reader = read("/org/sonar/plugins/pmd/export_xpath_rules.xml");
-
- RulesProfile profile = importer.importProfile(reader, messages);
-
- assertThat(profile.getActiveRules()).isEmpty();
- assertThat(messages.hasWarnings()).isTrue();
- }
-
- @Test
- public void should_import_parameter() {
- Reader reader = read("/org/sonar/plugins/pmd/simple.xml");
-
- RulesProfile profile = importer.importProfile(reader, messages);
- ActiveRule activeRule = profile.getActiveRuleByConfigKey("pmd", "rulesets/coupling.xml/ExcessiveImports");
-
- assertThat(activeRule.getParameter("max")).isEqualTo("30");
- }
-
- @Test
- public void should_import_default_priority() {
- Reader reader = read("/org/sonar/plugins/pmd/simple.xml");
-
- RulesProfile profile = importer.importProfile(reader, messages);
- ActiveRule activeRule = profile.getActiveRuleByConfigKey("pmd", "rulesets/coupling.xml/ExcessiveImports");
-
- assertThat(activeRule.getSeverity()).isSameAs(RulePriority.BLOCKER);
- }
-
- @Test
- public void should_import_priority() {
- Reader reader = read("/org/sonar/plugins/pmd/simple.xml");
-
- RulesProfile profile = importer.importProfile(reader, messages);
-
- ActiveRule activeRule = profile.getActiveRuleByConfigKey("pmd", "rulesets/design.xml/UseNotifyAllInsteadOfNotify");
- assertThat(activeRule.getSeverity()).isSameAs(RulePriority.MINOR);
-
- activeRule = profile.getActiveRuleByConfigKey("pmd", "rulesets/coupling.xml/CouplingBetweenObjects");
- assertThat(activeRule.getSeverity()).isSameAs(RulePriority.CRITICAL);
- }
-
- @Test
- public void should_import_pmd_configuration_with_unknown_nodes() {
- Reader reader = read("/org/sonar/plugins/pmd/complex-with-unknown-nodes.xml");
-
- RulesProfile profile = importer.importProfile(reader, messages);
-
- assertThat(profile.getActiveRules()).hasSize(3);
- }
-
- @Test
- public void should_deal_with_unsupported_property() {
- Reader reader = read("/org/sonar/plugins/pmd/simple.xml");
-
- RulesProfile profile = importer.importProfile(reader, messages);
- ActiveRule check = profile.getActiveRuleByConfigKey("pmd", "rulesets/coupling.xml/CouplingBetweenObjects");
-
- assertThat(check.getParameter("threshold")).isNull();
- assertThat(messages.getWarnings()).hasSize(1);
- }
-
- @Test
- public void should_fail_on_invalid_xml() {
- Reader reader = new StringReader("not xml");
-
- importer.importProfile(reader, messages);
-
- assertThat(messages.getErrors()).hasSize(1);
- }
-
- @Test
- public void should_warn_on_unknown_rule() {
- Reader reader = read("/org/sonar/plugins/pmd/simple.xml");
-
- importer = new PmdProfileImporter(mock(RuleFinder.class));
- RulesProfile profile = importer.importProfile(reader, messages);
-
- assertThat(profile.getActiveRules()).isEmpty();
- assertThat(messages.getWarnings()).hasSize(3);
- }
-
- static Reader read(String path) {
- return new StringReader(TestUtils.getResourceContent(path));
- }
-
- static RuleFinder createRuleFinder() {
- RuleFinder ruleFinder = mock(RuleFinder.class);
- when(ruleFinder.find(any(RuleQuery.class))).then(new Answer<Rule>() {
- public Rule answer(InvocationOnMock invocation) {
- RuleQuery query = (RuleQuery) invocation.getArguments()[0];
- Rule rule = Rule.create(query.getRepositoryKey(), "", "").setConfigKey(query.getConfigKey()).setSeverity(RulePriority.BLOCKER);
- if (rule.getConfigKey().equals("rulesets/coupling.xml/ExcessiveImports")) {
- rule.createParameter("max");
- }
- return rule;
- }
- });
- return ruleFinder;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.sonar.api.profiles.ProfileDefinition;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.RuleQuery;
-import org.sonar.api.utils.ValidationMessages;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class PmdProfilesTest {
- ValidationMessages validation = ValidationMessages.create();
-
- @Test
- public void should_create_sun_convention_profile() {
- SunConventionsProfile sunConvention = new SunConventionsProfile(new PmdProfileImporter(ruleFinder()));
-
- RulesProfile profile = sunConvention.createProfile(validation);
-
- assertThat(profile.getActiveRulesByRepository(PmdConstants.REPOSITORY_KEY)).isNotEmpty();
- assertThat(validation.hasErrors()).isFalse();
- }
-
- @Test
- public void should_create_sonar_way_profile() {
- ProfileDefinition sonarWay = new SonarWayProfile(new PmdProfileImporter(ruleFinder()));
-
- RulesProfile profile = sonarWay.createProfile(validation);
-
- assertThat(profile.getActiveRulesByRepository(PmdConstants.REPOSITORY_KEY)).isNotEmpty();
- assertThat(validation.hasErrors()).isFalse();
- }
-
- @Test
- public void should_create_sonar_way_with_findbugs_profile() {
- ProfileDefinition sonarWayWithFindbugs = new SonarWayWithFindbugsProfile(new SonarWayProfile(new PmdProfileImporter(ruleFinder())));
-
- RulesProfile profile = sonarWayWithFindbugs.createProfile(validation);
-
- assertThat(profile.getActiveRulesByRepository(PmdConstants.REPOSITORY_KEY)).isNotEmpty();
- assertThat(validation.hasErrors()).isFalse();
- }
-
- static RuleFinder ruleFinder() {
- RuleFinder ruleFinder = mock(RuleFinder.class);
- when(ruleFinder.find(any(RuleQuery.class))).then(new Answer<Rule>() {
- public Rule answer(InvocationOnMock invocation) {
- RuleQuery query = (RuleQuery) invocation.getArguments()[0];
- return Rule.create(query.getRepositoryKey(), "", "");
- }
- });
- return ruleFinder;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.PropertyType;
-import org.sonar.api.platform.ServerFileSystem;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.XMLRuleParser;
-import org.sonar.test.TestUtils;
-import org.sonar.test.i18n.RuleRepositoryTestHelper;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class PmdRuleRepositoryTest {
- PmdRuleRepository repository;
-
- ServerFileSystem fileSystem = mock(ServerFileSystem.class);
-
- @Before
- public void setUpRuleRepository() {
- repository = new PmdRuleRepository(fileSystem, new XMLRuleParser());
- }
-
- @Test
- public void should_have_correct_name_and_key() {
- assertThat(repository.getKey()).isEqualTo("pmd");
- assertThat(repository.getLanguage()).isEqualTo("java");
- assertThat(repository.getName()).isEqualTo("PMD");
- }
-
- @Test
- public void should_load_repository_from_xml() {
- List<Rule> rules = repository.createRules();
-
- assertThat(rules.size()).isGreaterThan(100);
- }
-
- @Test
- public void should_load_extensions() {
- File file = TestUtils.getResource("/org/sonar/plugins/pmd/rules-extension.xml");
- when(fileSystem.getExtensions("pmd", "xml")).thenReturn(Arrays.asList(file));
-
- List<Rule> rules = repository.createRules();
-
- assertThat(rules).onProperty("key").contains("Extension");
- }
-
- @Test
- public void should_exclude_junit_rules() {
- List<Rule> rules = repository.createRules();
-
- assertThat(rules).onProperty("key").excludes("JUnitStaticSuite");
- }
-
- @Test
- public void should_use_text_parameter_for_xpath_rule() {
- Rule xpathRule = Iterables.find(repository.createRules(), new Predicate<Rule>() {
- public boolean apply(Rule rule) {
- return rule.getKey().equals("XPathRule");
- }
- });
-
- assertThat(xpathRule.getParam("xpath").getType()).isEqualTo(PropertyType.TEXT.name());
- }
-
- @Test
- public void should_provide_a_name_and_description_for_each_rule() {
- List<Rule> rules = RuleRepositoryTestHelper.createRulesWithNameAndDescription("pmd", repository);
-
- assertThat(rules).onProperty("name").excludes(null, "");
- assertThat(rules).onProperty("description").excludes(null, "");
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import org.junit.rules.ExpectedException;
-
-import org.junit.Rule;
-
-import org.sonar.api.utils.XmlParserException;
-
-import com.google.common.collect.Iterators;
-import net.sourceforge.pmd.IRuleViolation;
-import net.sourceforge.pmd.Report;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.Project;
-import org.sonar.api.rules.Violation;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-public class PmdSensorTest {
- PmdSensor pmdSensor;
-
- Project project = mock(Project.class, RETURNS_DEEP_STUBS);
- RulesProfile profile = mock(RulesProfile.class, RETURNS_DEEP_STUBS);
- PmdExecutor executor = mock(PmdExecutor.class);
- PmdViolationToRuleViolation pmdViolationToRuleViolation = mock(PmdViolationToRuleViolation.class);
- SensorContext sensorContext = mock(SensorContext.class);
- Violation violation = mock(Violation.class);
-
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
- @Before
- public void setUpPmdSensor() {
- pmdSensor = new PmdSensor(profile, executor, pmdViolationToRuleViolation);
- }
-
- @Test
- public void should_execute_on_project_without_main_files() {
- when(project.getFileSystem().mainFiles(Java.KEY).isEmpty()).thenReturn(true);
-
- boolean shouldExecute = pmdSensor.shouldExecuteOnProject(project);
-
- assertThat(shouldExecute).isTrue();
- }
-
- @Test
- public void should_execute_on_project_without_test_files() {
- when(project.getFileSystem().testFiles(Java.KEY).isEmpty()).thenReturn(true);
-
- boolean shouldExecute = pmdSensor.shouldExecuteOnProject(project);
-
- assertThat(shouldExecute).isTrue();
- }
-
- @Test
- public void should_not_execute_on_project_without_any_files() {
- when(project.getFileSystem().mainFiles(Java.KEY).isEmpty()).thenReturn(true);
- when(project.getFileSystem().testFiles(Java.KEY).isEmpty()).thenReturn(true);
-
- boolean shouldExecute = pmdSensor.shouldExecuteOnProject(project);
-
- assertThat(shouldExecute).isFalse();
- }
-
- @Test
- public void should_not_execute_on_project_without_active_rules() {
- when(profile.getActiveRulesByRepository(PmdConstants.REPOSITORY_KEY).isEmpty()).thenReturn(true);
- when(profile.getActiveRulesByRepository(PmdConstants.TEST_REPOSITORY_KEY).isEmpty()).thenReturn(true);
-
- boolean shouldExecute = pmdSensor.shouldExecuteOnProject(project);
-
- assertThat(shouldExecute).isFalse();
- }
-
- @Test
- public void should_report_violations() {
- IRuleViolation pmdViolation = violation();
- Report report = report(pmdViolation);
- when(executor.execute()).thenReturn(report);
- when(pmdViolationToRuleViolation.toViolation(pmdViolation, sensorContext)).thenReturn(violation);
-
- pmdSensor.analyse(project, sensorContext);
-
- verify(sensorContext).saveViolation(violation);
- }
-
- @Test
- public void shouldnt_report_zero_violation() {
- Report report = report();
- when(executor.execute()).thenReturn(report);
-
- pmdSensor.analyse(project, sensorContext);
-
- verifyZeroInteractions(sensorContext);
- }
-
- @Test
- public void shouldnt_report_invalid_violation() {
- IRuleViolation pmdViolation = violation();
- Report report = report(pmdViolation);
- when(executor.execute()).thenReturn(report);
- when(report.iterator()).thenReturn(Iterators.forArray(pmdViolation));
- when(pmdViolationToRuleViolation.toViolation(pmdViolation, sensorContext)).thenReturn(null);
-
- pmdSensor.analyse(project, sensorContext);
-
- verifyZeroInteractions(sensorContext);
- }
-
- @Test
- public void should_report_analyse_failure() {
- when(executor.execute()).thenThrow(new RuntimeException());
-
- exception.expect(XmlParserException.class);
-
- pmdSensor.analyse(project, sensorContext);
- }
-
- @Test
- public void should_to_string() {
- String toString = pmdSensor.toString();
-
- assertThat(toString).isEqualTo("PmdSensor");
- }
-
- static IRuleViolation violation() {
- return mock(IRuleViolation.class);
- }
-
- static Report report(IRuleViolation... violations) {
- Report report = mock(Report.class);
- when(report.iterator()).thenReturn(Iterators.forArray(violations));
- return report;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import com.google.common.base.Charsets;
-import net.sourceforge.pmd.PMD;
-import net.sourceforge.pmd.PMDException;
-import net.sourceforge.pmd.RuleContext;
-import net.sourceforge.pmd.RuleSets;
-import net.sourceforge.pmd.SourceType;
-import org.junit.Test;
-import org.sonar.api.resources.InputFile;
-import org.sonar.api.utils.SonarException;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class PmdTemplateTest {
- InputFile inputFile = mock(InputFile.class);
- RuleSets rulesets = mock(RuleSets.class);
- RuleContext ruleContext = mock(RuleContext.class);
- InputStream inputStream = mock(InputStream.class);
- PMD pmd = mock(PMD.class);
-
- @Test
- public void should_process_input_file() throws PMDException, FileNotFoundException {
- when(inputFile.getFile()).thenReturn(new File("source.java"));
- when(inputFile.getInputStream()).thenReturn(inputStream);
-
- new PmdTemplate(pmd).process(inputFile, Charsets.UTF_8, rulesets, ruleContext);
-
- verify(ruleContext).setSourceCodeFilename(new File("source.java").getAbsolutePath());
- verify(pmd).processFile(inputStream, Charsets.UTF_8.displayName(), rulesets, ruleContext);
- }
-
- @Test
- public void should_ignore_PMD_error() throws PMDException, FileNotFoundException {
- when(inputFile.getFile()).thenReturn(new File("source.java"));
- when(inputFile.getInputStream()).thenReturn(inputStream);
- doThrow(new PMDException("BUG")).when(pmd).processFile(inputStream, Charsets.UTF_8.displayName(), rulesets, ruleContext);
-
- new PmdTemplate(pmd).process(inputFile, Charsets.UTF_8, rulesets, ruleContext);
- }
-
- @Test
- public void should_set_java11_version() {
- PmdTemplate.setJavaVersion(pmd, "1.1");
-
- verify(pmd).setJavaVersion(SourceType.JAVA_13);
- }
-
- @Test
- public void should_set_java12_version() {
- PmdTemplate.setJavaVersion(pmd, "1.2");
-
- verify(pmd).setJavaVersion(SourceType.JAVA_13);
- }
-
- @Test
- public void should_set_java5_version() {
- PmdTemplate.setJavaVersion(pmd, "5");
-
- verify(pmd).setJavaVersion(SourceType.JAVA_15);
- }
-
- @Test
- public void should_set_java6_version() {
- PmdTemplate.setJavaVersion(pmd, "6");
-
- verify(pmd).setJavaVersion(SourceType.JAVA_16);
- }
-
- @Test(expected = SonarException.class)
- public void should_fail_on_invalid_java_version() {
- new PmdTemplate("12.2");
- }
-
- @Test
- public void shouldnt_fail_on_valid_java_version() {
- new PmdTemplate("6");
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.XMLRuleParser;
-import org.sonar.test.i18n.RuleRepositoryTestHelper;
-
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class PmdUnitTestsRuleRepositoryTest {
- PmdUnitTestsRuleRepository repository;
-
- @Before
- public void setUpRuleRepository() {
- repository = new PmdUnitTestsRuleRepository(new XMLRuleParser());
- }
-
- @Test
- public void should_have_correct_name_and_key() {
- assertThat(repository.getKey()).isEqualTo("pmd-unit-tests");
- assertThat(repository.getLanguage()).isEqualTo("java");
- assertThat(repository.getName()).isEqualTo("PMD Unit Tests");
- }
-
- @Test
- public void should_load_repository_from_xml() {
- List<Rule> rules = repository.createRules();
-
- assertThat(rules).onProperty("key").containsOnly(
- "JUnitStaticSuite",
- "JUnitSpelling",
- "JUnitAssertionsShouldIncludeMessage",
- "JUnitTestsShouldIncludeAssert",
- "TestClassWithoutTestCases",
- "UnnecessaryBooleanAssertion",
- "UseAssertEqualsInsteadOfAssertTrue",
- "UseAssertSameInsteadOfAssertTrue",
- "UseAssertNullInsteadOfAssertTrue",
- "SimplifyBooleanAssertion");
- }
-
- @Test
- public void should_provide_a_name_and_description_for_each_rule() {
- List<Rule> rules = RuleRepositoryTestHelper.createRulesWithNameAndDescription("pmd", repository);
-
- assertThat(rules).onProperty("name").excludes(null, "");
- assertThat(rules).onProperty("description").excludes(null, "");
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class PmdVersionTest {
- @Test
- public void should_get_pmd_version() {
- assertThat(PmdVersion.getVersion()).isNotEmpty();
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.pmd;
-
-import net.sourceforge.pmd.IRuleViolation;
-import net.sourceforge.pmd.Rule;
-import org.junit.Test;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.resources.JavaFile;
-import org.sonar.api.resources.ProjectFileSystem;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.Violation;
-
-import java.io.File;
-import java.util.Arrays;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.test.MoreConditions.reflectionEqualTo;
-
-public class PmdViolationToRuleViolationTest {
- private org.sonar.api.rules.Rule sonarRule = org.sonar.api.rules.Rule.create("pmd", "RULE");
- private ProjectFileSystem projectFileSystem = mock(ProjectFileSystem.class);
- private IRuleViolation pmdViolation = mock(IRuleViolation.class);
- private SensorContext context = mock(SensorContext.class);
- private RuleFinder ruleFinder = mock(RuleFinder.class);
- private Rule rule = mock(Rule.class);
-
- @Test
- public void should_convert_pmd_violation_to_sonar_violation() {
- when(projectFileSystem.getSourceDirs()).thenReturn(Arrays.asList(new File("/src")));
- when(pmdViolation.getFilename()).thenReturn("/src/source.java");
- when(pmdViolation.getBeginLine()).thenReturn(42);
- when(pmdViolation.getDescription()).thenReturn("Description");
- when(pmdViolation.getRule()).thenReturn(rule);
- when(rule.getName()).thenReturn("RULE");
- when(context.getResource(new JavaFile("[default].source"))).thenReturn(new JavaFile("[default].source"));
- when(ruleFinder.findByKey("pmd", "RULE")).thenReturn(sonarRule);
-
- PmdViolationToRuleViolation pmdViolationToRuleViolation = new PmdViolationToRuleViolation(projectFileSystem, ruleFinder);
- Violation violation = pmdViolationToRuleViolation.toViolation(pmdViolation, context);
-
- assertThat(violation).is(reflectionEqualTo(Violation.create(sonarRule, new JavaFile("[default].source")).setLineId(42).setMessage("Description")));
- }
-
- @Test
- public void should_ignore_violation_on_unknown_resource() {
- when(projectFileSystem.getSourceDirs()).thenReturn(Arrays.asList(new File("/src")));
- when(pmdViolation.getFilename()).thenReturn("/src/UNKNOWN.java");
-
- PmdViolationToRuleViolation pmdViolationToRuleViolation = new PmdViolationToRuleViolation(projectFileSystem, ruleFinder);
- Violation violation = pmdViolationToRuleViolation.toViolation(pmdViolation, context);
-
- assertThat(violation).isNull();
- }
-
- @Test
- public void should_ignore_violation_on_unknown_rule() {
- when(projectFileSystem.getTestDirs()).thenReturn(Arrays.asList(new File("/test")));
- when(pmdViolation.getFilename()).thenReturn("/test/source.java");
- when(pmdViolation.getRule()).thenReturn(rule);
- when(rule.getName()).thenReturn("UNKNOWN");
- when(context.getResource(new JavaFile("[default].source"))).thenReturn(new JavaFile("[default].source"));
-
- PmdViolationToRuleViolation pmdViolationToRuleViolation = new PmdViolationToRuleViolation(projectFileSystem, ruleFinder);
- Violation violation = pmdViolationToRuleViolation.toViolation(pmdViolation, context);
-
- assertThat(violation).isNull();
- }
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Sonar PMD rules generated configuration -->
-<ruleset language="My language" name="My name">
- <description>Sonar PMD rules</description>
- <exclude-pattern>to exclude</exclude-pattern>
- <include-pattern>to include</include-pattern>
- <rule ref="rulesets/coupling.xml/CouplingBetweenObjects" externalInfoUrl="String" typeResolution="false" dfa="true"
- name="ID_1" message="String" since="String">
- <description>rule description</description>
- <priority>2</priority>
- <properties>
- <property name="threshold" value="20"/>
- </properties>
- <exclude name="NMTOKEN"/>
- <example>an example</example>
- </rule>
- <rule ref="rulesets/coupling.xml/ExcessiveImports">
- <priority>3</priority>
- <properties>
- <property name="max" value="30" pluginname="plugin name" description="property description"/>
- </properties>
- </rule>
- <rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify">
- <priority>4</priority>
- </rule>
-</ruleset>
-
-
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<ruleset>
- <rule ref="rulesets/coupling.xml/CouplingBetweenObjects">
- <priority>2</priority>
- <properties>
- <property name="threshold" value="20" />
- </properties>
- </rule>
- <rule ref="rulesets/coupling.xml/ExcessiveImports">
- <priority>3</priority>
- </rule>
- <rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify">
- <priority>4</priority>
- </rule>
-</ruleset>
-
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<ruleset>
- <rule class="net.sourceforge.pmd.rules.XPathRule" message="This is bad" name="MyOwnRule">
- <priority>3</priority>
- <properties>
- <property name="xpath">
- <value><![CDATA[//FieldDeclaration]]></value>
- </property>
- </properties>
- </rule>
-</ruleset>
-
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<ruleset>
- <description>Sonar PMD Unit Tests rules</description>
- <rule ref="rulesets/junit.xml/SimplifyBooleanAssertion">
- <priority>2</priority>
- </rule>
-</ruleset>
\ No newline at end of file
+++ /dev/null
-<rules>
- <rule key="Extension">
- <priority>MAJOR</priority>
- <configKey>rulesets.xml/extension</configKey>
- </rule>
-</rules>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<ruleset>
- <description>Sonar PMD rules</description>
- <rule ref="rulesets/coupling.xml/CouplingBetweenObjects">
- <priority>2</priority>
- <properties>
- <property name="threshold" value="20"/>
- </properties>
- </rule>
- <rule ref="rulesets/coupling.xml/ExcessiveImports">
- <properties>
- <property name="max" value="30"/>
- </properties>
- </rule>
- <rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify">
- <priority>4</priority>
- </rule>
-</ruleset>
\ No newline at end of file
<module>plugins/sonar-core-plugin</module>
<module>plugins/sonar-dbcleaner-plugin</module>
<module>plugins/sonar-checkstyle-plugin</module>
- <module>plugins/sonar-pmd-plugin</module>
<module>plugins/sonar-cobertura-plugin</module>
<module>plugins/sonar-surefire-plugin</module>
<module>plugins/sonar-findbugs-plugin</module>
<artifactId>sonar-squid-java-plugin</artifactId>
<version>${sonarJava.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar-plugins.java</groupId>
+ <artifactId>sonar-pmd-plugin</artifactId>
+ <version>${sonarJava.version}</version>
+ </dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-all</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
- <groupId>org.codehaus.sonar.plugins</groupId>
+ <groupId>org.codehaus.sonar-plugins.java</groupId>
<artifactId>sonar-pmd-plugin</artifactId>
- <version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.codehaus.sonar.plugins</groupId>
+ <groupId>org.codehaus.sonar-plugins.java</groupId>
<artifactId>sonar-pmd-plugin</artifactId>
- <version>${project.version}</version>
+ <version>${sonarJava.version}</version>
<type>sonar-plugin</type>
<scope>provided</scope>
</dependency>