diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2012-05-03 09:14:29 +0000 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2012-05-03 09:14:29 +0000 |
commit | 84e2798123e242bfe786359dfff9865e1a230793 (patch) | |
tree | e6a2bc27af521e3b96782d39a2ed162ed02074be /src | |
parent | 83e9baf9a94f52fe5f8a3ba0ad8a819a021fd68d (diff) | |
download | sonar-scanner-cli-84e2798123e242bfe786359dfff9865e1a230793.tar.gz sonar-scanner-cli-84e2798123e242bfe786359dfff9865e1a230793.zip |
SONARPLUGINS-1619 Support the properties sonar.showSql and sonar.showSqlResults
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/sonar/runner/Launcher.java | 43 | ||||
-rw-r--r-- | src/test/java/org/sonar/runner/LauncherTest.java | 35 |
2 files changed, 62 insertions, 16 deletions
diff --git a/src/main/java/org/sonar/runner/Launcher.java b/src/main/java/org/sonar/runner/Launcher.java index 3567126..a429d0f 100644 --- a/src/main/java/org/sonar/runner/Launcher.java +++ b/src/main/java/org/sonar/runner/Launcher.java @@ -20,16 +20,14 @@ package org.sonar.runner; -import java.io.File; -import java.io.FileFilter; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.JoranConfigurator; import ch.qos.logback.core.joran.spi.JoranException; -import org.apache.commons.configuration.*; +import org.apache.commons.configuration.CompositeConfiguration; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.EnvironmentConfiguration; +import org.apache.commons.configuration.MapConfiguration; +import org.apache.commons.configuration.SystemConfiguration; import org.apache.commons.io.IOUtils; import org.apache.commons.io.filefilter.AndFileFilter; import org.apache.commons.io.filefilter.FileFileFilter; @@ -42,6 +40,12 @@ import org.sonar.batch.bootstrapper.EnvironmentInformation; import org.sonar.batch.bootstrapper.ProjectDefinition; import org.sonar.batch.bootstrapper.Reactor; +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + public class Launcher { private Runner runner; @@ -54,24 +58,27 @@ public class Launcher { * This method invoked from {@link Main}. Do not rename it. */ public void execute() { - initLogging(); - executeBatch(); + ProjectDefinition project = defineProject(); + Configuration initialConfiguration = getInitialConfiguration(project); + initLogging(initialConfiguration); + executeBatch(project, initialConfiguration); } - private void executeBatch() { - ProjectDefinition project = defineProject(); + private void executeBatch(ProjectDefinition project, Configuration initialConfiguration) { Reactor reactor = new Reactor(project); - Batch batch = new Batch(getInitialConfiguration(project), new EnvironmentInformation("Runner", runner.getRunnerVersion()), reactor); + Batch batch = new Batch(initialConfiguration, new EnvironmentInformation("Runner", runner.getRunnerVersion()), reactor); batch.execute(); } - private void initLogging() { + private void initLogging(Configuration initialConfiguration) { LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator jc = new JoranConfigurator(); jc.setContext(context); context.reset(); InputStream input = Batch.class.getResourceAsStream("/org/sonar/batch/logback.xml"); System.setProperty("ROOT_LOGGER_LEVEL", runner.isDebug() ? "DEBUG" : "INFO"); + context.putProperty("SQL_LOGGER_LEVEL", getSqlLevel(initialConfiguration));// since 2.14. Ignored on previous versions. + context.putProperty("SQL_RESULTS_LOGGER_LEVEL", getSqlResultsLevel(initialConfiguration));// since 2.14. Ignored on previous versions. try { jc.doConfigure(input); @@ -83,6 +90,16 @@ public class Launcher { } } + protected static String getSqlLevel(Configuration config) { + boolean showSql = config.getBoolean("sonar.showSql", false); + return showSql ? "DEBUG" : "WARN"; + } + + protected static String getSqlResultsLevel(Configuration config) { + boolean showSql = config.getBoolean("sonar.showSqlResults", false); + return showSql ? "DEBUG" : "WARN"; + } + private ProjectDefinition defineProject() { File baseDir = runner.getProjectDir(); Properties properties = runner.getProperties(); diff --git a/src/test/java/org/sonar/runner/LauncherTest.java b/src/test/java/org/sonar/runner/LauncherTest.java index f857441..ea3de33 100644 --- a/src/test/java/org/sonar/runner/LauncherTest.java +++ b/src/test/java/org/sonar/runner/LauncherTest.java @@ -19,14 +19,17 @@ */ package org.sonar.runner; +import org.apache.commons.configuration.BaseConfiguration; +import org.apache.commons.configuration.Configuration; +import org.junit.Test; + +import java.io.File; + import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import java.io.File; -import org.junit.Test; - public class LauncherTest { @Test @@ -56,4 +59,30 @@ public class LauncherTest { } } + @Test + public void testGetSqlLevel() throws Exception { + Configuration conf = new BaseConfiguration(); + + assertThat(Launcher.getSqlLevel(conf), is("WARN")); + + conf.setProperty("sonar.showSql", "true"); + assertThat(Launcher.getSqlLevel(conf), is("DEBUG")); + + conf.setProperty("sonar.showSql", "false"); + assertThat(Launcher.getSqlLevel(conf), is("WARN")); + } + + @Test + public void testGetSqlResultsLevel() throws Exception { + Configuration conf = new BaseConfiguration(); + + assertThat(Launcher.getSqlResultsLevel(conf), is("WARN")); + + conf.setProperty("sonar.showSqlResults", "true"); + assertThat(Launcher.getSqlResultsLevel(conf), is("DEBUG")); + + conf.setProperty("sonar.showSqlResults", "false"); + assertThat(Launcher.getSqlResultsLevel(conf), is("WARN")); + } + } |