import org.sonar.api.*;
import org.sonar.api.checks.NoSonarFilter;
import org.sonar.core.timemachine.Periods;
-import org.sonar.plugins.core.batch.IndexProjectPostJob;
import org.sonar.plugins.core.charts.DistributionAreaChart;
import org.sonar.plugins.core.charts.DistributionBarChart;
import org.sonar.plugins.core.colorizers.JavaColorizerFormat;
NoSonarFilter.class,
DirectoriesDecorator.class,
FilesDecorator.class,
- IndexProjectPostJob.class,
ManualMeasureDecorator.class,
FileHashSensor.class,
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.plugins.core.batch;
-
-import org.sonar.core.DryRunIncompatible;
-import org.sonar.api.batch.PostJob;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.resources.Project;
-import org.sonar.core.resource.ResourceIndexerDao;
-
-/**
- * @since 2.13
- */
-@DryRunIncompatible
-public class IndexProjectPostJob implements PostJob {
- private ResourceIndexerDao indexer;
-
- public IndexProjectPostJob(ResourceIndexerDao indexer) {
- this.indexer = indexer;
- }
-
- @Override
- public void executeOn(Project project, SensorContext context) {
- if (project.getId() != null) {
- indexer.indexProject(project.getId());
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-/**
- * Deprecated in 4.5.1. JFreechart charts are replaced by Javascript charts.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.plugins.core.batch;
-
-import javax.annotation.ParametersAreNonnullByDefault;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.plugins.core.batch;
-
-import org.junit.Test;
-import org.sonar.api.resources.Project;
-import org.sonar.core.resource.ResourceIndexerDao;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-
-public class IndexProjectPostJobTest {
- @Test
- public void shouldIndexProject() {
- ResourceIndexerDao indexer = mock(ResourceIndexerDao.class);
- IndexProjectPostJob job = new IndexProjectPostJob(indexer);
- Project project = new Project("foo");
- project.setId(123);
-
- job.executeOn(project, null);
-
- verify(indexer).indexProject(123);
- }
-
- @Test
- public void shouldNotIndexProjectIfMissingId() {
- ResourceIndexerDao indexer = mock(ResourceIndexerDao.class);
- IndexProjectPostJob job = new IndexProjectPostJob(indexer);
-
- job.executeOn(new Project("foo"), null);
-
- verifyZeroInteractions(indexer);
- }
-
-}
try {
report.succeed();
for (ComputationStep step : stepRegistry.steps()) {
- TimeProfiler stepProfiler = new TimeProfiler(LOG).start(step.description());
+ TimeProfiler stepProfiler = new TimeProfiler(LOG).start(step.getDescription());
step.execute(session, report, project);
session.commit();
stepProfiler.stop();
void execute(DbSession session, AnalysisReportDto analysisReportDto, ComponentDto project);
- String description();
+ String getDescription();
}
package org.sonar.server.computation;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
import org.sonar.api.ServerComponent;
+import org.sonar.api.platform.ComponentContainer;
import java.util.List;
public class ComputationStepRegistry implements ServerComponent {
- private final List<ComputationStep> steps;
+ private final ComponentContainer pico;
+
+ public ComputationStepRegistry(ComponentContainer pico) {
+ this.pico = pico;
- public ComputationStepRegistry(
- SynchronizeProjectPermissionsStep synchronizeProjectPermissionsStep,
- IndexProjectIssuesStep indexProjectIssuesStep,
- SwitchSnapshotStep switchSnapshotStep,
- DataCleanerStep dataCleanerStep,
- InvalidatePreviewCacheStep invalidatePreviewCacheStep) {
- steps = ImmutableList.of(synchronizeProjectPermissionsStep, switchSnapshotStep, invalidatePreviewCacheStep, dataCleanerStep, indexProjectIssuesStep);
}
public List<ComputationStep> steps() {
- return steps;
+ List<ComputationStep> steps = Lists.newArrayList();
+ steps.add(pico.getComponentByType(SynchronizeProjectPermissionsStep.class));
+ steps.add(pico.getComponentByType(SwitchSnapshotStep.class));
+ steps.add(pico.getComponentByType(InvalidatePreviewCacheStep.class));
+ steps.add(pico.getComponentByType(DataCleanerStep.class));
+ steps.add(pico.getComponentByType(ProjectDatabaseIndexationStep.class));
+ steps.add(pico.getComponentByType(IndexProjectIssuesStep.class));
+
+ return ImmutableList.copyOf(steps);
}
}
}
@Override
- public String description() {
+ public String getDescription() {
return "Purge database";
}
}
}
@Override
- public String description() {
+ public String getDescription() {
return "Update issues index";
}
}
@Override
- public String description() {
+ public String getDescription() {
return "Invalidate preview cache";
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation;
+
+import org.sonar.core.component.ComponentDto;
+import org.sonar.core.computation.db.AnalysisReportDto;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.resource.ResourceIndexerDao;
+
+public class ProjectDatabaseIndexationStep implements ComputationStep {
+ private final ResourceIndexerDao resourceIndexerDao;
+
+ public ProjectDatabaseIndexationStep(ResourceIndexerDao resourceIndexerDao) {
+ this.resourceIndexerDao = resourceIndexerDao;
+ }
+
+ @Override
+ public void execute(DbSession session, AnalysisReportDto analysisReportDto, ComponentDto project) {
+ resourceIndexerDao.indexProject(project.getId().intValue());
+ }
+
+ @Override
+ public String getDescription() {
+ return "Index project in database";
+ }
+}
}
@Override
- public String description() {
+ public String getDescription() {
return "Switch last snapshot flag";
}
}
@Override
- public String description() {
+ public String getDescription() {
return "Synchronize project permissions";
}
ActivityNormalizer.class,
ActivityIndex.class,
ActivityDao.class
- ));
+ ));
components.addAll(CorePropertyDefinitions.all());
components.addAll(DatabaseMigrations.CLASSES);
components.addAll(DaoUtils.getDaoClasses());
// ws
RestartHandler.class,
SystemWs.class
- );
+ );
}
/**
HttpDownloader.class,
UriReader.class,
ServerIdGenerator.class
- );
+ );
}
void startLevel4Components(ComponentContainer pico) {
IndexProjectIssuesStep.class,
SwitchSnapshotStep.class,
InvalidatePreviewCacheStep.class,
+ ProjectDatabaseIndexationStep.class,
DataCleanerStep.class));
pico.addSingleton(AnalysisReportQueue.class);
pico.addSingleton(AnalysisReportTaskLauncher.class);
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation;
+
+import com.google.common.collect.Lists;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.platform.ComponentContainer;
+import org.sonar.server.tester.ServerTester;
+
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class ComputationStepRegistryMediumTest {
+
+ @ClassRule
+ public static ServerTester tester = new ServerTester();
+
+ private ComputationStepRegistry sut;
+
+ @Before
+ public void before() {
+ ComponentContainer pico = new ComponentContainer();
+
+ pico.addSingleton(mock(SynchronizeProjectPermissionsStep.class));
+ pico.addSingleton(mock(IndexProjectIssuesStep.class));
+ pico.addSingleton(mock(SwitchSnapshotStep.class));
+ pico.addSingleton(mock(DataCleanerStep.class));
+ pico.addSingleton(mock(InvalidatePreviewCacheStep.class));
+ pico.addSingleton(mock(ProjectDatabaseIndexationStep.class));
+
+ sut = new ComputationStepRegistry(pico);
+ }
+
+ @Test
+ public void steps_returned_in_the_right_order() throws Exception {
+ List<Class<? extends ComputationStep>> wishStepsClasses = Lists.newArrayList(
+ SynchronizeProjectPermissionsStep.class,
+ SwitchSnapshotStep.class,
+ InvalidatePreviewCacheStep.class,
+ DataCleanerStep.class,
+ ProjectDatabaseIndexationStep.class,
+ IndexProjectIssuesStep.class
+ );
+ List<ComputationStep> steps = sut.steps();
+
+ assertThat(steps).hasSize(wishStepsClasses.size());
+ for (int i = 0; i < steps.size(); i++) {
+ assertThat(steps.get(i)).isInstanceOf(wishStepsClasses.get(i));
+ }
+ }
+
+ @Test
+ public void steps_have_a_non_empty_description() {
+ ComputationStepRegistry sut = tester.get(ComputationStepRegistry.class);
+
+ List<ComputationStep> steps = sut.steps();
+
+ assertThat(steps).onProperty("description").excludes(null, "");
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class ComputationStepRegistryTest {
-
- private ComputationStepRegistry sut;
- private SynchronizeProjectPermissionsStep synchronizeProjectPermissionsStep;
- private IndexProjectIssuesStep indexProjectIssuesStep;
- private SwitchSnapshotStep switchSnapshotStep;
- private DataCleanerStep dataCleanerStep;
- private InvalidatePreviewCacheStep invalidatePreviewCacheStep;
-
- @Before
- public void before() {
- synchronizeProjectPermissionsStep = mock(SynchronizeProjectPermissionsStep.class);
- indexProjectIssuesStep = mock(IndexProjectIssuesStep.class);
- switchSnapshotStep = mock(SwitchSnapshotStep.class);
- dataCleanerStep = mock(DataCleanerStep.class);
- invalidatePreviewCacheStep = mock(InvalidatePreviewCacheStep.class);
-
- sut = new ComputationStepRegistry(synchronizeProjectPermissionsStep, indexProjectIssuesStep, switchSnapshotStep, dataCleanerStep, invalidatePreviewCacheStep);
- }
-
- @Test
- public void steps_returned_in_the_right_order() throws Exception {
- assertThat(sut.steps()).containsExactly(synchronizeProjectPermissionsStep, switchSnapshotStep, invalidatePreviewCacheStep, dataCleanerStep, indexProjectIssuesStep);
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.core.component.ComponentDto;
+import org.sonar.core.computation.db.AnalysisReportDto;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.resource.ResourceIndexerDao;
+
+import static org.mockito.Mockito.*;
+
+public class ProjectDatabaseIndexationStepTest {
+
+ private ProjectDatabaseIndexationStep sut;
+ private ResourceIndexerDao resourceIndexerDao;
+
+ @Before
+ public void before() {
+ this.resourceIndexerDao = mock(ResourceIndexerDao.class);
+ this.sut = new ProjectDatabaseIndexationStep(resourceIndexerDao);
+ }
+
+ @Test
+ public void call_indexProject_of_dao() {
+ ComponentDto project = mock(ComponentDto.class);
+ when(project.getId()).thenReturn(123L);
+
+ sut.execute(mock(DbSession.class), mock(AnalysisReportDto.class), project);
+
+ verify(resourceIndexerDao).indexProject(123);
+ }
+
+}