*/
package org.sonar.plugins.checkstyle;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.util.List;
+import java.util.Properties;
+
import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.PropertiesExpander;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.SonarException;
-import java.io.*;
-import java.nio.charset.Charset;
-import java.util.List;
-import java.util.Properties;
-
public class CheckstyleConfiguration implements BatchExtension {
- private static Logger LOG = LoggerFactory.getLogger(CheckstyleConfiguration.class);
+ private static final Logger LOG = LoggerFactory.getLogger(CheckstyleConfiguration.class);
private CheckstyleProfileExporter confExporter;
private RulesProfile profile;
public static final String FILTERS_DEFAULT_VALUE = "<module name=\"SuppressionCommentFilter\"/>";
public static final String GENERATE_XML_KEY = "sonar.checkstyle.generateXml";
public static final boolean GENERATE_XML_DEFAULT_VALUE = false;
+
+ private CheckstyleConstants() {
+ }
}
*/
package org.sonar.plugins.checkstyle;
+import java.io.File;
+import java.io.OutputStream;
+
import com.puppycrawl.tools.checkstyle.Checker;
import com.puppycrawl.tools.checkstyle.PackageNamesLoader;
import com.puppycrawl.tools.checkstyle.XMLLogger;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.TimeProfiler;
-import java.io.File;
-import java.io.OutputStream;
-
public class CheckstyleExecutor implements BatchExtension {
- private static Logger LOG = LoggerFactory.getLogger(CheckstyleExecutor.class);
+ private static final Logger LOG = LoggerFactory.getLogger(CheckstyleExecutor.class);
private CheckstyleConfiguration configuration;
private ClassLoader projectClassloader;
this.projectClassloader = classpath.getClassloader();
}
-
CheckstyleExecutor(CheckstyleConfiguration configuration, CheckstyleAuditListener listener, ClassLoader projectClassloader) {
this.configuration = configuration;
this.listener = listener;
}
}
-
}
\ No newline at end of file
*/
package org.sonar.plugins.checkstyle;
+import java.io.Reader;
+import java.util.Map;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+
import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
import org.codehaus.stax2.XMLInputFactory2;
import org.sonar.api.rules.RuleQuery;
import org.sonar.api.utils.ValidationMessages;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-
-import java.io.Reader;
-import java.util.Map;
-
public class CheckstyleProfileImporter extends ProfileImporter {
private static final String CHECKER_MODULE = "Checker";
xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
- SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
- return inputFactory;
+ return new SMInputFactory(xmlFactory);
}
- private void processModule(RulesProfile profile, String path, SMInputCursor moduleCursor, ValidationMessages messages) throws XMLStreamException {
+ private void processModule(RulesProfile profile, String path, SMInputCursor moduleCursor, ValidationMessages messages)
+ throws XMLStreamException {
String moduleName = moduleCursor.getAttrValue("name");
if (isFilter(moduleName)) {
messages.addWarningText("Checkstyle filters are not imported: " + moduleName);
StringUtils.equals(configKey, "SuppressWithNearbyCommentFilter");
}
- private void processRule(RulesProfile profile, String path, String moduleName, SMInputCursor moduleCursor, ValidationMessages messages) throws XMLStreamException {
+ private void processRule(RulesProfile profile, String path, String moduleName, SMInputCursor moduleCursor, ValidationMessages messages)
+ throws XMLStreamException {
Map<String, String> properties = processProps(moduleCursor);
Rule rule;
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 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";
+ 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() {
+ }
}
*/
package org.sonar.plugins.pmd;
-import net.sourceforge.pmd.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.List;
+
+import net.sourceforge.pmd.PMD;
+import net.sourceforge.pmd.PMDException;
+import net.sourceforge.pmd.Report;
+import net.sourceforge.pmd.RuleContext;
+import net.sourceforge.pmd.RuleSetFactory;
+import net.sourceforge.pmd.RuleSets;
+import net.sourceforge.pmd.SourceType;
import net.sourceforge.pmd.renderers.Renderer;
import net.sourceforge.pmd.renderers.XMLRenderer;
import org.apache.commons.io.IOUtils;
import org.sonar.api.utils.TimeProfiler;
import org.sonar.java.api.JavaUtils;
-import java.io.*;
-import java.util.List;
-
public class PmdExecutor implements BatchExtension {
- private static Logger LOG = LoggerFactory.getLogger(PmdExecutor.class);
+ private static final Logger LOG = LoggerFactory.getLogger(PmdExecutor.class);
private PmdConfiguration configuration;
private Project project;
*/
package org.sonar.plugins.pmd;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
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.CoreProperties;
import org.sonar.api.profiles.ProfileExporter;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Java;
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() {
protected PmdRuleset createPmdRuleset(List<ActiveRule> activeRules, String profileName) {
PmdRuleset ruleset = new PmdRuleset(profileName);
for (ActiveRule activeRule : activeRules) {
- if (activeRule.getRule().getPluginName().equals(CoreProperties.PMD_PLUGIN)) {
+ if (activeRule.getRule().getRepositoryKey().equals(PmdConstants.REPOSITORY_KEY)) {
String configKey = activeRule.getRule().getConfigKey();
PmdRule rule = new PmdRule(configKey, PmdLevelUtils.toLevel(activeRule.getSeverity()));
if (activeRule.getActiveRuleParams() != null && !activeRule.getActiveRuleParams().isEmpty()) {
public class PmdProfileImporter extends ProfileImporter {
private final RuleFinder ruleFinder;
- private static Logger LOG = LoggerFactory.getLogger(PmdProfileImporter.class);
+ private static final Logger LOG = LoggerFactory.getLogger(PmdProfileImporter.class);
public PmdProfileImporter(RuleFinder ruleFinder) {
super(PmdConstants.REPOSITORY_KEY, PmdConstants.PLUGIN_NAME);
@Override
public RulesProfile importProfile(Reader pmdConfigurationFile, ValidationMessages messages) {
PmdRuleset pmdRuleset = parsePmdRuleset(pmdConfigurationFile, messages);
- RulesProfile profile = createRuleProfile(pmdRuleset, messages);
- return profile;
+ return createRuleProfile(pmdRuleset, messages);
}
protected RulesProfile createRuleProfile(PmdRuleset pmdRuleset, ValidationMessages messages) {