extensions.add(ReferenceAnalysis.class);
// time machine
- extensions.add(TimeMachineConfiguration.class);
extensions.add(TendencyDecorator.class);
extensions.add(VariationDecorator.class);
extensions.add(ViolationTrackingDecorator.class);
import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.core.NotDryRun;
import java.util.Arrays;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.rules.Violation;
import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.core.NotDryRun;
import java.util.*;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
+import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.core.NotDryRun;
import java.util.List;
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.plugins.core.timemachine;
-
-import com.google.common.collect.Lists;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.BatchExtension;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.utils.Logs;
-import org.sonar.batch.components.PastSnapshot;
-import org.sonar.batch.components.PastSnapshotFinder;
-
-import javax.persistence.Query;
-import java.util.Collections;
-import java.util.List;
-
-public class TimeMachineConfiguration implements BatchExtension {
-
- private static final int NUMBER_OF_VARIATION_SNAPSHOTS = 5;
-
- private Project project;
- private final Configuration configuration;
- private List<PastSnapshot> projectPastSnapshots;
- private DatabaseSession session;
-
- public TimeMachineConfiguration(DatabaseSession session, Project project, Configuration configuration, PastSnapshotFinder pastSnapshotFinder) {
- this.session = session;
- this.project = project;
- this.configuration = configuration;
- initPastSnapshots(pastSnapshotFinder);
- }
-
- private void initPastSnapshots(PastSnapshotFinder pastSnapshotFinder) {
- Snapshot projectSnapshot = buildProjectSnapshot();
-
- projectPastSnapshots = Lists.newLinkedList();
- if (projectSnapshot != null) {
- for (int index = 1; index <= NUMBER_OF_VARIATION_SNAPSHOTS; index++) {
- PastSnapshot pastSnapshot = pastSnapshotFinder.find(projectSnapshot, configuration, index);
- if (pastSnapshot != null) {
- log(pastSnapshot);
- projectPastSnapshots.add(pastSnapshot);
- }
- }
- }
- }
-
- private Snapshot buildProjectSnapshot() {
- Query query = session.createNativeQuery("select p.id from projects p where p.kee=:resourceKey and p.qualifier<>:lib and p.enabled=:enabled");
- query.setParameter("resourceKey", project.getKey());
- query.setParameter("lib", Qualifiers.LIBRARY);
- query.setParameter("enabled", Boolean.TRUE);
-
- Snapshot snapshot = null;
- Number projectId = session.getSingleResult(query, null);
- if (projectId != null) {
- snapshot = new Snapshot();
- snapshot.setResourceId(projectId.intValue());
- snapshot.setCreatedAt(project.getAnalysisDate());
- }
- return snapshot;
- }
-
- private void log(PastSnapshot pastSnapshot) {
- String qualifier = pastSnapshot.getQualifier();
- // hack to avoid too many logs when the views plugin is installed
- if (StringUtils.equals(Qualifiers.VIEW, qualifier) || StringUtils.equals(Qualifiers.SUBVIEW, qualifier)) {
- LoggerFactory.getLogger(getClass()).debug(pastSnapshot.toString());
- } else {
- Logs.INFO.info(pastSnapshot.toString());
- }
- }
-
- public boolean skipTendencies() {
- return configuration.getBoolean(CoreProperties.SKIP_TENDENCIES_PROPERTY, CoreProperties.SKIP_TENDENCIES_DEFAULT_VALUE);
- }
-
- public int getTendencyPeriodInDays() {
- return configuration.getInt(CoreProperties.CORE_TENDENCY_DEPTH_PROPERTY, CoreProperties.CORE_TENDENCY_DEPTH_DEFAULT_VALUE);
- }
-
- public List<PastSnapshot> getProjectPastSnapshots() {
- return projectPastSnapshots;
- }
-
- public boolean isFileVariationEnabled() {
- return configuration.getBoolean("sonar.enableFileVariation", Boolean.FALSE);
- }
-}
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.core.NotDryRun;
import java.util.List;
import org.sonar.api.resources.Scopes;
import org.sonar.batch.components.PastMeasuresLoader;
import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.TimeMachineConfiguration;
import java.util.Collection;
import java.util.List;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.rules.Violation;
import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.TimeMachineConfiguration;
import java.util.Arrays;
import java.util.Date;
*/
package org.sonar.plugins.core.timemachine;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.TimeMachine;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.resources.JavaPackage;
import org.sonar.api.resources.Project;
+import org.sonar.batch.components.TimeMachineConfiguration;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.utils.DateUtils;
import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.text.ParseException;
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.plugins.core.timemachine;
-
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Project;
-import org.sonar.batch.components.PastSnapshotFinder;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
-
-public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase {
-
- @Test
- public void shouldSkipTendencies() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty(CoreProperties.SKIP_TENDENCIES_PROPERTY, true);
- assertThat(new TimeMachineConfiguration(getSession(), new Project("my:project"), conf, mock(PastSnapshotFinder.class)).skipTendencies(), is(true));
- }
-
- @Test
- public void shouldNotSkipTendenciesByDefault() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- assertThat(new TimeMachineConfiguration(getSession(), new Project("my:project"), conf, mock(PastSnapshotFinder.class)).skipTendencies(), is(false));
- }
-
- @Test
- public void shouldInitPastSnapshots() {
- setupData("shared");
- PropertiesConfiguration conf = new PropertiesConfiguration();
- PastSnapshotFinder pastSnapshotFinder = mock(PastSnapshotFinder.class);
-
- new TimeMachineConfiguration(getSession(), new Project("my:project"), conf, pastSnapshotFinder);
-
- verify(pastSnapshotFinder).find(argThat(new BaseMatcher<Snapshot>() {
- public boolean matches(Object o) {
- return ((Snapshot) o).getResourceId() == 2 /* see database in shared.xml */;
- }
-
- public void describeTo(Description description) {
- }
- }), eq(conf), eq(1));
- }
-
- @Test
- public void shouldNotInitPastSnapshotsIfFirstAnalysis() {
- setupData("shared");
- PropertiesConfiguration conf = new PropertiesConfiguration();
- PastSnapshotFinder pastSnapshotFinder = mock(PastSnapshotFinder.class);
-
- new TimeMachineConfiguration(getSession(), new Project("new:project"), conf, pastSnapshotFinder);
-
- verifyZeroInteractions(pastSnapshotFinder);
- }
-}
import org.sonar.api.resources.*;
import org.sonar.batch.components.PastMeasuresLoader;
import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.util.Arrays;
+++ /dev/null
-<dataset>
-
- <projects long_name="[null]" id="1" scope="PRJ" kee="my:project" qualifier="LIB" name="my project as lib"
- root_id="[null]" description="[null]" enabled="true" profile_id="[null]" language="java" copy_resource_id="[null]"/>
-
- <projects long_name="[null]" id="2" scope="PRJ" kee="my:project" qualifier="TRK" name="my project"
- root_id="[null]" description="[null]" enabled="true" profile_id="[null]" language="java" copy_resource_id="[null]"/>
-
- <projects long_name="[null]" id="3" scope="DIR" kee="my:project:path/to/dir" qualifier="TRK" name="my dir"
- root_id="2" description="[null]" enabled="true" profile_id="[null]" language="java" copy_resource_id="[null]"/>
-
-</dataset>
import org.sonar.api.rules.DefaultRulesManager;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.*;
+import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.index.DefaultIndex;
import org.sonar.batch.index.DefaultResourcePersister;
// the Snapshot component will be removed when asynchronous measures are improved (required for AsynchronousMeasureSensor)
addComponent(getComponent(DefaultResourcePersister.class).getSnapshot(project));
}
+ addComponent(TimeMachineConfiguration.class);
addComponent(org.sonar.api.database.daos.MeasuresDao.class);
addComponent(ProfilesDao.class);
addComponent(AsyncMeasuresDao.class);
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * 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 com.google.common.collect.Lists;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.database.DatabaseSession;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.utils.Logs;
+import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.PastSnapshotFinder;
+
+import javax.persistence.Query;
+import java.util.Collections;
+import java.util.List;
+
+public class TimeMachineConfiguration implements BatchExtension {
+
+ private static final int NUMBER_OF_VARIATION_SNAPSHOTS = 5;
+
+ private Project project;
+ private final Configuration configuration;
+ private List<PastSnapshot> projectPastSnapshots;
+ private DatabaseSession session;
+
+ public TimeMachineConfiguration(DatabaseSession session, Project project, Configuration configuration, PastSnapshotFinder pastSnapshotFinder) {
+ this.session = session;
+ this.project = project;
+ this.configuration = configuration;
+ initPastSnapshots(pastSnapshotFinder);
+ }
+
+ private void initPastSnapshots(PastSnapshotFinder pastSnapshotFinder) {
+ Snapshot projectSnapshot = buildProjectSnapshot();
+
+ projectPastSnapshots = Lists.newLinkedList();
+ if (projectSnapshot != null) {
+ for (int index = 1; index <= NUMBER_OF_VARIATION_SNAPSHOTS; index++) {
+ PastSnapshot pastSnapshot = pastSnapshotFinder.find(projectSnapshot, configuration, index);
+ if (pastSnapshot != null) {
+ log(pastSnapshot);
+ projectPastSnapshots.add(pastSnapshot);
+ }
+ }
+ }
+ }
+
+ private Snapshot buildProjectSnapshot() {
+ Query query = session.createNativeQuery("select p.id from projects p where p.kee=:resourceKey and p.qualifier<>:lib and p.enabled=:enabled");
+ query.setParameter("resourceKey", project.getKey());
+ query.setParameter("lib", Qualifiers.LIBRARY);
+ query.setParameter("enabled", Boolean.TRUE);
+
+ Snapshot snapshot = null;
+ Number projectId = session.getSingleResult(query, null);
+ if (projectId != null) {
+ snapshot = new Snapshot();
+ snapshot.setResourceId(projectId.intValue());
+ snapshot.setCreatedAt(project.getAnalysisDate());
+ }
+ return snapshot;
+ }
+
+ private void log(PastSnapshot pastSnapshot) {
+ String qualifier = pastSnapshot.getQualifier();
+ // hack to avoid too many logs when the views plugin is installed
+ if (StringUtils.equals(Qualifiers.VIEW, qualifier) || StringUtils.equals(Qualifiers.SUBVIEW, qualifier)) {
+ LoggerFactory.getLogger(getClass()).debug(pastSnapshot.toString());
+ } else {
+ Logs.INFO.info(pastSnapshot.toString());
+ }
+ }
+
+ public boolean skipTendencies() {
+ return configuration.getBoolean(CoreProperties.SKIP_TENDENCIES_PROPERTY, CoreProperties.SKIP_TENDENCIES_DEFAULT_VALUE);
+ }
+
+ public int getTendencyPeriodInDays() {
+ return configuration.getInt(CoreProperties.CORE_TENDENCY_DEPTH_PROPERTY, CoreProperties.CORE_TENDENCY_DEPTH_DEFAULT_VALUE);
+ }
+
+ public List<PastSnapshot> getProjectPastSnapshots() {
+ return projectPastSnapshots;
+ }
+
+ public boolean isFileVariationEnabled() {
+ return configuration.getBoolean("sonar.enableFileVariation", Boolean.FALSE);
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * 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.apache.commons.configuration.PropertiesConfiguration;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.junit.Test;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.Project;
+import org.sonar.batch.components.PastSnapshotFinder;
+import org.sonar.batch.components.TimeMachineConfiguration;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.*;
+
+public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase {
+
+ @Test
+ public void shouldSkipTendencies() {
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ conf.setProperty(CoreProperties.SKIP_TENDENCIES_PROPERTY, true);
+ assertThat(new TimeMachineConfiguration(getSession(), new Project("my:project"), conf, mock(PastSnapshotFinder.class)).skipTendencies(), is(true));
+ }
+
+ @Test
+ public void shouldNotSkipTendenciesByDefault() {
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ assertThat(new TimeMachineConfiguration(getSession(), new Project("my:project"), conf, mock(PastSnapshotFinder.class)).skipTendencies(), is(false));
+ }
+
+ @Test
+ public void shouldInitPastSnapshots() {
+ setupData("shared");
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ PastSnapshotFinder pastSnapshotFinder = mock(PastSnapshotFinder.class);
+
+ new TimeMachineConfiguration(getSession(), new Project("my:project"), conf, pastSnapshotFinder);
+
+ verify(pastSnapshotFinder).find(argThat(new BaseMatcher<Snapshot>() {
+ public boolean matches(Object o) {
+ return ((Snapshot) o).getResourceId() == 2 /* see database in shared.xml */;
+ }
+
+ public void describeTo(Description description) {
+ }
+ }), eq(conf), eq(1));
+ }
+
+ @Test
+ public void shouldNotInitPastSnapshotsIfFirstAnalysis() {
+ setupData("shared");
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ PastSnapshotFinder pastSnapshotFinder = mock(PastSnapshotFinder.class);
+
+ new TimeMachineConfiguration(getSession(), new Project("new:project"), conf, pastSnapshotFinder);
+
+ verifyZeroInteractions(pastSnapshotFinder);
+ }
+}
--- /dev/null
+<dataset>
+
+ <projects long_name="[null]" id="1" scope="PRJ" kee="my:project" qualifier="LIB" name="my project as lib"
+ root_id="[null]" description="[null]" enabled="true" profile_id="[null]" language="java" copy_resource_id="[null]"/>
+
+ <projects long_name="[null]" id="2" scope="PRJ" kee="my:project" qualifier="TRK" name="my project"
+ root_id="[null]" description="[null]" enabled="true" profile_id="[null]" language="java" copy_resource_id="[null]"/>
+
+ <projects long_name="[null]" id="3" scope="DIR" kee="my:project:path/to/dir" qualifier="TRK" name="my dir"
+ root_id="2" description="[null]" enabled="true" profile_id="[null]" language="java" copy_resource_id="[null]"/>
+
+</dataset>