From: simonbrandhof Date: Mon, 3 Jan 2011 15:34:11 +0000 (+0000) Subject: improve batch logs : more details on the comparison periods X-Git-Tag: 2.6~202 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=84895c287349677e47e16ce65674420d2038cf5e;p=sonarqube.git improve batch logs : more details on the comparison periods --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java index b55ad44d661..04140ae8c16 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java @@ -19,7 +19,9 @@ */ package org.sonar.batch.components; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ReflectionToStringBuilder; +import org.sonar.api.CoreProperties; import org.sonar.api.database.model.Snapshot; import java.util.Date; @@ -73,7 +75,7 @@ public class PastSnapshot { } public Integer getProjectSnapshotId() { - return (projectSnapshot!=null ? projectSnapshot.getId() : null); + return (projectSnapshot != null ? projectSnapshot.getId() : null); } public Date getTargetDate() { @@ -87,6 +89,18 @@ public class PastSnapshot { @Override public String toString() { + if (StringUtils.equals(mode, PastSnapshotFinderByVersion.MODE)) { + return String.format("Compare to version " + modeParameter + "(" + targetDate + ")"); + } + if (StringUtils.equals(mode, PastSnapshotFinderByDays.MODE)) { + return String.format("Compare over " + modeParameter + " days (" + targetDate + ")"); + } + if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS)) { + return String.format("Compare to previous analysis " + " (" + targetDate + ")"); + } + if (StringUtils.equals(mode, PastSnapshotFinderByDate.MODE)) { + return String.format("Compare to date " + targetDate); + } return ReflectionToStringBuilder.toString(this); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java index 00f112a1b56..85b7c29e80d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java @@ -52,7 +52,7 @@ public class PastSnapshotFinder implements BatchExtension { String propertyValue = getPropertyValue(conf, index); PastSnapshot pastSnapshot = find(projectSnapshot, index, propertyValue); if (pastSnapshot==null && StringUtils.isNotBlank(propertyValue)) { - Logs.INFO.warn("The property " + CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index + " has an unvalid value: " + propertyValue); + Logs.INFO.debug("The property " + CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index + " has an unvalid value: " + propertyValue); } return pastSnapshot; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java index eb1977270e7..0274fb22637 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java @@ -44,10 +44,10 @@ public class TimeMachineConfiguration implements BatchExtension { private void initPastSnapshots(PastSnapshotFinder pastSnapshotFinder, Snapshot projectSnapshot) { projectPastSnapshots = Lists.newLinkedList(); for (int index = 1; index <= NUMBER_OF_VARIATION_SNAPSHOTS; index++) { - PastSnapshot variationSnapshot = pastSnapshotFinder.find(projectSnapshot, configuration, index); - if (variationSnapshot != null) { - Logs.INFO.info("Comparison date: " + variationSnapshot.getDate()); - projectPastSnapshots.add(variationSnapshot); + PastSnapshot pastSnapshot = pastSnapshotFinder.find(projectSnapshot, configuration, index); + if (pastSnapshot != null) { + Logs.INFO.info(pastSnapshot.toString()); + projectPastSnapshots.add(pastSnapshot); } } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java new file mode 100644 index 00000000000..4f0fbde6573 --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java @@ -0,0 +1,56 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2009 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.batch.components; + +import org.junit.Test; +import org.sonar.api.CoreProperties; +import org.sonar.api.database.model.Snapshot; + +import java.util.Date; + +import static org.hamcrest.Matchers.startsWith; +import static org.junit.Assert.assertThat; + +public class PastSnapshotTest { + + @Test + public void testToStringForVersion() { + PastSnapshot pastSnapshot = new PastSnapshot(PastSnapshotFinderByVersion.MODE, new Snapshot()).setModeParameter("2.3"); + assertThat(pastSnapshot.toString(), startsWith("Compare to version 2.3")); + } + + @Test + public void testToStringForNumberOfDays() { + PastSnapshot pastSnapshot = new PastSnapshot(PastSnapshotFinderByDays.MODE, new Snapshot()).setModeParameter("30"); + assertThat(pastSnapshot.toString(), startsWith("Compare over 30 days")); + } + + @Test + public void testToStringForDate() { + PastSnapshot pastSnapshot = new PastSnapshot(PastSnapshotFinderByDate.MODE, new Snapshot()).setTargetDate(new Date()); + assertThat(pastSnapshot.toString(), startsWith("Compare to date ")); + } + + @Test + public void testToStringForPreviousAnalysis() { + PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Snapshot()).setTargetDate(new Date()); + assertThat(pastSnapshot.toString(), startsWith("Compare to previous analysis")); + } +}