Browse Source

fix various quality flaws

tags/5.2-RC1
Sébastien Lesaint 9 years ago
parent
commit
34f120e872

+ 1
- 1
server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureRepositoryImpl.java View File

@@ -146,7 +146,7 @@ public class MeasureRepositoryImpl implements MeasureRepository {
addLocal(component, metric, measure, OverridePolicy.OVERRIDE);
}

private void checkValueTypeConsistency(Metric metric, Measure measure) {
private static void checkValueTypeConsistency(Metric metric, Measure measure) {
checkArgument(
measure.getValueType() == Measure.ValueType.NO_VALUE || measure.getValueType() == metric.getType().getValueType(),
format(

+ 1
- 1
server/sonar-server/src/main/java/org/sonar/server/computation/measure/qualitygatedetails/QualityGateDetailsData.java View File

@@ -52,7 +52,7 @@ public class QualityGateDetailsData {
return details.toString();
}

private JsonObject toJson(EvaluatedCondition evaluatedCondition) {
private static JsonObject toJson(EvaluatedCondition evaluatedCondition) {
Condition condition = evaluatedCondition.getCondition();

JsonObject result = new JsonObject();

+ 2
- 1
server/sonar-server/src/main/java/org/sonar/server/computation/qualitygate/EvaluationResultTextConverterImpl.java View File

@@ -34,6 +34,7 @@ import org.sonar.server.computation.period.Period;
import org.sonar.server.computation.period.PeriodsHolder;

import static java.util.Objects.requireNonNull;
import static org.sonar.server.computation.measure.Measure.Level.ERROR;

public final class EvaluationResultTextConverterImpl implements EvaluationResultTextConverter {
private static final String VARIATION_METRIC_PREFIX = "new_";
@@ -91,7 +92,7 @@ public final class EvaluationResultTextConverterImpl implements EvaluationResult
}

private String alertValue(Condition condition, Measure.Level level) {
String value = (level == Measure.Level.ERROR ? condition.getErrorThreshold() : condition.getWarningThreshold());
String value = level == ERROR ? condition.getErrorThreshold() : condition.getWarningThreshold();
if (condition.getMetric().getType() == Metric.MetricType.WORK_DUR) {
return formatDuration(value);
}

+ 1
- 2
server/sonar-server/src/main/java/org/sonar/server/computation/step/QualityGateLoadingStep.java View File

@@ -84,8 +84,7 @@ public class QualityGateLoadingStep implements ComputationStep {
Optional<QualityGate> qualityGate = qualityGateService.findById(qualityGateId);
if (qualityGate.isPresent()) {
qualityGateHolder.setQualityGate(qualityGate.get());
}
else {
} else {
qualityGateHolder.setNoQualityGate();
}
} catch (NumberFormatException e) {

+ 6
- 5
server/sonar-server/src/main/java/org/sonar/server/platform/Platform.java View File

@@ -19,13 +19,12 @@
*/
package org.sonar.server.platform;

import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.List;
import java.util.Properties;

import javax.annotation.CheckForNull;
import javax.servlet.ServletContext;

import org.sonar.api.platform.Server;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
@@ -40,8 +39,6 @@ import org.sonar.server.platform.platformlevel.PlatformLevel4;
import org.sonar.server.platform.platformlevel.PlatformLevelSafeMode;
import org.sonar.server.platform.platformlevel.PlatformLevelStartup;

import com.google.common.collect.Lists;

/**
* @since 2.2
*/
@@ -53,7 +50,11 @@ public class Platform {

private Properties properties;
private ServletContext servletContext;
private PlatformLevel level1, level2, levelSafeMode, level3, level4;
private PlatformLevel level1;
private PlatformLevel level2;
private PlatformLevel levelSafeMode;
private PlatformLevel level3;
private PlatformLevel level4;
private PlatformLevel currentLevel;
private boolean dbConnected = false;
private boolean started = false;

+ 2
- 21
server/sonar-server/src/test/java/org/sonar/server/computation/container/ComputeEngineContainerImplTest.java View File

@@ -26,7 +26,6 @@ import com.google.common.collect.Sets;
import java.util.Set;
import org.junit.Test;
import org.picocontainer.ComponentAdapter;
import org.reflections.Reflections;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.server.computation.ReportQueue;
import org.sonar.server.computation.step.ComputationStep;
@@ -59,7 +58,7 @@ public class ComputeEngineContainerImplTest {
public void all_steps_from_package_step_are_present_in_container() {
ComputeEngineContainerImpl ceContainer = new ComputeEngineContainerImpl(new ComponentContainer(), mock(ReportQueue.Item.class));

Set<String> stepsCanonicalNames = retrieveStepPackageStepsCanonicalNames();
Set<String> stepsCanonicalNames = StepsExplorer.retrieveStepPackageStepsCanonicalNames();

Set<String> typesInContainer = Sets.newHashSet(
Iterables.transform(
@@ -68,7 +67,7 @@ public class ComputeEngineContainerImplTest {
ceContainer.getPicoContainer().getComponentAdapters(),
ComponentAdapterToImplementationClass.INSTANCE),
IsComputationStep.INSTANCE),
ClassToCanonicalName.INSTANCE));
StepsExplorer.ClassToCanonicalName.INSTANCE));

assertThat(typesInContainer).isEqualTo(stepsCanonicalNames);
}
@@ -80,24 +79,6 @@ public class ComputeEngineContainerImplTest {
assertThat(new ComputeEngineContainerImpl(new ComponentContainer(), item).getItem()).isSameAs(item);
}

/**
* Compute set of canonical names of classes implementing ComputationStep in package step using reflection.
*/
private Set<String> retrieveStepPackageStepsCanonicalNames() {
Reflections reflections = new Reflections("org.sonar.server.computation.step");

return Sets.newHashSet(Iterables.transform(reflections.getSubTypesOf(ComputationStep.class), ClassToCanonicalName.INSTANCE));
}

private enum ClassToCanonicalName implements Function<Class<?>, String> {
INSTANCE;

@Override
public String apply(Class<?> input) {
return input.getCanonicalName();
}
}

private enum ComponentAdapterToImplementationClass implements Function<ComponentAdapter<?>, Class<?>> {
INSTANCE;


+ 47
- 0
server/sonar-server/src/test/java/org/sonar/server/computation/container/StepsExplorer.java View File

@@ -0,0 +1,47 @@
/*
* 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.container;

import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import java.util.Set;
import org.reflections.Reflections;
import org.sonar.server.computation.step.ComputationStep;

public class StepsExplorer {
/**
* Compute set of canonical names of classes implementing ComputationStep in package step using reflection.
*/
static Set<String> retrieveStepPackageStepsCanonicalNames() {
Reflections reflections = new Reflections("org.sonar.server.computation.step");

return Sets.newHashSet(Iterables.transform(reflections.getSubTypesOf(ComputationStep.class), ClassToCanonicalName.INSTANCE));
}

enum ClassToCanonicalName implements Function<Class<?>, String> {
INSTANCE;

@Override
public String apply(Class<?> input) {
return input.getCanonicalName();
}
}
}

+ 5
- 0
server/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java View File

@@ -38,6 +38,7 @@ import org.sonar.api.database.DatabaseProperties;
import org.sonar.api.resources.Language;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.process.ProcessProperties;
import org.sonar.server.es.EsServerHolder;
import org.sonar.server.platform.BackendCleanup;
@@ -234,6 +235,10 @@ public class ServerTester extends ExternalResource {
return platform.getContainer().getComponentByType(component);
}

public ComponentContainer getContainer() {
return platform.getContainer();
}

public WsTester wsTester() {
return get(WsTester.class);
}

Loading…
Cancel
Save