2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2009 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * Sonar is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * Sonar is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.plugins.core.timemachine;
22 import com.google.common.collect.Lists;
23 import org.apache.commons.configuration.Configuration;
24 import org.sonar.api.BatchExtension;
25 import org.sonar.api.CoreProperties;
26 import org.sonar.api.utils.Logs;
28 import java.util.Collections;
29 import java.util.List;
31 public class TimeMachineConfiguration implements BatchExtension {
33 private static final int NUMBER_OF_VARIATION_SNAPSHOTS = 5;
35 private final Configuration configuration;
36 private List<PastSnapshot> projectPastSnapshots;
38 public TimeMachineConfiguration(Configuration configuration, PastSnapshotFinder variationSnapshotFinder) {
39 this.configuration = configuration;
40 initVariationSnapshots(variationSnapshotFinder);
43 private void initVariationSnapshots(PastSnapshotFinder variationSnapshotFinder) {
44 projectPastSnapshots = Lists.newLinkedList();
45 for (int index = 1; index <= NUMBER_OF_VARIATION_SNAPSHOTS; index++) {
46 PastSnapshot variationSnapshot = variationSnapshotFinder.find(configuration, index);
47 if (variationSnapshot != null) {
48 Logs.INFO.info("Comparison date: " + variationSnapshot.getDate());
49 projectPastSnapshots.add(variationSnapshot);
58 TimeMachineConfiguration(Configuration configuration) {
59 this.configuration = configuration;
60 this.projectPastSnapshots = Collections.emptyList();
64 public boolean skipTendencies() {
65 return configuration.getBoolean(CoreProperties.SKIP_TENDENCIES_PROPERTY, CoreProperties.SKIP_TENDENCIES_DEFAULT_VALUE);
68 public int getTendencyPeriodInDays() {
69 return configuration.getInt(CoreProperties.CORE_TENDENCY_DEPTH_PROPERTY, CoreProperties.CORE_TENDENCY_DEPTH_DEFAULT_VALUE);
72 public List<PastSnapshot> getProjectPastSnapshots() {
73 return projectPastSnapshots;