From f2e74b6d6935082e4d75a5ddfaf66e8ba1079f1f Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 16 Jun 2015 17:38:52 +0200 Subject: SONARUNNER-138 Allow to redirect logs to a custom stream --- .../java/org/sonar/runner/api/EmbeddedRunner.java | 28 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java') diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java index 9dfad19..e1c04b7 100644 --- a/sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java +++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java @@ -19,13 +19,15 @@ */ package org.sonar.runner.api; +import org.sonar.home.log.LogListener; + +import org.sonar.runner.impl.Logs; import org.sonar.runner.batch.IsolatedLauncher; import org.sonar.runner.impl.IsolatedLauncherFactory; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.Properties; /** @@ -36,9 +38,9 @@ import java.util.Properties; * @since 2.2 */ public class EmbeddedRunner extends Runner { - private final IsolatedLauncherFactory launcherFactory; private IsolatedLauncher launcher; + private String sqVersion; private final List extensions = new ArrayList(); private static final String MASK_RULES_PROP = "sonarRunner.maskRules"; @@ -53,6 +55,11 @@ public class EmbeddedRunner extends Runner { return new EmbeddedRunner(new IsolatedLauncherFactory()); } + public static EmbeddedRunner create(LogListener logListener) { + Logs.setListener(logListener); + return new EmbeddedRunner(new IsolatedLauncherFactory()); + } + /** * Sonar is executed in an almost fully isolated classloader (mask everything by default). This method allows to unmask some classes based on * a prefix of their fully qualified name. It is related to the extensions provided by {@link #addExtensions(Object...)}. @@ -104,16 +111,27 @@ public class EmbeddedRunner extends Runner { @Override protected void doStart() { launcher = launcherFactory.createLauncher(globalProperties()); - launcher.start(globalProperties(), extensions); + if (Utils.isAtLeast52(launcher.getVersion())) { + launcher.start(globalProperties(), extensions, Logs.getListener()); + } } @Override protected void doStop() { - launcher.stop(); + if (Utils.isAtLeast52(launcher.getVersion())) { + launcher.stop(); + } } @Override protected void doExecute(Properties analysisProperties) { - launcher.execute(analysisProperties); + if (Utils.isAtLeast52(launcher.getVersion())) { + launcher.execute(analysisProperties); + } else { + Properties prop = new Properties(); + prop.putAll(globalProperties()); + prop.putAll(analysisProperties); + launcher.executeOldVersion(prop, extensions); + } } } -- cgit v1.2.3