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;
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;
* 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);
}
}
+ 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();
*/
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
}
}
+ @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"));
+ }
+
}