From: Julien HENRY Date: Fri, 31 May 2013 06:43:49 +0000 (+0200) Subject: Fix some quality flaws X-Git-Tag: 3.6~159 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4f4091d09b31b18c3053518c84dff26e3a6d48ce;p=sonarqube.git Fix some quality flaws --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/AbstractTimeProfiling.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/AbstractTimeProfiling.java index 41997fa0eef..a610520ef5f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/AbstractTimeProfiling.java +++ b/sonar-batch/src/main/java/org/sonar/batch/profiling/AbstractTimeProfiling.java @@ -91,4 +91,8 @@ public abstract class AbstractTimeProfiling { return result; } + protected void println(String msg) { + PhasesSumUpTimeProfiler.println(msg); + } + } diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java index b67b454e573..e1b48fcba69 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java +++ b/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java @@ -63,14 +63,14 @@ public class ModuleProfiling extends AbstractTimeProfiling { StringBuilder sb = new StringBuilder(); sb.append(" * ").append(phaseProfiling.phase()).append(" execution time: ").append(phaseProfiling.totalTimeAsString()) .append(" (").append((int) (phaseProfiling.totalTime() / percent)).append("%)"); - System.out.println(sb.toString()); + println(sb.toString()); } for (Phase phase : Phases.Phase.values()) { if (profilingPerPhase.containsKey(phase)) { StringBuilder sb = new StringBuilder(); sb.append("\n * ").append(phase).append(" execution time breakdown: ") .append(TimeUtils.formatDuration(getProfilingPerPhase(phase).totalTime())); - System.out.println(sb.toString()); + println(sb.toString()); getProfilingPerPhase(phase).dump(); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java index 581be48c740..8bb5bcbdacd 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java +++ b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java @@ -77,7 +77,7 @@ public class PhaseProfiling extends AbstractTimeProfiling { StringBuilder sb = new StringBuilder(); sb.append(" o ").append(itemProfiling.itemName()).append(": ").append(itemProfiling.totalTimeAsString()) .append(" (").append((int) (itemProfiling.totalTime() / percent)).append("%)"); - System.out.println(sb.toString()); + println(sb.toString()); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java index f1c573eaf61..6137b79875e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java +++ b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java @@ -21,6 +21,8 @@ package org.sonar.batch.profiling; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Lists; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.sonar.api.batch.Decorator; import org.sonar.api.batch.events.DecoratorExecutionHandler; import org.sonar.api.batch.events.DecoratorsPhaseHandler; @@ -44,6 +46,8 @@ import static org.sonar.batch.profiling.AbstractTimeProfiling.truncate; public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorExecutionHandler, DecoratorExecutionHandler, PostJobExecutionHandler, DecoratorsPhaseHandler, SensorsPhaseHandler, PostJobsPhaseHandler { + static Logger LOG = LoggerFactory.getLogger(PhasesSumUpTimeProfiler.class); + @VisibleForTesting ModuleProfiling currentModuleProfiling; @VisibleForTesting @@ -57,6 +61,10 @@ public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorEx this(new Clock()); } + static void println(String msg) { + LOG.info(msg); + } + @VisibleForTesting PhasesSumUpTimeProfiler(Clock clock) { this.clock = clock; @@ -74,9 +82,9 @@ public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorEx currentModuleProfiling.stop(); modulesProfilings.add(currentModuleProfiling); long moduleTotalTime = currentModuleProfiling.totalTime(); - System.out.println("\n -------- Profiling of module " + module.getName() + ": " + TimeUtils.formatDuration(moduleTotalTime) + " --------\n"); + println("\n -------- Profiling of module " + module.getName() + ": " + TimeUtils.formatDuration(moduleTotalTime) + " --------\n"); currentModuleProfiling.dump(); - System.out.println("\n -------- End of profiling of module " + module.getName() + " --------\n"); + println("\n -------- End of profiling of module " + module.getName() + " --------\n"); totalProfiling.merge(currentModuleProfiling); if (module.isRoot() && !module.getModules().isEmpty()) { dumpTotalExecutionSummary(); @@ -87,18 +95,18 @@ public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorEx private void dumpTotalExecutionSummary() { totalProfiling.stop(); long totalTime = totalProfiling.totalTime(); - System.out.println("\n ======== Profiling of total execution: " + TimeUtils.formatDuration(totalTime) + " ========\n"); - System.out.println(" * Module execution time breakdown: "); + println("\n ======== Profiling of total execution: " + TimeUtils.formatDuration(totalTime) + " ========\n"); + println(" * Module execution time breakdown: "); double percent = totalTime / 100.0; for (ModuleProfiling modulesProfiling : truncate(sortByDescendingTotalTime(modulesProfilings))) { StringBuilder sb = new StringBuilder(); sb.append(" o ").append(modulesProfiling.moduleName()).append(" execution time: ").append(modulesProfiling.totalTimeAsString()) .append(" (").append((int) (modulesProfiling.totalTime() / percent)).append("%)"); - System.out.println(sb.toString()); + println(sb.toString()); } - System.out.println(); + println(""); totalProfiling.dump(); - System.out.println("\n ======== End of profiling of total execution ========\n"); + println("\n ======== End of profiling of total execution ========\n"); } public void onSensorsPhase(SensorsPhaseEvent event) {