aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-runner-api/src
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-06-23 15:17:34 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-06-23 15:17:34 +0200
commita0d8eb29a08a4cb13e548fa88b51dd71f27e556c (patch)
tree1cec1f59584837092bdeb76256b24782215b67a4 /sonar-runner-api/src
parent25a566485179819c127aea3fbf7d3c4a2d3e36a9 (diff)
downloadsonar-scanner-cli-a0d8eb29a08a4cb13e548fa88b51dd71f27e556c.tar.gz
sonar-scanner-cli-a0d8eb29a08a4cb13e548fa88b51dd71f27e556c.zip
add LogListener in API
Diffstat (limited to 'sonar-runner-api/src')
-rw-r--r--sonar-runner-api/src/main/java/org/sonar/runner/api/ForkedRunner.java6
-rw-r--r--sonar-runner-api/src/main/java/org/sonar/runner/api/LogListener.java28
-rw-r--r--sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java34
-rw-r--r--sonar-runner-api/src/main/java/org/sonar/runner/api/Utils.java6
4 files changed, 66 insertions, 8 deletions
diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/ForkedRunner.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/ForkedRunner.java
index 565e330..2a3e2b5 100644
--- a/sonar-runner-api/src/main/java/org/sonar/runner/api/ForkedRunner.java
+++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/ForkedRunner.java
@@ -215,19 +215,19 @@ public class ForkedRunner extends Runner<ForkedRunner> {
}
}
}
-
+
private static class OutConsumer implements StreamConsumer {
@Override
public void consumeLine(String line) {
Logs.info(line);
}
- };
+ }
private static class ErrConsumer implements StreamConsumer {
@Override
public void consumeLine(String line) {
Logs.error(line);
}
- };
+ }
static class ForkCommand {
Command command;
diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/LogListener.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/LogListener.java
new file mode 100644
index 0000000..bfcfdc4
--- /dev/null
+++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/LogListener.java
@@ -0,0 +1,28 @@
+/*
+ * SonarQube Runner - API
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * 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
+ */
+package org.sonar.runner.api;
+
+public interface LogListener {
+ void log(String msg, Level level);
+
+ enum Level {
+ ERROR, WARN, INFO, DEBUG, TRACE;
+ }
+}
diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java
index 863b08c..fed9134 100644
--- a/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java
+++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java
@@ -20,7 +20,6 @@
package org.sonar.runner.api;
import org.sonar.home.log.LogListener;
-
import org.sonar.runner.impl.Logs;
import org.sonar.runner.impl.InternalProperties;
@@ -43,14 +42,14 @@ public abstract class Runner<T extends Runner<?>> {
clone.putAll(globalProperties);
return clone;
}
-
+
/**
* Set a log stream. All log events will be redirected to the listener.
* By default, all logs are sent to stdout, except for logs of ERROR level, which are sent to stderr.
* If null is given, the default is behavior is set.
*/
public T setLogListener(LogListener stream) {
- Logs.setListener(stream);
+ Logs.setListener(new LogListenerAdapter(stream));
return (T) this;
}
@@ -152,5 +151,32 @@ public abstract class Runner<T extends Runner<?>> {
setGlobalProperty(key, value);
}
}
-
+
+ private class LogListenerAdapter implements org.sonar.home.log.LogListener {
+ private LogListener adaptedListener;
+
+ LogListenerAdapter(LogListener listener) {
+ this.adaptedListener = listener;
+ }
+
+ @Override
+ public void log(String msg, org.sonar.home.log.LogListener.Level level) {
+ this.adaptedListener.log(msg, translate(level));
+ }
+ private LogListener.Level translate(org.sonar.home.log.LogListener.Level level) {
+ switch(level) {
+ case ERROR:
+ return LogListener.Level.ERROR;
+ case WARN:
+ return LogListener.Level.WARN;
+ case INFO:
+ return LogListener.Level.INFO;
+ case DEBUG:
+ default:
+ return LogListener.Level.DEBUG;
+ case TRACE:
+ return LogListener.Level.TRACE;
+ }
+ }
+ }
}
diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/Utils.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/Utils.java
index efe39c4..1c0dc96 100644
--- a/sonar-runner-api/src/main/java/org/sonar/runner/api/Utils.java
+++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/Utils.java
@@ -47,7 +47,11 @@ class Utils {
}
int endIndex = Math.min(3, version.length());
- return Double.parseDouble(version.substring(0, endIndex)) >= 5.2;
+ try {
+ return Double.parseDouble(version.substring(0, endIndex)) >= 5.2;
+ } catch (NumberFormatException e) {
+ return false;
+ }
}
/**