]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
Fix violations / improve documentation / refactor some code
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Fri, 7 Sep 2012 16:39:15 +0000 (18:39 +0200)
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Fri, 7 Sep 2012 16:39:15 +0000 (18:39 +0200)
15 files changed:
src/main/java/org/sonar/runner/Main.java
src/main/java/org/sonar/runner/Runner.java
src/main/java/org/sonar/runner/RunnerException.java
src/main/java/org/sonar/runner/bootstrapper/BootstrapException.java
src/main/java/org/sonar/runner/bootstrapper/Bootstrapper.java
src/main/java/org/sonar/runner/bootstrapper/utils/PrivateIOUtils.java [new file with mode: 0644]
src/main/java/org/sonar/runner/bootstrapper/utils/package-info.java [new file with mode: 0644]
src/main/java/org/sonar/runner/internal/PrivateIOUtils.java [deleted file]
src/main/java/org/sonar/runner/internal/package-info.java [deleted file]
src/main/java/org/sonar/runner/model/Launcher.java
src/main/java/org/sonar/runner/utils/SonarRunnerVersion.java
src/test/java/org/sonar/runner/bootstrapper/BootstrapClassLoaderTest.java
src/test/java/org/sonar/runner/bootstrapper/BootstrapperTest.java
src/test/java/org/sonar/runner/model/LauncherTest.java
src/test/java/org/sonar/runner/utils/SonarRunnerVersionTest.java

index 89c8dcf164366035facc3b9ad43458d3df19eb15..633401f010cbe318da60031dac46dde39b70af35 100644 (file)
@@ -20,8 +20,9 @@
 
 package org.sonar.runner;
 
+import org.sonar.runner.bootstrapper.utils.PrivateIOUtils;
+
 import org.sonar.runner.bootstrapper.BootstrapException;
-import org.sonar.runner.internal.PrivateIOUtils;
 import org.sonar.runner.utils.SonarRunnerVersion;
 
 import java.io.File;
@@ -51,6 +52,9 @@ public final class Main {
 
   private static boolean debugMode = false;
 
+  /**
+   * Entry point of the program.
+   */
   public static void main(String[] args) {
     long startTime = System.currentTimeMillis();
     try {
index 85197d61ca65b45c0c19abecb3d6832ade73c205..f2ef6f8f706151fe4bb4d6440feee7907409dd08 100644 (file)
@@ -52,33 +52,49 @@ import java.util.Properties;
 public final class Runner {
 
   /**
+   * Old property used to activate debug level for logging.
+   * 
    * @deprecated Replaced by sonar.verbose since 1.2
    */
   @Deprecated
   public static final String PROPERTY_OLD_DEBUG_MODE = "runner.debug";
 
   /**
+   * Property used to increase logging information.
+   * 
    * @since 1.2
    */
   public static final String PROPERTY_VERBOSE = "sonar.verbose";
 
   /**
+   * Property used to specify the working directory for the runner. May be a relative or absolute path. 
+   * 
    * @since 1.4
    */
   public static final String PROPERTY_WORK_DIRECTORY = "sonar.working.directory";
+
+  /**
+   * Default value of the working directory.
+   */
   public static final String DEF_VALUE_WORK_DIRECTORY = ".sonar";
 
   /**
+   * Property used to specify the base directory of the project to analyse.
+   * 
    * @since 1.5
    */
   public static final String PROPERTY_PROJECT_DIR = "sonar.projectDir";
 
   /**
+   * Property used to specify the name of the tool that will run a Sonar analysis.
+   * 
    * @since 1.5
    */
   public static final String PROPERTY_ENVIRONMENT_INFORMATION_KEY = "sonar.environment.information.key";
 
   /**
+   * Property used to specify the version of the tool that will run a Sonar analysis.
+   * 
    * @since 1.5
    */
   public static final String PROPERTY_ENVIRONMENT_INFORMATION_VERSION = "sonar.environment.information.version";
index 5d61d06a07a8abc0e1754686c0ed1a3382bb8b27..78925429421052ee12c9922a6ffcd30853c6dd42 100644 (file)
 package org.sonar.runner;
 
 /**
+ * Exception thrown by the Sonar Runner when something bad happens.
+ * 
  * @since 1.2
  */
 public class RunnerException extends RuntimeException {
 
   private static final long serialVersionUID = 4810407777585753030L;
 
+  /**
+   * See {@link RuntimeException}
+   */
   public RunnerException(String message) {
     super(message);
   }
 
+  /**
+   * See {@link RuntimeException}
+   */
   public RunnerException(Throwable cause) {
     super(cause);
   }
 
+  /**
+   * See {@link RuntimeException}
+   */
   public RunnerException(String message, Throwable cause) {
     super(message, cause);
   }
index 7bad396825f72481dd7f44b146bf8f501b5eafd8..d7803641eee0defa6d49309af20320fb664a23c3 100644 (file)
  */
 package org.sonar.runner.bootstrapper;
 
+/**
+ * Exception thrown by the bootstrapper when something bad happens.
+ */
 public class BootstrapException extends RuntimeException {
 
+  private static final long serialVersionUID = -4974995497654796971L;
+
+  /**
+   * See {@link RuntimeException}
+   */
   public BootstrapException(String message) {
     super(message);
   }
 
+  /**
+   * See {@link RuntimeException}
+   */
   public BootstrapException(Throwable cause) {
     super(cause);
   }
 
+  /**
+   * See {@link RuntimeException}
+   */
   public BootstrapException(String message, Throwable cause) {
     super(message, cause);
   }
index 18b5ccce5750bb02654af0db98cc0716c91bf434..f13c2dda1ab1b015b08877fbc02d1e95d0a3d3fd 100644 (file)
@@ -19,7 +19,8 @@
  */
 package org.sonar.runner.bootstrapper;
 
-import org.sonar.runner.internal.PrivateIOUtils;
+import org.sonar.runner.bootstrapper.utils.PrivateIOUtils;
+
 import org.sonar.runner.utils.SonarRunnerVersion;
 
 import java.io.File;
@@ -34,6 +35,9 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 
+/**
+ * Bootstrapper used to download everything from the server and create the correct classloader required to execute a Sonar analysis in isolation.
+ */
 public class Bootstrapper {
 
   private static final String VERSION_PATH = "/api/server/version";
diff --git a/src/main/java/org/sonar/runner/bootstrapper/utils/PrivateIOUtils.java b/src/main/java/org/sonar/runner/bootstrapper/utils/PrivateIOUtils.java
new file mode 100644 (file)
index 0000000..5276571
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Sonar Standalone Runner
+ * 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.bootstrapper.utils;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+
+/**
+ * Internal class used only by the Runner as we don't want it to depend on third-party libs.
+ * This class should not be used by Sonar Runner consumers. 
+ */
+public final class PrivateIOUtils {
+
+  private PrivateIOUtils() {
+    // only static methods
+  }
+
+  /**
+   * The default buffer size to use.
+   */
+  private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+
+  /**
+   * Unconditionally close a <code>Closeable</code>.
+   */
+  public static void closeQuietly(Closeable closeable) {
+    try {
+      if (closeable != null) {
+        closeable.close();
+      }
+    } catch (IOException ioe) {
+    }
+  }
+
+  /**
+   * Get the contents of a <code>Reader</code> as a String.
+   */
+  public static String toString(Reader input) throws IOException {
+    StringWriter sw = new StringWriter();
+    copyLarge(input, sw);
+    return sw.toString();
+  }
+
+  /**
+   * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
+   */
+  public static long copyLarge(InputStream input, OutputStream output) throws IOException {
+    byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+    long count = 0;
+    int n = 0;
+    while (-1 != (n = input.read(buffer))) {
+      output.write(buffer, 0, n);
+      count += n;
+    }
+    return count;
+  }
+
+  /**
+   * Copy chars from a <code>Reader</code> to a <code>Writer</code>.
+   */
+  public static long copyLarge(Reader input, Writer output) throws IOException {
+    char[] buffer = new char[DEFAULT_BUFFER_SIZE];
+    long count = 0;
+    int n = 0;
+    while (-1 != (n = input.read(buffer))) {
+      output.write(buffer, 0, n);
+      count += n;
+    }
+    return count;
+  }
+
+  /**
+   * Deletes a file (not a directory).
+   */
+  public static boolean deleteFileQuietly(File file) {
+    if (file == null) {
+      return false;
+    }
+    try {
+      return file.delete();
+    } catch (Exception e) {
+      return false;
+    }
+  }
+
+}
diff --git a/src/main/java/org/sonar/runner/bootstrapper/utils/package-info.java b/src/main/java/org/sonar/runner/bootstrapper/utils/package-info.java
new file mode 100644 (file)
index 0000000..3b9f5ed
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Sonar Standalone Runner
+ * 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
+ */
+/**
+ * Internal package that provides utils for internal purposes.
+ * Should not be used by consumers.
+ */
+package org.sonar.runner.bootstrapper.utils;
\ No newline at end of file
diff --git a/src/main/java/org/sonar/runner/internal/PrivateIOUtils.java b/src/main/java/org/sonar/runner/internal/PrivateIOUtils.java
deleted file mode 100644 (file)
index 7b7f1de..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Sonar Standalone Runner
- * 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.internal;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.StringWriter;
-import java.io.Writer;
-
-/**
- * Internal class used only by the Runner as we don't want it to depend on third-party libs.
- * This class should not be used by Sonar Runner consumers. 
- */
-public final class PrivateIOUtils {
-
-  private PrivateIOUtils() {
-    // only static methods
-  }
-
-  /**
-   * The default buffer size to use.
-   */
-  private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
-
-  /**
-   * Unconditionally close a <code>Closeable</code>.
-   */
-  public static void closeQuietly(Closeable closeable) {
-    try {
-      if (closeable != null) {
-        closeable.close();
-      }
-    } catch (IOException ioe) {
-    }
-  }
-
-  /**
-   * Get the contents of a <code>Reader</code> as a String.
-   */
-  public static String toString(Reader input) throws IOException {
-    StringWriter sw = new StringWriter();
-    copyLarge(input, sw);
-    return sw.toString();
-  }
-
-  /**
-   * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
-   */
-  public static long copyLarge(InputStream input, OutputStream output) throws IOException {
-    byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
-    long count = 0;
-    int n = 0;
-    while (-1 != (n = input.read(buffer))) {
-      output.write(buffer, 0, n);
-      count += n;
-    }
-    return count;
-  }
-
-  /**
-   * Copy chars from a <code>Reader</code> to a <code>Writer</code>.
-   */
-  public static long copyLarge(Reader input, Writer output) throws IOException {
-    char[] buffer = new char[DEFAULT_BUFFER_SIZE];
-    long count = 0;
-    int n = 0;
-    while (-1 != (n = input.read(buffer))) {
-      output.write(buffer, 0, n);
-      count += n;
-    }
-    return count;
-  }
-
-  /**
-   * Deletes a file (not a directory).
-   */
-  public static boolean deleteFileQuietly(File file) {
-    if (file == null) {
-      return false;
-    }
-    try {
-      return file.delete();
-    } catch (Exception e) {
-      return false;
-    }
-  }
-
-}
diff --git a/src/main/java/org/sonar/runner/internal/package-info.java b/src/main/java/org/sonar/runner/internal/package-info.java
deleted file mode 100644 (file)
index 64ccad4..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Sonar Standalone Runner
- * 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
- */
-/**
- * Internal package that provides utils for internal purposes.
- * Should not be used by consumers.
- */
-package org.sonar.runner.internal;
\ No newline at end of file
index cfa14b33c4f5d86fd74a8bd8b3222300d1de1b43..e18ba1e56028e04b5b193dfebda60f142156e9f5 100644 (file)
@@ -36,7 +36,6 @@ import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.utils.SonarException;
 import org.sonar.batch.Batch;
 import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import org.sonar.runner.Main;
 import org.sonar.runner.Runner;
 
 import java.io.File;
@@ -56,7 +55,7 @@ public class Launcher {
   }
 
   /**
-   * This method invoked from {@link Main}. Do not rename it.
+   * Main entry point.
    */
   public void execute() {
     File baseDir = new File(propertiesFromRunner.getProperty(Runner.PROPERTY_PROJECT_DIR));
index 5cc15779c185243bb08faaf4113385cb5e140be3..e429fdcf060bb7d353db10850e5ab852cc11e9a6 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.runner.utils;
 
-import org.sonar.runner.internal.PrivateIOUtils;
+import org.sonar.runner.bootstrapper.utils.PrivateIOUtils;
 
 import java.io.IOException;
 import java.io.InputStream;
index 87496bad4ce8f454cde38acbe600e5a5110959bb..17ddce5e17aba3b055fa806dfec37c838673a04f 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.runner.bootstrapper;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.runner.bootstrapper.BootstrapClassLoader;
 
 import static org.fest.assertions.Assertions.assertThat;
 
index 07417011b3144df6716eedce58a533f8b5d4f63c..b09afaead7a2c78cd43e456c3f276b616422d653 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.runner.bootstrapper;
 
 import org.junit.Test;
-import org.sonar.runner.bootstrapper.Bootstrapper;
 
 import java.io.File;
 import java.io.IOException;
index e3b6f15b092b33fef7bfcadf6f774dbde622b5b1..33a7ebf47243cd8ae8a1009886c142c6d97d000c 100644 (file)
  */
 package org.sonar.runner.model;
 
-import org.sonar.runner.Runner;
-
-import org.sonar.runner.model.Launcher;
-
 import org.apache.commons.configuration.BaseConfiguration;
 import org.apache.commons.configuration.Configuration;
 import org.junit.Test;
+import org.sonar.runner.Runner;
 
 import java.util.Properties;
 
index bfbf7201b2963206a085e25a085775544130bba1..5b94ee43f8e26f379a22727b77fc499ded18502b 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.runner.utils;
 
-import org.sonar.runner.utils.SonarRunnerVersion;
-
 import org.junit.Test;
 
 import static org.fest.assertions.Assertions.assertThat;