diff --git a/checkstyle-sonar-plugin/config/suppressions.xml b/checkstyle-sonar-plugin/config/suppressions.xml
index 85506ccd..65e1a12b 100644
--- a/checkstyle-sonar-plugin/config/suppressions.xml
+++ b/checkstyle-sonar-plugin/config/suppressions.xml
@@ -6,51 +6,30 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -58,4 +37,10 @@
+
+
+
+
+
+
diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleAuditListener.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleAuditListener.java
index dfbe7ed3..a45bd1cc 100644
--- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleAuditListener.java
+++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleAuditListener.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import org.apache.commons.lang.StringUtils;
@@ -40,119 +40,124 @@
*/
public class CheckstyleAuditListener implements AuditListener, BatchExtension {
- private static final Logger LOG = LoggerFactory.getLogger(CheckstyleAuditListener.class);
-
- private final RuleFinder ruleFinder;
- private final FileSystem fs;
- private final ResourcePerspectives perspectives;
- private InputFile currentResource;
-
- public CheckstyleAuditListener(RuleFinder ruleFinder, FileSystem fs,
- ResourcePerspectives perspectives) {
- this.ruleFinder = ruleFinder;
- this.fs = fs;
- this.perspectives = perspectives;
- }
-
- @Override
- public void auditStarted(AuditEvent event) {
- // nop
- }
-
- @Override
- public void auditFinished(AuditEvent event) {
- // nop
- }
-
- @Override
- public void fileStarted(AuditEvent event) {
- // nop
- }
-
- @Override
- public void fileFinished(AuditEvent event) {
- currentResource = null;
- }
-
- @Override
- public void addError(AuditEvent event) {
- String ruleKey = getRuleKey(event);
- if (ruleKey != null) {
- String message = getMessage(event);
- // In Checkstyle 5.5 exceptions are reported as an events from TreeWalker
- if ("com.puppycrawl.tools.checkstyle.TreeWalker".equals(ruleKey)) {
- LOG.warn("{} : {}", event.getFileName(), message);
- }
- initResource(event);
- Issuable issuable = perspectives.as(Issuable.class, currentResource);
- Rule rule = ruleFinder.findByKey(CheckstyleConstants.REPOSITORY_KEY, ruleKey);
- if (rule != null && issuable != null) {
- IssueBuilder issueBuilder = issuable.newIssueBuilder()
- .ruleKey(rule.ruleKey())
- .message(message)
- .line(getLineId(event));
- issuable.addIssue(issueBuilder.build());
- }
+ private static final Logger LOG = LoggerFactory.getLogger(CheckstyleAuditListener.class);
+
+ private final RuleFinder ruleFinder;
+ private final FileSystem fs;
+ private final ResourcePerspectives perspectives;
+ private InputFile currentResource;
+
+ public CheckstyleAuditListener(RuleFinder ruleFinder, FileSystem fs,
+ ResourcePerspectives perspectives) {
+ this.ruleFinder = ruleFinder;
+ this.fs = fs;
+ this.perspectives = perspectives;
}
- }
- private void initResource(AuditEvent event) {
- if (currentResource == null) {
- String absoluteFilename = event.getFileName();
- currentResource = fs.inputFile(fs.predicates().hasAbsolutePath(absoluteFilename));
+ @Override
+ public void auditStarted(AuditEvent event) {
+ // nop
}
- }
-
- @VisibleForTesting
- static String getRuleKey(AuditEvent event) {
- String key = null;
- try {
- key = event.getModuleId();
- } catch (Exception e) {
- LOG.warn("AuditEvent is created incorrectly. Exception happen during getModuleId()", e);
+
+ @Override
+ public void auditFinished(AuditEvent event) {
+ // nop
}
- if (StringUtils.isBlank(key)) {
- try {
- key = event.getSourceName();
- } catch (Exception e) {
- LOG.warn("AuditEvent is created incorrectly. Exception happen during getSourceName()", e);
- }
+
+ @Override
+ public void fileStarted(AuditEvent event) {
+ // nop
+ }
+
+ @Override
+ public void fileFinished(AuditEvent event) {
+ currentResource = null;
}
- return key;
- }
- @VisibleForTesting
- static String getMessage(AuditEvent event) {
- try {
- return event.getMessage();
+ @Override
+ public void addError(AuditEvent event) {
+ String ruleKey = getRuleKey(event);
+ if (ruleKey != null) {
+ String message = getMessage(event);
+ // In Checkstyle 5.5 exceptions are reported as an events from
+ // TreeWalker
+ if ("com.puppycrawl.tools.checkstyle.TreeWalker".equals(ruleKey)) {
+ LOG.warn("{} : {}", event.getFileName(), message);
+ }
+ initResource(event);
+ Issuable issuable = perspectives.as(Issuable.class, currentResource);
+ Rule rule = ruleFinder.findByKey(CheckstyleConstants.REPOSITORY_KEY, ruleKey);
+ if (rule != null && issuable != null) {
+ IssueBuilder issueBuilder = issuable.newIssueBuilder().ruleKey(rule.ruleKey())
+ .message(message).line(getLineId(event));
+ issuable.addIssue(issueBuilder.build());
+ }
+ }
+ }
- } catch (Exception e) {
- LOG.warn("AuditEvent is created incorrectly. Exception happen during getMessage()", e);
- return null;
+ private void initResource(AuditEvent event) {
+ if (currentResource == null) {
+ String absoluteFilename = event.getFileName();
+ currentResource = fs.inputFile(fs.predicates().hasAbsolutePath(absoluteFilename));
+ }
}
- }
-
- @VisibleForTesting
- static Integer getLineId(AuditEvent event) {
- Integer result = null;
- try {
- int line = event.getLine();
- // checkstyle returns 0 if there is no relation to a file content, but we use null
- if (line != 0) {
- result = line;
- }
- } catch (Exception e) {
- LOG.warn("AuditEvent is created incorrectly. Exception happen during getLine()", e);
+
+ @VisibleForTesting
+ static String getRuleKey(AuditEvent event) {
+ String key = null;
+ try {
+ key = event.getModuleId();
+ }
+ catch (Exception e) {
+ LOG.warn("AuditEvent is created incorrectly. Exception happen during getModuleId()", e);
+ }
+ if (StringUtils.isBlank(key)) {
+ try {
+ key = event.getSourceName();
+ }
+ catch (Exception e) {
+ LOG.warn("AuditEvent is created incorrectly."
+ + "Exception happen during getSourceName()", e);
+ }
+ }
+ return key;
+ }
+
+ @VisibleForTesting
+ static String getMessage(AuditEvent event) {
+ try {
+ return event.getMessage();
+
+ }
+ catch (Exception e) {
+ LOG.warn("AuditEvent is created incorrectly. Exception happen during getMessage()", e);
+ return null;
+ }
+ }
+
+ @VisibleForTesting
+ static Integer getLineId(AuditEvent event) {
+ Integer result = null;
+ try {
+ int line = event.getLine();
+ // checkstyle returns 0 if there is no relation to a file content,
+ // but we use null
+ if (line != 0) {
+ result = line;
+ }
+ }
+ catch (Exception e) {
+ LOG.warn("AuditEvent is created incorrectly. Exception happen during getLine()", e);
+ }
+ return result;
+ }
+
+ /**
+ * Note that this method never invoked from Checkstyle 5.5.
+ */
+ @Override
+ public void addException(AuditEvent event, Throwable throwable) {
+ // nop
}
- return result;
- }
-
- /**
- * Note that this method never invoked from Checkstyle 5.5.
- */
- @Override
- public void addException(AuditEvent event, Throwable throwable) {
- // nop
- }
}
diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
index 3100d94c..9c8066da 100644
--- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
+++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import java.io.File;
@@ -48,93 +48,92 @@
public class CheckstyleConfiguration implements BatchExtension {
- private static final Logger LOG = LoggerFactory.getLogger(CheckstyleConfiguration.class);
- public static final String PROPERTY_GENERATE_XML = "sonar.checkstyle.generateXml";
+ private static final Logger LOG = LoggerFactory.getLogger(CheckstyleConfiguration.class);
+ public static final String PROPERTY_GENERATE_XML = "sonar.checkstyle.generateXml";
- private final CheckstyleProfileExporter confExporter;
- private final RulesProfile profile;
- private final Settings conf;
- private final FileSystem fileSystem;
+ private final CheckstyleProfileExporter confExporter;
+ private final RulesProfile profile;
+ private final Settings conf;
+ private final FileSystem fileSystem;
- public CheckstyleConfiguration(Settings conf, CheckstyleProfileExporter confExporter,
- RulesProfile profile, FileSystem fileSystem) {
- this.conf = conf;
- this.confExporter = confExporter;
- this.profile = profile;
- this.fileSystem = fileSystem;
- }
+ public CheckstyleConfiguration(Settings conf, CheckstyleProfileExporter confExporter,
+ RulesProfile profile, FileSystem fileSystem) {
+ this.conf = conf;
+ this.confExporter = confExporter;
+ this.profile = profile;
+ this.fileSystem = fileSystem;
+ }
- public File getXmlDefinitionFile() {
- File xmlFile = new File(fileSystem.workDir(), "checkstyle.xml");
- try (Writer writer =
- new OutputStreamWriter(new FileOutputStream(xmlFile, false),
- StandardCharsets.UTF_8)) {
+ public File getXmlDefinitionFile() {
+ File xmlFile = new File(fileSystem.workDir(), "checkstyle.xml");
+ try (Writer writer = new OutputStreamWriter(new FileOutputStream(xmlFile, false),
+ StandardCharsets.UTF_8)) {
- confExporter.exportProfile(profile, writer);
- writer.flush();
- return xmlFile;
+ confExporter.exportProfile(profile, writer);
+ writer.flush();
+ return xmlFile;
- } catch (IOException e) {
- throw new IllegalStateException("Fail to save the Checkstyle configuration to "
- + xmlFile.getPath(), e);
+ }
+ catch (IOException e) {
+ throw new IllegalStateException("Fail to save the Checkstyle configuration to "
+ + xmlFile.getPath(), e);
+ }
}
- }
-
- public List getSourceFiles() {
- FilePredicates predicates = fileSystem.predicates();
- Iterable files = fileSystem.files(predicates.and(
- predicates.hasLanguage(CheckstyleConstants.JAVA_KEY),
- predicates.hasType(InputFile.Type.MAIN)));
- List fileList = new ArrayList<>();
- for (File file : files) {
- fileList.add(file);
+
+ public List getSourceFiles() {
+ FilePredicates predicates = fileSystem.predicates();
+ Iterable files = fileSystem.files(predicates.and(
+ predicates.hasLanguage(CheckstyleConstants.JAVA_KEY),
+ predicates.hasType(InputFile.Type.MAIN)));
+ List fileList = new ArrayList<>();
+ for (File file : files) {
+ fileList.add(file);
+ }
+ return fileList;
}
- return fileList;
- }
- public File getTargetXmlReport() {
- if (conf.getBoolean(PROPERTY_GENERATE_XML)) {
- return new File(fileSystem.workDir(), "checkstyle-result.xml");
+ public File getTargetXmlReport() {
+ if (conf.getBoolean(PROPERTY_GENERATE_XML)) {
+ return new File(fileSystem.workDir(), "checkstyle-result.xml");
+ }
+ return null;
}
- return null;
- }
-
- public Configuration getCheckstyleConfiguration() throws CheckstyleException {
- File xmlConfig = getXmlDefinitionFile();
-
- LOG.info("Checkstyle configuration: {}", xmlConfig.getAbsolutePath());
- Configuration configuration = toCheckstyleConfiguration(xmlConfig);
- defineCharset(configuration);
- return configuration;
- }
-
- @VisibleForTesting
- static Configuration toCheckstyleConfiguration(File xmlConfig) throws CheckstyleException {
- return ConfigurationLoader.loadConfiguration(xmlConfig.getAbsolutePath(),
- new PropertiesExpander(new Properties()));
- }
-
- private void defineCharset(Configuration configuration) {
- defineModuleCharset(configuration);
- for (Configuration module : configuration.getChildren()) {
- defineModuleCharset(module);
+
+ public Configuration getCheckstyleConfiguration() throws CheckstyleException {
+ File xmlConfig = getXmlDefinitionFile();
+
+ LOG.info("Checkstyle configuration: {}", xmlConfig.getAbsolutePath());
+ Configuration configuration = toCheckstyleConfiguration(xmlConfig);
+ defineCharset(configuration);
+ return configuration;
}
- }
-
- private void defineModuleCharset(Configuration module) {
- if (("Checker".equals(module.getName())
- || "com.puppycrawl.tools.checkstyle.Checker".equals(module.getName()))
- && module instanceof DefaultConfiguration) {
- Charset charset = getCharset();
- String charsetName = charset.name();
- LOG.info("Checkstyle charset: {}", charsetName);
- ((DefaultConfiguration) module).addAttribute("charset", charsetName);
+
+ @VisibleForTesting
+ static Configuration toCheckstyleConfiguration(File xmlConfig) throws CheckstyleException {
+ return ConfigurationLoader.loadConfiguration(xmlConfig.getAbsolutePath(),
+ new PropertiesExpander(new Properties()));
}
- }
- public Charset getCharset() {
- return fileSystem.encoding();
- }
+ private void defineCharset(Configuration configuration) {
+ defineModuleCharset(configuration);
+ for (Configuration module : configuration.getChildren()) {
+ defineModuleCharset(module);
+ }
+ }
+
+ private void defineModuleCharset(Configuration module) {
+ if (("Checker".equals(module.getName()) || "com.puppycrawl.tools.checkstyle.Checker"
+ .equals(module.getName())) && module instanceof DefaultConfiguration) {
+ Charset charset = getCharset();
+ String charsetName = charset.name();
+ LOG.info("Checkstyle charset: {}", charsetName);
+ ((DefaultConfiguration) module).addAttribute("charset", charsetName);
+ }
+ }
+
+ public Charset getCharset() {
+ return fileSystem.encoding();
+ }
}
diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConstants.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConstants.java
index da3ed1b4..b5e2653c 100644
--- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConstants.java
+++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConstants.java
@@ -1,39 +1,39 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
public final class CheckstyleConstants {
- public static final String REPOSITORY_NAME = "Checkstyle";
- public static final String PLUGIN_KEY = "checkstyle";
- public static final String PLUGIN_NAME = REPOSITORY_NAME;
- public static final String REPOSITORY_KEY = PLUGIN_KEY;
+ public static final String REPOSITORY_NAME = "Checkstyle";
+ public static final String PLUGIN_KEY = "checkstyle";
+ public static final String PLUGIN_NAME = REPOSITORY_NAME;
+ public static final String REPOSITORY_KEY = PLUGIN_KEY;
- public static final String FILTERS_KEY = "sonar.checkstyle.filters";
+ public static final String FILTERS_KEY = "sonar.checkstyle.filters";
- public static final String FILTERS_DEFAULT_VALUE =
- "" +
- "";
+ public static final String FILTERS_DEFAULT_VALUE =
+ ""
+ + "";
- public static final String JAVA_KEY = "java";
+ public static final String JAVA_KEY = "java";
- private CheckstyleConstants() {
- }
+ private CheckstyleConstants() {
+ }
}
diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleExecutor.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleExecutor.java
index dee440d4..a166c58e 100644
--- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleExecutor.java
+++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleExecutor.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import java.io.Closeable;
@@ -45,97 +45,102 @@
import com.puppycrawl.tools.checkstyle.XMLLogger;
public class CheckstyleExecutor implements BatchExtension {
- private static final Logger LOG = LoggerFactory.getLogger(CheckstyleExecutor.class);
-
- private final CheckstyleConfiguration configuration;
- private final CheckstyleAuditListener listener;
- private final JavaResourceLocator javaResourceLocator;
-
- public CheckstyleExecutor(CheckstyleConfiguration configuration, CheckstyleAuditListener listener,
- JavaResourceLocator javaResourceLocator) {
- this.configuration = configuration;
- this.listener = listener;
- this.javaResourceLocator = javaResourceLocator;
- }
-
- /**
- * Execute Checkstyle and return the generated XML report.
- */
- public void execute() {
-
- Locale initialLocale = Locale.getDefault();
- Locale.setDefault(Locale.ENGLISH);
- ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(PackageNamesLoader.class.getClassLoader());
- URLClassLoader projectClassloader = createClassloader();
- try {
- executeWithClassLoader(projectClassloader);
- } finally {
- Thread.currentThread().setContextClassLoader(initialClassLoader);
- Locale.setDefault(initialLocale);
- close(projectClassloader);
+ private static final Logger LOG = LoggerFactory.getLogger(CheckstyleExecutor.class);
+
+ private final CheckstyleConfiguration configuration;
+ private final CheckstyleAuditListener listener;
+ private final JavaResourceLocator javaResourceLocator;
+
+ public CheckstyleExecutor(CheckstyleConfiguration configuration,
+ CheckstyleAuditListener listener, JavaResourceLocator javaResourceLocator) {
+ this.configuration = configuration;
+ this.listener = listener;
+ this.javaResourceLocator = javaResourceLocator;
+ }
+
+ /**
+ * Execute Checkstyle and return the generated XML report.
+ */
+ public void execute() {
+
+ Locale initialLocale = Locale.getDefault();
+ Locale.setDefault(Locale.ENGLISH);
+ ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(PackageNamesLoader.class.getClassLoader());
+ URLClassLoader projectClassloader = createClassloader();
+ try {
+ executeWithClassLoader(projectClassloader);
+ }
+ finally {
+ Thread.currentThread().setContextClassLoader(initialClassLoader);
+ Locale.setDefault(initialLocale);
+ close(projectClassloader);
+ }
}
- }
-
- private void executeWithClassLoader(URLClassLoader projectClassloader) {
- TimeProfiler profiler =
- new TimeProfiler().start("Execute Checkstyle " + CheckstyleVersion.getVersion());
- Checker checker = new Checker();
- OutputStream xmlOutput = null;
- try {
- checker.setClassLoader(projectClassloader);
- checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
- checker.addListener(listener);
-
- File xmlReport = configuration.getTargetXmlReport();
- if (xmlReport != null) {
- LOG.info("Checkstyle output report: {}", xmlReport.getAbsolutePath());
- xmlOutput = FileUtils.openOutputStream(xmlReport);
- checker.addListener(new XMLLogger(xmlOutput, true));
- }
-
- checker.setCharset(configuration.getCharset().name());
- checker.configure(configuration.getCheckstyleConfiguration());
- checker.process(configuration.getSourceFiles());
-
- profiler.stop();
-
- } catch (Exception e) {
- throw new IllegalStateException("Can not execute Checkstyle", e);
- } finally {
- checker.destroy();
- if (xmlOutput != null) {
- close(xmlOutput);
- }
+
+ private void executeWithClassLoader(URLClassLoader projectClassloader) {
+ TimeProfiler profiler = new TimeProfiler().start("Execute Checkstyle "
+ + CheckstyleVersion.getVersion());
+ Checker checker = new Checker();
+ OutputStream xmlOutput = null;
+ try {
+ checker.setClassLoader(projectClassloader);
+ checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
+ checker.addListener(listener);
+
+ File xmlReport = configuration.getTargetXmlReport();
+ if (xmlReport != null) {
+ LOG.info("Checkstyle output report: {}", xmlReport.getAbsolutePath());
+ xmlOutput = FileUtils.openOutputStream(xmlReport);
+ checker.addListener(new XMLLogger(xmlOutput, true));
+ }
+
+ checker.setCharset(configuration.getCharset().name());
+ checker.configure(configuration.getCheckstyleConfiguration());
+ checker.process(configuration.getSourceFiles());
+
+ profiler.stop();
+
+ }
+ catch (Exception e) {
+ throw new IllegalStateException("Can not execute Checkstyle", e);
+ }
+ finally {
+ checker.destroy();
+ if (xmlOutput != null) {
+ close(xmlOutput);
+ }
+ }
}
- }
-
- @VisibleForTesting
- static void close(Closeable closeable) {
- try {
- closeable.close();
- } catch (IOException e) {
- throw new IllegalStateException("failed to close object", e);
+
+ @VisibleForTesting
+ static void close(Closeable closeable) {
+ try {
+ closeable.close();
+ }
+ catch (IOException e) {
+ throw new IllegalStateException("failed to close object", e);
+ }
}
- }
-
- @VisibleForTesting
- URL getUrl(URI uri) {
- try {
- return uri.toURL();
- } catch (MalformedURLException e) {
- throw new IllegalStateException("Fail to create the project classloader. "
- + "Classpath element is invalid: " + uri, e);
+
+ @VisibleForTesting
+ URL getUrl(URI uri) {
+ try {
+ return uri.toURL();
+ }
+ catch (MalformedURLException e) {
+ throw new IllegalStateException("Fail to create the project classloader. "
+ + "Classpath element is invalid: " + uri, e);
+ }
}
- }
- private URLClassLoader createClassloader() {
- Collection classpathElements = javaResourceLocator.classpath();
- List urls = new ArrayList<>(classpathElements.size());
- for (File file : classpathElements) {
- urls.add(getUrl(file.toURI()));
+ private URLClassLoader createClassloader() {
+ Collection classpathElements = javaResourceLocator.classpath();
+ List urls = new ArrayList<>(classpathElements.size());
+ for (File file : classpathElements) {
+ urls.add(getUrl(file.toURI()));
+ }
+ return new URLClassLoader(urls.toArray(new URL[urls.size()]), null);
}
- return new URLClassLoader(urls.toArray(new URL[urls.size()]), null);
- }
}
diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstylePlugin.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstylePlugin.java
index 32ae36b9..dd00aa30 100644
--- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstylePlugin.java
+++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstylePlugin.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import java.util.Arrays;
@@ -30,45 +30,40 @@
public final class CheckstylePlugin extends SonarPlugin {
- private static final String CHECKSTYLE_SUB_CATEGORY_NAME = "Checkstyle";
+ private static final String CHECKSTYLE_SUB_CATEGORY_NAME = "Checkstyle";
- @Override
- public List getExtensions() {
- return Arrays.asList(
- PropertyDefinition
- .builder(CheckstyleConstants.FILTERS_KEY)
- .defaultValue(CheckstyleConstants.FILTERS_DEFAULT_VALUE)
- .category(CoreProperties.CATEGORY_JAVA)
- .subCategory(CHECKSTYLE_SUB_CATEGORY_NAME)
- .name("Filters")
- .description(
- "Checkstyle supports four error filtering mechanisms: "
- + "SuppressionCommentFilter
, "
- + "SuppressWithNearbyCommentFilter
, "
- + "SuppressionFilter
, and SuppressWarningsFilter
."
- + "This property allows the configuration of those filters with a "
- + "native XML format. See the "
- + "Checkstyle "
- + "configuration for more information.")
- .type(PropertyType.TEXT)
- .onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
- .build(),
- PropertyDefinition.builder(CheckstyleConfiguration.PROPERTY_GENERATE_XML)
- .defaultValue("false")
- .category(CoreProperties.CATEGORY_JAVA)
- .subCategory(CHECKSTYLE_SUB_CATEGORY_NAME)
- .name("Generate XML Report")
- .type(PropertyType.BOOLEAN)
- .hidden()
- .build(),
+ @Override
+ public List getExtensions() {
+ return Arrays
+ .asList(PropertyDefinition
+ .builder(CheckstyleConstants.FILTERS_KEY)
+ .defaultValue(CheckstyleConstants.FILTERS_DEFAULT_VALUE)
+ .category(CoreProperties.CATEGORY_JAVA)
+ .subCategory(CHECKSTYLE_SUB_CATEGORY_NAME)
+ .name("Filters")
+ .description(
+ "Checkstyle supports four error filtering mechanisms: "
+ + "SuppressionCommentFilter
, "
+ + "SuppressWithNearbyCommentFilter
, "
+ + "SuppressionFilter
,"
+ + " and SuppressWarningsFilter
."
+ + "This property allows the configuration of those filters with a "
+ + "native XML format. See the "
+ + ""
+ + "Checkstyle "
+ + "configuration for more information.")
+ .type(PropertyType.TEXT)
+ .onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE).build(),
+ PropertyDefinition.builder(CheckstyleConfiguration.PROPERTY_GENERATE_XML)
+ .defaultValue("false").category(CoreProperties.CATEGORY_JAVA)
+ .subCategory(CHECKSTYLE_SUB_CATEGORY_NAME)
+ .name("Generate XML Report").type(PropertyType.BOOLEAN).hidden()
+ .build(),
- CheckstyleSensor.class,
- CheckstyleConfiguration.class,
- CheckstyleExecutor.class,
- CheckstyleAuditListener.class,
- CheckstyleProfileExporter.class,
- CheckstyleProfileImporter.class,
- CheckstyleRulesDefinition.class);
- }
+ CheckstyleSensor.class, CheckstyleConfiguration.class,
+ CheckstyleExecutor.class, CheckstyleAuditListener.class,
+ CheckstyleProfileExporter.class, CheckstyleProfileImporter.class,
+ CheckstyleRulesDefinition.class);
+ }
}
diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java
index 97699cf3..92061d5c 100644
--- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java
+++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import java.io.IOException;
@@ -40,158 +40,158 @@
public class CheckstyleProfileExporter extends ProfileExporter {
- public static final String DOCTYPE_DECLARATION =
- "";
- private final Settings settings;
- private static final String CLOSE_MODULE = "";
-
- public CheckstyleProfileExporter(Settings settings) {
- super(CheckstyleConstants.REPOSITORY_KEY, CheckstyleConstants.PLUGIN_NAME);
- this.settings = settings;
- setSupportedLanguages(CheckstyleConstants.JAVA_KEY);
- setMimeType("application/xml");
- }
-
- @Override
- public void exportProfile(RulesProfile profile, Writer writer) {
- try {
- List activeRules =
- profile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY);
- if (activeRules != null) {
- Map> activeRulesByConfigKey =
- arrangeByConfigKey(activeRules);
- generateXml(writer, activeRulesByConfigKey);
- }
- } catch (IOException e) {
- throw new IllegalStateException("Fail to export the profile " + profile, e);
+ public static final String DOCTYPE_DECLARATION =
+ "";
+ private final Settings settings;
+ private static final String CLOSE_MODULE = "";
+
+ public CheckstyleProfileExporter(Settings settings) {
+ super(CheckstyleConstants.REPOSITORY_KEY, CheckstyleConstants.PLUGIN_NAME);
+ this.settings = settings;
+ setSupportedLanguages(CheckstyleConstants.JAVA_KEY);
+ setMimeType("application/xml");
+ }
+
+ @Override
+ public void exportProfile(RulesProfile profile, Writer writer) {
+ try {
+ List activeRules = profile
+ .getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY);
+ if (activeRules != null) {
+ Map> activeRulesByConfigKey =
+ arrangeByConfigKey(activeRules);
+ generateXml(writer, activeRulesByConfigKey);
+ }
+ }
+ catch (IOException e) {
+ throw new IllegalStateException("Fail to export the profile " + profile, e);
+ }
+
}
- }
-
- private void generateXml(Writer writer, Map> activeRulesByConfigKey)
- throws IOException {
- appendXmlHeader(writer);
- appendCustomFilters(writer);
- appendCheckerModules(writer, activeRulesByConfigKey);
- appendTreeWalker(writer, activeRulesByConfigKey);
- appendXmlFooter(writer);
- }
-
- private static void appendXmlHeader(Writer writer) throws IOException {
- writer.append(""
- + DOCTYPE_DECLARATION
- + ""
- + "");
- }
-
- private void appendCustomFilters(Writer writer) throws IOException {
- String filtersXml = settings.getString(CheckstyleConstants.FILTERS_KEY);
- if (StringUtils.isNotBlank(filtersXml)) {
- writer.append(filtersXml);
+ private void generateXml(Writer writer, Map> activeRulesByConfigKey)
+ throws IOException {
+ appendXmlHeader(writer);
+ appendCustomFilters(writer);
+ appendCheckerModules(writer, activeRulesByConfigKey);
+ appendTreeWalker(writer, activeRulesByConfigKey);
+ appendXmlFooter(writer);
}
- }
-
- private static void appendCheckerModules(Writer writer,
- Map> activeRulesByConfigKey) throws IOException {
- for (Entry> entry : activeRulesByConfigKey.entrySet()) {
- String configKey = entry.getKey();
- if (!isInTreeWalker(configKey)) {
- List activeRules = entry.getValue();
- for (ActiveRule activeRule : activeRules) {
- appendModule(writer, activeRule);
+
+ private static void appendXmlHeader(Writer writer) throws IOException {
+ writer.append("" + DOCTYPE_DECLARATION
+ + "" + "");
+ }
+
+ private void appendCustomFilters(Writer writer) throws IOException {
+ String filtersXml = settings.getString(CheckstyleConstants.FILTERS_KEY);
+ if (StringUtils.isNotBlank(filtersXml)) {
+ writer.append(filtersXml);
}
- }
}
- }
-
- private void appendTreeWalker(Writer writer,
- Map> activeRulesByConfigKey) throws IOException {
- writer.append("");
- writer.append(" ");
- if (isSuppressWarningsEnabled()) {
- writer.append(" ");
+
+ private static void appendCheckerModules(Writer writer,
+ Map> activeRulesByConfigKey) throws IOException {
+ for (Entry> entry : activeRulesByConfigKey.entrySet()) {
+ String configKey = entry.getKey();
+ if (!isInTreeWalker(configKey)) {
+ List activeRules = entry.getValue();
+ for (ActiveRule activeRule : activeRules) {
+ appendModule(writer, activeRule);
+ }
+ }
+ }
}
- List ruleSet = new ArrayList<>(activeRulesByConfigKey.keySet());
- Collections.sort(ruleSet);
- for (String configKey : ruleSet) {
- if (isInTreeWalker(configKey)) {
- List activeRules = activeRulesByConfigKey.get(configKey);
- for (ActiveRule activeRule : activeRules) {
- appendModule(writer, activeRule);
+
+ private void appendTreeWalker(Writer writer,
+ Map> activeRulesByConfigKey) throws IOException {
+ writer.append("");
+ writer.append(" ");
+ if (isSuppressWarningsEnabled()) {
+ writer.append(" ");
+ }
+ List ruleSet = new ArrayList<>(activeRulesByConfigKey.keySet());
+ Collections.sort(ruleSet);
+ for (String configKey : ruleSet) {
+ if (isInTreeWalker(configKey)) {
+ List activeRules = activeRulesByConfigKey.get(configKey);
+ for (ActiveRule activeRule : activeRules) {
+ appendModule(writer, activeRule);
+ }
+ }
}
- }
+ writer.append(CLOSE_MODULE);
}
- writer.append(CLOSE_MODULE);
- }
-
- private boolean isSuppressWarningsEnabled() {
- String filtersXml = settings.getString(CheckstyleConstants.FILTERS_KEY);
- boolean result = false;
- if (filtersXml != null) {
- result = filtersXml.contains("");
+
+ private boolean isSuppressWarningsEnabled() {
+ String filtersXml = settings.getString(CheckstyleConstants.FILTERS_KEY);
+ boolean result = false;
+ if (filtersXml != null) {
+ result = filtersXml.contains("");
+ }
+ return result;
}
- return result;
- }
-
- private static void appendXmlFooter(Writer writer) throws IOException {
- writer.append(CLOSE_MODULE);
- }
-
- @VisibleForTesting
- static boolean isInTreeWalker(String configKey) {
- return StringUtils.startsWithIgnoreCase(configKey, "Checker/TreeWalker/");
- }
-
- private static Map> arrangeByConfigKey(List activeRules) {
- Map> result = new HashMap<>();
- for (ActiveRule activeRule : activeRules) {
- String key = activeRule.getConfigKey();
- if (result.containsKey(key)) {
- List rules = result.get(key);
- rules.add(activeRule);
- } else {
- List rules = new ArrayList<>();
- rules.add(activeRule);
- result.put(key, rules);
- }
+
+ private static void appendXmlFooter(Writer writer) throws IOException {
+ writer.append(CLOSE_MODULE);
}
- return result;
- }
-
- private static void appendModule(Writer writer, ActiveRule activeRule) throws IOException {
- String moduleName = StringUtils.substringAfterLast(activeRule.getConfigKey(), "/");
- writer.append("");
- if (activeRule.getRule().getTemplate() != null) {
- appendModuleProperty(writer, "id", activeRule.getRuleKey());
+
+ @VisibleForTesting
+ static boolean isInTreeWalker(String configKey) {
+ return StringUtils.startsWithIgnoreCase(configKey, "Checker/TreeWalker/");
}
- appendModuleProperty(writer, "severity",
- CheckstyleSeverityUtils.toSeverity(activeRule.getSeverity()));
- appendRuleParameters(writer, activeRule);
- writer.append(CLOSE_MODULE);
- }
-
- private static void appendRuleParameters(Writer writer, ActiveRule activeRule)
- throws IOException {
- for (RuleParam ruleParam : activeRule.getRule().getParams()) {
- String value = activeRule.getParameter(ruleParam.getKey());
- if (StringUtils.isNotBlank(value)) {
- appendModuleProperty(writer, ruleParam.getKey(), value);
- }
+
+ private static Map> arrangeByConfigKey(List activeRules) {
+ Map> result = new HashMap<>();
+ for (ActiveRule activeRule : activeRules) {
+ String key = activeRule.getConfigKey();
+ if (result.containsKey(key)) {
+ List rules = result.get(key);
+ rules.add(activeRule);
+ }
+ else {
+ List rules = new ArrayList<>();
+ rules.add(activeRule);
+ result.put(key, rules);
+ }
+ }
+ return result;
}
- }
-
- private static void appendModuleProperty(Writer writer, String propertyKey, String propertyValue)
- throws IOException {
- if (StringUtils.isNotBlank(propertyValue)) {
- writer.append("");
+
+ private static void appendModule(Writer writer, ActiveRule activeRule) throws IOException {
+ String moduleName = StringUtils.substringAfterLast(activeRule.getConfigKey(), "/");
+ writer.append("");
+ if (activeRule.getRule().getTemplate() != null) {
+ appendModuleProperty(writer, "id", activeRule.getRuleKey());
+ }
+ appendModuleProperty(writer, "severity",
+ CheckstyleSeverityUtils.toSeverity(activeRule.getSeverity()));
+ appendRuleParameters(writer, activeRule);
+ writer.append(CLOSE_MODULE);
+ }
+
+ private static void appendRuleParameters(Writer writer, ActiveRule activeRule)
+ throws IOException {
+ for (RuleParam ruleParam : activeRule.getRule().getParams()) {
+ String value = activeRule.getParameter(ruleParam.getKey());
+ if (StringUtils.isNotBlank(value)) {
+ appendModuleProperty(writer, ruleParam.getKey(), value);
+ }
+ }
+ }
+
+ private static void appendModuleProperty(Writer writer, String propertyKey,
+ String propertyValue) throws IOException {
+ if (StringUtils.isNotBlank(propertyValue)) {
+ writer.append("");
+ }
}
- }
}
diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporter.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporter.java
index 56c9faca..0340c2d2 100644
--- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporter.java
+++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporter.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import java.io.Reader;
@@ -45,158 +45,165 @@
public class CheckstyleProfileImporter extends ProfileImporter {
- private static final Logger LOG = LoggerFactory.getLogger(CheckstyleProfileImporter.class);
-
- private static final String CHECKER_MODULE = "Checker";
- private static final String TREEWALKER_MODULE = "TreeWalker";
- private static final String MODULE_NODE = "module";
- private static final String[] FILTERS = {
- "SeverityMatchFilter",
- "SuppressionFilter",
- "SuppressWarningsFilter",
- "SuppressionCommentFilter",
- "SuppressWithNearbyCommentFilter"
- };
- private final RuleFinder ruleFinder;
-
- private static class Module {
- private String name;
- private final Map properties = new HashMap<>();
- private final List modules = new ArrayList<>();
- }
-
- public CheckstyleProfileImporter(RuleFinder ruleFinder) {
- super(CheckstyleConstants.REPOSITORY_KEY, CheckstyleConstants.PLUGIN_NAME);
- setSupportedLanguages(CheckstyleConstants.JAVA_KEY);
- this.ruleFinder = ruleFinder;
- }
-
- private Module loadModule(SMInputCursor parentCursor) throws XMLStreamException {
- Module result = new Module();
- result.name = parentCursor.getAttrValue("name");
- SMInputCursor cursor = parentCursor.childElementCursor();
- while (cursor.getNext() != null) {
- String nodeName = cursor.getLocalName();
- if (MODULE_NODE.equals(nodeName)) {
- result.modules.add(loadModule(cursor));
- } else if ("property".equals(nodeName)) {
- String key = cursor.getAttrValue("name");
- String value = cursor.getAttrValue("value");
- result.properties.put(key, value);
- }
+ private static final Logger LOG = LoggerFactory.getLogger(CheckstyleProfileImporter.class);
+
+ private static final String CHECKER_MODULE = "Checker";
+ private static final String TREEWALKER_MODULE = "TreeWalker";
+ private static final String MODULE_NODE = "module";
+ private static final String[] FILTERS = {
+ "SeverityMatchFilter",
+ "SuppressionFilter",
+ "SuppressWarningsFilter",
+ "SuppressionCommentFilter",
+ "SuppressWithNearbyCommentFilter",
+ };
+ private final RuleFinder ruleFinder;
+
+ private static class Module {
+ private String name;
+ private final Map properties = new HashMap<>();
+ private final List modules = new ArrayList<>();
+ }
+
+ public CheckstyleProfileImporter(RuleFinder ruleFinder) {
+ super(CheckstyleConstants.REPOSITORY_KEY, CheckstyleConstants.PLUGIN_NAME);
+ setSupportedLanguages(CheckstyleConstants.JAVA_KEY);
+ this.ruleFinder = ruleFinder;
}
- return result;
- }
-
- @Override
- public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
- SMInputFactory inputFactory = initStax();
- RulesProfile profile = RulesProfile.create();
- try {
- Module checkerModule = loadModule(inputFactory.rootElementCursor(reader).advance());
-
- for (Module rootModule : checkerModule.modules) {
- Map rootModuleProperties = new HashMap<>(checkerModule.properties);
- rootModuleProperties.putAll(rootModule.properties);
-
- if (StringUtils.equals(TREEWALKER_MODULE, rootModule.name)) {
- processTreewalker(profile, rootModule, rootModuleProperties, messages);
- } else {
- processModule(profile, CHECKER_MODULE + "/", rootModule.name,
- rootModuleProperties, messages);
+
+ private Module loadModule(SMInputCursor parentCursor) throws XMLStreamException {
+ Module result = new Module();
+ result.name = parentCursor.getAttrValue("name");
+ SMInputCursor cursor = parentCursor.childElementCursor();
+ while (cursor.getNext() != null) {
+ String nodeName = cursor.getLocalName();
+ if (MODULE_NODE.equals(nodeName)) {
+ result.modules.add(loadModule(cursor));
+ }
+ else if ("property".equals(nodeName)) {
+ String key = cursor.getAttrValue("name");
+ String value = cursor.getAttrValue("value");
+ result.properties.put(key, value);
+ }
}
- }
+ return result;
+ }
+
+ @Override
+ public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
+ SMInputFactory inputFactory = initStax();
+ RulesProfile profile = RulesProfile.create();
+ try {
+ Module checkerModule = loadModule(inputFactory.rootElementCursor(reader).advance());
+
+ for (Module rootModule : checkerModule.modules) {
+ Map rootModuleProperties = new HashMap<>(checkerModule.properties);
+ rootModuleProperties.putAll(rootModule.properties);
+
+ if (StringUtils.equals(TREEWALKER_MODULE, rootModule.name)) {
+ processTreewalker(profile, rootModule, rootModuleProperties, messages);
+ }
+ else {
+ processModule(profile, CHECKER_MODULE + "/", rootModule.name,
+ rootModuleProperties, messages);
+ }
+ }
- } catch (XMLStreamException e) {
- String message = "XML is not valid: " + e.getMessage();
- LOG.error(message, e);
- messages.addErrorText(message);
+ }
+ catch (XMLStreamException e) {
+ String message = "XML is not valid: " + e.getMessage();
+ LOG.error(message, e);
+ messages.addErrorText(message);
+ }
+ return profile;
}
- return profile;
- }
-
- private void processTreewalker(RulesProfile profile, Module rootModule,
- Map rootModuleProperties,
- ValidationMessages messages) {
- for (Module treewalkerModule : rootModule.modules) {
- Map treewalkerModuleProperties = new HashMap<>(rootModuleProperties);
- treewalkerModuleProperties.putAll(treewalkerModule.properties);
-
- processModule(profile, CHECKER_MODULE + "/" + TREEWALKER_MODULE + "/",
- treewalkerModule.name, treewalkerModuleProperties, messages);
+
+ private void processTreewalker(RulesProfile profile, Module rootModule,
+ Map rootModuleProperties, ValidationMessages messages) {
+ for (Module treewalkerModule : rootModule.modules) {
+ Map treewalkerModuleProperties = new HashMap<>(rootModuleProperties);
+ treewalkerModuleProperties.putAll(treewalkerModule.properties);
+
+ processModule(profile, CHECKER_MODULE + "/" + TREEWALKER_MODULE + "/",
+ treewalkerModule.name, treewalkerModuleProperties, messages);
+ }
}
- }
-
- private static SMInputFactory initStax() {
- XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
- xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
- xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
- xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
- xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
- return new SMInputFactory(xmlFactory);
- }
-
- private void processModule(RulesProfile profile, String path, String moduleName,
- Map properties, ValidationMessages messages) {
- if (isFilter(moduleName)) {
- messages.addWarningText("Checkstyle filters are not imported: " + moduleName);
-
- } else if (!isIgnored(moduleName)) {
- processRule(profile, path, moduleName, properties, messages);
+
+ private static SMInputFactory initStax() {
+ XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
+ xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
+ xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
+ xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
+ xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
+ return new SMInputFactory(xmlFactory);
}
- }
-
- @VisibleForTesting
- static boolean isIgnored(String configKey) {
- return StringUtils.equals(configKey, "FileContentsHolder")
- || StringUtils.equals(configKey, "SuppressWarningsHolder");
- }
-
- @VisibleForTesting
- static boolean isFilter(String configKey) {
- for (String filter : FILTERS) {
- if (StringUtils.equals(configKey, filter)) {
- return true;
- }
+
+ private void processModule(RulesProfile profile, String path, String moduleName,
+ Map properties, ValidationMessages messages) {
+ if (isFilter(moduleName)) {
+ messages.addWarningText("Checkstyle filters are not imported: " + moduleName);
+
+ }
+ else if (!isIgnored(moduleName)) {
+ processRule(profile, path, moduleName, properties, messages);
+ }
}
- return false;
- }
-
- private void processRule(RulesProfile profile, String path, String moduleName,
- Map properties, ValidationMessages messages) {
- Rule rule;
- String id = properties.get("id");
- String warning;
- if (StringUtils.isNotBlank(id)) {
- rule = ruleFinder.find(RuleQuery.create()
- .withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withKey(id));
- warning = "Checkstyle rule with key '" + id + "' not found";
-
- } else {
- String configKey = path + moduleName;
- rule = ruleFinder.find(RuleQuery.create()
- .withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withConfigKey(configKey));
- warning = "Checkstyle rule with config key '" + configKey + "' not found";
+
+ @VisibleForTesting
+ static boolean isIgnored(String configKey) {
+ return StringUtils.equals(configKey, "FileContentsHolder")
+ || StringUtils.equals(configKey, "SuppressWarningsHolder");
}
- if (rule == null) {
- messages.addWarningText(warning);
+ @VisibleForTesting
+ static boolean isFilter(String configKey) {
+ for (String filter : FILTERS) {
+ if (StringUtils.equals(configKey, filter)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void processRule(RulesProfile profile, String path, String moduleName,
+ Map properties, ValidationMessages messages) {
+ Rule rule;
+ String id = properties.get("id");
+ String warning;
+ if (StringUtils.isNotBlank(id)) {
+ rule = ruleFinder.find(RuleQuery.create()
+ .withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withKey(id));
+ warning = "Checkstyle rule with key '" + id + "' not found";
- } else {
- ActiveRule activeRule = profile.activateRule(rule, null);
- activateProperties(activeRule, properties);
+ }
+ else {
+ String configKey = path + moduleName;
+ rule = ruleFinder
+ .find(RuleQuery.create().withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY)
+ .withConfigKey(configKey));
+ warning = "Checkstyle rule with config key '" + configKey + "' not found";
+ }
+
+ if (rule == null) {
+ messages.addWarningText(warning);
+
+ }
+ else {
+ ActiveRule activeRule = profile.activateRule(rule, null);
+ activateProperties(activeRule, properties);
+ }
}
- }
- private static void activateProperties(ActiveRule activeRule, Map properties) {
- for (Map.Entry property : properties.entrySet()) {
- if (StringUtils.equals("severity", property.getKey())) {
- activeRule.setSeverity(CheckstyleSeverityUtils.fromSeverity(property.getValue()));
+ private static void activateProperties(ActiveRule activeRule, Map properties) {
+ for (Map.Entry property : properties.entrySet()) {
+ if (StringUtils.equals("severity", property.getKey())) {
+ activeRule.setSeverity(CheckstyleSeverityUtils.fromSeverity(property.getValue()));
- } else if (!StringUtils.equals("id", property.getKey())) {
- activeRule.setParameter(property.getKey(), property.getValue());
- }
+ }
+ else if (!StringUtils.equals("id", property.getKey())) {
+ activeRule.setParameter(property.getKey(), property.getValue());
+ }
+ }
}
- }
}
diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleRulesDefinition.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleRulesDefinition.java
index ba7fc07c..ef06500e 100644
--- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleRulesDefinition.java
+++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleRulesDefinition.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import java.io.IOException;
@@ -32,35 +32,35 @@
public final class CheckstyleRulesDefinition implements RulesDefinition {
- @Override
- public void define(Context context) {
- NewRepository repository = context
- .createRepository(CheckstyleConstants.REPOSITORY_KEY, "java")
- .setName(CheckstyleConstants.REPOSITORY_NAME);
-
- try {
- extractRulesData(repository, "/org/sonar/plugins/checkstyle/rules.xml",
- "/org/sonar/l10n/checkstyle/rules/checkstyle");
- } catch (IOException e) {
- throw new IllegalStateException("Exception during extractRulesData", e);
- }
+ @Override
+ public void define(Context context) {
+ NewRepository repository = context.createRepository(CheckstyleConstants.REPOSITORY_KEY,
+ "java").setName(CheckstyleConstants.REPOSITORY_NAME);
- repository.done();
- }
+ try {
+ extractRulesData(repository, "/org/sonar/plugins/checkstyle/rules.xml",
+ "/org/sonar/l10n/checkstyle/rules/checkstyle");
+ }
+ catch (IOException e) {
+ throw new IllegalStateException("Exception during extractRulesData", e);
+ }
- @VisibleForTesting
- static void extractRulesData(NewRepository repository, String xmlRulesFilePath,
- String htmlDescriptionFolder) throws IOException {
- RulesDefinitionXmlLoader ruleLoader = new RulesDefinitionXmlLoader();
- try (InputStream resource =
- CheckstyleRulesDefinition.class.getResourceAsStream(xmlRulesFilePath)) {
- ruleLoader.load(repository, resource, "UTF-8");
+ repository.done();
}
- ExternalDescriptionLoader.loadHtmlDescriptions(repository, htmlDescriptionFolder);
- try (InputStream resource = CheckstyleRulesDefinition.class
- .getResourceAsStream("/org/sonar/l10n/checkstyle.properties")) {
- PropertyFileLoader.loadNames(repository, resource);
+
+ @VisibleForTesting
+ static void extractRulesData(NewRepository repository, String xmlRulesFilePath,
+ String htmlDescriptionFolder) throws IOException {
+ RulesDefinitionXmlLoader ruleLoader = new RulesDefinitionXmlLoader();
+ try (InputStream resource = CheckstyleRulesDefinition.class
+ .getResourceAsStream(xmlRulesFilePath)) {
+ ruleLoader.load(repository, resource, "UTF-8");
+ }
+ ExternalDescriptionLoader.loadHtmlDescriptions(repository, htmlDescriptionFolder);
+ try (InputStream resource = CheckstyleRulesDefinition.class
+ .getResourceAsStream("/org/sonar/l10n/checkstyle.properties")) {
+ PropertyFileLoader.loadNames(repository, resource);
+ }
+ SqaleXmlLoader.load(repository, "/com/sonar/sqale/checkstyle-model.xml");
}
- SqaleXmlLoader.load(repository, "/com/sonar/sqale/checkstyle-model.xml");
- }
}
diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java
index d283d8b9..5f32912d 100644
--- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java
+++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import java.io.File;
@@ -31,34 +31,35 @@
public class CheckstyleSensor implements Sensor {
- private final RulesProfile profile;
- private final CheckstyleExecutor executor;
- private final FileSystem fs;
+ private final RulesProfile profile;
+ private final CheckstyleExecutor executor;
+ private final FileSystem fs;
- public CheckstyleSensor(RulesProfile profile, CheckstyleExecutor executor, FileSystem fs) {
- this.profile = profile;
- this.executor = executor;
- this.fs = fs;
- }
+ public CheckstyleSensor(RulesProfile profile, CheckstyleExecutor executor, FileSystem fs) {
+ this.profile = profile;
+ this.executor = executor;
+ this.fs = fs;
+ }
- @Override
- public boolean shouldExecuteOnProject(Project project) {
- FilePredicates predicates = fs.predicates();
- Iterable mainFiles = fs.files(predicates.and(
- predicates.hasLanguage(CheckstyleConstants.JAVA_KEY),
- predicates.hasType(Type.MAIN)));
- boolean mainFilesIsEmpty = !mainFiles.iterator().hasNext();
- return !mainFilesIsEmpty &&
- !profile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY).isEmpty();
- }
+ @Override
+ public boolean shouldExecuteOnProject(Project project) {
+ FilePredicates predicates = fs.predicates();
+ Iterable mainFiles = fs
+ .files(predicates.and(predicates.hasLanguage(CheckstyleConstants.JAVA_KEY),
+ predicates.hasType(Type.MAIN)));
+ boolean mainFilesIsEmpty = !mainFiles.iterator().hasNext();
+ return !mainFilesIsEmpty
+ && !profile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY)
+ .isEmpty();
+ }
- @Override
- public void analyse(Project project, SensorContext context) {
- executor.execute();
- }
+ @Override
+ public void analyse(Project project, SensorContext context) {
+ executor.execute();
+ }
- @Override
- public String toString() {
- return getClass().getSimpleName();
- }
+ @Override
+ public String toString() {
+ return getClass().getSimpleName();
+ }
}
diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtils.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtils.java
index f4f751ad..6eb30cb1 100644
--- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtils.java
+++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtils.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import org.slf4j.Logger;
@@ -27,45 +27,46 @@
public final class CheckstyleSeverityUtils {
- private static final Logger LOG = LoggerFactory.getLogger(CheckstyleSeverityUtils.class);
-
- private CheckstyleSeverityUtils() {
- // only static methods
- }
+ private static final Logger LOG = LoggerFactory.getLogger(CheckstyleSeverityUtils.class);
- public static String toSeverity(RulePriority priority) {
- switch (priority) {
- case BLOCKER:
- case CRITICAL:
- return SeverityLevel.ERROR.getName();
- case MAJOR:
- return SeverityLevel.WARNING.getName();
- case MINOR:
- case INFO:
- return SeverityLevel.INFO.getName();
- default:
- throw new IllegalArgumentException("Priority not supported: " + priority);
+ private CheckstyleSeverityUtils() {
+ // only static methods
}
- }
- public static RulePriority fromSeverity(String severity) {
- SeverityLevel severityLevel;
- try {
- severityLevel = SeverityLevel.getInstance(severity);
- } catch (Exception exc) {
- LOG.warn("Smth wrong severity", exc);
- return null;
+ public static String toSeverity(RulePriority priority) {
+ switch (priority) {
+ case BLOCKER:
+ case CRITICAL:
+ return SeverityLevel.ERROR.getName();
+ case MAJOR:
+ return SeverityLevel.WARNING.getName();
+ case MINOR:
+ case INFO:
+ return SeverityLevel.INFO.getName();
+ default:
+ throw new IllegalArgumentException("Priority not supported: " + priority);
+ }
}
- switch (severityLevel) {
- case ERROR:
- return RulePriority.BLOCKER;
- case WARNING:
- return RulePriority.MAJOR;
- case INFO:
- case IGNORE:
- return RulePriority.INFO;
- default:
- return null;
+
+ public static RulePriority fromSeverity(String severity) {
+ SeverityLevel severityLevel;
+ try {
+ severityLevel = SeverityLevel.getInstance(severity);
+ }
+ catch (Exception exc) {
+ LOG.warn("Smth wrong severity", exc);
+ return null;
+ }
+ switch (severityLevel) {
+ case ERROR:
+ return RulePriority.BLOCKER;
+ case WARNING:
+ return RulePriority.MAJOR;
+ case INFO:
+ case IGNORE:
+ return RulePriority.INFO;
+ default:
+ return null;
+ }
}
- }
}
diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleVersion.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleVersion.java
index e30137a3..2daa38e3 100644
--- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleVersion.java
+++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleVersion.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import java.io.IOException;
@@ -27,29 +27,31 @@
import org.slf4j.LoggerFactory;
public enum CheckstyleVersion {
- INSTANCE;
-
- private static final String PROPERTIES_PATH =
- "/org/sonar/plugins/checkstyle/checkstyle-plugin.properties";
- private String version;
-
- CheckstyleVersion() {
- InputStream input = getClass().getResourceAsStream(PROPERTIES_PATH);
- try {
- Properties properties = new Properties();
- properties.load(input);
- this.version = properties.getProperty("checkstyle.version");
-
- } catch (IOException e) {
- LoggerFactory.getLogger(getClass()).warn("Can not load the Checkstyle version from the file "
- + PROPERTIES_PATH, e);
- this.version = "";
- } finally {
- IOUtils.closeQuietly(input);
+ INSTANCE;
+
+ private static final String PROPERTIES_PATH =
+ "/org/sonar/plugins/checkstyle/checkstyle-plugin.properties";
+ private String version;
+
+ CheckstyleVersion() {
+ InputStream input = getClass().getResourceAsStream(PROPERTIES_PATH);
+ try {
+ Properties properties = new Properties();
+ properties.load(input);
+ this.version = properties.getProperty("checkstyle.version");
+
+ }
+ catch (IOException e) {
+ LoggerFactory.getLogger(getClass()).warn(
+ "Can not load the Checkstyle version from the file " + PROPERTIES_PATH, e);
+ this.version = "";
+ }
+ finally {
+ IOUtils.closeQuietly(input);
+ }
}
- }
- public static String getVersion() {
- return INSTANCE.version;
- }
+ public static String getVersion() {
+ return INSTANCE.version;
+ }
}
diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/package-info.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/package-info.java
index 9474ad34..011c9e11 100644
--- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/package-info.java
+++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/package-info.java
@@ -1,23 +1,23 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
@ParametersAreNonnullByDefault
+
package org.sonar.plugins.checkstyle;
import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleAuditListenerTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleAuditListenerTest.java
index 59b8b2b5..897f24a8 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleAuditListenerTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleAuditListenerTest.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import static org.fest.assertions.Assertions.assertThat;
@@ -44,103 +44,99 @@
public class CheckstyleAuditListenerTest {
- private final File file = new File("file1");
- private final AuditEvent event =
- new AuditEvent(this, file.getAbsolutePath(),
- new LocalizedMessage(42, "", "", null, "",
- CheckstyleAuditListenerTest.class, "msg"));
- private final DefaultFileSystem fs = new DefaultFileSystem(new File(""));
- private final RuleFinder ruleFinder = mock(RuleFinder.class);
- private final DefaultInputFile inputFile = new DefaultInputFile("", file.getPath());
- private final ResourcePerspectives perspectives = mock(ResourcePerspectives.class);
-
- @Before
- public void before() {
- //inputFile.setAbsolutePath(file.getAbsolutePath());
- fs.add(inputFile);
- }
-
- @Test
- public void testUtilityMethods() {
- AuditEvent event;
-
- event = new AuditEvent(this, "",
- new LocalizedMessage(0, "", "", null, "",
- CheckstyleAuditListenerTest.class, "msg"));
- assertThat(CheckstyleAuditListener.getLineId(event)).isNull();
- assertThat(CheckstyleAuditListener.getMessage(event)).isEqualTo("msg");
- assertThat(CheckstyleAuditListener.getRuleKey(event))
- .isEqualTo(CheckstyleAuditListenerTest.class.getName());
-
- event = new AuditEvent(this, "",
- new LocalizedMessage(1, "", "", null, "",
- CheckstyleAuditListenerTest.class, "msg"));
- assertThat(CheckstyleAuditListener.getLineId(event)).isEqualTo(1);
- assertThat(CheckstyleAuditListener.getMessage(event)).isEqualTo("msg");
- assertThat(CheckstyleAuditListener.getRuleKey(event))
- .isEqualTo(CheckstyleAuditListenerTest.class.getName());
-
- event = new AuditEvent(this);
- assertThat(CheckstyleAuditListener.getLineId(event)).isNull();
- assertThat(CheckstyleAuditListener.getMessage(event)).isNull();
- assertThat(CheckstyleAuditListener.getRuleKey(event)).isNull();
- }
-
-
- @Test
- public void addErrorTest() {
- Rule rule = setupRule("repo", "key");
-
- Issuable issuable = setupIssuable();
- IssueBuilder issueBuilder = mock(IssueBuilder.class);
- Issue issue = mock(Issue.class);
- when(issuable.newIssueBuilder()).thenReturn(issueBuilder);
- when(issueBuilder.ruleKey(RuleKey.of("repo", "key"))).thenReturn(issueBuilder);
- when(issueBuilder.message(event.getMessage())).thenReturn(issueBuilder);
- when(issueBuilder.line(event.getLine())).thenReturn(issueBuilder);
- when(issueBuilder.build()).thenReturn(issue);
-
- addErrorToListener();
-
- verify(issuable).addIssue(issue);
- verify(issueBuilder).ruleKey(RuleKey.of("repo", "key"));
- verify(issueBuilder).message(event.getMessage());
- verify(issueBuilder).line(event.getLine());
- verify(rule).ruleKey();
- }
-
- @Test
- public void addErrorOnUnknownRule() {
- Issuable issuable = setupIssuable();
- addErrorToListener();
- verifyZeroInteractions(issuable);
- }
-
- @Test
- public void addErrorOnUnknownFile() {
- Rule rule = setupRule("repo", "key");
- addErrorToListener();
- verifyZeroInteractions(rule);
- }
-
- private CheckstyleAuditListener addErrorToListener() {
- CheckstyleAuditListener listener = new CheckstyleAuditListener(ruleFinder, fs, perspectives);
- listener.addError(event);
- return listener;
- }
-
- private Rule setupRule(String repo, String key) {
- Rule rule = mock(Rule.class);
- when(rule.ruleKey()).thenReturn(RuleKey.of(repo, key));
- when(ruleFinder.findByKey(CheckstyleConstants.REPOSITORY_KEY,
- CheckstyleAuditListenerTest.class.getCanonicalName()))
- .thenReturn(rule);
- return rule;
- }
-
- private Issuable setupIssuable() {
- Issuable issuable = mock(Issuable.class);
- when(perspectives.as(Issuable.class, inputFile)).thenReturn(issuable);
- return issuable;
- }
+ private final File file = new File("file1");
+ private final AuditEvent event = new AuditEvent(this, file.getAbsolutePath(),
+ new LocalizedMessage(42, "", "", null, "", CheckstyleAuditListenerTest.class, "msg"));
+ private final DefaultFileSystem fs = new DefaultFileSystem(new File(""));
+ private final RuleFinder ruleFinder = mock(RuleFinder.class);
+ private final DefaultInputFile inputFile = new DefaultInputFile("", file.getPath());
+ private final ResourcePerspectives perspectives = mock(ResourcePerspectives.class);
+
+ @Before
+ public void before() {
+ // inputFile.setAbsolutePath(file.getAbsolutePath());
+ fs.add(inputFile);
+ }
+
+ @Test
+ public void testUtilityMethods() {
+ AuditEvent event;
+
+ event = new AuditEvent(this, "", new LocalizedMessage(0, "", "", null, "",
+ CheckstyleAuditListenerTest.class, "msg"));
+ assertThat(CheckstyleAuditListener.getLineId(event)).isNull();
+ assertThat(CheckstyleAuditListener.getMessage(event)).isEqualTo("msg");
+ assertThat(CheckstyleAuditListener.getRuleKey(event)).isEqualTo(
+ CheckstyleAuditListenerTest.class.getName());
+
+ event = new AuditEvent(this, "", new LocalizedMessage(1, "", "", null, "",
+ CheckstyleAuditListenerTest.class, "msg"));
+ assertThat(CheckstyleAuditListener.getLineId(event)).isEqualTo(1);
+ assertThat(CheckstyleAuditListener.getMessage(event)).isEqualTo("msg");
+ assertThat(CheckstyleAuditListener.getRuleKey(event)).isEqualTo(
+ CheckstyleAuditListenerTest.class.getName());
+
+ event = new AuditEvent(this);
+ assertThat(CheckstyleAuditListener.getLineId(event)).isNull();
+ assertThat(CheckstyleAuditListener.getMessage(event)).isNull();
+ assertThat(CheckstyleAuditListener.getRuleKey(event)).isNull();
+ }
+
+ @Test
+ public void addErrorTest() {
+ Rule rule = setupRule("repo", "key");
+
+ Issuable issuable = setupIssuable();
+ IssueBuilder issueBuilder = mock(IssueBuilder.class);
+ Issue issue = mock(Issue.class);
+ when(issuable.newIssueBuilder()).thenReturn(issueBuilder);
+ when(issueBuilder.ruleKey(RuleKey.of("repo", "key"))).thenReturn(issueBuilder);
+ when(issueBuilder.message(event.getMessage())).thenReturn(issueBuilder);
+ when(issueBuilder.line(event.getLine())).thenReturn(issueBuilder);
+ when(issueBuilder.build()).thenReturn(issue);
+
+ addErrorToListener();
+
+ verify(issuable).addIssue(issue);
+ verify(issueBuilder).ruleKey(RuleKey.of("repo", "key"));
+ verify(issueBuilder).message(event.getMessage());
+ verify(issueBuilder).line(event.getLine());
+ verify(rule).ruleKey();
+ }
+
+ @Test
+ public void addErrorOnUnknownRule() {
+ Issuable issuable = setupIssuable();
+ addErrorToListener();
+ verifyZeroInteractions(issuable);
+ }
+
+ @Test
+ public void addErrorOnUnknownFile() {
+ Rule rule = setupRule("repo", "key");
+ addErrorToListener();
+ verifyZeroInteractions(rule);
+ }
+
+ private CheckstyleAuditListener addErrorToListener() {
+ CheckstyleAuditListener listener = new CheckstyleAuditListener(ruleFinder, fs,
+ perspectives);
+ listener.addError(event);
+ return listener;
+ }
+
+ private Rule setupRule(String repo, String key) {
+ Rule rule = mock(Rule.class);
+ when(rule.ruleKey()).thenReturn(RuleKey.of(repo, key));
+ when(
+ ruleFinder.findByKey(CheckstyleConstants.REPOSITORY_KEY,
+ CheckstyleAuditListenerTest.class.getCanonicalName())).thenReturn(rule);
+ return rule;
+ }
+
+ private Issuable setupIssuable() {
+ Issuable issuable = mock(Issuable.class);
+ when(perspectives.as(Issuable.class, inputFile)).thenReturn(issuable);
+ return issuable;
+ }
}
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
index cb084950..4edd80ec 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import static org.fest.assertions.Assertions.assertThat;
@@ -42,95 +42,97 @@
public class CheckstyleConfigurationTest {
- private DefaultFileSystem fileSystem;
-
- @Before
- public void beforeClass() {
- fileSystem = new DefaultFileSystem(new File(""));
- fileSystem.setWorkDir(new File(""));
- DefaultInputFile inputFile = new DefaultInputFile("", "mainFile");
- inputFile.setLanguage("java");
- inputFile.setType(InputFile.Type.MAIN);
- fileSystem.add(inputFile);
- DefaultInputFile testFile = new DefaultInputFile("", "testFile");
- testFile.setLanguage("java");
- testFile.setType(InputFile.Type.TEST);
- fileSystem.add(testFile);
- }
-
- @Test
- public void getSourceFiles() {
- CheckstyleProfileExporter exporter = new FakeExporter();
- CheckstyleConfiguration configuration = new CheckstyleConfiguration(null, exporter,
- null, fileSystem);
- assertThat(configuration.getSourceFiles()).hasSize(1);
- assertThat(configuration.getSourceFiles().iterator().next().toString()).contains("mainFile");
- }
-
- @Test
- public void getTargetXmlReport() {
- Settings conf = new Settings();
- CheckstyleConfiguration configuration = new CheckstyleConfiguration(conf, null,
- null, fileSystem);
- assertThat(configuration.getTargetXmlReport()).isNull();
-
- conf.setProperty(CheckstyleConfiguration.PROPERTY_GENERATE_XML, "true");
- configuration = new CheckstyleConfiguration(conf, null, null, fileSystem);
- assertThat(configuration.getTargetXmlReport()).isEqualTo(new File(fileSystem.workDir(),
- "checkstyle-result.xml"));
- }
-
- @Test
- public void writeConfigurationToWorkingDir() throws IOException {
- CheckstyleProfileExporter exporter = new FakeExporter();
- CheckstyleConfiguration configuration = new CheckstyleConfiguration(null, exporter,
- null, fileSystem);
- File xmlFile = configuration.getXmlDefinitionFile();
-
- assertThat(xmlFile.exists()).isTrue();
- assertThat(FileUtils.readFileToString(xmlFile)).isEqualTo("");
- FileUtils.forceDelete(xmlFile);
- }
-
- @Test
- public void getCheckstyleConfiguration() throws IOException, CheckstyleException {
- fileSystem.setEncoding(StandardCharsets.UTF_8);
- Settings settings =
- new Settings(new PropertyDefinitions(new CheckstylePlugin().getExtensions()));
- settings.setProperty(CheckstyleConstants.FILTERS_KEY,
- CheckstyleConstants.FILTERS_DEFAULT_VALUE);
-
- RulesProfile profile = RulesProfile.create("sonar way", "java");
-
- Rule rule = Rule.create("checkstyle", "CheckStyleRule1", "checkstyle rule one");
- rule.setConfigKey("checkstyle/rule1");
- profile.activateRule(rule, null);
-
- CheckstyleConfiguration configuration = new CheckstyleConfiguration(settings,
- new CheckstyleProfileExporter(settings), profile, fileSystem);
- Configuration checkstyleConfiguration = configuration.getCheckstyleConfiguration();
- assertThat(checkstyleConfiguration).isNotNull();
- assertThat(checkstyleConfiguration.getAttribute("charset")).isEqualTo("UTF-8");
- File xmlFile = new File("checkstyle.xml");
- assertThat(xmlFile.exists()).isTrue();
-
- FileUtils.forceDelete(xmlFile);
- }
-
- /* default */ static class FakeExporter extends CheckstyleProfileExporter {
-
- FakeExporter() {
- super(new Settings());
+ private DefaultFileSystem fileSystem;
+
+ @Before
+ public void beforeClass() {
+ fileSystem = new DefaultFileSystem(new File(""));
+ fileSystem.setWorkDir(new File(""));
+ DefaultInputFile inputFile = new DefaultInputFile("", "mainFile");
+ inputFile.setLanguage("java");
+ inputFile.setType(InputFile.Type.MAIN);
+ fileSystem.add(inputFile);
+ DefaultInputFile testFile = new DefaultInputFile("", "testFile");
+ testFile.setLanguage("java");
+ testFile.setType(InputFile.Type.TEST);
+ fileSystem.add(testFile);
+ }
+
+ @Test
+ public void getSourceFiles() {
+ CheckstyleProfileExporter exporter = new FakeExporter();
+ CheckstyleConfiguration configuration = new CheckstyleConfiguration(null, exporter, null,
+ fileSystem);
+ assertThat(configuration.getSourceFiles()).hasSize(1);
+ assertThat(configuration.getSourceFiles().iterator().next().toString())
+ .contains("mainFile");
+ }
+
+ @Test
+ public void getTargetXmlReport() {
+ Settings conf = new Settings();
+ CheckstyleConfiguration configuration = new CheckstyleConfiguration(conf, null, null,
+ fileSystem);
+ assertThat(configuration.getTargetXmlReport()).isNull();
+
+ conf.setProperty(CheckstyleConfiguration.PROPERTY_GENERATE_XML, "true");
+ configuration = new CheckstyleConfiguration(conf, null, null, fileSystem);
+ assertThat(configuration.getTargetXmlReport()).isEqualTo(
+ new File(fileSystem.workDir(), "checkstyle-result.xml"));
+ }
+
+ @Test
+ public void writeConfigurationToWorkingDir() throws IOException {
+ CheckstyleProfileExporter exporter = new FakeExporter();
+ CheckstyleConfiguration configuration = new CheckstyleConfiguration(null, exporter, null,
+ fileSystem);
+ File xmlFile = configuration.getXmlDefinitionFile();
+
+ assertThat(xmlFile.exists()).isTrue();
+ assertThat(FileUtils.readFileToString(xmlFile)).isEqualTo("");
+ FileUtils.forceDelete(xmlFile);
+ }
+
+ @Test
+ public void getCheckstyleConfiguration() throws IOException, CheckstyleException {
+ fileSystem.setEncoding(StandardCharsets.UTF_8);
+ Settings settings = new Settings(new PropertyDefinitions(
+ new CheckstylePlugin().getExtensions()));
+ settings.setProperty(CheckstyleConstants.FILTERS_KEY,
+ CheckstyleConstants.FILTERS_DEFAULT_VALUE);
+
+ RulesProfile profile = RulesProfile.create("sonar way", "java");
+
+ Rule rule = Rule.create("checkstyle", "CheckStyleRule1", "checkstyle rule one");
+ rule.setConfigKey("checkstyle/rule1");
+ profile.activateRule(rule, null);
+
+ CheckstyleConfiguration configuration = new CheckstyleConfiguration(settings,
+ new CheckstyleProfileExporter(settings), profile, fileSystem);
+ Configuration checkstyleConfiguration = configuration.getCheckstyleConfiguration();
+ assertThat(checkstyleConfiguration).isNotNull();
+ assertThat(checkstyleConfiguration.getAttribute("charset")).isEqualTo("UTF-8");
+ File xmlFile = new File("checkstyle.xml");
+ assertThat(xmlFile.exists()).isTrue();
+
+ FileUtils.forceDelete(xmlFile);
}
- @Override
- public void exportProfile(RulesProfile profile, Writer writer) {
- try {
- writer.write("");
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
+ /* default */static class FakeExporter extends CheckstyleProfileExporter {
+
+ FakeExporter() {
+ super(new Settings());
+ }
+
+ @Override
+ public void exportProfile(RulesProfile profile, Writer writer) {
+ try {
+ writer.write("");
+ }
+ catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
}
- }
}
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConstantsTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConstantsTest.java
index 37eb4dc2..a3257f1a 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConstantsTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConstantsTest.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import static org.fest.assertions.Assertions.assertThat;
@@ -27,13 +27,13 @@
public class CheckstyleConstantsTest {
- @Test
- public void privateConstructor() throws ReflectiveOperationException {
- Constructor constructor =
- CheckstyleConstants.class.getDeclaredConstructor();
- assertThat(constructor.isAccessible()).isFalse();
- constructor.setAccessible(true);
- constructor.newInstance();
- }
+ @Test
+ public void privateConstructor() throws ReflectiveOperationException {
+ Constructor constructor = CheckstyleConstants.class
+ .getDeclaredConstructor();
+ assertThat(constructor.isAccessible()).isFalse();
+ constructor.setAccessible(true);
+ constructor.newInstance();
+ }
}
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java
index bb9a3347..1824c168 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import static org.fest.assertions.Assertions.assertThat;
@@ -54,138 +54,139 @@
public class CheckstyleExecutorTest {
- @Rule
- public final ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void execute() throws CheckstyleException {
- CheckstyleConfiguration conf = mockConf();
- CheckstyleAuditListener listener = mockListener();
- CheckstyleExecutor executor =
- new CheckstyleExecutor(conf, listener, createJavaResourceLocator());
- executor.execute();
-
- verify(listener, times(1)).auditStarted(any(AuditEvent.class));
- verify(listener, times(1)).auditFinished(any(AuditEvent.class));
-
- InOrder inOrder = Mockito.inOrder(listener);
- ArgumentCaptor captor = ArgumentCaptor.forClass(AuditEvent.class);
- inOrder.verify(listener).fileStarted(captor.capture());
- assertThat(captor.getValue().getFileName()).matches(".*Hello.java");
- inOrder.verify(listener).fileFinished(captor.capture());
- assertThat(captor.getValue().getFileName()).matches(".*Hello.java");
- inOrder.verify(listener).fileStarted(captor.capture());
- assertThat(captor.getValue().getFileName()).matches(".*World.java");
- inOrder.verify(listener).fileFinished(captor.capture());
- assertThat(captor.getValue().getFileName()).matches(".*World.java");
- verify(listener, atLeast(1)).addError(captor.capture());
- AuditEvent event = captor.getValue();
- assertThat(event.getFileName()).matches(".*Hello.java");
- assertThat(event.getSourceName())
- .matches("com.puppycrawl.tools.checkstyle.checks.coding.EmptyStatementCheck");
- }
-
- @Test
- public void executeException() throws CheckstyleException {
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Can not execute Checkstyle");
- CheckstyleConfiguration conf = mockConf();
- CheckstyleExecutor executor =
- new CheckstyleExecutor(conf, null, createJavaResourceLocator());
- executor.execute();
- }
-
- @Test
- public void getUrlException() throws URISyntaxException {
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Fail to create the project classloader. "
- + "Classpath element is invalid: htp://aa");
- CheckstyleExecutor executor =
- new CheckstyleExecutor(null, null, createJavaResourceLocator());
- executor.getUrl(new URI("htp://aa"));
- }
-
- private static JavaResourceLocator createJavaResourceLocator() {
- JavaClasspath javaClasspath = mock(JavaClasspath.class);
- when(javaClasspath.getElements()).thenReturn(ImmutableList.of(new File(".")));
- return new DefaultJavaResourceLocator(null, javaClasspath, null);
- }
-
- @Test
- public void canGenerateXmlReportInEnglish() throws CheckstyleException, IOException {
- Locale initialLocale = Locale.getDefault();
- Locale.setDefault(Locale.FRENCH);
-
- try {
- CheckstyleConfiguration conf = mockConf();
- File report = new File("target/test-tmp/checkstyle-report.xml");
- report.delete(); // delete if exists from a previous run
- when(conf.getTargetXmlReport()).thenReturn(report);
- CheckstyleAuditListener listener = mockListener();
- CheckstyleExecutor executor =
- new CheckstyleExecutor(conf, listener, createJavaResourceLocator());
- executor.execute();
-
- Assert.assertTrue(report.exists());
-
- String reportContents = FileUtils.readFileToString(report);
- assertThat(reportContents).contains(" captor = ArgumentCaptor.forClass(AuditEvent.class);
+ inOrder.verify(listener).fileStarted(captor.capture());
+ assertThat(captor.getValue().getFileName()).matches(".*Hello.java");
+ inOrder.verify(listener).fileFinished(captor.capture());
+ assertThat(captor.getValue().getFileName()).matches(".*Hello.java");
+ inOrder.verify(listener).fileStarted(captor.capture());
+ assertThat(captor.getValue().getFileName()).matches(".*World.java");
+ inOrder.verify(listener).fileFinished(captor.capture());
+ assertThat(captor.getValue().getFileName()).matches(".*World.java");
+ verify(listener, atLeast(1)).addError(captor.capture());
+ AuditEvent event = captor.getValue();
+ assertThat(event.getFileName()).matches(".*Hello.java");
+ assertThat(event.getSourceName()).matches(
+ "com.puppycrawl.tools.checkstyle.checks.coding.EmptyStatementCheck");
+ }
+
+ @Test
+ public void executeException() throws CheckstyleException {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("Can not execute Checkstyle");
+ CheckstyleConfiguration conf = mockConf();
+ CheckstyleExecutor executor = new CheckstyleExecutor(conf, null,
+ createJavaResourceLocator());
+ executor.execute();
+ }
+
+ @Test
+ public void getUrlException() throws URISyntaxException {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("Fail to create the project classloader. "
+ + "Classpath element is invalid: htp://aa");
+ CheckstyleExecutor executor = new CheckstyleExecutor(null, null,
+ createJavaResourceLocator());
+ executor.getUrl(new URI("htp://aa"));
+ }
+
+ private static JavaResourceLocator createJavaResourceLocator() {
+ JavaClasspath javaClasspath = mock(JavaClasspath.class);
+ when(javaClasspath.getElements()).thenReturn(ImmutableList.of(new File(".")));
+ return new DefaultJavaResourceLocator(null, javaClasspath, null);
+ }
+
+ @Test
+ public void canGenerateXmlReportInEnglish() throws CheckstyleException, IOException {
+ Locale initialLocale = Locale.getDefault();
+ Locale.setDefault(Locale.FRENCH);
+
+ try {
+ CheckstyleConfiguration conf = mockConf();
+ File report = new File("target/test-tmp/checkstyle-report.xml");
+ // delete if exists from a previous run
+ report.delete();
+ when(conf.getTargetXmlReport()).thenReturn(report);
+ CheckstyleAuditListener listener = mockListener();
+ CheckstyleExecutor executor = new CheckstyleExecutor(conf, listener,
+ createJavaResourceLocator());
+ executor.execute();
+
+ Assert.assertTrue(report.exists());
+
+ String reportContents = FileUtils.readFileToString(report);
+ assertThat(reportContents).contains(" not exported in checkstyle
- rule.createParameter("message");
- rule.createParameter("ignore");
-
- profile.activateRule(rule, RulePriority.MAJOR)
- .setParameter("format", "abcde");
-
- StringWriter writer = new StringWriter();
- new CheckstyleProfileExporter(settings).exportProfile(profile, writer);
-
- CheckstyleTestUtils.assertSimilarXmlWithResource(
- "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
- + "exportParameters.xml",
- sanitizeForTests(writer.toString()));
- }
-
- @Test
- public void addCustomFilters() {
- settings.setProperty(CheckstyleConstants.FILTERS_KEY,
- ""
- + ""
- + "" + ""
- + ""
- + ""
- + ""
- + ""
- + "");
-
- RulesProfile profile = RulesProfile.create("sonar way", "java");
- StringWriter writer = new StringWriter();
- new CheckstyleProfileExporter(settings).exportProfile(profile, writer);
-
- CheckstyleTestUtils.assertSimilarXmlWithResource(
- "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
- + "addCustomFilters.xml",
- sanitizeForTests(writer.toString()));
- }
-
- private static String sanitizeForTests(String xml) {
- // remove the doctype declaration, else the unit test fails when executed offline
- return StringUtils.remove(xml, CheckstyleProfileExporter.DOCTYPE_DECLARATION);
- }
+ private Settings settings;
+
+ @Before
+ public void prepare() {
+ settings = new Settings(new PropertyDefinitions(new CheckstylePlugin().getExtensions()));
+ }
+
+ @Test
+ public void alwaysSetFileContentsHolderAndSuppressionCommentFilter() {
+ RulesProfile profile = RulesProfile.create("sonar way", "java");
+
+ StringWriter writer = new StringWriter();
+ new CheckstyleProfileExporter(settings).exportProfile(profile, writer);
+
+ CheckstyleTestUtils.assertSimilarXmlWithResource(
+ "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
+ + "alwaysSetFileContentsHolderAndSuppressionCommentFilter.xml",
+ sanitizeForTests(writer.toString()));
+ }
+
+ @Test
+ public void noCheckstyleRulesToExport() {
+ RulesProfile profile = RulesProfile.create("sonar way", "java");
+
+ // this is a PMD rule
+ profile.activateRule(Rule.create("pmd", "PmdRule1", "PMD rule one"), null);
+
+ StringWriter writer = new StringWriter();
+ new CheckstyleProfileExporter(settings).exportProfile(profile, writer);
+
+ CheckstyleTestUtils.assertSimilarXmlWithResource(
+ "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
+ + "noCheckstyleRulesToExport.xml", sanitizeForTests(writer.toString()));
+ }
+
+ @Test
+ public void singleCheckstyleRulesToExport() {
+ RulesProfile profile = RulesProfile.create("sonar way", "java");
+ profile.activateRule(Rule.create("pmd", "PmdRule1", "PMD rule one"), null);
+ profile.activateRule(
+ Rule.create("checkstyle",
+ "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck",
+ "Javadoc").setConfigKey("Checker/JavadocPackage"), RulePriority.MAJOR);
+ profile.activateRule(
+ Rule.create("checkstyle",
+ "com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck",
+ "Line Length").setConfigKey("Checker/TreeWalker/LineLength"),
+ RulePriority.CRITICAL);
+ profile.activateRule(
+ Rule.create(
+ "checkstyle",
+ "com.puppycrawl.tools.checkstyle.checks.naming.LocalFinalVariableNameCheck",
+ "Local Variable").setConfigKey(
+ "Checker/TreeWalker/Checker/TreeWalker/LocalFinalVariableName"),
+ RulePriority.MINOR);
+
+ StringWriter writer = new StringWriter();
+ new CheckstyleProfileExporter(settings).exportProfile(profile, writer);
+
+ CheckstyleTestUtils.assertSimilarXmlWithResource(
+ "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
+ + "singleCheckstyleRulesToExport.xml", sanitizeForTests(writer.toString()));
+ }
+
+ @Test
+ public void addTheIdPropertyWhenManyInstancesWithTheSameConfigKey() {
+ RulesProfile profile = RulesProfile.create("sonar way", "java");
+ Rule rule1 = Rule.create("checkstyle",
+ "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck", "Javadoc")
+ .setConfigKey("Checker/JavadocPackage");
+ Rule rule2 = Rule
+ .create("checkstyle",
+ "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck_12345",
+ "Javadoc").setConfigKey("Checker/JavadocPackage").setParent(rule1);
+
+ profile.activateRule(rule1, RulePriority.MAJOR);
+ profile.activateRule(rule2, RulePriority.CRITICAL);
+
+ StringWriter writer = new StringWriter();
+ new CheckstyleProfileExporter(settings).exportProfile(profile, writer);
+
+ CheckstyleTestUtils.assertSimilarXmlWithResource(
+ "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
+ + "addTheIdPropertyWhenManyInstancesWithTheSameConfigKey.xml",
+ sanitizeForTests(writer.toString()));
+ }
+
+ @Test
+ public void exportParameters() {
+ RulesProfile profile = RulesProfile.create("sonar way", "java");
+ Rule rule = Rule.create("checkstyle",
+ "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck", "Javadoc")
+ .setConfigKey("Checker/JavadocPackage");
+ rule.createParameter("format");
+ // not set in the profile and no default value => not exported in
+ // checkstyle
+ rule.createParameter("message");
+ rule.createParameter("ignore");
+
+ profile.activateRule(rule, RulePriority.MAJOR).setParameter("format", "abcde");
+
+ StringWriter writer = new StringWriter();
+ new CheckstyleProfileExporter(settings).exportProfile(profile, writer);
+
+ CheckstyleTestUtils.assertSimilarXmlWithResource(
+ "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
+ + "exportParameters.xml", sanitizeForTests(writer.toString()));
+ }
+
+ @Test
+ public void addCustomFilters() {
+ settings.setProperty(CheckstyleConstants.FILTERS_KEY,
+ ""
+ + ""
+ + ""
+ + "" + ""
+ + ""
+ + ""
+ + "" + "");
+
+ RulesProfile profile = RulesProfile.create("sonar way", "java");
+ StringWriter writer = new StringWriter();
+ new CheckstyleProfileExporter(settings).exportProfile(profile, writer);
+
+ CheckstyleTestUtils.assertSimilarXmlWithResource(
+ "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
+ + "addCustomFilters.xml", sanitizeForTests(writer.toString()));
+ }
+
+ private static String sanitizeForTests(String xml) {
+ // remove the doctype declaration, else the unit test fails when
+ // executed offline
+ return StringUtils.remove(xml, CheckstyleProfileExporter.DOCTYPE_DECLARATION);
+ }
}
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java
index b3d65985..c353f41b 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import static org.fest.assertions.Assertions.assertThat;
@@ -44,188 +44,196 @@
public class CheckstyleProfileImporterTest {
- private ValidationMessages messages;
- private CheckstyleProfileImporter importer;
-
- @Before
- public void before() {
- messages = ValidationMessages.create();
-
- /*
- * The mocked rule finder defines 3 rules :
- *
- * - JavadocCheck with 2 paramters format and ignore, default priority is MAJOR
- * - EqualsHashCodeCheck without parameters, default priority is BLOCKER
- * - MissingOverride with 1 parameter javaFiveCompatibility, default priority is MINOR
- */
- importer = new CheckstyleProfileImporter(newRuleFinder());
- }
-
- @Test
- public void importSimpleProfile() {
- Reader reader = new StringReader(
- CheckstyleTestUtils.getResourceContent(
- "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/simple.xml"));
- RulesProfile profile = importer.importProfile(reader, messages);
-
- assertThat(profile.getActiveRules().size()).isEqualTo(2);
- assertNotNull(profile.getActiveRuleByConfigKey("checkstyle",
- "Checker/TreeWalker/EqualsHashCode"));
- assertNotNull(profile.getActiveRuleByConfigKey("checkstyle",
- "Checker/JavadocPackage"));
- assertThat(messages.hasErrors()).isFalse();
- }
-
- @Test
- public void importParameters() {
- Reader reader = new StringReader(
- CheckstyleTestUtils.getResourceContent(
- "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/simple.xml"));
- RulesProfile profile = importer.importProfile(reader, messages);
-
- ActiveRule javadocCheck = profile.getActiveRuleByConfigKey("checkstyle",
- "Checker/JavadocPackage");
- assertThat(javadocCheck.getActiveRuleParams()).hasSize(2);
- assertThat(javadocCheck.getParameter("format")).isEqualTo("abcde");
- assertThat(javadocCheck.getParameter("ignore")).isEqualTo("true");
- assertThat(javadocCheck.getParameter("severity")).isNull(); // checkstyle internal parameter
- }
-
- @Test
- public void propertiesShouldBeInherited() {
- Reader reader = new StringReader(
- CheckstyleTestUtils.getResourceContent(
- "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/"
- + "inheritance_of_properties.xml"));
- RulesProfile profile = importer.importProfile(reader, messages);
-
- ActiveRule activeRule = profile.getActiveRuleByConfigKey("checkstyle",
- "Checker/TreeWalker/MissingOverride");
- assertThat(activeRule.getSeverity()).isEqualTo(RulePriority.BLOCKER);
- assertThat(activeRule.getParameter("javaFiveCompatibility")).isEqualTo("true");
- }
-
- @Test
- public void importPriorities() {
- Reader reader = new StringReader(
- CheckstyleTestUtils.getResourceContent(
- "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/simple.xml"));
- RulesProfile profile = importer.importProfile(reader, messages);
-
- ActiveRule javadocCheck = profile.getActiveRuleByConfigKey("checkstyle",
- "Checker/JavadocPackage");
- assertThat(javadocCheck.getSeverity()).isEqualTo(RulePriority.BLOCKER);
- }
-
- @Test
- public void priorityIsOptional() {
- Reader reader = new StringReader(
- CheckstyleTestUtils.getResourceContent("/org/sonar/plugins/checkstyle/"
- + "CheckstyleProfileImporterTest/simple.xml"));
- RulesProfile profile = importer.importProfile(reader, messages);
-
- ActiveRule activeRule = profile.getActiveRuleByConfigKey("checkstyle",
- "Checker/TreeWalker/EqualsHashCode");
- // reuse the rule default priority
- assertThat(activeRule.getSeverity()).isEqualTo(RulePriority.BLOCKER);
- }
-
- @Test
- public void idPropertyShouldBeTheRuleKey() {
- Reader reader = new StringReader(CheckstyleTestUtils.getResourceContent(
- "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/"
- + "idPropertyShouldBeTheRuleKey.xml"));
- RulesProfile profile = importer.importProfile(reader, messages);
-
- assertNull(profile.getActiveRuleByConfigKey("checkstyle",
- "Checker/JavadocPackage"));
- assertThat(messages.getWarnings().size()).isEqualTo(1);
- }
-
- @Test
- public void shouldUseTheIdPropertyToFindRule() {
- Reader reader = new StringReader(
- CheckstyleTestUtils.getResourceContent("/org/sonar/plugins/checkstyle/"
- + "CheckstyleProfileImporterTest/shouldUseTheIdPropertyToFindRule.xml"));
- RulesProfile profile = importer.importProfile(reader, messages);
-
- assertNotNull(profile.getActiveRuleByConfigKey("checkstyle",
- "Checker/JavadocPackage"));
- assertThat(profile.getActiveRuleByConfigKey("checkstyle",
- "Checker/JavadocPackage").getRule().getKey())
- .isEqualTo("com.puppycrawl.tools.checkstyle.checks.javadoc."
- + "JavadocPackageCheck_12345");
- assertThat(messages.getWarnings().size()).isEqualTo(0);
- }
-
- @Test
- public void testUnvalidXml() {
- Reader reader = new StringReader("not xml");
- importer.importProfile(reader, messages);
- assertThat(messages.getErrors().size()).isEqualTo(1);
- }
-
- @Test
- public void importingFiltersIsNotSupported() {
- Reader reader = new StringReader(
- CheckstyleTestUtils.getResourceContent("/org/sonar/plugins/checkstyle/"
- + "CheckstyleProfileImporterTest/importingFiltersIsNotSupported.xml"));
- RulesProfile profile = importer.importProfile(reader, messages);
-
- assertNull(profile.getActiveRuleByConfigKey("checkstyle",
- "Checker/SuppressionCommentFilter"));
- assertNull(profile.getActiveRuleByConfigKey("checkstyle",
- "Checker/TreeWalker/FileContentsHolder"));
- assertThat(profile.getActiveRules().size()).isEqualTo(2);
- assertThat(messages.getWarnings().size()).isEqualTo(5); // no warning for FileContentsHolder
- }
-
- private static RuleFinder newRuleFinder() {
- RuleFinder ruleFinder = mock(RuleFinder.class);
- when(ruleFinder.find(any(RuleQuery.class))).thenAnswer(new Answer() {
- @Override
- public Rule answer(InvocationOnMock iom) throws Throwable {
- RuleQuery query = (RuleQuery) iom.getArguments()[0];
- Rule rule = null;
- if (StringUtils.equals(query.getConfigKey(), "Checker/JavadocPackage")) {
- rule = Rule.create(query.getRepositoryKey(),
- "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck",
- "Javadoc Package")
- .setConfigKey("Checker/JavadocPackage")
- .setSeverity(RulePriority.MAJOR);
- rule.createParameter("format");
- rule.createParameter("ignore");
-
- } else if (StringUtils.equals(query.getConfigKey(),
- "Checker/TreeWalker/EqualsHashCode")) {
- rule = Rule.create(query.getRepositoryKey(),
- "com.puppycrawl.tools.checkstyle.checks.coding.EqualsHashCodeCheck",
- "Equals HashCode")
- .setConfigKey("Checker/TreeWalker/EqualsHashCode")
- .setSeverity(RulePriority.BLOCKER);
-
- } else if (StringUtils.equals(query.getKey(),
- "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck_12345")) {
- rule = Rule.create(query.getRepositoryKey(),
- "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck_12345",
- "Javadoc Package")
- .setConfigKey("Checker/JavadocPackage")
- .setSeverity(RulePriority.MAJOR);
- rule.createParameter("format");
- rule.createParameter("ignore");
- } else if (StringUtils.equals(query.getConfigKey(),
- "Checker/TreeWalker/MissingOverride")) {
- rule = Rule.create(query.getRepositoryKey(),
- "com.puppycrawl.tools.checkstyle.checks.annotation.MissingOverrideCheck",
- "Missing Override")
- .setConfigKey("Checker/TreeWalker/MissingOverride")
- .setSeverity(RulePriority.MINOR);
- rule.createParameter("javaFiveCompatibility");
- }
- return rule;
- }
- });
- return ruleFinder;
- }
+ private ValidationMessages messages;
+ private CheckstyleProfileImporter importer;
+
+ @Before
+ public void before() {
+ messages = ValidationMessages.create();
+
+ /*
+ * The mocked rule finder defines 3 rules :
+ *
+ * - JavadocCheck with 2 paramters format and ignore, default priority
+ * is MAJOR
+ * - EqualsHashCodeCheck without parameters, default priority
+ * is BLOCKER
+ * - MissingOverride with 1 parameter javaFiveCompatibility,
+ * default priority is MINOR
+ */
+ importer = new CheckstyleProfileImporter(newRuleFinder());
+ }
+
+ @Test
+ public void importSimpleProfile() {
+ Reader reader = new StringReader(CheckstyleTestUtils.getResourceContent(
+ "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/simple.xml"));
+ RulesProfile profile = importer.importProfile(reader, messages);
+
+ assertThat(profile.getActiveRules().size()).isEqualTo(2);
+ assertNotNull(profile.getActiveRuleByConfigKey("checkstyle",
+ "Checker/TreeWalker/EqualsHashCode"));
+ assertNotNull(profile.getActiveRuleByConfigKey("checkstyle", "Checker/JavadocPackage"));
+ assertThat(messages.hasErrors()).isFalse();
+ }
+
+ @Test
+ public void importParameters() {
+ Reader reader = new StringReader(CheckstyleTestUtils.getResourceContent(
+ "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/simple.xml"));
+ RulesProfile profile = importer.importProfile(reader, messages);
+
+ ActiveRule javadocCheck = profile.getActiveRuleByConfigKey("checkstyle",
+ "Checker/JavadocPackage");
+ assertThat(javadocCheck.getActiveRuleParams()).hasSize(2);
+ assertThat(javadocCheck.getParameter("format")).isEqualTo("abcde");
+ assertThat(javadocCheck.getParameter("ignore")).isEqualTo("true");
+ // checkstyle internal parameter
+ assertThat(javadocCheck.getParameter("severity")).isNull();
+ }
+
+ @Test
+ public void propertiesShouldBeInherited() {
+ Reader reader = new StringReader(CheckstyleTestUtils.getResourceContent(
+ "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/"
+ + "inheritance_of_properties.xml"));
+ RulesProfile profile = importer.importProfile(reader, messages);
+
+ ActiveRule activeRule = profile.getActiveRuleByConfigKey("checkstyle",
+ "Checker/TreeWalker/MissingOverride");
+ assertThat(activeRule.getSeverity()).isEqualTo(RulePriority.BLOCKER);
+ assertThat(activeRule.getParameter("javaFiveCompatibility")).isEqualTo("true");
+ }
+
+ @Test
+ public void importPriorities() {
+ Reader reader = new StringReader(CheckstyleTestUtils.getResourceContent(
+ "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/simple.xml"));
+ RulesProfile profile = importer.importProfile(reader, messages);
+
+ ActiveRule javadocCheck = profile.getActiveRuleByConfigKey("checkstyle",
+ "Checker/JavadocPackage");
+ assertThat(javadocCheck.getSeverity()).isEqualTo(RulePriority.BLOCKER);
+ }
+
+ @Test
+ public void priorityIsOptional() {
+ Reader reader = new StringReader(CheckstyleTestUtils.getResourceContent(
+ "/org/sonar/plugins/checkstyle/"
+ + "CheckstyleProfileImporterTest/simple.xml"));
+ RulesProfile profile = importer.importProfile(reader, messages);
+
+ ActiveRule activeRule = profile.getActiveRuleByConfigKey("checkstyle",
+ "Checker/TreeWalker/EqualsHashCode");
+ // reuse the rule default priority
+ assertThat(activeRule.getSeverity()).isEqualTo(RulePriority.BLOCKER);
+ }
+
+ @Test
+ public void idPropertyShouldBeTheRuleKey() {
+ Reader reader = new StringReader(CheckstyleTestUtils.getResourceContent(
+ "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/"
+ + "idPropertyShouldBeTheRuleKey.xml"));
+ RulesProfile profile = importer.importProfile(reader, messages);
+
+ assertNull(profile.getActiveRuleByConfigKey("checkstyle", "Checker/JavadocPackage"));
+ assertThat(messages.getWarnings().size()).isEqualTo(1);
+ }
+
+ @Test
+ public void shouldUseTheIdPropertyToFindRule() {
+ Reader reader = new StringReader(
+ CheckstyleTestUtils.getResourceContent("/org/sonar/plugins/checkstyle/"
+ + "CheckstyleProfileImporterTest/shouldUseTheIdPropertyToFindRule.xml"));
+ RulesProfile profile = importer.importProfile(reader, messages);
+
+ assertNotNull(profile.getActiveRuleByConfigKey("checkstyle", "Checker/JavadocPackage"));
+ assertThat(
+ profile.getActiveRuleByConfigKey("checkstyle", "Checker/JavadocPackage").getRule()
+ .getKey()).isEqualTo(
+ "com.puppycrawl.tools.checkstyle.checks.javadoc." + "JavadocPackageCheck_12345");
+ assertThat(messages.getWarnings().size()).isEqualTo(0);
+ }
+
+ @Test
+ public void testUnvalidXml() {
+ Reader reader = new StringReader("not xml");
+ importer.importProfile(reader, messages);
+ assertThat(messages.getErrors().size()).isEqualTo(1);
+ }
+
+ @Test
+ public void importingFiltersIsNotSupported() {
+ Reader reader = new StringReader(
+ CheckstyleTestUtils.getResourceContent("/org/sonar/plugins/checkstyle/"
+ + "CheckstyleProfileImporterTest/importingFiltersIsNotSupported.xml"));
+ RulesProfile profile = importer.importProfile(reader, messages);
+
+ assertNull(profile.getActiveRuleByConfigKey("checkstyle",
+ "Checker/SuppressionCommentFilter"));
+ assertNull(profile.getActiveRuleByConfigKey("checkstyle",
+ "Checker/TreeWalker/FileContentsHolder"));
+ assertThat(profile.getActiveRules().size()).isEqualTo(2);
+ // no warning for FileContentsHolder
+ assertThat(messages.getWarnings().size()).isEqualTo(5);
+ }
+
+ private static RuleFinder newRuleFinder() {
+ RuleFinder ruleFinder = mock(RuleFinder.class);
+ when(ruleFinder.find(any(RuleQuery.class))).thenAnswer(new Answer() {
+ @Override
+ public Rule answer(InvocationOnMock iom) throws Throwable {
+ RuleQuery query = (RuleQuery) iom.getArguments()[0];
+ Rule rule = null;
+ if (StringUtils.equals(query.getConfigKey(), "Checker/JavadocPackage")) {
+ rule = Rule
+ .create(query.getRepositoryKey(),
+ "com.puppycrawl.tools.checkstyle.checks.javadoc."
+ + "JavadocPackageCheck", "Javadoc Package")
+ .setConfigKey("Checker/JavadocPackage")
+ .setSeverity(RulePriority.MAJOR);
+ rule.createParameter("format");
+ rule.createParameter("ignore");
+
+ }
+ else if (StringUtils.equals(query.getConfigKey(),
+ "Checker/TreeWalker/EqualsHashCode")) {
+ rule = Rule
+ .create(query.getRepositoryKey(),
+ "com.puppycrawl.tools.checkstyle.checks.coding."
+ + "EqualsHashCodeCheck",
+ "Equals HashCode")
+ .setConfigKey("Checker/TreeWalker/EqualsHashCode")
+ .setSeverity(RulePriority.BLOCKER);
+
+ }
+ else if (StringUtils.equals(query.getKey(),
+ "com.puppycrawl.tools.checkstyle.checks.javadoc."
+ + "JavadocPackageCheck_12345")) {
+ rule = Rule
+ .create(query.getRepositoryKey(),
+ "com.puppycrawl.tools.checkstyle.checks.javadoc."
+ + "JavadocPackageCheck_12345",
+ "Javadoc Package").setConfigKey("Checker/JavadocPackage")
+ .setSeverity(RulePriority.MAJOR);
+ rule.createParameter("format");
+ rule.createParameter("ignore");
+ }
+ else if (StringUtils.equals(query.getConfigKey(),
+ "Checker/TreeWalker/MissingOverride")) {
+ rule = Rule
+ .create(query.getRepositoryKey(),
+ "com.puppycrawl.tools.checkstyle.checks.annotation."
+ + "MissingOverrideCheck",
+ "Missing Override")
+ .setConfigKey("Checker/TreeWalker/MissingOverride")
+ .setSeverity(RulePriority.MINOR);
+ rule.createParameter("javaFiveCompatibility");
+ }
+ return rule;
+ }
+ });
+ return ruleFinder;
+ }
}
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRulesDefinitionTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRulesDefinitionTest.java
index 40bd5518..746ac40d 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRulesDefinitionTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRulesDefinitionTest.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import static org.fest.assertions.Assertions.assertThat;
@@ -31,65 +31,62 @@
public class CheckstyleRulesDefinitionTest {
- private static final List NO_SQALE = ImmutableList.of(
- "com.puppycrawl.tools.checkstyle.checks.TranslationCheck",
- "com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck",
- "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck",
- "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck",
- "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpMultilineCheck",
- "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpOnFilenameCheck",
- "com.puppycrawl.tools.checkstyle.checks.RegexpCheck",
- "com.puppycrawl.tools.checkstyle.checks.header.RegexpHeaderCheck",
- "com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheck",
- "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationLocationCheck"
- );
+ private static final List NO_SQALE = ImmutableList.of(
+ "com.puppycrawl.tools.checkstyle.checks.TranslationCheck",
+ "com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck",
+ "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck",
+ "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck",
+ "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpMultilineCheck",
+ "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpOnFilenameCheck",
+ "com.puppycrawl.tools.checkstyle.checks.RegexpCheck",
+ "com.puppycrawl.tools.checkstyle.checks.header.RegexpHeaderCheck",
+ "com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheck",
+ "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationLocationCheck"
+ );
- @Ignore
- @Test
- public void test() {
- CheckstyleRulesDefinition definition = new CheckstyleRulesDefinition();
- RulesDefinition.Context context = new RulesDefinition.Context();
- definition.define(context);
- RulesDefinition.Repository repository = context.repository(CheckstyleConstants.REPOSITORY_KEY);
+ @Ignore
+ @Test
+ public void test() {
+ CheckstyleRulesDefinition definition = new CheckstyleRulesDefinition();
+ RulesDefinition.Context context = new RulesDefinition.Context();
+ definition.define(context);
+ RulesDefinition.Repository repository = context
+ .repository(CheckstyleConstants.REPOSITORY_KEY);
- assertThat(repository.name()).isEqualTo(CheckstyleConstants.REPOSITORY_NAME);
- assertThat(repository.language()).isEqualTo("java");
+ assertThat(repository.name()).isEqualTo(CheckstyleConstants.REPOSITORY_NAME);
+ assertThat(repository.language()).isEqualTo("java");
- List rules = repository.rules();
- assertThat(rules).hasSize(150);
+ List rules = repository.rules();
+ assertThat(rules).hasSize(150);
- for (RulesDefinition.Rule rule : rules) {
- assertThat(rule.key()).isNotNull();
- assertThat(rule.internalKey()).isNotNull();
- assertThat(rule.name()).isNotNull();
- assertThat(rule.htmlDescription()).isNotNull();
- assertThat(rule.severity()).isNotNull();
+ for (RulesDefinition.Rule rule : rules) {
+ assertThat(rule.key()).isNotNull();
+ assertThat(rule.internalKey()).isNotNull();
+ assertThat(rule.name()).isNotNull();
+ assertThat(rule.htmlDescription()).isNotNull();
+ assertThat(rule.severity()).isNotNull();
- for (RulesDefinition.Param param : rule.params()) {
- assertThat(param.name()).isNotNull();
- assertThat(param.description())
- .overridingErrorMessage("Description is not set for parameter '" + param.name()
- + "' of rule '" + rule.key())
- .isNotNull();
- }
+ for (RulesDefinition.Param param : rule.params()) {
+ assertThat(param.name()).isNotNull();
+ assertThat(param.description()).overridingErrorMessage(
+ "Description is not set for parameter '" + param.name() + "' of rule '"
+ + rule.key()).isNotNull();
+ }
- if (NO_SQALE.contains(rule.key())) {
- assertThat(rule.debtRemediationFunction())
- .overridingErrorMessage("Sqale remediation function is set for rule '" + rule.key())
- .isNull();
- assertThat(rule.debtSubCharacteristic())
- .overridingErrorMessage("Sqale characteristic is set for rule '" + rule.key())
- .isNull();
- } else {
- assertThat(rule.debtRemediationFunction())
- .overridingErrorMessage("Sqale remediation function is not set for rule '"
- + rule.key())
- .isNotNull();
- assertThat(rule.debtSubCharacteristic())
- .overridingErrorMessage("Sqale characteristic is not set for rule '" + rule.key())
- .isNotNull();
- }
+ if (NO_SQALE.contains(rule.key())) {
+ assertThat(rule.debtRemediationFunction()).overridingErrorMessage(
+ "Sqale remediation function is set for rule '" + rule.key()).isNull();
+ assertThat(rule.debtSubCharacteristic()).overridingErrorMessage(
+ "Sqale characteristic is set for rule '" + rule.key()).isNull();
+ }
+ else {
+ assertThat(rule.debtRemediationFunction()).overridingErrorMessage(
+ "Sqale remediation function is not set for rule '" + rule.key())
+ .isNotNull();
+ assertThat(rule.debtSubCharacteristic()).overridingErrorMessage(
+ "Sqale characteristic is not set for rule '" + rule.key()).isNotNull();
+ }
+ }
}
- }
}
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSensorTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSensorTest.java
index 1d8daa6a..c327ce38 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSensorTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSensorTest.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import static org.fest.assertions.Assertions.assertThat;
@@ -37,46 +37,45 @@
public class CheckstyleSensorTest {
- private final RulesProfile profile = mock(RulesProfile.class);
- private final DefaultFileSystem fileSystem = new DefaultFileSystem(new File(""));
- private final CheckstyleSensor sensor = new CheckstyleSensor(profile, null, fileSystem);
+ private final RulesProfile profile = mock(RulesProfile.class);
+ private final DefaultFileSystem fileSystem = new DefaultFileSystem(new File(""));
+ private final CheckstyleSensor sensor = new CheckstyleSensor(profile, null, fileSystem);
- private final Project project = new Project("projectKey");
+ private final Project project = new Project("projectKey");
- @Test
- public void shouldExecuteOnProjectWithoutJavaFileAndWithRule() {
- addOneActiveRule();
- assertThat(sensor.shouldExecuteOnProject(project)).isFalse();
- }
+ @Test
+ public void shouldExecuteOnProjectWithoutJavaFileAndWithRule() {
+ addOneActiveRule();
+ assertThat(sensor.shouldExecuteOnProject(project)).isFalse();
+ }
- @Test
- public void shouldExecuteOnProjectWithJavaFileAndWithoutRule() {
- addOneJavaFile();
- assertThat(sensor.shouldExecuteOnProject(project)).isFalse();
- }
+ @Test
+ public void shouldExecuteOnProjectWithJavaFileAndWithoutRule() {
+ addOneJavaFile();
+ assertThat(sensor.shouldExecuteOnProject(project)).isFalse();
+ }
- @Test
- public void shouldExecuteOnProjectWithJavaFilesAndRules() {
- addOneJavaFile();
- addOneActiveRule();
- assertThat(sensor.shouldExecuteOnProject(project)).isTrue();
- }
+ @Test
+ public void shouldExecuteOnProjectWithJavaFilesAndRules() {
+ addOneJavaFile();
+ addOneActiveRule();
+ assertThat(sensor.shouldExecuteOnProject(project)).isTrue();
+ }
- @Test
- public void testToString() {
- assertThat(new CheckstyleSensor(null, null, null).toString())
- .isEqualTo("CheckstyleSensor");
- }
+ @Test
+ public void testToString() {
+ assertThat(new CheckstyleSensor(null, null, null).toString()).isEqualTo("CheckstyleSensor");
+ }
- private void addOneJavaFile() {
- File file = new File("MyClass.java");
- fileSystem.add(new DefaultInputFile("", file.getName())
- .setLanguage("java").setType(Type.MAIN));
- }
+ private void addOneJavaFile() {
+ File file = new File("MyClass.java");
+ fileSystem.add(new DefaultInputFile("", file.getName()).setLanguage("java").setType(
+ Type.MAIN));
+ }
- private void addOneActiveRule() {
- when(profile.getActiveRulesByRepository("checkstyle"))
- .thenReturn(ImmutableList.of(mock(ActiveRule.class)));
- }
+ private void addOneActiveRule() {
+ when(profile.getActiveRulesByRepository("checkstyle")).thenReturn(
+ ImmutableList.of(mock(ActiveRule.class)));
+ }
}
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtilsTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtilsTest.java
index 78dc960c..72b72967 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtilsTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtilsTest.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import static org.fest.assertions.Assertions.assertThat;
@@ -28,35 +28,31 @@
public class CheckstyleSeverityUtilsTest {
- @Test
- public void testToSeverity() {
- assertThat(CheckstyleSeverityUtils.toSeverity(RulePriority.BLOCKER))
- .isEqualTo("error");
- assertThat(CheckstyleSeverityUtils.toSeverity(RulePriority.CRITICAL))
- .isEqualTo("error");
- assertThat(CheckstyleSeverityUtils.toSeverity(RulePriority.MAJOR)).isEqualTo("warning");
- assertThat(CheckstyleSeverityUtils.toSeverity(RulePriority.MINOR)).isEqualTo("info");
- assertThat(CheckstyleSeverityUtils.toSeverity(RulePriority.INFO)).isEqualTo("info");
- }
-
- @Test
- public void testFromSeverity() {
- assertThat(CheckstyleSeverityUtils.fromSeverity("error"))
- .isEqualTo(RulePriority.BLOCKER);
- assertThat(CheckstyleSeverityUtils.fromSeverity("warning"))
- .isEqualTo(RulePriority.MAJOR);
- assertThat(CheckstyleSeverityUtils.fromSeverity("info")).isEqualTo(RulePriority.INFO);
- assertThat(CheckstyleSeverityUtils.fromSeverity("ignore")).isEqualTo(RulePriority.INFO);
- assertThat(CheckstyleSeverityUtils.fromSeverity("")).isNull();
- }
-
- @Test
- public void privateConstructor() throws ReflectiveOperationException {
- Constructor constructor =
- CheckstyleSeverityUtils.class.getDeclaredConstructor();
- assertThat(constructor.isAccessible()).isFalse();
- constructor.setAccessible(true);
- constructor.newInstance();
- }
+ @Test
+ public void testToSeverity() {
+ assertThat(CheckstyleSeverityUtils.toSeverity(RulePriority.BLOCKER)).isEqualTo("error");
+ assertThat(CheckstyleSeverityUtils.toSeverity(RulePriority.CRITICAL)).isEqualTo("error");
+ assertThat(CheckstyleSeverityUtils.toSeverity(RulePriority.MAJOR)).isEqualTo("warning");
+ assertThat(CheckstyleSeverityUtils.toSeverity(RulePriority.MINOR)).isEqualTo("info");
+ assertThat(CheckstyleSeverityUtils.toSeverity(RulePriority.INFO)).isEqualTo("info");
+ }
+
+ @Test
+ public void testFromSeverity() {
+ assertThat(CheckstyleSeverityUtils.fromSeverity("error")).isEqualTo(RulePriority.BLOCKER);
+ assertThat(CheckstyleSeverityUtils.fromSeverity("warning")).isEqualTo(RulePriority.MAJOR);
+ assertThat(CheckstyleSeverityUtils.fromSeverity("info")).isEqualTo(RulePriority.INFO);
+ assertThat(CheckstyleSeverityUtils.fromSeverity("ignore")).isEqualTo(RulePriority.INFO);
+ assertThat(CheckstyleSeverityUtils.fromSeverity("")).isNull();
+ }
+
+ @Test
+ public void privateConstructor() throws ReflectiveOperationException {
+ Constructor constructor = CheckstyleSeverityUtils.class
+ .getDeclaredConstructor();
+ assertThat(constructor.isAccessible()).isFalse();
+ constructor.setAccessible(true);
+ constructor.newInstance();
+ }
}
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleTestUtils.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleTestUtils.java
index 58cf5593..6d4fdf93 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleTestUtils.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleTestUtils.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import static org.junit.Assert.assertTrue;
@@ -33,33 +33,35 @@
public final class CheckstyleTestUtils {
- private CheckstyleTestUtils() {
- // no code
- }
+ private CheckstyleTestUtils() {
+ // no code
+ }
- public static String getResourceContent(String path) {
- try {
- return Resources.toString(Resources.getResource(CheckstyleTestUtils.class, path),
- Charsets.UTF_8);
- } catch (IOException e) {
- throw new IllegalArgumentException("Could not load resource " + path, e);
+ public static String getResourceContent(String path) {
+ try {
+ return Resources.toString(Resources.getResource(CheckstyleTestUtils.class, path),
+ Charsets.UTF_8);
+ }
+ catch (IOException e) {
+ throw new IllegalArgumentException("Could not load resource " + path, e);
+ }
}
- }
- public static void assertSimilarXml(String expectedXml, String xml) {
- XMLUnit.setIgnoreWhitespace(true);
- Diff diff;
- try {
- diff = XMLUnit.compareXML(xml, expectedXml);
- } catch (SAXException | IOException e) {
- throw new IllegalArgumentException("Could not run XML comparison", e);
+ public static void assertSimilarXml(String expectedXml, String xml) {
+ XMLUnit.setIgnoreWhitespace(true);
+ Diff diff;
+ try {
+ diff = XMLUnit.compareXML(xml, expectedXml);
+ }
+ catch (SAXException | IOException e) {
+ throw new IllegalArgumentException("Could not run XML comparison", e);
+ }
+ String message = "Diff: " + diff + CharUtils.LF + "XML: " + xml;
+ assertTrue(message, diff.similar());
}
- String message = "Diff: " + diff + CharUtils.LF + "XML: " + xml;
- assertTrue(message, diff.similar());
- }
- public static void assertSimilarXmlWithResource(String expectedXmlResourcePath, String xml) {
- assertSimilarXml(getResourceContent(expectedXmlResourcePath), xml);
- }
+ public static void assertSimilarXmlWithResource(String expectedXmlResourcePath, String xml) {
+ assertSimilarXml(getResourceContent(expectedXmlResourcePath), xml);
+ }
}
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleVersionTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleVersionTest.java
index c350016b..0624ea8a 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleVersionTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleVersionTest.java
@@ -1,22 +1,22 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
package org.sonar.plugins.checkstyle;
import static org.fest.assertions.Assertions.assertThat;
@@ -25,9 +25,9 @@
public class CheckstyleVersionTest {
- @Test
- public void getCheckstyleVersion() {
- assertThat(CheckstyleVersion.getVersion().length()).isGreaterThan(1);
- }
+ @Test
+ public void getCheckstyleVersion() {
+ assertThat(CheckstyleVersion.getVersion().length()).isGreaterThan(1);
+ }
}
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/CheckUtil.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/CheckUtil.java
index 66ba4e49..d54e0ba9 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/CheckUtil.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/CheckUtil.java
@@ -1,22 +1,21 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
package org.sonar.plugins.checkstyle.internal;
@@ -64,7 +63,9 @@ public static Set> getCheckstyleModules() throws IOException {
}
}
return checkstyleModules;
- } /**
+ }
+
+ /**
* Checks whether a class may be considered as a checkstyle module. Checkstyle's modules are
* non-abstract classes, which names do not start with the word 'Input' (are not input files for
* UTs), and are either checkstyle's checks, file sets, filters, file filters, or root module.
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/ChecksTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/ChecksTest.java
index 663aa21e..003f78b9 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/ChecksTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/ChecksTest.java
@@ -1,22 +1,21 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
package org.sonar.plugins.checkstyle.internal;
@@ -51,7 +50,7 @@
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
import com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck;
-public final class ChecksTest {
+public class ChecksTest {
private static final String RULES_PATH =
"src/main/resources/org/sonar/plugins/checkstyle/rules.xml";
private static final String MODULE_PROPERTIES_PATH =
@@ -98,8 +97,7 @@ private static void validateSonarRules(Set> modules)
validateSonarRules(document, modules);
}
- private static void validateSonarRules(Document document, Set> modules)
- {
+ private static void validateSonarRules(Document document, Set> modules) {
final NodeList rules = document.getElementsByTagName("rule");
for (int position = 0; position < rules.getLength(); position++) {
@@ -152,8 +150,7 @@ private static void validateSonarRules(Document document, Set> modules)
}
}
- private static void validateSonarRuleProperties(Class> module, Set parameters)
- {
+ private static void validateSonarRuleProperties(Class> module, Set parameters) {
final String moduleName = module.getName();
final Set properties = getFinalProperties(module);
@@ -186,7 +183,7 @@ private static void validateSonarProperties(Set> modules) throws IOExce
final Properties properties = new Properties();
try (InputStream stream = new FileInputStream(propertiesFile)) {
- properties.load(stream);
+ properties.load(stream);
}
validateSonarProperties(properties, modules);
@@ -309,7 +306,8 @@ else if (AbstractFileSetCheck.class.isAssignableFrom(clss)) {
final AbstractCheck check;
try {
check = (AbstractCheck) clss.getConstructor().newInstance();
- } catch (ReflectiveOperationException e) {
+ }
+ catch (ReflectiveOperationException e) {
throw new IllegalStateException(e);
}
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/XmlUtil.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/XmlUtil.java
index b53ddf5f..c2a8a97f 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/XmlUtil.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/XmlUtil.java
@@ -1,22 +1,21 @@
-/*
- * SonarQube Checkstyle Plugin
- * Copyright (C) 2012 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2017 the original author or authors.
+//
+// This library 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.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
package org.sonar.plugins.checkstyle.internal;
diff --git a/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/failIfConfigurationToReuseDoesNotExist/pom.xml b/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/failIfConfigurationToReuseDoesNotExist/pom.xml
index 7c63bf8a..49e9beaa 100644
--- a/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/failIfConfigurationToReuseDoesNotExist/pom.xml
+++ b/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/failIfConfigurationToReuseDoesNotExist/pom.xml
@@ -21,4 +21,4 @@
-
\ No newline at end of file
+
diff --git a/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/findConfigurationToReuse/checkstyle.xml b/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/findConfigurationToReuse/checkstyle.xml
index 723c9eb7..12906559 100644
--- a/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/findConfigurationToReuse/checkstyle.xml
+++ b/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/findConfigurationToReuse/checkstyle.xml
@@ -1 +1 @@
-
\ No newline at end of file
+
diff --git a/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/findConfigurationToReuse/pom.xml b/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/findConfigurationToReuse/pom.xml
index 90f0ad59..5a138bcd 100644
--- a/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/findConfigurationToReuse/pom.xml
+++ b/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/findConfigurationToReuse/pom.xml
@@ -22,4 +22,4 @@
-
\ No newline at end of file
+
diff --git a/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/writeConfigurationToWorkingDir/pom.xml b/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/writeConfigurationToWorkingDir/pom.xml
index b4e9f41a..4e1c827a 100644
--- a/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/writeConfigurationToWorkingDir/pom.xml
+++ b/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/writeConfigurationToWorkingDir/pom.xml
@@ -5,4 +5,4 @@
fake.artifactId
jar
1.0-SNAPSHOT
-
\ No newline at end of file
+
diff --git a/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/idPropertyShouldBeTheRuleKey.xml b/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/idPropertyShouldBeTheRuleKey.xml
index d8dec5d9..0229f0c2 100644
--- a/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/idPropertyShouldBeTheRuleKey.xml
+++ b/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/idPropertyShouldBeTheRuleKey.xml
@@ -3,7 +3,7 @@
-
+
diff --git a/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/shouldUseTheIdPropertyToFindRule.xml b/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/shouldUseTheIdPropertyToFindRule.xml
index 97fdf2fa..149a5ed0 100644
--- a/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/shouldUseTheIdPropertyToFindRule.xml
+++ b/checkstyle-sonar-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/shouldUseTheIdPropertyToFindRule.xml
@@ -3,7 +3,7 @@
-
+