diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-06-23 14:25:51 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-06-23 14:25:51 +0200 |
commit | 25a566485179819c127aea3fbf7d3c4a2d3e36a9 (patch) | |
tree | 860512ef86ccecfc7ee8ff69c21935e0db13cc14 /sonar-runner-api/src/main/java/org/sonar | |
parent | 75a661f61c2e0667b626bd17853eaf3e5201b4f0 (diff) | |
download | sonar-scanner-cli-25a566485179819c127aea3fbf7d3c4a2d3e36a9.tar.gz sonar-scanner-cli-25a566485179819c127aea3fbf7d3c4a2d3e36a9.zip |
Fix quality flaws and formatting
Diffstat (limited to 'sonar-runner-api/src/main/java/org/sonar')
7 files changed, 45 insertions, 35 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; } } |