Replaced System.out.println by java logging.

Change-Id: I83789e0cf5726f7bab8139289197de9c7b87fe0c
diff --git a/src/main/java/com/google/gwt/benchmark/git/GitInterface.java b/src/main/java/com/google/gwt/benchmark/git/GitInterface.java
index 3c5f78d..0ddba68 100644
--- a/src/main/java/com/google/gwt/benchmark/git/GitInterface.java
+++ b/src/main/java/com/google/gwt/benchmark/git/GitInterface.java
@@ -36,6 +36,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.util.List;
+import java.util.logging.Logger;
 
 /**
  * Utility class to interface with JGit.
@@ -43,6 +44,7 @@
  * Designed for single thread access; not threadsafe.
  */
 public class GitInterface {
+  private static final Logger log = Logger.getLogger(GitInterface.class.getName());
 
   private static final Function<String, TreeFilter> PREFIX_FILTER_FROM_STRING =
       new Function<String, TreeFilter>() {
@@ -65,7 +67,7 @@
    */
   public static RevisionInfo checkout(String repo, String revision) throws GitException {
     Git git = null;
-    System.out.println("Checking out " + revision);
+    log.info("Checking out " + revision);
     try {
       git = Git.open(new File(repo));
       CheckoutCommand checkoutCommand = git.checkout().setName(revision);
@@ -107,13 +109,13 @@
    */
   public static List<RevisionInfo> getRevisionsAffectingTargets(String repo, List<String> prefixes,
       List<String> suffixes) throws GitException {
-    System.out.println("Computing revisions to test");
+    log.info("Computing revisions to test");
     List<RevisionInfo> revisionsToTest = Lists.newArrayList();
     Git git = null;
     try {
       git = Git.open(new File(repo));
-      LogCommand log = git.log();
-      for (RevCommit commit : log.all().call()) {
+      LogCommand logCommand = git.log();
+      for (RevCommit commit : logCommand.all().call()) {
         RevisionInfo revInfo = maybeGetRevisionInfo(git.getRepository(), commit, prefixes,
             suffixes);
         if (revInfo == null){
@@ -121,7 +123,7 @@
         }
         revisionsToTest.add(revInfo);
       }
-      System.out.println("Revisions to test : " + revisionsToTest.size());
+      log.info("Revisions to test : " + revisionsToTest.size());
     } catch (IOException | GitAPIException e) {
       throw new GitException("Could not get revision list" , e);
     } finally {
diff --git a/src/main/java/com/google/gwt/benchmark/project/ProjectConfiguration.java b/src/main/java/com/google/gwt/benchmark/project/ProjectConfiguration.java
index 731e7bd..747aef9 100644
--- a/src/main/java/com/google/gwt/benchmark/project/ProjectConfiguration.java
+++ b/src/main/java/com/google/gwt/benchmark/project/ProjectConfiguration.java
@@ -26,12 +26,14 @@
 import java.io.IOException;
 import java.util.List;
 import java.util.Properties;
+import java.util.logging.Logger;
 
 /**
  * Represents a project for the benchmarking system, and includes all the information on how to
  * compile it.
  */
 public class ProjectConfiguration {
+  private static final Logger log = Logger.getLogger(ProjectConfiguration.class.getName());
 
   private static final String GWT_DEFAULT_ENTRY_POINT_PROPERTY = "com.google.gwt.dev.Compiler";
   private static final String GWT_ENTRY_POINT_PROPERTY = "gwt.compiler.entrypoint";
@@ -47,7 +49,7 @@
   @VisibleForTesting
   static ProjectConfiguration getProjectConfiguration(String baseDir, String projectDir) {
     ProjectConfiguration projectConfiguration = new ProjectConfiguration(projectDir);
-    System.out.println("Processing project at " + projectDir);
+    log.info("Processing project at " + projectDir);
     Properties projectProperties = new Properties();
     try {
       final String projectPath = baseDir + "/" + projectDir;
@@ -61,16 +63,16 @@
 
       final String targetModule = projectProperties.getProperty(TARGET_MODULE_PROPERTY);
       if (targetModule == null || targetModule.isEmpty()) {
-        System.err.format(
-            "[ERROR]: Project '%s': target module can not be empty or ommitted in project.config\n",
-            projectDir);
+        log.severe(String.format(
+            "Project '%s': target module can not be empty or ommitted in project.config",
+            projectDir));
         return null;
       }
       projectConfiguration.setTargetModule(targetModule);
       projectConfiguration.setPath(projectPath);
     } catch (IOException e) {
-      System.err.format("[ERROR]: Project '%s': could not read 'project.config' file\n",
-          projectDir);
+      log.severe(String.format("Project '%s': could not read 'project.config' file",
+          projectDir));
       return null;
     }
     return projectConfiguration;
@@ -104,7 +106,6 @@
    * Constructs a project configuration.
    */
   public ProjectConfiguration(String name) {
-    super();
     Preconditions.checkNotNull("Project name should not be null", name);
     this.name = name;
   }
diff --git a/src/main/java/com/google/gwt/benchmark/runner/ProcessRunner.java b/src/main/java/com/google/gwt/benchmark/runner/ProcessRunner.java
index 026717f..1a47633 100644
--- a/src/main/java/com/google/gwt/benchmark/runner/ProcessRunner.java
+++ b/src/main/java/com/google/gwt/benchmark/runner/ProcessRunner.java
@@ -17,6 +17,7 @@
 import com.google.common.base.Charsets;
 import com.google.common.base.Joiner;
 import com.google.common.collect.Maps;
+import com.google.gwt.benchmark.project.ProjectConfiguration;
 
 import org.apache.commons.exec.CommandLine;
 import org.apache.commons.exec.DefaultExecutor;
@@ -31,11 +32,13 @@
 import java.nio.file.Files;
 import java.util.List;
 import java.util.Map;
+import java.util.logging.Logger;
 
 /**
  * A thin layer to execute commands as separate processes and capture their output.
  */
 public class ProcessRunner {
+  private static final Logger log = Logger.getLogger(ProjectConfiguration.class.getName());
 
   /**
    * How long to wait after the process has been stopped until the handler is forcefully stopped.
@@ -54,12 +57,12 @@
     try {
       File runnerOut = File.createTempFile("runner", ".out");
       File runnerErr = File.createTempFile("runner", ".err");
-      System.out.println("Output will be stored at " + runnerOut.getPath() + " and "
+      log.info("Output will be stored at " + runnerOut.getPath() + " and "
           + runnerErr.getPath());
       ProcessStats processStats =
           runAndTimeCommand(currentDir, runnerOut, runnerErr, Maps.<String, String>newHashMap(),
               args);
-      System.out.println(processStats);
+      log.info(processStats.toString());
     } catch (RunnerException | IOException e) {
       e.printStackTrace();
     }
@@ -108,7 +111,7 @@
    */
   public static ProcessStats runAndTimeCommand(File workdir, File stdOutput, File stdError,
       Map<String, String> newEnviromentVars, String... commandPlusArgs) throws RunnerException {
-    System.out.println("Running command " + Joiner.on(" ").join(commandPlusArgs));
+    log.info("Running command " + Joiner.on(" ").join(commandPlusArgs));
 
     File timerOutputFile = null;
 
@@ -138,7 +141,7 @@
       pumpStreamHandler.setStopTimeout(STREAM_HANDLER_STOP_TIMEOUT);
       executor.setStreamHandler(pumpStreamHandler);
 
-      System.out.println("Setting workdir to " + workdir);
+      log.info("Setting workdir to " + workdir);
       executor.setWorkingDirectory(workdir);
 
       Map<String, String> environment = Maps.newHashMap(System.getenv());
diff --git a/src/main/java/com/google/gwt/benchmark/util/Util.java b/src/main/java/com/google/gwt/benchmark/util/Util.java
new file mode 100644
index 0000000..e34aaf2
--- /dev/null
+++ b/src/main/java/com/google/gwt/benchmark/util/Util.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.benchmark.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+
+/**
+ * Utilities.
+ */
+public class Util {
+
+  /**
+   * Format size in bytes in a human readable form.
+   */
+  public static String formatSize(double size) {
+    String finalQ = "";
+    for (String q: new String[] {"k", "M", "G"}) {
+      if (size < 1024) break;
+      finalQ = q;
+      size /= 1024;
+    }
+    return String.format("%.4f", size) + finalQ;
+  }
+
+  /**
+   * Returns the size of the uncompressed stream content assuming that the stream is
+   * gzipped and its compressed size is {@code compressedSize}
+   */
+  public static long getGzUncompressedSizeFromInputStream(InputStream entryStream,
+      long compressedSize) throws IOException {
+    byte[] encodedUncompressedSize = new byte[4];
+    entryStream.skip(compressedSize - 4);
+    entryStream.read(encodedUncompressedSize, 0, 4);
+    return ByteBuffer.wrap(encodedUncompressedSize).order(ByteOrder.LITTLE_ENDIAN).getInt();
+  }
+
+  private Util() {}
+}