aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2018-11-08 13:28:40 -0600
committerSonarTech <sonartech@sonarsource.com>2018-11-13 20:20:57 +0100
commit59be49ed6f4107e6b76cc70229804e1badabad09 (patch)
tree438d3159a955d4ad20e03ab54383c0b0fe250b1b /server
parentbdd538eb0c2b5937c565480ecab58908d095aad2 (diff)
downloadsonarqube-59be49ed6f4107e6b76cc70229804e1badabad09.tar.gz
sonarqube-59be49ed6f4107e6b76cc70229804e1badabad09.zip
Replace guava optional with java.util.Optional
Diffstat (limited to 'server')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasures.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/AverageFormula.java10
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/CounterInitializationContext.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/DistributionFormula.java9
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/Formula.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/FormulaExecutorComponentVisitor.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/SumFormula.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/VariationSumFormula.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/IntSumCounter.java5
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/LongSumCounter.java5
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/SumCounter.java3
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageFormula.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageVariationFormula.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationCounter.java3
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/AbstractCoverageRule.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/CommentDensityRule.java16
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/DuplicatedBlockRule.java3
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/SkippedTestRule.java5
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/TestErrorRule.java7
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/language/LanguageRepository.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImpl.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasure.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasure.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java17
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java7
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasure.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepository.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImpl.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStep.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitor.java9
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java11
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitor.java8
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CommentMeasuresStep.java25
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComputeMeasureVariationsStep.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LanguageDistributionMeasuresStep.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java8
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStep.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStep.java8
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SizeMeasuresStep.java8
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCase.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java8
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java7
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasuresTest.java3
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/AverageFormulaTest.java15
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/DistributionFormulaTest.java9
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/IntSumFormulaTest.java9
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/LongSumFormulaTest.java9
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/IntSumCounterTest.java11
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/LongSumCounterTest.java11
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImplTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java5
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java5
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java9
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java5
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureLevelTest.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java17
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitorTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStepTest.java13
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStepTest.java3
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java7
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStepTest.java10
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportCommentMeasuresStepTest.java16
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportComplexityMeasuresStepTest.java9
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportLanguageDistributionMeasuresStepTest.java17
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportUnitTestMeasuresStepTest.java33
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsCommentMeasuresStepTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsUnitTestMeasuresStepTest.java2
78 files changed, 249 insertions, 289 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java
index 80f660c3cd7..84367b85ecf 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java
@@ -20,11 +20,11 @@
package org.sonar.ce.task.projectanalysis.api.measurecomputer;
import com.google.common.base.Function;
-import com.google.common.base.Optional;
import com.google.common.base.Predicates;
import com.google.common.collect.FluentIterable;
import java.util.HashSet;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasures.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasures.java
index be7e5e52ef7..d1c975db3f4 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasures.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasures.java
@@ -19,9 +19,9 @@
*/
package org.sonar.ce.task.projectanalysis.duplication;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import java.util.HashSet;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -192,7 +192,7 @@ public class DuplicationMeasures {
double density = Math.min(100d, 100d * duplicatedLines / nbLines);
return Optional.of(Measure.newMeasureBuilder().create(density, context.getMetric().getDecimalScale()));
}
- return Optional.absent();
+ return Optional.empty();
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/AverageFormula.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/AverageFormula.java
index e0158e51b72..452478ae475 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/AverageFormula.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/AverageFormula.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.formula;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import static java.util.Objects.requireNonNull;
@@ -53,7 +53,7 @@ public class AverageFormula implements Formula<AverageFormula.AverageCounter> {
return Optional.of(Measure.newMeasureBuilder().create(mainValue / byValue, context.getMetric().getDecimalScale()));
}
}
- return Optional.absent();
+ return Optional.empty();
}
@Override
@@ -136,12 +136,12 @@ public class AverageFormula implements Formula<AverageFormula.AverageCounter> {
if (initialized) {
return Optional.of(value);
}
- return Optional.absent();
+ return Optional.empty();
}
private Optional<Double> getDoubleValue(Optional<Measure> measureOptional) {
if (!measureOptional.isPresent()) {
- return Optional.absent();
+ return Optional.empty();
}
Measure measure = measureOptional.get();
switch (measure.getValueType()) {
@@ -152,7 +152,7 @@ public class AverageFormula implements Formula<AverageFormula.AverageCounter> {
case INT:
return Optional.of((double) measure.getIntValue());
case NO_VALUE:
- return Optional.absent();
+ return Optional.empty();
default:
throw new IllegalArgumentException(String.format("Measure of type '%s' are not supported", measure.getValueType().name()));
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/CounterInitializationContext.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/CounterInitializationContext.java
index f952bf15ca9..a8771ee4750 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/CounterInitializationContext.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/CounterInitializationContext.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.formula;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.measure.Measure;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/DistributionFormula.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/DistributionFormula.java
index cf688c6dbe2..ec51a9a900b 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/DistributionFormula.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/DistributionFormula.java
@@ -19,10 +19,9 @@
*/
package org.sonar.ce.task.projectanalysis.formula;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.api.ce.measure.RangeDistributionBuilder;
import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
import org.sonar.ce.task.projectanalysis.measure.Measure;
@@ -48,7 +47,7 @@ public class DistributionFormula implements Formula<DistributionFormula.Distribu
if (value.isPresent() && CrawlerDepthLimit.LEAVES.isDeeperThan(componentType)) {
return Optional.of(Measure.newMeasureBuilder().create(value.get()));
}
- return Optional.absent();
+ return Optional.empty();
}
@Override
@@ -82,9 +81,9 @@ public class DistributionFormula implements Formula<DistributionFormula.Distribu
public Optional<String> getValue() {
if (initialized) {
- return Optional.fromNullable(distribution.build());
+ return Optional.ofNullable(distribution.build());
}
- return Optional.absent();
+ return Optional.empty();
}
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/Formula.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/Formula.java
index 848dcd7ad49..e3d4d0fffdf 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/Formula.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/Formula.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.formula;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.ce.task.projectanalysis.measure.Measure;
/**
@@ -34,7 +34,7 @@ public interface Formula<T extends Counter> {
/**
* This method is used to create a measure on each node, using the value of the counter
- * If {@link Optional#absent()} is returned, no measure will be created
+ * If {@link Optional#empty()} is returned, no measure will be created
*
* @param context the context for which the measure must be created
*/
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/FormulaExecutorComponentVisitor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/FormulaExecutorComponentVisitor.java
index 8f172573644..e3387a2fcf2 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/FormulaExecutorComponentVisitor.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/FormulaExecutorComponentVisitor.java
@@ -19,11 +19,11 @@
*/
package org.sonar.ce.task.projectanalysis.formula;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import javax.annotation.CheckForNull;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.ComponentVisitor;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/SumFormula.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/SumFormula.java
index a95bee24b0c..f60f7ec6947 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/SumFormula.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/SumFormula.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.formula;
-import com.google.common.base.Optional;
+import java.util.Optional;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
@@ -64,7 +64,7 @@ public abstract class SumFormula<T extends SumCounter<U, T>, U extends Number> i
if (shouldCreateMeasure(context, valueOptional)) {
return Optional.of(Measure.newMeasureBuilder().create(valueOptional.get()));
}
- return Optional.absent();
+ return Optional.empty();
}
}
@@ -92,7 +92,7 @@ public abstract class SumFormula<T extends SumCounter<U, T>, U extends Number> i
if (shouldCreateMeasure(context, valueOptional)) {
return Optional.of(Measure.newMeasureBuilder().create(valueOptional.get()));
}
- return Optional.absent();
+ return Optional.empty();
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/VariationSumFormula.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/VariationSumFormula.java
index b1672b58c63..59a27c24cc3 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/VariationSumFormula.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/VariationSumFormula.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.formula;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
import org.sonar.ce.task.projectanalysis.formula.counter.DoubleValue;
import org.sonar.ce.task.projectanalysis.measure.Measure;
@@ -46,7 +46,7 @@ public class VariationSumFormula implements Formula<VariationSumFormula.Variatio
@Override
public Optional<Measure> createMeasure(VariationSumCounter counter, CreateMeasureContext context) {
if (!CrawlerDepthLimit.LEAVES.isDeeperThan(context.getComponent().getType()) || !counter.doubleValue.isSet()) {
- return Optional.absent();
+ return Optional.empty();
}
return Optional.of(newMeasureBuilder().setVariation(counter.doubleValue.getValue()).createNoValue());
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/IntSumCounter.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/IntSumCounter.java
index f941889cc04..381a4582785 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/IntSumCounter.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/IntSumCounter.java
@@ -19,11 +19,10 @@
*/
package org.sonar.ce.task.projectanalysis.formula.counter;
-import com.google.common.base.Optional;
+import java.util.Optional;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext;
-import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import static java.util.Objects.requireNonNull;
@@ -76,6 +75,6 @@ public class IntSumCounter implements SumCounter<Integer, IntSumCounter> {
if (initialized) {
return Optional.of(value);
}
- return Optional.absent();
+ return Optional.empty();
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/LongSumCounter.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/LongSumCounter.java
index d395e9deb65..0156e5bb7c0 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/LongSumCounter.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/LongSumCounter.java
@@ -19,11 +19,10 @@
*/
package org.sonar.ce.task.projectanalysis.formula.counter;
-import com.google.common.base.Optional;
+import java.util.Optional;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext;
-import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import static java.util.Objects.requireNonNull;
@@ -76,6 +75,6 @@ public class LongSumCounter implements SumCounter<Long, LongSumCounter> {
if (initialized) {
return Optional.of(value);
}
- return Optional.absent();
+ return Optional.empty();
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/SumCounter.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/SumCounter.java
index 40a422d095c..bad78cbdea9 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/SumCounter.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/counter/SumCounter.java
@@ -19,8 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.formula.counter;
-import com.google.common.base.Optional;
-import org.sonar.ce.task.projectanalysis.formula.Counter;
+import java.util.Optional;
import org.sonar.ce.task.projectanalysis.formula.Counter;
public interface SumCounter<T extends Number, COUNTER extends SumCounter<T, COUNTER>> extends Counter<COUNTER> {
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageFormula.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageFormula.java
index 4dc37f4586f..4306648b851 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageFormula.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageFormula.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.formula.coverage;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.ce.task.projectanalysis.formula.Counter;
import org.sonar.ce.task.projectanalysis.formula.CreateMeasureContext;
import org.sonar.ce.task.projectanalysis.formula.Formula;
@@ -41,7 +41,7 @@ public abstract class CoverageFormula<T extends ElementsAndCoveredElementsCounte
if (elements > 0L) {
return Optional.of(newMeasureBuilder().create(calculateCoverage(coveredElements, elements), context.getMetric().getDecimalScale()));
}
- return Optional.absent();
+ return Optional.empty();
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java
index 7de4698807a..28c14818738 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.formula.coverage;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext;
import org.sonar.ce.task.projectanalysis.measure.Measure;
@@ -37,7 +37,7 @@ public final class CoverageUtils {
}
static long getLongMeasureValue(CounterInitializationContext counterContext, String metricKey) {
- Measure measure = counterContext.getMeasure(metricKey).or(DEFAULT_MEASURE);
+ Measure measure = counterContext.getMeasure(metricKey).orElse(DEFAULT_MEASURE);
if (measure.getValueType() == Measure.ValueType.NO_VALUE) {
return 0L;
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageVariationFormula.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageVariationFormula.java
index b5abe339336..c072e631ff7 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageVariationFormula.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageVariationFormula.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.formula.coverage;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.ce.task.projectanalysis.formula.CreateMeasureContext;
import org.sonar.ce.task.projectanalysis.formula.Formula;
import org.sonar.ce.task.projectanalysis.formula.counter.LongValue;
@@ -42,7 +42,7 @@ public abstract class CoverageVariationFormula<T extends ElementsAndCoveredEleme
double variation = calculateCoverage(coveredElements.getValue(), elements.getValue());
return Optional.of(newMeasureBuilder().setVariation(variation).createNoValue());
}
- return Optional.absent();
+ return Optional.empty();
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationCounter.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationCounter.java
index 83fb4ca2814..932fa96d044 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationCounter.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationCounter.java
@@ -19,8 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.formula.coverage;
-import com.google.common.base.Optional;
-import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext;
+import java.util.Optional;
import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext;
import org.sonar.ce.task.projectanalysis.measure.Measure;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/AbstractCoverageRule.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/AbstractCoverageRule.java
index 74643580c40..bd4f7342ceb 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/AbstractCoverageRule.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/AbstractCoverageRule.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.issue.commonrule;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/CommentDensityRule.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/CommentDensityRule.java
index 5778ad7123d..1d25dc62b06 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/CommentDensityRule.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/CommentDensityRule.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.issue.commonrule;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.measure.Measure;
@@ -57,7 +57,7 @@ public class CommentDensityRule extends CommonRule {
// this is a small optimization to not load the minimum value when the measures are not present
double minCommentDensity = getMinDensity(activeRule);
if (commentDensityMeasure.get().getDoubleValue() < minCommentDensity) {
- return generateIssue(commentDensityMeasure, commentLinesMeasure, nclocMeasure, minCommentDensity);
+ return generateIssue(commentDensityMeasure.get(), commentLinesMeasure, nclocMeasure.get(), minCommentDensity);
}
}
return null;
@@ -71,15 +71,15 @@ public class CommentDensityRule extends CommonRule {
return min;
}
- private static CommonRuleIssue generateIssue(Optional<Measure> commentDensityMeasure, Optional<Measure> commentLinesMeasure,
- Optional<Measure> nclocMeasure, double minCommentDensity) {
- int commentLines = commentLinesMeasure.isPresent() ? commentLinesMeasure.get().getIntValue() : 0;
- int ncloc = nclocMeasure.get().getIntValue();
+ private static CommonRuleIssue generateIssue(Measure commentDensityMeasure, Optional<Measure> commentLinesMeasure,
+ Measure nclocMeasure, double minCommentDensity) {
+ int commentLines = commentLinesMeasure.map(Measure::getIntValue).orElse(0);
+ int ncloc = nclocMeasure.getIntValue();
int minExpectedCommentLines = (int) Math.ceil(minCommentDensity * ncloc / (100 - minCommentDensity));
int missingCommentLines = minExpectedCommentLines - commentLines;
if (missingCommentLines <= 0) {
- throw new IllegalStateException(format("Bug in measures of comment lines - density=%s, comment_lines= %d, ncloc=%d, threshold=%s%%", commentDensityMeasure.get()
- .getDoubleValue(), commentLines, nclocMeasure.get().getIntValue(), minCommentDensity));
+ throw new IllegalStateException(format("Bug in measures of comment lines - density=%s, comment_lines= %d, ncloc=%d, threshold=%s%%",
+ commentDensityMeasure.getDoubleValue(), commentLines, nclocMeasure.getIntValue(), minCommentDensity));
}
// TODO declare min threshold as int but not float ?
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/DuplicatedBlockRule.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/DuplicatedBlockRule.java
index 58c46a52b81..f69c6b7740e 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/DuplicatedBlockRule.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/DuplicatedBlockRule.java
@@ -19,10 +19,9 @@
*/
package org.sonar.ce.task.projectanalysis.issue.commonrule;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
import org.sonar.ce.task.projectanalysis.metric.Metric;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/SkippedTestRule.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/SkippedTestRule.java
index 439c6c99662..cc4f2566a4a 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/SkippedTestRule.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/SkippedTestRule.java
@@ -19,10 +19,9 @@
*/
package org.sonar.ce.task.projectanalysis.issue.commonrule;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
import org.sonar.ce.task.projectanalysis.metric.Metric;
@@ -48,7 +47,7 @@ public class SkippedTestRule extends CommonRule {
protected CommonRuleIssue doProcessFile(Component file, ActiveRule activeRule) {
Optional<Measure> measure = measureRepository.getRawMeasure(file, skippedTestsMetric);
- int skipped = measure.isPresent() ? measure.get().getIntValue() : 0;
+ int skipped = measure.map(Measure::getIntValue).orElse(0);
if (skipped > 0) {
String message = format("Fix or remove skipped unit tests in file \"%s\".", file.getName());
return new CommonRuleIssue(skipped, message);
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/TestErrorRule.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/TestErrorRule.java
index 7c7df1deec3..48f828dc41d 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/TestErrorRule.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/commonrule/TestErrorRule.java
@@ -19,10 +19,9 @@
*/
package org.sonar.ce.task.projectanalysis.issue.commonrule;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
import org.sonar.ce.task.projectanalysis.metric.Metric;
@@ -51,8 +50,8 @@ public class TestErrorRule extends CommonRule {
Optional<Measure> errorsMeasure = measureRepository.getRawMeasure(file, testErrorMetric);
Optional<Measure> failuresMeasure = measureRepository.getRawMeasure(file, testFailureMetric);
- int errors = errorsMeasure.isPresent() ? errorsMeasure.get().getIntValue() : 0;
- int failures = failuresMeasure.isPresent() ? failuresMeasure.get().getIntValue() : 0;
+ int errors = errorsMeasure.map(Measure::getIntValue).orElse(0);
+ int failures = failuresMeasure.map(Measure::getIntValue).orElse(0);
int total = errors + failures;
if (total > 0) {
String message = format("Fix failing unit tests on file \"%s\".", file.getName());
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/language/LanguageRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/language/LanguageRepository.java
index 53b7f73b3b5..e78efb0d93c 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/language/LanguageRepository.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/language/LanguageRepository.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.language;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.api.resources.Language;
public interface LanguageRepository {
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImpl.java
index 04654f373c3..b60f5c0c63c 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImpl.java
@@ -20,9 +20,9 @@
package org.sonar.ce.task.projectanalysis.language;
import com.google.common.base.Function;
-import com.google.common.base.Optional;
import java.util.Collections;
import java.util.Map;
+import java.util.Optional;
import javax.annotation.Nonnull;
import org.sonar.api.resources.Language;
@@ -48,7 +48,7 @@ public class LanguageRepositoryImpl implements LanguageRepository {
@Override
public Optional<Language> find(String languageKey) {
- return Optional.fromNullable(languagesByKey.get(languageKey));
+ return Optional.ofNullable(languagesByKey.get(languageKey));
}
private enum LanguageToKey implements Function<Language, String> {
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasure.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasure.java
index 782a0ae4eac..432b486cfa1 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasure.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasure.java
@@ -19,14 +19,14 @@
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.google.common.base.Optional;
import java.util.Objects;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.sonar.ce.task.projectanalysis.metric.Metric;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Measure.ValueCase;
-import static com.google.common.base.Optional.of;
+import static java.util.Optional.of;
import static org.apache.commons.lang.StringUtils.trimToNull;
public class BatchMeasureToMeasure {
@@ -34,7 +34,7 @@ public class BatchMeasureToMeasure {
public Optional<Measure> toMeasure(@Nullable ScannerReport.Measure batchMeasure, Metric metric) {
Objects.requireNonNull(metric);
if (batchMeasure == null) {
- return Optional.absent();
+ return Optional.empty();
}
Measure.NewMeasureBuilder builder = Measure.newMeasureBuilder();
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasure.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasure.java
index 8eb3f96a3c7..34cff0fc3e4 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasure.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasure.java
@@ -19,13 +19,13 @@
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.google.common.base.Optional;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.sonar.ce.task.projectanalysis.metric.Metric;
import org.sonar.db.measure.LiveMeasureDto;
-import static com.google.common.base.Optional.of;
import static java.util.Objects.requireNonNull;
+import static java.util.Optional.of;
import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.toLevel;
public class LiveMeasureDtoToMeasure {
@@ -33,7 +33,7 @@ public class LiveMeasureDtoToMeasure {
public Optional<Measure> toMeasure(@Nullable LiveMeasureDto measureDto, Metric metric) {
requireNonNull(metric);
if (measureDto == null) {
- return Optional.absent();
+ return Optional.empty();
}
Double value = measureDto.getValue();
String data = measureDto.getDataAsString();
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java
index 1fd083edc6e..b79e9b77952 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java
@@ -20,13 +20,13 @@
package org.sonar.ce.task.projectanalysis.measure;
import com.google.common.base.Function;
-import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.SetMultimap;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -40,7 +40,6 @@ import static java.util.Objects.requireNonNull;
/**
* Map based implementation of MeasureRepository which supports only raw measures.
- *
* Intended to be used as a delegate of other MeasureRepository implementations (hence the final keyword).
*/
public final class MapBasedRawMeasureRepository<T> implements MeasureRepository {
@@ -138,18 +137,18 @@ public final class MapBasedRawMeasureRepository<T> implements MeasureRepository
T componentKey = componentToKey.apply(component);
Map<MeasureKey, Measure> measuresPerMetric = measures.get(componentKey);
if (measuresPerMetric == null) {
- return Optional.absent();
+ return Optional.empty();
}
- return Optional.fromNullable(measuresPerMetric.get(new MeasureKey(metric.getKey(), null)));
+ return Optional.ofNullable(measuresPerMetric.get(new MeasureKey(metric.getKey(), null)));
}
private Optional<Measure> find(Component component, Metric metric, Measure measure) {
T componentKey = componentToKey.apply(component);
Map<MeasureKey, Measure> measuresPerMetric = measures.get(componentKey);
if (measuresPerMetric == null) {
- return Optional.absent();
+ return Optional.empty();
}
- return Optional.fromNullable(measuresPerMetric.get(new MeasureKey(metric.getKey(), measure.getDeveloper())));
+ return Optional.ofNullable(measuresPerMetric.get(new MeasureKey(metric.getKey(), measure.getDeveloper())));
}
public void add(Component component, Metric metric, Measure measure, OverridePolicy overridePolicy) {
@@ -159,11 +158,7 @@ public final class MapBasedRawMeasureRepository<T> implements MeasureRepository
requireNonNull(overridePolicy);
T componentKey = componentToKey.apply(component);
- Map<MeasureKey, Measure> measuresPerMetric = measures.get(componentKey);
- if (measuresPerMetric == null) {
- measuresPerMetric = new HashMap<>();
- measures.put(componentKey, measuresPerMetric);
- }
+ Map<MeasureKey, Measure> measuresPerMetric = measures.computeIfAbsent(componentKey, key -> new HashMap<>());
MeasureKey key = new MeasureKey(metric.getKey(), measure.getDeveloper());
if (!measuresPerMetric.containsKey(key) || overridePolicy == OverridePolicy.OVERRIDE) {
measuresPerMetric.put(key, measure);
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java
index 09c0b76734c..3d006923fd2 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java
@@ -19,15 +19,14 @@
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.google.common.base.Optional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Locale;
import java.util.Objects;
+import java.util.Optional;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.ce.task.projectanalysis.component.Developer;
-import org.sonar.ce.task.projectanalysis.component.Developer;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
@@ -56,13 +55,13 @@ public final class Measure {
public static Optional<Level> toLevel(@Nullable String level) {
if (level == null) {
- return Optional.absent();
+ return Optional.empty();
}
try {
return Optional.of(Level.valueOf(level));
} catch (IllegalArgumentException e) {
- return Optional.absent();
+ return Optional.empty();
}
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasure.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasure.java
index 7bd3094e2b5..6df08c2f993 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasure.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasure.java
@@ -19,13 +19,13 @@
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.google.common.base.Optional;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.sonar.ce.task.projectanalysis.metric.Metric;
import org.sonar.db.measure.MeasureDto;
-import static com.google.common.base.Optional.of;
import static java.util.Objects.requireNonNull;
+import static java.util.Optional.of;
import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.toLevel;
public class MeasureDtoToMeasure {
@@ -33,7 +33,7 @@ public class MeasureDtoToMeasure {
public Optional<Measure> toMeasure(@Nullable MeasureDto measureDto, Metric metric) {
requireNonNull(metric);
if (measureDto == null) {
- return Optional.absent();
+ return Optional.empty();
}
Double value = measureDto.getValue();
String data = measureDto.getData();
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepository.java
index 71bac5bc012..e521d3e7f39 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepository.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepository.java
@@ -19,8 +19,8 @@
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.google.common.base.Optional;
import com.google.common.collect.SetMultimap;
+import java.util.Optional;
import java.util.Set;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.metric.Metric;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImpl.java
index f83f96ee94c..5803826f6c0 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImpl.java
@@ -19,9 +19,9 @@
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.google.common.base.Optional;
import com.google.common.collect.SetMultimap;
import java.util.HashSet;
+import java.util.Optional;
import java.util.Set;
import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
import org.sonar.ce.task.projectanalysis.component.Component;
@@ -65,11 +65,11 @@ public class MeasureRepositoryImpl implements MeasureRepository {
requireNonNull(metric);
try (DbSession dbSession = dbClient.openSession(false)) {
- java.util.Optional<MeasureDto> measureDto = dbClient.measureDao().selectLastMeasure(dbSession, component.getUuid(), metric.getKey());
+ Optional<MeasureDto> measureDto = dbClient.measureDao().selectLastMeasure(dbSession, component.getUuid(), metric.getKey());
if (measureDto.isPresent()) {
return measureTransformer.toMeasure(measureDto.get(), metric);
}
- return Optional.absent();
+ return Optional.empty();
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStep.java
index 4c882c23f17..eb9cffc6059 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStep.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
@@ -83,7 +83,7 @@ public class PostMeasuresComputationChecksStep implements ComputationStep {
public int getNcloc() {
Metric nclocMetric = metricRepository.getByKey(CoreMetrics.NCLOC_KEY);
Optional<Measure> nclocMeasure = measureRepository.getRawMeasure(treeRootHolder.getRoot(), nclocMetric);
- return nclocMeasure.isPresent() ? nclocMeasure.get().getIntValue() : 0;
+ return nclocMeasure.map(Measure::getIntValue).orElse(0);
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitor.java
index fc1f27f4ed3..6ec71ab1fe8 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitor.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitor.java
@@ -19,13 +19,9 @@
*/
package org.sonar.ce.task.projectanalysis.qualitymodel;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.ce.task.projectanalysis.component.PathAwareVisitorAdapter;
-import org.sonar.ce.task.projectanalysis.metric.Metric;
-import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
-import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
import org.sonar.ce.task.projectanalysis.component.PathAwareVisitorAdapter;
import org.sonar.ce.task.projectanalysis.formula.counter.RatingValue;
@@ -41,7 +37,6 @@ import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
import static org.sonar.api.measures.CoreMetrics.SQALE_DEBT_RATIO_KEY;
import static org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY;
import static org.sonar.api.measures.CoreMetrics.TECHNICAL_DEBT_KEY;
-import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
/**
@@ -102,7 +97,7 @@ public class MaintainabilityMeasuresVisitor extends PathAwareVisitorAdapter<Main
private long computeDevelopmentCost(Component file) {
Optional<Measure> measure = measureRepository.getRawMeasure(file, nclocMetric);
- long ncloc = measure.isPresent() ? measure.get().getIntValue() : 0;
+ long ncloc = measure.map(Measure::getIntValue).orElse(0);
return ncloc * ratingSettings.getDevCost(file.getFileAttributes().getLanguageKey());
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java
index 2fed329b51a..9d4769ec961 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java
@@ -19,8 +19,8 @@
*/
package org.sonar.ce.task.projectanalysis.qualitymodel;
-import com.google.common.base.Optional;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.sonar.api.measures.CoreMetrics;
@@ -50,7 +50,6 @@ import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilde
/**
* This visitor depends on {@link IntegrateIssuesVisitor} for the computation of
* metric {@link CoreMetrics#NEW_TECHNICAL_DEBT}.
- *
* Compute following measure :
* {@link CoreMetrics#NEW_SQALE_DEBT_RATIO_KEY}
* {@link CoreMetrics#NEW_MAINTAINABILITY_RATING_KEY}
@@ -136,10 +135,7 @@ public class NewMaintainabilityMeasuresVisitor extends PathAwareVisitorAdapter<N
}
private static long getLongValue(Optional<Measure> measure) {
- if (!measure.isPresent()) {
- return 0L;
- }
- return getLongValue(measure.get());
+ return measure.map(NewMaintainabilityMeasuresVisitor::getLongValue).orElse(0L);
}
private static long getLongValue(Measure measure) {
@@ -155,7 +151,7 @@ public class NewMaintainabilityMeasuresVisitor extends PathAwareVisitorAdapter<N
return;
}
- java.util.Optional<Set<Integer>> changedLines = newLinesRepository.getNewLines(file);
+ Optional<Set<Integer>> changedLines = newLinesRepository.getNewLines(file);
if (!changedLines.isPresent()) {
LOG.trace(String.format("No information about changed lines is available for file '%s'. Dev cost will be zero.", file.getKey()));
@@ -193,7 +189,6 @@ public class NewMaintainabilityMeasuresVisitor extends PathAwareVisitorAdapter<N
/**
* NCLOC_DATA contains Key-value pairs, where key - is a number of line, and value - is an indicator of whether line
* contains code (1) or not (0).
- *
* This method parses the value of the NCLOC_DATA measure and return the line numbers of lines which contain code.
*/
private static Iterable<Integer> nclocLineIndexes(Measure nclocDataMeasure) {
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitor.java
index a22f52b2fdb..55bdaaa6f65 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitor.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitor.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.source;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
@@ -99,10 +99,8 @@ public class LastCommitVisitor extends PathAwareVisitorAdapter<LastCommitVisitor
@Override
public void visitProjectView(Component projectView, Path<LastCommit> path) {
Optional<Measure> rawMeasure = measureRepository.getRawMeasure(projectView, lastCommitDateMetric);
- if (rawMeasure.isPresent()) {
- // path.parent() should never fail as a project view must never be a root component
- path.parent().addDate(rawMeasure.get().getLongValue());
- }
+ // path.parent() should never fail as a project view must never be a root component
+ rawMeasure.ifPresent(measure -> path.parent().addDate(measure.getLongValue()));
}
private void saveAndAggregate(Component component, Path<LastCommit> path) {
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CommentMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CommentMeasuresStep.java
index 7d95e27677e..14ff1a89c5d 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CommentMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CommentMeasuresStep.java
@@ -19,8 +19,8 @@
*/
package org.sonar.ce.task.projectanalysis.step;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
+import java.util.Optional;
import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
import org.sonar.ce.task.projectanalysis.component.PathAwareCrawler;
import org.sonar.ce.task.projectanalysis.component.TreeRootHolder;
@@ -70,7 +70,7 @@ public class CommentMeasuresStep implements ComputationStep {
public void execute(ComputationStep.Context context) {
new PathAwareCrawler<>(
FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository).buildFor(formulas))
- .visit(treeRootHolder.getRoot());
+ .visit(treeRootHolder.getRoot());
}
private class CommentDensityFormula implements Formula<IntSumCounter> {
@@ -88,8 +88,8 @@ public class CommentMeasuresStep implements ComputationStep {
@Override
public Optional<Measure> createMeasure(IntSumCounter counter, CreateMeasureContext context) {
- return createCommentLinesMeasure(counter, context)
- .or(createCommentLinesDensityMeasure(counter, context));
+ Optional<Measure> measure = createCommentLinesMeasure(counter, context);
+ return measure.isPresent() ? measure : createCommentLinesDensityMeasure(counter, context);
}
private Optional<Measure> createCommentLinesMeasure(SumCounter counter, CreateMeasureContext context) {
@@ -99,7 +99,7 @@ public class CommentMeasuresStep implements ComputationStep {
&& CrawlerDepthLimit.LEAVES.isDeeperThan(context.getComponent().getType())) {
return Optional.of(Measure.newMeasureBuilder().create(commentLines.get()));
}
- return Optional.absent();
+ return Optional.empty();
}
private Optional<Measure> createCommentLinesDensityMeasure(SumCounter counter, CreateMeasureContext context) {
@@ -116,7 +116,7 @@ public class CommentMeasuresStep implements ComputationStep {
}
}
}
- return Optional.absent();
+ return Optional.empty();
}
@Override
@@ -134,9 +134,12 @@ public class CommentMeasuresStep implements ComputationStep {
@Override
public Optional<Measure> createMeasure(DocumentationCounter counter, CreateMeasureContext context) {
- return getMeasure(context, counter.getPublicApiValue(), PUBLIC_API_KEY)
- .or(getMeasure(context, counter.getPublicUndocumentedApiValue(), PUBLIC_UNDOCUMENTED_API_KEY))
- .or(getDensityMeasure(counter, context));
+ Optional<Measure> measure = getMeasure(context, counter.getPublicApiValue(), PUBLIC_API_KEY);
+ if (measure.isPresent()) {
+ return measure;
+ }
+ measure = getMeasure(context, counter.getPublicUndocumentedApiValue(), PUBLIC_UNDOCUMENTED_API_KEY);
+ return measure.isPresent() ? measure : getDensityMeasure(counter, context);
}
private static Optional<Measure> getMeasure(CreateMeasureContext context, Optional<Integer> metricValue, String metricKey) {
@@ -144,7 +147,7 @@ public class CommentMeasuresStep implements ComputationStep {
&& CrawlerDepthLimit.LEAVES.isDeeperThan(context.getComponent().getType())) {
return Optional.of(Measure.newMeasureBuilder().create(metricValue.get()));
}
- return Optional.absent();
+ return Optional.empty();
}
private static Optional<Measure> getDensityMeasure(DocumentationCounter counter, CreateMeasureContext context) {
@@ -158,7 +161,7 @@ public class CommentMeasuresStep implements ComputationStep {
return Optional.of(Measure.newMeasureBuilder().create(value, context.getMetric().getDecimalScale()));
}
}
- return Optional.absent();
+ return Optional.empty();
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComputeMeasureVariationsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComputeMeasureVariationsStep.java
index c05f75916e2..f0a3329763c 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComputeMeasureVariationsStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComputeMeasureVariationsStep.java
@@ -19,11 +19,11 @@
*/
package org.sonar.ce.task.projectanalysis.step;
-import com.google.common.base.Optional;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.StreamSupport;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LanguageDistributionMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LanguageDistributionMeasuresStep.java
index 80a9e2c0a71..65c4087359d 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LanguageDistributionMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LanguageDistributionMeasuresStep.java
@@ -20,11 +20,11 @@
package org.sonar.ce.task.projectanalysis.step;
import com.google.common.base.Function;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multiset;
import com.google.common.collect.TreeMultiset;
import java.util.Map;
+import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.sonar.api.measures.CoreMetrics;
@@ -83,7 +83,7 @@ public class LanguageDistributionMeasuresStep implements ComputationStep {
@Override
public Optional<Measure> createMeasure(LanguageDistributionCounter counter, CreateMeasureContext context) {
if (counter.multiset.isEmpty()) {
- return Optional.absent();
+ return Optional.empty();
}
return Optional.of(newMeasureBuilder().create(format(asMap(counter.multiset.elementSet(), new LanguageToTotalCount(counter.multiset)))));
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java
index ed00e29c933..e20ce133cb0 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java
@@ -19,12 +19,12 @@
*/
package org.sonar.ce.task.projectanalysis.step;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
@@ -188,7 +188,7 @@ public class NewCoverageMeasuresStep implements ComputationStep {
int value = computeValueForMetric(counter, context.getMetric());
return Optional.of(newMeasureBuilder().setVariation(value).createNoValue());
}
- return Optional.absent();
+ return Optional.empty();
}
private int computeValueForMetric(NewCoverageCounter counter, Metric metric) {
@@ -242,7 +242,7 @@ public class NewCoverageMeasuresStep implements ComputationStep {
@Override
public void initialize(CounterInitializationContext context) {
Component fileComponent = context.getLeaf();
- java.util.Optional<Set<Integer>> newLinesSet = newLinesRepository.getNewLines(fileComponent);
+ Optional<Set<Integer>> newLinesSet = newLinesRepository.getNewLines(fileComponent);
if (!newLinesSet.isPresent()) {
return;
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java
index bc1b3c2f5b6..24635c55068 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java
@@ -19,9 +19,9 @@
*/
package org.sonar.ce.task.projectanalysis.step;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import java.util.HashSet;
+import java.util.Optional;
import java.util.Set;
import java.util.stream.IntStream;
import org.sonar.ce.task.projectanalysis.component.Component;
@@ -102,7 +102,7 @@ public class NewSizeMeasuresStep implements ComputationStep {
@Override
public void initialize(CounterInitializationContext context) {
Component leaf = context.getLeaf();
- java.util.Optional<Set<Integer>> changedLines = newLinesRepository.getNewLines(leaf);
+ Optional<Set<Integer>> changedLines = newLinesRepository.getNewLines(leaf);
if (!changedLines.isPresent()) {
return;
}
@@ -203,7 +203,7 @@ public class NewSizeMeasuresStep implements ComputationStep {
private static Optional<Measure> createMeasure(IntValue intValue) {
return intValue.isSet()
? Optional.of(Measure.newMeasureBuilder().setVariation(intValue.getValue()).createNoValue())
- : Optional.absent();
+ : Optional.empty();
}
private static Optional<Measure> createNewDuplicatedLinesDensityMeasure(NewSizeCounter counter) {
@@ -217,7 +217,7 @@ public class NewSizeMeasuresStep implements ComputationStep {
return Optional.of(Measure.newMeasureBuilder().setVariation(density).createNoValue());
}
}
- return Optional.absent();
+ return Optional.empty();
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java
index 60625f3c169..819b6f7bc4a 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.step;
-import com.google.common.base.Optional;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.notifications.Notification;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStep.java
index 6791b2af52d..05c7607d602 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStep.java
@@ -177,7 +177,7 @@ public class QualityGateMeasuresStep implements ComputationStep {
boolean ignoredConditions = false;
for (Map.Entry<Metric, Collection<Condition>> entry : conditionsPerMetric.asMap().entrySet()) {
Metric metric = entry.getKey();
- com.google.common.base.Optional<Measure> measure = measureRepository.getRawMeasure(project, metric);
+ Optional<Measure> measure = measureRepository.getRawMeasure(project, metric);
if (!measure.isPresent()) {
continue;
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStep.java
index e6d979361e6..66ad67230ef 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStep.java
@@ -19,11 +19,11 @@
*/
package org.sonar.ce.task.projectanalysis.step;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSortedMap;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.apache.commons.lang.time.DateUtils;
import org.sonar.api.measures.CoreMetrics;
@@ -95,13 +95,13 @@ public class QualityProfileEventsStep implements ComputationStep {
}
Map<String, QualityProfile> rawProfiles = QPMeasureData.fromJson(rawMeasure.get().getStringValue()).getProfilesByKey();
- Map<String, QualityProfile> baseProfiles = parseJsonData(baseMeasure);
+ Map<String, QualityProfile> baseProfiles = parseJsonData(baseMeasure.get());
detectNewOrUpdatedProfiles(projectComponent, baseProfiles, rawProfiles);
detectNoMoreUsedProfiles(projectComponent, baseProfiles, rawProfiles);
}
- private static Map<String, QualityProfile> parseJsonData(Optional<Measure> measure) {
- String data = measure.get().getStringValue();
+ private static Map<String, QualityProfile> parseJsonData(Measure measure) {
+ String data = measure.getStringValue();
if (data == null) {
return Collections.emptyMap();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SizeMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SizeMeasuresStep.java
index 906923b66f2..edf6f404f01 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SizeMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SizeMeasuresStep.java
@@ -19,10 +19,10 @@
*/
package org.sonar.ce.task.projectanalysis.step;
-import com.google.common.base.Optional;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
import org.sonar.ce.task.projectanalysis.component.PathAwareCrawler;
@@ -78,10 +78,10 @@ public class SizeMeasuresStep implements ComputationStep {
metricRepository.getByKey(DIRECTORIES_KEY),
metricRepository.getByKey(FILES_KEY),
metricRepository.getByKey(LINES_KEY)))
- .visit(treeRootHolder.getRoot());
+ .visit(treeRootHolder.getRoot());
new PathAwareCrawler<>(FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository)
.buildFor(AGGREGATED_SIZE_MEASURE_FORMULAS))
- .visit(treeRootHolder.getRoot());
+ .visit(treeRootHolder.getRoot());
}
@Override
@@ -165,7 +165,7 @@ public class SizeMeasuresStep implements ComputationStep {
private int getIntValue(Component component, Metric metric) {
Optional<Measure> fileMeasure = measureRepository.getRawMeasure(component, metric);
- return fileMeasure.isPresent() ? fileMeasure.get().getIntValue() : 0;
+ return fileMeasure.map(Measure::getIntValue).orElse(0);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCase.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCase.java
index 8aa32e1d9ca..bdaa46d8019 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCase.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCase.java
@@ -67,7 +67,7 @@ public class SmallChangesetQualityGateSpecialCase {
private boolean isSmallChangeset(Component project) {
return measureRepository.getRawMeasure(project, metricRepository.getByKey(CoreMetrics.NEW_LINES_KEY))
- .transform(newLines -> newLines.hasVariation() && newLines.getVariation() <= MAXIMUM_NEW_LINES_FOR_SMALL_CHANGESETS)
- .or(false);
+ .map(newLines -> newLines.hasVariation() && newLines.getVariation() <= MAXIMUM_NEW_LINES_FOR_SMALL_CHANGESETS)
+ .orElse(false);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java
index 9cf89f9c5f7..a7e870c3cf2 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java
@@ -19,8 +19,8 @@
*/
package org.sonar.ce.task.projectanalysis.step;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
+import java.util.Optional;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.PathAwareCrawler;
import org.sonar.ce.task.projectanalysis.component.TreeRootHolder;
@@ -102,14 +102,14 @@ public class UnitTestMeasuresStep implements ComputationStep {
if (metricValue.isPresent() && leafComponent.getType().isDeeperThan(currentComponent.getType())) {
return Optional.of(Measure.newMeasureBuilder().create(metricValue.get()));
}
- return Optional.absent();
+ return Optional.empty();
}
private static Optional<Measure> createLongMeasure(Component currentComponent, Component leafComponent, Optional<Long> metricValue) {
if (metricValue.isPresent() && leafComponent.getType().isDeeperThan(currentComponent.getType())) {
return Optional.of(Measure.newMeasureBuilder().create(metricValue.get()));
}
- return Optional.absent();
+ return Optional.empty();
}
private static Optional<Measure> createDensityMeasure(UnitTestsCounter counter, int decimalScale) {
@@ -122,7 +122,7 @@ public class UnitTestMeasuresStep implements ComputationStep {
double density = (errors + failures) * 100d / tests;
return Optional.of(Measure.newMeasureBuilder().create(100d - density, decimalScale));
}
- return Optional.absent();
+ return Optional.empty();
}
private static boolean isPositive(Optional<Integer> value, boolean isStrictComparison) {
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java
index 1bacce8bc59..0c48938545b 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java
@@ -19,9 +19,9 @@
*/
package org.sonar.ce.task.projectanalysis.step;
-import com.google.common.base.Optional;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java
index c0a84122968..c353c1148cb 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java
@@ -19,10 +19,10 @@
*/
package org.sonar.ce.task.projectanalysis.api.measurecomputer;
-import com.google.common.base.Optional;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -43,7 +43,6 @@ import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule;
import org.sonar.core.issue.DefaultIssue;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.api.measures.CoreMetrics.COMMENT_LINES_KEY;
@@ -69,8 +68,8 @@ public class MeasureComputerContextImplTest {
private static final org.sonar.ce.task.projectanalysis.component.Component FILE_1 = builder(
org.sonar.ce.task.projectanalysis.component.Component.Type.FILE, FILE_1_REF)
- .setKey(FILE_1_KEY)
- .build();
+ .setKey(FILE_1_KEY)
+ .build();
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule()
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasuresTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasuresTest.java
index 504937a1683..ea7efa3c028 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasuresTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasuresTest.java
@@ -28,7 +28,6 @@ import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule;
import static com.google.common.base.Preconditions.checkArgument;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.api.measures.CoreMetrics.DUPLICATED_BLOCKS;
@@ -361,7 +360,7 @@ public class DuplicationMeasuresTest {
}
private void assertNoRawMeasure(int componentRef, String metricKey) {
- assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)).isNotPresent();
}
private void assertRawMeasureValue(int componentRef, String metricKey, int value) {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/AverageFormulaTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/AverageFormulaTest.java
index 9a355b83701..8c23184351b 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/AverageFormulaTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/AverageFormulaTest.java
@@ -19,8 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.formula;
-import com.google.common.base.Optional;
-import org.assertj.guava.api.Assertions;
+import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -159,7 +158,7 @@ public class AverageFormulaTest {
when(counterInitializationContext.getMeasure(FUNCTIONS_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().createNoValue()));
counter.initialize(counterInitializationContext);
- Assertions.assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext)).isAbsent();
+ assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext)).isNotPresent();
}
@Test
@@ -178,20 +177,20 @@ public class AverageFormulaTest {
@Test
public void no_measure_created_when_counter_has_no_value() {
AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter();
- when(counterInitializationContext.getMeasure(anyString())).thenReturn(Optional.absent());
+ when(counterInitializationContext.getMeasure(anyString())).thenReturn(Optional.empty());
counter.initialize(counterInitializationContext);
- Assertions.assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext)).isAbsent();
+ assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext)).isNotPresent();
}
@Test
public void not_create_measure_when_only_one_measure() {
AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter();
addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10L);
- when(counterInitializationContext.getMeasure(FUNCTIONS_KEY)).thenReturn(Optional.absent());
+ when(counterInitializationContext.getMeasure(FUNCTIONS_KEY)).thenReturn(Optional.empty());
counter.initialize(counterInitializationContext);
- Assertions.assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext)).isAbsent();
+ assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext)).isNotPresent();
}
@Test
@@ -201,7 +200,7 @@ public class AverageFormulaTest {
addMeasure(FUNCTIONS_KEY, 0d);
counter.initialize(counterInitializationContext);
- Assertions.assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext)).isAbsent();
+ assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext)).isNotPresent();
}
private void addMeasure(String metricKey, double value) {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/DistributionFormulaTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/DistributionFormulaTest.java
index 58637b42e18..08f13161f53 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/DistributionFormulaTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/DistributionFormulaTest.java
@@ -19,8 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.formula;
-import com.google.common.base.Optional;
-import org.assertj.guava.api.Assertions;
+import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -89,10 +88,10 @@ public class DistributionFormulaTest {
@Test
public void create_no_measure_when_no_value() {
DistributionFormula.DistributionCounter counter = BASIC_DISTRIBUTION_FORMULA.createNewCounter();
- when(counterInitializationContext.getMeasure(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(Optional.absent());
+ when(counterInitializationContext.getMeasure(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(Optional.empty());
counter.initialize(counterInitializationContext);
- Assertions.assertThat(BASIC_DISTRIBUTION_FORMULA.createMeasure(counter, projectCreateMeasureContext)).isAbsent();
+ assertThat(BASIC_DISTRIBUTION_FORMULA.createMeasure(counter, projectCreateMeasureContext)).isNotPresent();
}
@Test
@@ -101,7 +100,7 @@ public class DistributionFormulaTest {
addMeasure(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, "0=3;3=7;6=10");
counter.initialize(counterInitializationContext);
- Assertions.assertThat(BASIC_DISTRIBUTION_FORMULA.createMeasure(counter, fileCreateMeasureContext)).isAbsent();
+ assertThat(BASIC_DISTRIBUTION_FORMULA.createMeasure(counter, fileCreateMeasureContext)).isNotPresent();
}
private void addMeasure(String metricKey, String value) {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/IntSumFormulaTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/IntSumFormulaTest.java
index 3338ae9f1ce..71a685ea9ad 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/IntSumFormulaTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/IntSumFormulaTest.java
@@ -19,9 +19,8 @@
*/
package org.sonar.ce.task.projectanalysis.formula;
-import com.google.common.base.Optional;
+import java.util.Optional;
import javax.annotation.Nullable;
-import org.assertj.guava.api.Assertions;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -144,7 +143,7 @@ public class IntSumFormulaTest {
}
private void assertCreateNoMeasure(IntSumCounter counter) {
- Assertions.assertThat(INT_SUM_FORMULA.createMeasure(counter, projectCreateMeasureContext)).isAbsent();
+ assertThat(INT_SUM_FORMULA.createMeasure(counter, projectCreateMeasureContext)).isNotPresent();
}
private void assertCreateMeasureValue(IntSumCounter counter, int expectMeasureValue) {
@@ -154,7 +153,7 @@ public class IntSumFormulaTest {
private void initialize_does_not_create_measure_on_file(IntSumCounter counter) {
counter.initialize(createMeasureInInitContext(10));
- Assertions.assertThat(INT_SUM_FORMULA.createMeasure(counter, fileCreateMeasureContext)).isAbsent();
+ assertThat(INT_SUM_FORMULA.createMeasure(counter, fileCreateMeasureContext)).isNotPresent();
}
private static CounterInitializationContext createMeasureInInitContext(int value) {
@@ -165,7 +164,7 @@ public class IntSumFormulaTest {
private static CounterInitializationContext createNoMeasureInInitContext() {
CounterInitializationContext initContext = mock(CounterInitializationContext.class);
- when(initContext.getMeasure(LINES_KEY)).thenReturn(Optional.absent());
+ when(initContext.getMeasure(LINES_KEY)).thenReturn(Optional.empty());
return initContext;
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/LongSumFormulaTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/LongSumFormulaTest.java
index 3bb9101060d..dd6d121df98 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/LongSumFormulaTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/LongSumFormulaTest.java
@@ -19,9 +19,8 @@
*/
package org.sonar.ce.task.projectanalysis.formula;
-import com.google.common.base.Optional;
+import java.util.Optional;
import javax.annotation.Nullable;
-import org.assertj.guava.api.Assertions;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -143,7 +142,7 @@ public class LongSumFormulaTest {
}
private void assertCreateNoMeasure(LongSumCounter counter) {
- Assertions.assertThat(LONG_SUM_FORMULA.createMeasure(counter, projectCreateMeasureContext)).isAbsent();
+ assertThat(LONG_SUM_FORMULA.createMeasure(counter, projectCreateMeasureContext)).isNotPresent();
}
private void assertCreateMeasureValue(LongSumCounter counter, long expectMeasureValue) {
@@ -153,7 +152,7 @@ public class LongSumFormulaTest {
private void initialize_does_not_create_measure_on_file(LongSumCounter counter) {
counter.initialize(createMeasureInInitContext(10));
- Assertions.assertThat(LONG_SUM_FORMULA.createMeasure(counter, fileCreateMeasureContext)).isAbsent();
+ assertThat(LONG_SUM_FORMULA.createMeasure(counter, fileCreateMeasureContext)).isNotPresent();
}
private static CounterInitializationContext createMeasureInInitContext(long value) {
@@ -164,7 +163,7 @@ public class LongSumFormulaTest {
private static CounterInitializationContext createNoMeasureInInitContext() {
CounterInitializationContext initContext = mock(CounterInitializationContext.class);
- when(initContext.getMeasure(LINES_KEY)).thenReturn(Optional.absent());
+ when(initContext.getMeasure(LINES_KEY)).thenReturn(Optional.empty());
return initContext;
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java
index 7d4944a18ab..2872d301d91 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java
@@ -19,8 +19,8 @@
*/
package org.sonar.ce.task.projectanalysis.formula;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
+import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -401,7 +401,7 @@ public class ReportFormulaExecutorComponentVisitorTest {
.setVariation(measureVariations.getValue())
.createNoValue());
}
- return Optional.absent();
+ return Optional.empty();
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java
index 2dac82ceef7..59a36633418 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java
@@ -19,8 +19,8 @@
*/
package org.sonar.ce.task.projectanalysis.formula;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
+import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.measures.CoreMetrics;
@@ -293,7 +293,7 @@ public class ViewsFormulaExecutorComponentVisitorTest {
.setVariation(measureVariations.getValue())
.createNoValue());
}
- return Optional.absent();
+ return Optional.empty();
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/IntSumCounterTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/IntSumCounterTest.java
index 705df0b8aab..f3a7f7f4a63 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/IntSumCounterTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/IntSumCounterTest.java
@@ -19,13 +19,12 @@
*/
package org.sonar.ce.task.projectanalysis.formula.counter;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.junit.Test;
import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -40,7 +39,7 @@ public class IntSumCounterTest {
@Test
public void no_value_when_no_aggregation() {
- assertThat(sumCounter.getValue()).isAbsent();
+ assertThat(sumCounter.getValue()).isNotPresent();
}
@Test
@@ -54,11 +53,11 @@ public class IntSumCounterTest {
@Test
public void no_value_when_aggregate_from_context_but_no_measure() {
- when(counterInitializationContext.getMeasure(anyString())).thenReturn(Optional.absent());
+ when(counterInitializationContext.getMeasure(anyString())).thenReturn(Optional.empty());
sumCounter.initialize(counterInitializationContext);
- assertThat(sumCounter.getValue()).isAbsent();
+ assertThat(sumCounter.getValue()).isNotPresent();
}
@Test
@@ -78,7 +77,7 @@ public class IntSumCounterTest {
sumCounter.aggregate(anotherCounter);
- assertThat(sumCounter.getValue()).isAbsent();
+ assertThat(sumCounter.getValue()).isNotPresent();
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/LongSumCounterTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/LongSumCounterTest.java
index 94c4ad42db8..f9443279a38 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/LongSumCounterTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/LongSumCounterTest.java
@@ -19,13 +19,12 @@
*/
package org.sonar.ce.task.projectanalysis.formula.counter;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.junit.Test;
import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -41,7 +40,7 @@ public class LongSumCounterTest {
@Test
public void no_value_when_no_aggregation() {
- assertThat(sumCounter.getValue()).isAbsent();
+ assertThat(sumCounter.getValue()).isNotPresent();
}
@Test
@@ -55,11 +54,11 @@ public class LongSumCounterTest {
@Test
public void no_value_when_aggregate_from_context_but_no_measure() {
- when(counterInitializationContext.getMeasure(anyString())).thenReturn(Optional.absent());
+ when(counterInitializationContext.getMeasure(anyString())).thenReturn(Optional.empty());
sumCounter.initialize(counterInitializationContext);
- assertThat(sumCounter.getValue()).isAbsent();
+ assertThat(sumCounter.getValue()).isNotPresent();
}
@Test
@@ -79,7 +78,7 @@ public class LongSumCounterTest {
sumCounter.aggregate(anotherCounter);
- assertThat(sumCounter.getValue()).isAbsent();
+ assertThat(sumCounter.getValue()).isNotPresent();
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java
index b0933675b2f..aefbcdc5d17 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java
@@ -19,9 +19,9 @@
*/
package org.sonar.ce.task.projectanalysis.formula.coverage;
-import com.google.common.base.Optional;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -130,7 +130,7 @@ public class CoverageUtilsTest {
@Override
public Optional<Measure> getMeasure(String metricKey) {
- return Optional.fromNullable(measures.get(metricKey));
+ return Optional.ofNullable(measures.get(metricKey));
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImplTest.java
index a24300e79b4..49b273e8d2b 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImplTest.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.language;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.junit.Test;
import org.sonar.api.resources.Language;
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java
index 3e46760891c..8c417c2dae2 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java
@@ -19,9 +19,9 @@
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.google.common.base.Optional;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import java.util.Optional;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sonar.ce.task.projectanalysis.metric.Metric;
@@ -34,7 +34,6 @@ import org.sonar.scanner.protocol.output.ScannerReport.Measure.LongValue;
import org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
@RunWith(DataProviderRunner.class)
public class BatchMeasureToMeasureTest {
@@ -52,7 +51,7 @@ public class BatchMeasureToMeasureTest {
@Test
public void toMeasure_returns_absent_for_null_argument() {
- assertThat(underTest.toMeasure(null, SOME_INT_METRIC)).isAbsent();
+ assertThat(underTest.toMeasure(null, SOME_INT_METRIC)).isNotPresent();
}
@Test(expected = NullPointerException.class)
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java
index 83552d3b4ee..b5ad70c2487 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java
@@ -19,10 +19,10 @@
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.google.common.base.Optional;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
+import java.util.Optional;
import org.assertj.core.data.Offset;
import org.junit.Rule;
import org.junit.Test;
@@ -34,7 +34,6 @@ import org.sonar.ce.task.projectanalysis.metric.MetricImpl;
import org.sonar.db.measure.LiveMeasureDto;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
@RunWith(DataProviderRunner.class)
public class LiveMeasureDtoToMeasureTest {
@@ -56,7 +55,7 @@ public class LiveMeasureDtoToMeasureTest {
@Test
public void toMeasure_returns_absent_for_null_argument() {
- assertThat(underTest.toMeasure(null, SOME_INT_METRIC)).isAbsent();
+ assertThat(underTest.toMeasure(null, SOME_INT_METRIC)).isNotPresent();
}
@Test(expected = NullPointerException.class)
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java
index fad761f8ffa..6d2ff029a6c 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java
@@ -20,13 +20,13 @@
package org.sonar.ce.task.projectanalysis.measure;
import com.google.common.base.Function;
-import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -53,7 +53,6 @@ import org.sonar.db.rule.RuleDto;
import static com.google.common.collect.FluentIterable.from;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -156,7 +155,7 @@ public class MapBasedRawMeasureRepositoryTest {
Measure.newMeasureBuilder().create("sds"),
Measure.newMeasureBuilder().create(Measure.Level.OK),
Measure.newMeasureBuilder().createNoValue()
- );
+ );
@DataProvider
public static Object[][] measures() {
@@ -261,8 +260,8 @@ public class MapBasedRawMeasureRepositoryTest {
assertThat(res.get()).isSameAs(SOME_MEASURE);
// make sure we really match on the specified component and metric
- assertThat(underTest.getRawMeasure(OTHER_COMPONENT, metric1)).isAbsent();
- assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric2)).isAbsent();
+ assertThat(underTest.getRawMeasure(OTHER_COMPONENT, metric1)).isNotPresent();
+ assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric2)).isNotPresent();
}
@Test(expected = NullPointerException.class)
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java
index f0c1008d38f..26c29b9083a 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java
@@ -19,8 +19,8 @@
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.google.common.base.Optional;
import java.util.Objects;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.data.Offset;
@@ -38,7 +38,7 @@ public class MeasureAssert extends AbstractAssert<MeasureAssert, Measure> {
}
public static MeasureAssert assertThat(@Nullable Optional<Measure> actual) {
- return new MeasureAssert(actual == null ? null : actual.orNull());
+ return new MeasureAssert(actual == null ? null : actual.orElse(null));
}
public MeasureAssert hasValueType(Measure.ValueType expected) {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java
index 23cda6c1527..f048d61e446 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java
@@ -19,10 +19,10 @@
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.google.common.base.Optional;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
+import java.util.Optional;
import org.assertj.core.data.Offset;
import org.junit.Rule;
import org.junit.Test;
@@ -34,7 +34,6 @@ import org.sonar.ce.task.projectanalysis.metric.MetricImpl;
import org.sonar.db.measure.MeasureDto;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
@RunWith(DataProviderRunner.class)
public class MeasureDtoToMeasureTest {
@@ -56,7 +55,7 @@ public class MeasureDtoToMeasureTest {
@Test
public void toMeasure_returns_absent_for_null_argument() {
- assertThat(underTest.toMeasure(null, SOME_INT_METRIC)).isAbsent();
+ assertThat(underTest.toMeasure(null, SOME_INT_METRIC)).isNotPresent();
}
@Test(expected = NullPointerException.class)
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureLevelTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureLevelTest.java
index c726580c562..1caed09734b 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureLevelTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureLevelTest.java
@@ -27,7 +27,7 @@ import static org.assertj.guava.api.Assertions.assertThat;
public class MeasureLevelTest {
@Test
public void toLevel_return_absent_for_null_arg() {
- assertThat(Measure.Level.toLevel(null)).isAbsent();
+ assertThat(Measure.Level.toLevel(null)).isNotPresent();
}
@Test
@@ -40,12 +40,12 @@ public class MeasureLevelTest {
@Test
public void toLevel_is_case_sensitive_and_returns_absent() {
for (Measure.Level level : Measure.Level.values()) {
- assertThat(Measure.Level.toLevel(level.name().toLowerCase())).isAbsent();
+ assertThat(Measure.Level.toLevel(level.name().toLowerCase())).isNotPresent();
}
}
@Test
public void toLevel_returns_absent_when_value_is_unknown() {
- assertThat(Measure.Level.toLevel("trololo")).isAbsent();
+ assertThat(Measure.Level.toLevel("trololo")).isNotPresent();
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java
index c834a8b826f..3bc465bb188 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java
@@ -20,7 +20,6 @@
package org.sonar.ce.task.projectanalysis.measure;
import com.google.common.base.Function;
-import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.SetMultimap;
@@ -28,6 +27,7 @@ import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.util.List;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.Rule;
@@ -53,7 +53,6 @@ import org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue;
import static com.google.common.collect.FluentIterable.from;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -133,7 +132,7 @@ public class MeasureRepositoryImplTest {
public void getBaseMeasure_returns_absent_if_measure_does_not_exist_in_DB() {
Optional<Measure> res = underTest.getBaseMeasure(FILE_COMPONENT, metric1);
- assertThat(res).isAbsent();
+ assertThat(res).isNotPresent();
}
@Test
@@ -152,7 +151,7 @@ public class MeasureRepositoryImplTest {
// metric 2 is associated to snapshot with "last=false" => not retrieved
res = underTest.getBaseMeasure(FILE_COMPONENT, metric2);
- assertThat(res).isAbsent();
+ assertThat(res).isNotPresent();
}
@Test
@@ -318,8 +317,8 @@ public class MeasureRepositoryImplTest {
assertThat(res.get()).isSameAs(SOME_MEASURE);
// make sure we really match on the specified component and metric
- assertThat(underTest.getRawMeasure(OTHER_COMPONENT, metric1)).isAbsent();
- assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric2)).isAbsent();
+ assertThat(underTest.getRawMeasure(OTHER_COMPONENT, metric1)).isNotPresent();
+ assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric2)).isNotPresent();
}
@Test
@@ -337,8 +336,8 @@ public class MeasureRepositoryImplTest {
assertThat(res.get().getStringValue()).isEqualTo(value);
// make sure we really match on the specified component and metric
- assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric2)).isAbsent();
- assertThat(underTest.getRawMeasure(OTHER_COMPONENT, metric1)).isAbsent();
+ assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric2)).isNotPresent();
+ assertThat(underTest.getRawMeasure(OTHER_COMPONENT, metric1)).isNotPresent();
}
@Test
@@ -351,7 +350,7 @@ public class MeasureRepositoryImplTest {
ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_2).setStringValue(StringValue.newBuilder().setValue("value2")).build()));
assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric1)).isPresent();
- assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric2)).isAbsent();
+ assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric2)).isNotPresent();
}
@Test
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java
index 968f75f43ac..5a5616aca0d 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java
@@ -20,7 +20,6 @@
package org.sonar.ce.task.projectanalysis.measure;
import com.google.common.base.Function;
-import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.SetMultimap;
@@ -28,6 +27,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
@@ -151,7 +151,7 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe
Set<Measure> measures = getAddedRawMeasures(componentProvider.getByRef(componentRef)).get(metricKey);
if (measures.isEmpty()) {
- return Optional.absent();
+ return Optional.empty();
}
checkArgument(measures.size() == 1, String.format("There is more than one measure on metric '%s' for component '%s'", metricKey, componentRef));
return Optional.of(measures.iterator().next());
@@ -187,7 +187,7 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe
@Override
public Optional<Measure> getBaseMeasure(Component component, Metric metric) {
- return Optional.fromNullable(baseMeasures.get(new InternalKey(component, metric)));
+ return Optional.ofNullable(baseMeasures.get(new InternalKey(component, metric)));
}
public Collection<Component> getComponentsLoadedAsRaw() {
@@ -200,15 +200,15 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe
@Override
public Optional<Measure> getRawMeasure(Component component, Metric metric) {
- return Optional.fromNullable(rawMeasures.get(new InternalKey(component, metric)));
+ return Optional.ofNullable(rawMeasures.get(new InternalKey(component, metric)));
}
public Optional<Measure> getRawMeasure(Component component, Metric metric, DumbDeveloper developer) {
- return Optional.fromNullable(rawMeasures.get(new InternalKey(component, metric, developer)));
+ return Optional.ofNullable(rawMeasures.get(new InternalKey(component, metric, developer)));
}
public Optional<Measure> getRawRuleMeasure(Component component, Metric metric, int ruleId) {
- return Optional.fromNullable(rawMeasures.get(new InternalKey(component, metric, null)));
+ return Optional.ofNullable(rawMeasures.get(new InternalKey(component, metric, null)));
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitorTest.java
index f1049cc9bc6..3b5c087cebc 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitorTest.java
@@ -19,8 +19,8 @@
*/
package org.sonar.ce.task.projectanalysis.source;
-import com.google.common.base.Optional;
import com.google.common.collect.Lists;
+import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.measures.CoreMetrics;
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStepTest.java
index 687cd705196..e273e627615 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStepTest.java
@@ -30,7 +30,6 @@ import org.sonar.ce.task.step.ComputationStep;
import org.sonar.ce.task.step.TestComputationStepContext;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
import static org.sonar.api.measures.CoreMetrics.DUPLICATIONS_DATA;
import static org.sonar.api.measures.CoreMetrics.DUPLICATIONS_DATA_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
@@ -80,8 +79,8 @@ public class DuplicationDataMeasuresStepTest extends BaseStepTest {
public void nothing_to_do_when_no_duplication() {
underTest.execute(new TestComputationStepContext());
- assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, DUPLICATIONS_DATA_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, DUPLICATIONS_DATA_KEY)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, DUPLICATIONS_DATA_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, DUPLICATIONS_DATA_KEY)).isNotPresent();
}
@Test
@@ -94,7 +93,7 @@ public class DuplicationDataMeasuresStepTest extends BaseStepTest {
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, DUPLICATIONS_DATA_KEY).get().getData()).isEqualTo(
"<duplications><g><b s=\"1\" l=\"5\" t=\"false\" r=\"" + FILE_1_KEY + "\"/><b s=\"6\" l=\"5\" t=\"false\" r=\""
+ FILE_1_KEY + "\"/></g></duplications>");
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, DUPLICATIONS_DATA_KEY)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, DUPLICATIONS_DATA_KEY)).isNotPresent();
}
@Test
@@ -107,7 +106,7 @@ public class DuplicationDataMeasuresStepTest extends BaseStepTest {
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, DUPLICATIONS_DATA_KEY).get().getData()).isEqualTo(
"<duplications><g><b s=\"1\" l=\"5\" t=\"false\" r=\"" + FILE_1_KEY + "\"/><b s=\"6\" l=\"5\" t=\"false\" r=\""
+ FILE_2_KEY + "\"/></g></duplications>");
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, DUPLICATIONS_DATA_KEY)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, DUPLICATIONS_DATA_KEY)).isNotPresent();
}
@Test
@@ -120,7 +119,7 @@ public class DuplicationDataMeasuresStepTest extends BaseStepTest {
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, DUPLICATIONS_DATA_KEY).get().getData()).isEqualTo(
"<duplications><g><b s=\"1\" l=\"5\" t=\"false\" r=\"" + FILE_1_KEY + "\"/><b s=\"6\" l=\"5\" t=\"true\" r=\""
+ FILE_2_KEY + "\"/></g></duplications>");
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, DUPLICATIONS_DATA_KEY)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, DUPLICATIONS_DATA_KEY)).isNotPresent();
}
@Test
@@ -134,7 +133,7 @@ public class DuplicationDataMeasuresStepTest extends BaseStepTest {
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, DUPLICATIONS_DATA_KEY).get().getData()).isEqualTo(
"<duplications><g><b s=\"1\" l=\"5\" t=\"false\" r=\"" + FILE_1_KEY + "\"/><b s=\"6\" l=\"5\" t=\"false\" r=\""
+ fileKeyFromOtherProject + "\"/></g></duplications>");
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, DUPLICATIONS_DATA_KEY)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, DUPLICATIONS_DATA_KEY)).isNotPresent();
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStepTest.java
index e08097564cb..ff08f0cb2c4 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStepTest.java
@@ -37,7 +37,6 @@ import org.sonar.ce.task.step.TestComputationStepContext;
import static com.google.common.base.Preconditions.checkArgument;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.api.measures.CoreMetrics.NEW_BLOCKS_DUPLICATED;
@@ -411,7 +410,7 @@ public class NewSizeMeasuresStepTest {
}
private void assertNoRawMeasure(int componentRef, String metricKey) {
- assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)).isNotPresent();
}
private void assertNoRawMeasures(String metricKey) {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java
index 32bb8fcfab6..bd0dd84d13a 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.step;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -92,14 +92,15 @@ public class QualityGateEventsStepTest {
@Before
public void setUp() {
when(metricRepository.getByKey(ALERT_STATUS_KEY)).thenReturn(alertStatusMetric);
- analysisMetadataHolder.setProject(new Project(PROJECT_COMPONENT.getUuid(), PROJECT_COMPONENT.getDbKey(), PROJECT_COMPONENT.getName(), PROJECT_COMPONENT.getDescription(), emptyList()));
+ analysisMetadataHolder
+ .setProject(new Project(PROJECT_COMPONENT.getUuid(), PROJECT_COMPONENT.getDbKey(), PROJECT_COMPONENT.getName(), PROJECT_COMPONENT.getDescription(), emptyList()));
analysisMetadataHolder.setBranch(mock(Branch.class));
treeRootHolder.setRoot(PROJECT_COMPONENT);
}
@Test
public void no_event_if_no_raw_ALERT_STATUS_measure() {
- when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(Optional.absent());
+ when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(Optional.empty());
underTest.execute(new TestComputationStepContext());
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java
index 8f0fe48d65e..e6f7ef048ef 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java
@@ -19,7 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.step;
-import com.google.common.base.Optional;
+import java.util.Optional;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStepTest.java
index 212cc08b711..fc772bc3dd0 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStepTest.java
@@ -19,12 +19,12 @@
*/
package org.sonar.ce.task.projectanalysis.step;
-import com.google.common.base.Optional;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
import org.junit.Before;
@@ -89,7 +89,7 @@ public class QualityProfileEventsStepTest {
@Test
public void no_event_if_no_base_measure() {
- when(measureRepository.getBaseMeasure(treeRootHolder.getRoot(), qualityProfileMetric)).thenReturn(Optional.absent());
+ when(measureRepository.getBaseMeasure(treeRootHolder.getRoot(), qualityProfileMetric)).thenReturn(Optional.empty());
underTest.execute(new TestComputationStepContext());
@@ -99,7 +99,7 @@ public class QualityProfileEventsStepTest {
@Test
public void no_event_if_no_raw_measure() {
when(measureRepository.getBaseMeasure(treeRootHolder.getRoot(), qualityProfileMetric)).thenReturn(Optional.of(newMeasure()));
- when(measureRepository.getRawMeasure(treeRootHolder.getRoot(), qualityProfileMetric)).thenReturn(Optional.absent());
+ when(measureRepository.getRawMeasure(treeRootHolder.getRoot(), qualityProfileMetric)).thenReturn(Optional.empty());
underTest.execute(new TestComputationStepContext());
@@ -242,11 +242,11 @@ public class QualityProfileEventsStepTest {
}
private void mockLanguageNotInRepository(String languageKey) {
- when(languageRepository.find(languageKey)).thenReturn(Optional.absent());
+ when(languageRepository.find(languageKey)).thenReturn(Optional.empty());
}
private void mockNoLanguageInRepository() {
- when(languageRepository.find(anyString())).thenReturn(Optional.absent());
+ when(languageRepository.find(anyString())).thenReturn(Optional.empty());
}
private void mockMeasures(Component component, @Nullable QualityProfile[] previous, @Nullable QualityProfile[] current) {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportCommentMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportCommentMeasuresStepTest.java
index ee72a91fad5..dee159291ba 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportCommentMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportCommentMeasuresStepTest.java
@@ -104,8 +104,8 @@ public class ReportCommentMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, COMMENTED_OUT_CODE_LINES_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, COMMENTED_OUT_CODE_LINES_KEY)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, COMMENTED_OUT_CODE_LINES_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, COMMENTED_OUT_CODE_LINES_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, COMMENTED_OUT_CODE_LINES_KEY).get().getIntValue()).isEqualTo(500);
assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, COMMENTED_OUT_CODE_LINES_KEY).get().getIntValue()).isEqualTo(500);
assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, COMMENTED_OUT_CODE_LINES_KEY).get().getIntValue()).isEqualTo(500);
@@ -119,8 +119,8 @@ public class ReportCommentMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, COMMENT_LINES_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, COMMENT_LINES_KEY)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, COMMENT_LINES_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, COMMENT_LINES_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, COMMENT_LINES_KEY).get().getIntValue()).isEqualTo(500);
assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, COMMENT_LINES_KEY).get().getIntValue()).isEqualTo(500);
assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, COMMENT_LINES_KEY).get().getIntValue()).isEqualTo(500);
@@ -219,8 +219,8 @@ public class ReportCommentMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, PUBLIC_API_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, PUBLIC_API_KEY)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, PUBLIC_API_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, PUBLIC_API_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, PUBLIC_API_KEY).get().getIntValue()).isEqualTo(500);
assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, PUBLIC_API_KEY).get().getIntValue()).isEqualTo(500);
assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, PUBLIC_API_KEY).get().getIntValue()).isEqualTo(500);
@@ -234,8 +234,8 @@ public class ReportCommentMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, PUBLIC_UNDOCUMENTED_API_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, PUBLIC_UNDOCUMENTED_API_KEY)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, PUBLIC_UNDOCUMENTED_API_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, PUBLIC_UNDOCUMENTED_API_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, PUBLIC_UNDOCUMENTED_API_KEY).get().getIntValue()).isEqualTo(500);
assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, PUBLIC_UNDOCUMENTED_API_KEY).get().getIntValue()).isEqualTo(500);
assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, PUBLIC_UNDOCUMENTED_API_KEY).get().getIntValue()).isEqualTo(500);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportComplexityMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportComplexityMeasuresStepTest.java
index ca2bfb009b7..ef51cc47acf 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportComplexityMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportComplexityMeasuresStepTest.java
@@ -29,7 +29,6 @@ import org.sonar.ce.task.step.ComputationStep;
import org.sonar.ce.task.step.TestComputationStepContext;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
import static org.sonar.api.measures.CoreMetrics.CLASSES;
import static org.sonar.api.measures.CoreMetrics.CLASSES_KEY;
import static org.sonar.api.measures.CoreMetrics.CLASS_COMPLEXITY;
@@ -139,8 +138,8 @@ public class ReportComplexityMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isNotPresent();
int expectedNonFileValue = 50;
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue)));
@@ -170,8 +169,8 @@ public class ReportComplexityMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isNotPresent();
String expectedNonFileValue = "0.5=3;3.5=7;6.5=10";
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue)));
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportLanguageDistributionMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportLanguageDistributionMeasuresStepTest.java
index 189a496e32a..d225ff26779 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportLanguageDistributionMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportLanguageDistributionMeasuresStepTest.java
@@ -30,7 +30,6 @@ import org.sonar.ce.task.step.ComputationStep;
import org.sonar.ce.task.step.TestComputationStepContext;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
import static org.sonar.api.measures.CoreMetrics.NCLOC;
import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
import static org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION;
@@ -114,15 +113,15 @@ public class ReportLanguageDistributionMeasuresStepTest {
public void do_not_compute_ncloc_language_distribution_when_no_ncloc() {
underTest.execute(new TestComputationStepContext());
- assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_3_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_4_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_3_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_4_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isNotPresent();
- assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isNotPresent();
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportUnitTestMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportUnitTestMeasuresStepTest.java
index 0b4b6ea07fe..8ffa3ad9d37 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportUnitTestMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportUnitTestMeasuresStepTest.java
@@ -30,7 +30,6 @@ import org.sonar.ce.task.step.ComputationStep;
import org.sonar.ce.task.step.TestComputationStepContext;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
import static org.sonar.api.measures.CoreMetrics.SKIPPED_TESTS;
import static org.sonar.api.measures.CoreMetrics.SKIPPED_TESTS_KEY;
import static org.sonar.api.measures.CoreMetrics.TESTS;
@@ -233,12 +232,12 @@ public class ReportUnitTestMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
}
@Test
@@ -251,12 +250,12 @@ public class ReportUnitTestMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
}
@Test
@@ -313,8 +312,8 @@ public class ReportUnitTestMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isNotPresent();
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
@@ -327,8 +326,8 @@ public class ReportUnitTestMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isAbsent();
- assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isNotPresent();
+ assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isNotPresent();
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsCommentMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsCommentMeasuresStepTest.java
index 670b048ae57..52727b690f7 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsCommentMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsCommentMeasuresStepTest.java
@@ -314,7 +314,7 @@ public class ViewsCommentMeasuresStepTest {
}
private void assertNoRawMeasure(String metricKey, int componentRef) {
- assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)).isNotPresent();
}
private void addRawMeasure(int componentRef, String metricKey, int value) {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsUnitTestMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsUnitTestMeasuresStepTest.java
index bf83094d7e6..2a69c61ec55 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsUnitTestMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsUnitTestMeasuresStepTest.java
@@ -286,7 +286,7 @@ public class ViewsUnitTestMeasuresStepTest {
}
private void assertNoAddedRawMeasure(int componentRef, String metricKey) {
- assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)).isAbsent();
+ assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)).isNotPresent();
}
private void assertAddedRawMeasureValue(int componentRef, String metricKey, int expectedValue) {