From: Simon Brandhof Date: Wed, 10 Jun 2015 07:51:24 +0000 (+0200) Subject: Temporarily remove custom measures from batch X-Git-Tag: 5.2-RC1~1557 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fb72da37f25c49ca70518082ed70a8a1af4866b8;p=sonarqube.git Temporarily remove custom measures from batch They are being moved to Compute Engine. --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java index 1773cd1e7a6..34235ba135b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java @@ -35,7 +35,6 @@ import org.sonar.batch.compute.ItBranchCoverageDecorator; import org.sonar.batch.compute.ItCoverageDecorator; import org.sonar.batch.compute.ItLineCoverageDecorator; import org.sonar.batch.compute.LineCoverageDecorator; -import org.sonar.batch.compute.ManualMeasureDecorator; import org.sonar.batch.compute.NewCoverageAggregator; import org.sonar.batch.compute.NewCoverageFileAnalyzer; import org.sonar.batch.compute.NewItCoverageFileAnalyzer; @@ -132,7 +131,6 @@ public class BatchComponents { CommentDensityDecorator.class, DirectoriesDecorator.class, FilesDecorator.class, - ManualMeasureDecorator.class, VariationDecorator.class, TimeMachineConfigurationPersister.class, NewCoverageFileAnalyzer.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/compute/ManualMeasureDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/compute/ManualMeasureDecorator.java deleted file mode 100644 index 94346b30b8f..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/compute/ManualMeasureDecorator.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.batch.compute; - -import java.util.List; -import org.sonar.api.batch.Decorator; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.Phase; -import org.sonar.api.batch.RequiresDB; -import org.sonar.api.database.DatabaseSession; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.Metric; -import org.sonar.api.measures.MetricFinder; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; -import org.sonar.jpa.entity.ManualMeasure; - -import static com.google.common.base.Preconditions.checkState; - -@Phase(name = Phase.Name.PRE) -@RequiresDB -public class ManualMeasureDecorator implements Decorator { - - private DatabaseSession session; - private MetricFinder metricFinder; - - public ManualMeasureDecorator(DatabaseSession session, MetricFinder metricFinder) { - this.session = session; - this.metricFinder = metricFinder; - } - - @Override - public boolean shouldExecuteOnProject(Project project) { - return true; - } - - @Override - public void decorate(Resource resource, DecoratorContext context) { - if (resource.getId() != null) { - List manualMeasures = session.getResults(ManualMeasure.class, "resourceId", resource.getId()); - for (ManualMeasure manualMeasure : manualMeasures) { - context.saveMeasure(copy(manualMeasure)); - } - } - } - - private Measure copy(ManualMeasure manualMeasure) { - Metric metric = metricFinder.findById(manualMeasure.getMetricId()); - checkState(metric != null, "Unable to find manual metric with id: " + manualMeasure.getMetricId()); - - Measure measure = new Measure(metric); - measure.setValue(manualMeasure.getValue(), 5); - measure.setData(manualMeasure.getTextValue()); - measure.setDescription(manualMeasure.getDescription()); - return measure; - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/compute/ManualMeasureDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/compute/ManualMeasureDecoratorTest.java deleted file mode 100644 index bd86438ad05..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/compute/ManualMeasureDecoratorTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.batch.compute; - -import org.junit.Test; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.File; -import org.sonar.api.test.IsMeasure; -import org.sonar.core.metric.DefaultMetricFinder; -import org.sonar.jpa.test.AbstractDbUnitTestCase; - -import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -public class ManualMeasureDecoratorTest extends AbstractDbUnitTestCase { - - private Metric reviewNote = new Metric.Builder("review_note", "Note", Metric.ValueType.FLOAT).create().setId(2); - - @Test - public void testCopyManualMeasures() throws Exception { - setupData("testCopyManualMeasures"); - - File javaFile = File.create("Foo.java"); - javaFile.setId(40); - - ManualMeasureDecorator decorator = new ManualMeasureDecorator(getSession(), new DefaultMetricFinder(getSessionFactory())); - DecoratorContext context = mock(DecoratorContext.class); - decorator.decorate(javaFile, context); - - verify(context).saveMeasure(argThat(new IsMeasure(reviewNote, 6.0, "six"))); - } - -} diff --git a/sonar-batch/src/test/resources/org/sonar/batch/compute/ManualMeasureDecoratorTest/testCopyManualMeasures.xml b/sonar-batch/src/test/resources/org/sonar/batch/compute/ManualMeasureDecoratorTest/testCopyManualMeasures.xml deleted file mode 100644 index 0307f16e6e3..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/compute/ManualMeasureDecoratorTest/testCopyManualMeasures.xml +++ /dev/null @@ -1,11 +0,0 @@ - - \ No newline at end of file