aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-checkstyle-plugin/src/main
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-07 09:11:52 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-07 09:11:52 +0000
commite51183ff04b26f3e6481233fe7243d2b28b2411e (patch)
treebd0c86ac0e27ed41349252215ee3c175feecb4ef /plugins/sonar-checkstyle-plugin/src/main
parentaef2286bf00aca219862aa62ef5dcac4bb9d2e9a (diff)
downloadsonarqube-e51183ff04b26f3e6481233fe7243d2b28b2411e.tar.gz
sonarqube-e51183ff04b26f3e6481233fe7243d2b28b2411e.zip
checkstyle plugin : add some unit tests
Diffstat (limited to 'plugins/sonar-checkstyle-plugin/src/main')
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleAuditListener.java26
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java6
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleExecutor.java5
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java8
4 files changed, 19 insertions, 26 deletions
diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleAuditListener.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleAuditListener.java
index dd1dfd29768..9cb7b06fb88 100644
--- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleAuditListener.java
+++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleAuditListener.java
@@ -1,22 +1,4 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
+
package org.sonar.plugins.checkstyle;
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
@@ -34,7 +16,7 @@ import org.sonar.api.rules.Violation;
/**
* @since 2.3
*/
-public final class CheckstyleAuditListener implements AuditListener, BatchExtension {
+public class CheckstyleAuditListener implements AuditListener, BatchExtension {
private final SensorContext context;
private final Project project;
@@ -124,4 +106,8 @@ public final class CheckstyleAuditListener implements AuditListener, BatchExtens
public void addException(AuditEvent event, Throwable throwable) {
// TODO waiting for sonar technical events ?
}
+
+ Resource getCurrentResource() {
+ return currentResource;
+ }
}
diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
index 3a5332125cb..88ed5f9aabf 100644
--- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
+++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
@@ -109,11 +109,15 @@ public class CheckstyleConfiguration implements BatchExtension {
File xmlConfig = getXMLDefinitionFile();
LOG.info("Checkstyle configuration: " + xmlConfig.getAbsolutePath());
- Configuration configuration = ConfigurationLoader.loadConfiguration(xmlConfig.getAbsolutePath(), new PropertiesExpander(new Properties()));
+ Configuration configuration = toCheckstyleConfiguration(xmlConfig);
defineCharset(configuration);
return configuration;
}
+ static Configuration toCheckstyleConfiguration(File xmlConfig) throws CheckstyleException {
+ return ConfigurationLoader.loadConfiguration(xmlConfig.getAbsolutePath(), new PropertiesExpander(new Properties()));
+ }
+
private void defineCharset(Configuration configuration) {
Configuration[] modules = configuration.getChildren();
diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleExecutor.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleExecutor.java
index 2adf90c7930..418e77f67f4 100644
--- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleExecutor.java
+++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleExecutor.java
@@ -32,13 +32,12 @@ import org.sonar.api.utils.TimeProfiler;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
-import java.net.URLClassLoader;
public class CheckstyleExecutor implements BatchExtension {
private static Logger LOG = LoggerFactory.getLogger(CheckstyleExecutor.class);
private CheckstyleConfiguration configuration;
- private URLClassLoader projectClassloader;
+ private ClassLoader projectClassloader;
private CheckstyleAuditListener listener;
public CheckstyleExecutor(CheckstyleConfiguration configuration, CheckstyleAuditListener listener, ProjectClasspath classpath) {
@@ -48,7 +47,7 @@ public class CheckstyleExecutor implements BatchExtension {
}
- CheckstyleExecutor(CheckstyleConfiguration configuration, CheckstyleAuditListener listener, URLClassLoader projectClassloader) {
+ CheckstyleExecutor(CheckstyleConfiguration configuration, CheckstyleAuditListener listener, ClassLoader projectClassloader) {
this.configuration = configuration;
this.listener = listener;
this.projectClassloader = projectClassloader;
diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java
index 883013caf3a..6902348606c 100644
--- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java
+++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java
@@ -141,9 +141,14 @@ public class CheckstyleProfileExporter extends ProfileExporter {
appendModuleProperty(writer, "id", activeRule.getRuleKey());
}
appendModuleProperty(writer, "severity", toCheckstyleSeverity(activeRule.getPriority()));
+ appendRuleParameters(writer, activeRule);
+ writer.append("</module>");
+ }
+
+ private void appendRuleParameters(Writer writer, ActiveRule activeRule) throws IOException {
for (RuleParam ruleParam : activeRule.getRule().getParams()) {
ActiveRuleParam activeParam = activeRule.getParameter(ruleParam.getKey());
- String value = null;
+ String value;
if (activeParam == null) {
value = ruleParam.getDefaultValue();
} else {
@@ -153,7 +158,6 @@ public class CheckstyleProfileExporter extends ProfileExporter {
appendModuleProperty(writer, ruleParam.getKey(), value);
}
}
- writer.append("</module>");
}
private void appendModuleProperty(Writer writer, String propertyKey, String propertyValue) throws IOException {