From e727146d35b4053e8703e57753356ea33710f9cc Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Tue, 22 Jan 2013 09:53:57 +0100 Subject: Fix some quality flaws. --- src/main/java/org/sonar/runner/IOUtils.java | 3 ++- src/main/java/org/sonar/runner/Main.java | 12 ++++++++---- src/main/java/org/sonar/runner/Runner.java | 10 +++++++--- src/main/java/org/sonar/runner/internal/batch/Launcher.java | 3 +++ .../org/sonar/runner/internal/batch/SonarProjectBuilder.java | 2 +- 5 files changed, 21 insertions(+), 9 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/sonar/runner/IOUtils.java b/src/main/java/org/sonar/runner/IOUtils.java index 6c566a2..248d18d 100644 --- a/src/main/java/org/sonar/runner/IOUtils.java +++ b/src/main/java/org/sonar/runner/IOUtils.java @@ -130,7 +130,8 @@ final class IOUtils { } File[] files = directory.listFiles(); - if (files == null) { // null if security restricted + // null if security restricted + if (files == null) { throw new IOException("Failed to list contents of " + directory); } diff --git a/src/main/java/org/sonar/runner/Main.java b/src/main/java/org/sonar/runner/Main.java index 9cb9d47..add38bf 100644 --- a/src/main/java/org/sonar/runner/Main.java +++ b/src/main/java/org/sonar/runner/Main.java @@ -49,10 +49,14 @@ public final class Main { // TODO Remove this after everything is updated to support tasks private static final String TASK_COMMAND = "sonar.task"; - private boolean debugMode = false; - private boolean displayVersionOnly = false; - private boolean displayStackTrace = false; - private String command; + @VisibleForTesting + boolean debugMode = false; + @VisibleForTesting + boolean displayVersionOnly = false; + @VisibleForTesting + boolean displayStackTrace = false; + @VisibleForTesting + String command; @VisibleForTesting Properties globalProperties; @VisibleForTesting diff --git a/src/main/java/org/sonar/runner/Runner.java b/src/main/java/org/sonar/runner/Runner.java index e075f62..9d404da 100644 --- a/src/main/java/org/sonar/runner/Runner.java +++ b/src/main/java/org/sonar/runner/Runner.java @@ -19,6 +19,8 @@ */ package org.sonar.runner; +import com.google.common.annotations.VisibleForTesting; + import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -244,7 +246,8 @@ public final class Runner { /** * @return global properties, project properties and command-line properties */ - protected Properties getProperties() { + @VisibleForTesting + public Properties getProperties() { Properties props = new Properties(); props.putAll(globalProperties); props.putAll(projectProperties); @@ -266,7 +269,8 @@ public final class Runner { private BootstrapClassLoader createClassLoader(Bootstrapper bootstrapper) { URL url = getJarPath(); return bootstrapper.createClassLoader( - new URL[] {url}, // Add JAR with Sonar Runner - it's a Jar which contains this class + // Add JAR with Sonar Runner - it's a Jar which contains this class + new URL[] {url}, getClass().getClassLoader(), unmaskedPackages); } @@ -293,7 +297,7 @@ public final class Runner { if (uri != null) { try { return new URL(uri); - } catch (MalformedURLException e) { // NOSONAR + } catch (MalformedURLException e) { } } } diff --git a/src/main/java/org/sonar/runner/internal/batch/Launcher.java b/src/main/java/org/sonar/runner/internal/batch/Launcher.java index 5e36cfa..1aebbd9 100644 --- a/src/main/java/org/sonar/runner/internal/batch/Launcher.java +++ b/src/main/java/org/sonar/runner/internal/batch/Launcher.java @@ -50,6 +50,9 @@ public class Launcher { private Properties projectProperties; private List containerExtensions; + /** + * @deprecated Use {@link Launcher#Launcher(String, Properties, Properties, List)} instead + */ @Deprecated public Launcher(Properties properties, List containerExtensions) { this("project-analysis", new Properties(), properties, containerExtensions); diff --git a/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java b/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java index 46171b4..84b8788 100644 --- a/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java +++ b/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java @@ -128,7 +128,7 @@ public final class SonarProjectBuilder { } public ProjectDefinition generateProjectDefinition() { - if (StringUtils.isBlank(command) || command.equals("inspect")) { + if (StringUtils.isBlank(command) || "inspect".equals(command)) { ProjectDefinition rootProject = defineProject(properties, null); rootProjectWorkDir = rootProject.getWorkDir(); defineChildren(rootProject); -- cgit v1.2.3