Browse Source

Add @deprecated and all formulas api and remove some decorator usage in test

tags/5.2-RC1
Julien Lancelot 9 years ago
parent
commit
3d5c0f2170

+ 0
- 60
sonar-batch/src/test/java/org/sonar/batch/profiling/PhasesSumUpTimeProfilerTest.java View File

@@ -30,7 +30,6 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.Decorator;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.Initializer;
import org.sonar.api.batch.PostJob;
import org.sonar.api.batch.Sensor;
@@ -48,7 +47,6 @@ import org.sonar.api.batch.events.SensorExecutionHandler.SensorExecutionEvent;
import org.sonar.api.batch.events.SensorsPhaseHandler;
import org.sonar.api.batch.events.SensorsPhaseHandler.SensorsPhaseEvent;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.utils.System2;
import org.sonar.batch.bootstrap.BootstrapProperties;
import org.sonar.batch.events.BatchStepEvent;
@@ -83,10 +81,8 @@ public class PhasesSumUpTimeProfilerTest {

assertThat(profiler.currentModuleProfiling.getProfilingPerPhase(Phase.INIT).getProfilingPerItem(new FakeInitializer()).totalTime()).isEqualTo(7L);
assertThat(profiler.currentModuleProfiling.getProfilingPerPhase(Phase.SENSOR).getProfilingPerItem(new FakeSensor()).totalTime()).isEqualTo(10L);
assertThat(profiler.currentModuleProfiling.getProfilingPerPhase(Phase.DECORATOR).getProfilingPerItem(new FakeDecorator1()).totalTime()).isEqualTo(20L);
assertThat(profiler.currentModuleProfiling.getProfilingPerPhase(Phase.POSTJOB).getProfilingPerItem(new FakePostJob()).totalTime()).isEqualTo(30L);
assertThat(profiler.currentModuleProfiling.getProfilingPerBatchStep("Free memory").totalTime()).isEqualTo(9L);

}

@Test
@@ -102,14 +98,10 @@ public class PhasesSumUpTimeProfilerTest {

assertThat(profiler.currentModuleProfiling.getProfilingPerPhase(Phase.INIT).getProfilingPerItem(new FakeInitializer()).totalTime()).isEqualTo(7L);
assertThat(profiler.currentModuleProfiling.getProfilingPerPhase(Phase.SENSOR).getProfilingPerItem(new FakeSensor()).totalTime()).isEqualTo(10L);
assertThat(profiler.currentModuleProfiling.getProfilingPerPhase(Phase.DECORATOR).getProfilingPerItem(new FakeDecorator1()).totalTime()).isEqualTo(20L);
assertThat(profiler.currentModuleProfiling.getProfilingPerPhase(Phase.DECORATOR).getProfilingPerItem(new FakeDecorator2()).totalTime()).isEqualTo(10L);
assertThat(profiler.currentModuleProfiling.getProfilingPerPhase(Phase.POSTJOB).getProfilingPerItem(new FakePostJob()).totalTime()).isEqualTo(30L);

assertThat(profiler.totalProfiling.getProfilingPerPhase(Phase.INIT).getProfilingPerItem(new FakeInitializer()).totalTime()).isEqualTo(21L);
assertThat(profiler.totalProfiling.getProfilingPerPhase(Phase.SENSOR).getProfilingPerItem(new FakeSensor()).totalTime()).isEqualTo(30L);
assertThat(profiler.totalProfiling.getProfilingPerPhase(Phase.DECORATOR).getProfilingPerItem(new FakeDecorator1()).totalTime()).isEqualTo(60L);
assertThat(profiler.totalProfiling.getProfilingPerPhase(Phase.DECORATOR).getProfilingPerItem(new FakeDecorator2()).totalTime()).isEqualTo(30L);
assertThat(profiler.totalProfiling.getProfilingPerPhase(Phase.POSTJOB).getProfilingPerItem(new FakePostJob()).totalTime()).isEqualTo(90L);
}

@@ -156,42 +148,12 @@ public class PhasesSumUpTimeProfilerTest {
profiler.onProjectAnalysis(projectEvent(module, true));
initializerPhase(profiler);
sensorPhase(profiler);
decoratorPhase(profiler);
postJobPhase(profiler);
batchStep(profiler);
// End of moduleA
profiler.onProjectAnalysis(projectEvent(module, false));
}

private void decoratorPhase(PhasesSumUpTimeProfiler profiler) {
Decorator decorator1 = new FakeDecorator1();
Decorator decorator2 = new FakeDecorator2();
// Start of decorator phase
profiler.onDecoratorsPhase(decoratorsEvent(true));
// Start of decorator 1
profiler.onDecoratorExecution(decoratorEvent(decorator1, true));
clock.sleep(10);
// End of decorator 1
profiler.onDecoratorExecution(decoratorEvent(decorator1, false));
// Start of decorator 2
profiler.onDecoratorExecution(decoratorEvent(decorator2, true));
clock.sleep(5);
// End of decorator 2
profiler.onDecoratorExecution(decoratorEvent(decorator2, false));
// Start of decorator 1
profiler.onDecoratorExecution(decoratorEvent(decorator1, true));
clock.sleep(10);
// End of decorator 1
profiler.onDecoratorExecution(decoratorEvent(decorator1, false));
// Start of decorator 2
profiler.onDecoratorExecution(decoratorEvent(decorator2, true));
clock.sleep(5);
// End of decorator 2
profiler.onDecoratorExecution(decoratorEvent(decorator2, false));
// End of decorator phase
profiler.onDecoratorsPhase(decoratorsEvent(false));
}

private void batchStep(PhasesSumUpTimeProfiler profiler) {
// Start of batch step
profiler.onBatchStep(new BatchStepEvent("Free memory", true));
@@ -440,28 +402,6 @@ public class PhasesSumUpTimeProfilerTest {
}
}

public class FakeDecorator1 implements Decorator {
@Override
public void decorate(Resource resource, DecoratorContext context) {
}

@Override
public boolean shouldExecuteOnProject(Project project) {
return true;
}
}

public class FakeDecorator2 implements Decorator {
@Override
public void decorate(Resource resource, DecoratorContext context) {
}

@Override
public boolean shouldExecuteOnProject(Project project) {
return true;
}
}

public class FakePostJob implements PostJob {
@Override
public void executeOn(Project project, SensorContext context) {

+ 3
- 2
sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractSumChildrenDecorator.java View File

@@ -19,19 +19,20 @@
*/
package org.sonar.api.batch;

import java.util.List;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;

import java.util.List;

/**
* Sum measures of child resources.
*
* @since 1.10
* @deprecated since 5.2 there's no more decorator on batch side
*/
@Deprecated
public abstract class AbstractSumChildrenDecorator implements Decorator {



+ 2
- 0
sonar-plugin-api/src/main/java/org/sonar/api/measures/AverageFormula.java View File

@@ -31,7 +31,9 @@ import static com.google.common.collect.Lists.newArrayList;
* For example: to compute the metric "complexity by file", the main metric (A) is "complexity" and the other metric (B) is "file".
*
* @since 3.0
* @deprecated since 5.2 decorators are no more executed on batch side
*/
@Deprecated
public class AverageFormula implements Formula {

private Metric mainMetric;

+ 2
- 0
sonar-plugin-api/src/main/java/org/sonar/api/measures/MeanAggregationFormula.java View File

@@ -25,7 +25,9 @@ import java.util.List;

/**
* @since 2.0
* @deprecated since 5.2 decorators are no more executed on batch side
*/
@Deprecated
public class MeanAggregationFormula implements Formula {

private boolean forceZeroIfMissingData=false;

+ 3
- 2
sonar-plugin-api/src/main/java/org/sonar/api/measures/SumChildDistributionFormula.java View File

@@ -19,17 +19,18 @@
*/
package org.sonar.api.measures;

import org.sonar.api.resources.Scopes;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.sonar.api.resources.Scopes;

/**
* @since 2.0
*
* Used to consolidate a distribution measure throughout the resource tree
* @deprecated since 5.2 decorators are no more executed on batch side
*/
@Deprecated
public class SumChildDistributionFormula implements Formula {

private String minimumScopeToPersist= Scopes.FILE;

+ 2
- 0
sonar-plugin-api/src/main/java/org/sonar/api/measures/SumChildValuesFormula.java View File

@@ -24,7 +24,9 @@ import java.util.List;

/**
* @since 1.11
* @deprecated since 5.2 decorators are no more executed on batch side
*/
@Deprecated
public class SumChildValuesFormula implements Formula {

private boolean saveZeroIfNoChildValues;

+ 2
- 0
sonar-plugin-api/src/main/java/org/sonar/api/measures/WeightedMeanAggregationFormula.java View File

@@ -24,7 +24,9 @@ import java.util.List;

/**
* @since 2.0
* @deprecated since 5.2 decorators are no more executed on batch side
*/
@Deprecated
public class WeightedMeanAggregationFormula implements Formula {

private Metric weightingMetric;

Loading…
Cancel
Save