aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-runner-api/src
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-06-23 14:25:51 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-06-23 14:25:51 +0200
commit25a566485179819c127aea3fbf7d3c4a2d3e36a9 (patch)
tree860512ef86ccecfc7ee8ff69c21935e0db13cc14 /sonar-runner-api/src
parent75a661f61c2e0667b626bd17853eaf3e5201b4f0 (diff)
downloadsonar-scanner-cli-25a566485179819c127aea3fbf7d3c4a2d3e36a9.tar.gz
sonar-scanner-cli-25a566485179819c127aea3fbf7d3c4a2d3e36a9.zip
Fix quality flaws and formatting
Diffstat (limited to 'sonar-runner-api/src')
-rw-r--r--sonar-runner-api/src/main/java/org/sonar/runner/api/Command.java2
-rw-r--r--sonar-runner-api/src/main/java/org/sonar/runner/api/CommandExecutor.java6
-rw-r--r--sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java1
-rw-r--r--sonar-runner-api/src/main/java/org/sonar/runner/api/ForkedRunner.java27
-rw-r--r--sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java2
-rw-r--r--sonar-runner-api/src/main/java/org/sonar/runner/api/SourceEncoding.java3
-rw-r--r--sonar-runner-api/src/main/java/org/sonar/runner/api/Utils.java39
-rw-r--r--sonar-runner-api/src/test/java/org/sonar/runner/api/ForkedRunnerTest.java14
-rw-r--r--sonar-runner-api/src/test/java/org/sonar/runner/api/SimpleRunner.java2
-rw-r--r--sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java2
10 files changed, 54 insertions, 44 deletions
diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/Command.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/Command.java
index 01048ee..b427c14 100644
--- a/sonar-runner-api/src/main/java/org/sonar/runner/api/Command.java
+++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/Command.java
@@ -94,7 +94,7 @@ class Command {
Builder addArguments(List<String> args) {
for (String arg : args) {
- if (arg!=null && !"".equals(arg.trim())) {
+ if (arg != null && !"".equals(arg.trim())) {
arguments.add(arg);
}
}
diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/CommandExecutor.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/CommandExecutor.java
index fd5b6d8..27140b3 100644
--- a/sonar-runner-api/src/main/java/org/sonar/runner/api/CommandExecutor.java
+++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/CommandExecutor.java
@@ -131,13 +131,13 @@ class CommandExecutor {
});
}
- private void verifyGobbler(Command command, StreamGobbler gobbler, String type) {
+ private static void verifyGobbler(Command command, StreamGobbler gobbler, String type) {
if (gobbler.getException() != null) {
throw new CommandException("Error inside " + type + " stream", command, gobbler.getException());
}
}
- private void closeStreams(Process process) {
+ private static void closeStreams(Process process) {
if (process != null) {
Utils.closeQuietly(process.getInputStream());
Utils.closeQuietly(process.getInputStream());
@@ -146,7 +146,7 @@ class CommandExecutor {
}
}
- private void waitUntilFinish(StreamGobbler thread) {
+ private static void waitUntilFinish(StreamGobbler thread) {
if (thread != null) {
try {
thread.join();
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 e1c04b7..4883ea0 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
@@ -40,7 +40,6 @@ import java.util.Properties;
public class EmbeddedRunner extends Runner<EmbeddedRunner> {
private final IsolatedLauncherFactory launcherFactory;
private IsolatedLauncher launcher;
- private String sqVersion;
private final List<Object> extensions = new ArrayList<Object>();
private static final String MASK_RULES_PROP = "sonarRunner.maskRules";
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 31a932f..565e330 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
@@ -200,20 +200,10 @@ public class ForkedRunner extends Runner<ForkedRunner> {
private void fork(ForkCommand forkCommand) {
if (stdOut == null) {
- stdOut = new StreamConsumer() {
- @Override
- public void consumeLine(String line) {
- Logs.info(line);
- }
- };
+ stdOut = new OutConsumer();
}
if (stdErr == null) {
- stdErr = new StreamConsumer() {
- @Override
- public void consumeLine(String line) {
- Logs.error(line);
- }
- };
+ stdErr = new ErrConsumer();
}
int status = commandExecutor.execute(forkCommand.command, stdOut, stdErr, ONE_DAY_IN_MILLISECONDS, processMonitor);
@@ -225,6 +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/Runner.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java
index 890ce46..863b08c 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
@@ -32,7 +32,7 @@ import java.util.Properties;
/**
* @since 2.2
*/
-public abstract class Runner<T extends Runner> {
+public abstract class Runner<T extends Runner<?>> {
private final Properties globalProperties = new Properties();
protected Runner() {
diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/SourceEncoding.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/SourceEncoding.java
index 0029308..d21f9f3 100644
--- a/sonar-runner-api/src/main/java/org/sonar/runner/api/SourceEncoding.java
+++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/SourceEncoding.java
@@ -27,8 +27,9 @@ import java.util.Properties;
class SourceEncoding {
private SourceEncoding() {
-
+
}
+
static void init(Properties p) {
boolean onProject = Utils.taskRequiresProject(p);
if (onProject) {
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 4d4907a..efe39c4 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
@@ -39,13 +39,13 @@ class Utils {
private Utils() {
// only util static methods
}
-
+
static boolean isAtLeast52(String version) {
- //it can be snapshot (5.2-SNAPSHOT)
- if(version == null) {
+ // it can be snapshot (5.2-SNAPSHOT)
+ if (version == null) {
return false;
}
-
+
int endIndex = Math.min(3, version.length());
return Double.parseDouble(version.substring(0, endIndex)) >= 5.2;
}
@@ -81,34 +81,41 @@ class Utils {
static void deleteQuietly(File f) {
try {
- Files.walkFileTree(f.toPath(), new DeleteFileVisitor());
+ Files.walkFileTree(f.toPath(), new DeleteQuietlyFileVisitor());
} catch (IOException e) {
// ignore
}
}
- private static class DeleteFileVisitor extends SimpleFileVisitor<Path> {
+ private static class DeleteQuietlyFileVisitor extends SimpleFileVisitor<Path> {
@Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
- Files.delete(file);
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
+ try {
+ Files.delete(file);
+ } catch (IOException e) {
+ // ignore
+ }
return FileVisitResult.CONTINUE;
}
@Override
- public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
- Files.delete(file);
+ public FileVisitResult visitFileFailed(Path file, IOException exc) {
+ try {
+ Files.delete(file);
+ } catch (IOException e) {
+ // ignore
+ }
return FileVisitResult.CONTINUE;
}
@Override
- public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
- if (exc == null) {
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
+ try {
Files.delete(dir);
- return FileVisitResult.CONTINUE;
- } else {
- // directory iteration failed; propagate exception
- throw exc;
+ } catch (IOException e) {
+ // ignore
}
+ return FileVisitResult.CONTINUE;
}
}
diff --git a/sonar-runner-api/src/test/java/org/sonar/runner/api/ForkedRunnerTest.java b/sonar-runner-api/src/test/java/org/sonar/runner/api/ForkedRunnerTest.java
index e7c3a56..a15cb86 100644
--- a/sonar-runner-api/src/test/java/org/sonar/runner/api/ForkedRunnerTest.java
+++ b/sonar-runner-api/src/test/java/org/sonar/runner/api/ForkedRunnerTest.java
@@ -31,11 +31,9 @@ import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentMatcher;
import org.sonar.runner.impl.JarExtractor;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
-import java.io.PrintStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
@@ -91,16 +89,16 @@ public class ForkedRunnerTest {
ArgumentCaptor<StreamConsumer> arg1 = ArgumentCaptor.forClass(StreamConsumer.class);
ArgumentCaptor<StreamConsumer> arg2 = ArgumentCaptor.forClass(StreamConsumer.class);
-
+
verify(commandExecutor).execute(any(Command.class), arg1.capture(), arg2.capture(), anyLong(), any(ProcessMonitor.class));
arg1.getValue().consumeLine("test1");
arg2.getValue().consumeLine("test2");
-
+
verify(listener).log("test1", Level.INFO);
verify(listener).log("test2", Level.ERROR);
verifyNoMoreInteractions(listener);
}
-
+
@Test
public void should_print_to_consumers_by_default() throws IOException {
final List<String> printedLines = new LinkedList<>();
@@ -119,7 +117,7 @@ public class ForkedRunnerTest {
runner.execute();
verify(commandExecutor).execute(any(Command.class), eq(consumer), eq(consumer), anyLong(),
- any(ProcessMonitor.class));
+ any(ProcessMonitor.class));
}
@Test
@@ -143,7 +141,7 @@ public class ForkedRunnerTest {
assertThat(properties.getProperty("-Xmx512m")).isNull();
assertThat(properties.getProperty("SONAR_HOME")).isNull();
}
-
+
@Test
public void should_merge_properties() throws IOException {
JarExtractor jarExtractor = createMockExtractor();
@@ -157,7 +155,7 @@ public class ForkedRunnerTest {
verify(spy).writeProperties(properties.capture());
assertThat(properties.getValue().keySet()).contains("sonar.working.directory", "sonar.host.url", "sonar.sourceEncoding", "sonar.login");
}
-
+
@Test
public void test_java_command() throws IOException {
JarExtractor jarExtractor = mock(JarExtractor.class);
diff --git a/sonar-runner-api/src/test/java/org/sonar/runner/api/SimpleRunner.java b/sonar-runner-api/src/test/java/org/sonar/runner/api/SimpleRunner.java
index 5d3f0c2..6c356fe 100644
--- a/sonar-runner-api/src/test/java/org/sonar/runner/api/SimpleRunner.java
+++ b/sonar-runner-api/src/test/java/org/sonar/runner/api/SimpleRunner.java
@@ -21,7 +21,7 @@ package org.sonar.runner.api;
import java.util.Properties;
-class SimpleRunner extends Runner {
+class SimpleRunner extends Runner<SimpleRunner> {
@Override
protected void doExecute(Properties props) {
}
diff --git a/sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java b/sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java
index a268ec3..b8dfc3f 100644
--- a/sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java
+++ b/sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java
@@ -47,6 +47,8 @@ public class UtilsTest {
assertThat(Utils.isAtLeast52(null)).isFalse();
assertThat(Utils.isAtLeast52("52")).isTrue();
assertThat(Utils.isAtLeast52("5.0")).isFalse();
+ assertThat(Utils.isAtLeast52("")).isFalse();
+ assertThat(Utils.isAtLeast52("trash")).isFalse();
assertThat(Utils.isAtLeast52("6.0.0")).isTrue();
assertThat(Utils.isAtLeast52("5.2-SNAPSHOT")).isTrue();
}