From: Julien HENRY Date: Mon, 18 Mar 2013 08:50:45 +0000 (+0100) Subject: Fix some quality flaws X-Git-Tag: 2.5-rc1~182 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6d178e30d41bbe00852535d3b1af6bb3a200db6f;p=sonar-scanner-cli.git Fix some quality flaws --- diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/Bootstrapper.java b/sonar-runner-api/src/main/java/org/sonar/runner/Bootstrapper.java index 64e9694..9654f13 100644 --- a/sonar-runner-api/src/main/java/org/sonar/runner/Bootstrapper.java +++ b/sonar-runner-api/src/main/java/org/sonar/runner/Bootstrapper.java @@ -133,7 +133,7 @@ class Bootstrapper { } // Don't log for old versions without cache to not pollute logs else if (!isUnsupportedVersionForCache(getServerVersion())) { - Logs.info("Downloading " + path.substring(path.lastIndexOf("/") + 1)); + Logs.info("Downloading " + path.substring(path.lastIndexOf('/') + 1)); } try { HttpURLConnection connection = newHttpConnection(new URL(fullUrl)); diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/Main.java b/sonar-runner-api/src/main/java/org/sonar/runner/Main.java index a9a653a..7ccd5ca 100644 --- a/sonar-runner-api/src/main/java/org/sonar/runner/Main.java +++ b/sonar-runner-api/src/main/java/org/sonar/runner/Main.java @@ -46,7 +46,6 @@ public final class Main { private static final String RUNNER_SETTINGS = "runner.settings"; private static final String PROJECT_HOME = "project.home"; private static final String PROJECT_SETTINGS = "project.settings"; - // TODO Remove this after everything is updated to support tasks private static final String TASK_COMMAND = "sonar.task"; boolean debugMode = false; diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/Runner.java b/sonar-runner-api/src/main/java/org/sonar/runner/Runner.java index 5b1a436..0611d56 100644 --- a/sonar-runner-api/src/main/java/org/sonar/runner/Runner.java +++ b/sonar-runner-api/src/main/java/org/sonar/runner/Runner.java @@ -106,8 +106,8 @@ public final class Runner { * * @since 2.1 */ - String ENV_SONAR_USER_HOME = "SONAR_USER_HOME"; - String PROPERTY_SONAR_USER_HOME = "sonar.userHome"; + public static final String ENV_SONAR_USER_HOME = "SONAR_USER_HOME"; + public static final String PROPERTY_SONAR_USER_HOME = "sonar.userHome"; /** * Array of prefixes of versions of Sonar without support of this runner. diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/SonarCache.java b/sonar-runner-api/src/main/java/org/sonar/runner/SonarCache.java index cd8ae28..4bcf374 100644 --- a/sonar-runner-api/src/main/java/org/sonar/runner/SonarCache.java +++ b/sonar-runner-api/src/main/java/org/sonar/runner/SonarCache.java @@ -31,7 +31,7 @@ import java.io.IOException; * This class is responsible for managing Sonar batch file cache. You can put file into cache and * later try to retrieve them. MD5 is used to differentiate files (name is not secure as files may come * from different Sonar servers and have same name but be actually different, and same for SNAPSHOTs). - * Default location of cache is + * Default location of cache is * @author Julien HENRY * */ @@ -55,7 +55,7 @@ public class SonarCache { try { FileUtils.forceMkdir(cacheLocation); } catch (IOException e) { - throw new RuntimeException("Unable to create cache directory " + cacheLocation.getAbsolutePath(), e); + throw new RunnerException("Unable to create cache directory " + cacheLocation.getAbsolutePath(), e); } } } @@ -94,7 +94,7 @@ public class SonarCache { /** * Move the given file inside the cache. Return the MD5 of the cached file. * @param sourceFile - * @throws IOException + * @throws IOException */ public String cacheFile(File sourceFile, String filename) throws IOException { Logs.debug("Trying to cache file " + sourceFile.getAbsolutePath() + " with filename " + filename); @@ -123,13 +123,12 @@ public class SonarCache { FileUtils.forceMkdir(finalDir); // Now try to move the file from temporary folder to final location boolean rename = tmpFileName.renameTo(finalFileName); - if (!rename) { + if (!rename // Check if the file was already in cache - if (!finalFileName.exists()) { - Logs.warn("Unable to rename " + tmpFileName.getAbsolutePath() + " to " + finalFileName.getAbsolutePath()); - Logs.warn("A copy/delete will be tempted but with no garantee of atomicity"); - FileUtils.moveFile(tmpFileName, finalFileName); - } + && !finalFileName.exists()) { + Logs.warn("Unable to rename " + tmpFileName.getAbsolutePath() + " to " + finalFileName.getAbsolutePath()); + Logs.warn("A copy/delete will be tempted but with no garantee of atomicity"); + FileUtils.moveFile(tmpFileName, finalFileName); } Logs.debug("File cached at " + finalFileName.getAbsolutePath()); return md5; @@ -158,7 +157,7 @@ public class SonarCache { * asking for caching it with {@link #cacheFile(File)}. * This is to avoid extra copy. * @return - * @throws IOException + * @throws IOException */ public File getTemporaryFile() throws IOException { return createTempFile(getTmpDir()); @@ -168,7 +167,7 @@ public class SonarCache { * Create a temporary file in the given directory. * @param baseDir * @return - * @throws IOException + * @throws IOException */ private static File createTempFile(File baseDir) throws IOException { String baseName = System.currentTimeMillis() + "-"; @@ -190,7 +189,7 @@ public class SonarCache { try { FileUtils.forceMkdir(tmpDir); } catch (IOException e) { - throw new RuntimeException("Unable to create temporary cache directory " + tmpDir.getAbsolutePath(), e); + throw new RunnerException("Unable to create temporary cache directory " + tmpDir.getAbsolutePath(), e); } } return tmpDir;