diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2018-07-03 12:26:32 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2018-07-09 10:39:33 +0200 |
commit | 9e3bc71eb9e0ac3b384c2fbfaa8355596e5ea7f2 (patch) | |
tree | 5aa1306fd44789b6d17b3274c353420f492727d5 /server/sonar-server | |
parent | 12349c8c275dc316e09451c4f468376e26be53b3 (diff) | |
download | sonarqube-9e3bc71eb9e0ac3b384c2fbfaa8355596e5ea7f2.tar.gz sonarqube-9e3bc71eb9e0ac3b384c2fbfaa8355596e5ea7f2.zip |
sonar-ce-task-projectanalysis depends on only sonar-server-common
Diffstat (limited to 'server/sonar-server')
27 files changed, 1 insertions, 1775 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/organization/DefaultOrganizationLoader.java b/server/sonar-server/src/main/java/org/sonar/server/computation/organization/DefaultOrganizationLoader.java deleted file mode 100644 index 6ec301fc39e..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/organization/DefaultOrganizationLoader.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.computation.organization; - -import org.picocontainer.Startable; -import org.sonar.api.ce.ComputeEngineSide; -import org.sonar.ce.task.container.EagerStart; -import org.sonar.server.organization.DefaultOrganizationCache; - -@EagerStart -@ComputeEngineSide -public class DefaultOrganizationLoader implements Startable { - private final DefaultOrganizationCache defaultOrganizationCache; - - public DefaultOrganizationLoader(DefaultOrganizationCache defaultOrganizationCache) { - this.defaultOrganizationCache = defaultOrganizationCache; - } - - @Override - public void start() { - defaultOrganizationCache.load(); - } - - @Override - public void stop() { - defaultOrganizationCache.unload(); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/organization/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/computation/organization/package-info.java deleted file mode 100644 index 236691aec20..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/organization/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.ce.task.organization; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/settings/SettingsLoader.java b/server/sonar-server/src/main/java/org/sonar/server/computation/settings/SettingsLoader.java deleted file mode 100644 index a06aea409b8..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/settings/SettingsLoader.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.computation.settings; - -import org.picocontainer.Startable; -import org.sonar.api.ce.ComputeEngineSide; -import org.sonar.ce.task.container.EagerStart; -import org.sonar.ce.task.container.TaskContainerImpl; -import org.sonar.server.setting.ThreadLocalSettings; - -/** - * Add this class as the first components in the {@link TaskContainerImpl} - * to trigger loading of Thread local specific {@link org.sonar.api.config.Settings} in {@link ThreadLocalSettings}. - */ -@EagerStart -@ComputeEngineSide -public class SettingsLoader implements Startable { - private final ThreadLocalSettings threadLocalSettings; - - public SettingsLoader(ThreadLocalSettings threadLocalSettings) { - this.threadLocalSettings = threadLocalSettings; - } - - @Override - public void start() { - threadLocalSettings.load(); - } - - @Override - public void stop() { - threadLocalSettings.unload(); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/settings/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/computation/settings/package-info.java deleted file mode 100644 index 71c26a744ea..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/settings/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.ce.task.settings; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/DebtRatingGrid.java b/server/sonar-server/src/main/java/org/sonar/server/measure/DebtRatingGrid.java deleted file mode 100644 index faac02fc016..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/DebtRatingGrid.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.measure; - -import com.google.common.annotations.VisibleForTesting; -import java.util.Arrays; -import java.util.EnumMap; -import java.util.Map; -import org.sonar.api.config.Configuration; - -import static com.google.common.base.Preconditions.checkState; -import static java.lang.String.format; -import static org.sonar.api.CoreProperties.RATING_GRID; -import static org.sonar.api.CoreProperties.RATING_GRID_DEF_VALUES; -import static org.sonar.server.measure.Rating.A; -import static org.sonar.server.measure.Rating.B; -import static org.sonar.server.measure.Rating.C; -import static org.sonar.server.measure.Rating.D; -import static org.sonar.server.measure.Rating.E; - -public class DebtRatingGrid { - - private final double[] gridValues; - private final EnumMap<Rating, Bounds> ratingBounds; - - public DebtRatingGrid(Configuration config) { - try { - String[] grades = config.getStringArray(RATING_GRID); - gridValues = new double[4]; - for (int i = 0; i < 4; i++) { - gridValues[i] = Double.parseDouble(grades[i]); - } - this.ratingBounds = buildRatingBounds(gridValues); - } catch (Exception e) { - throw new IllegalArgumentException("The rating grid is incorrect. Expected something similar to '" - + RATING_GRID_DEF_VALUES + "' and got '" + config.get(RATING_GRID).orElse("") + "'", e); - } - } - - public DebtRatingGrid(double[] gridValues) { - this.gridValues = Arrays.copyOf(gridValues, gridValues.length); - this.ratingBounds = buildRatingBounds(gridValues); - } - - private static EnumMap<Rating, Bounds> buildRatingBounds(double[] gridValues) { - checkState(gridValues.length == 4, "Rating grid should contains 4 values"); - EnumMap<Rating, Bounds> ratingBounds = new EnumMap<>(Rating.class); - ratingBounds.put(A, new Bounds(0d, gridValues[0])); - ratingBounds.put(B, new Bounds(gridValues[0], gridValues[1])); - ratingBounds.put(C, new Bounds(gridValues[1], gridValues[2])); - ratingBounds.put(D, new Bounds(gridValues[2], gridValues[3])); - ratingBounds.put(E, new Bounds(gridValues[3], Double.MAX_VALUE)); - return ratingBounds; - } - - public Rating getRatingForDensity(double value) { - return ratingBounds.entrySet().stream() - .filter(e -> e.getValue().match(value)) - .map(Map.Entry::getKey) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException(format("Invalid value '%s'", value))); - } - - public double getGradeLowerBound(Rating rating) { - if (rating.getIndex() > 1) { - return gridValues[rating.getIndex() - 2]; - } - return 0; - } - - @VisibleForTesting - public double[] getGridValues() { - return gridValues; - } - - private static class Bounds { - private final double lowerBound; - private final double higherBound; - private final boolean isLowerBoundInclusive; - - private Bounds(double lowerBound, double higherBound) { - this.lowerBound = lowerBound; - this.higherBound = higherBound; - this.isLowerBoundInclusive = lowerBound == 0; - } - - boolean match(double value) { - boolean lowerBoundMatch = isLowerBoundInclusive ? (value >= lowerBound) : (value > lowerBound); - return lowerBoundMatch && value <= higherBound; - } - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/Rating.java b/server/sonar-server/src/main/java/org/sonar/server/measure/Rating.java deleted file mode 100644 index 873f682f998..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/Rating.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.measure; - -import com.google.common.collect.ImmutableMap; -import java.util.Map; - -import static java.lang.String.format; -import static java.util.Arrays.stream; -import static org.sonar.api.rule.Severity.BLOCKER; -import static org.sonar.api.rule.Severity.CRITICAL; -import static org.sonar.api.rule.Severity.INFO; -import static org.sonar.api.rule.Severity.MAJOR; -import static org.sonar.api.rule.Severity.MINOR; - -public enum Rating { - E(5), - D(4), - C(3), - B(2), - A(1); - - private final int index; - - Rating(int index) { - this.index = index; - } - - public int getIndex() { - return index; - } - - public static Rating valueOf(int index) { - return stream(Rating.values()) - .filter(r -> r.getIndex() == index) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException(format("Unknown value '%s'", index))); - } - - public static final Map<String, Rating> RATING_BY_SEVERITY = ImmutableMap.of( - BLOCKER, E, - CRITICAL, D, - MAJOR, C, - MINOR, B, - INFO, A); -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ShortLivingBranchQualityGate.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ShortLivingBranchQualityGate.java deleted file mode 100644 index f77b6e65ee8..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ShortLivingBranchQualityGate.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.qualitygate; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import java.util.List; -import javax.annotation.CheckForNull; -import org.sonar.api.measures.CoreMetrics; - -import static org.sonar.db.qualitygate.QualityGateConditionDto.OPERATOR_GREATER_THAN; - -/** - * Offers constants describing the Hardcoded Quality Gate for short living branches and pull requests. - */ -public final class ShortLivingBranchQualityGate { - public static final long ID = -1_963_456_987L; - public static final String NAME = "Hardcoded short living branch quality gate"; - public static final List<Condition> CONDITIONS = ImmutableList.of( - new Condition(CoreMetrics.OPEN_ISSUES_KEY, OPERATOR_GREATER_THAN, "0", false), - new Condition(CoreMetrics.REOPENED_ISSUES_KEY, OPERATOR_GREATER_THAN, "0", false)); - - public static final QualityGate GATE = new QualityGate(String.valueOf(ID), NAME, ImmutableSet.of( - new org.sonar.server.qualitygate.Condition(CoreMetrics.OPEN_ISSUES_KEY, org.sonar.server.qualitygate.Condition.Operator.GREATER_THAN, "0", null, false), - new org.sonar.server.qualitygate.Condition(CoreMetrics.REOPENED_ISSUES_KEY, org.sonar.server.qualitygate.Condition.Operator.GREATER_THAN, "0", null, false))); - - private ShortLivingBranchQualityGate() { - // prevents instantiation - } - - public static final class Condition { - private final String metricKey; - private final String operator; - private final String errorThreshold; - private final boolean onLeak; - - public Condition(String metricKey, String operator, String errorThreshold, boolean onLeak) { - this.metricKey = metricKey; - this.operator = operator; - this.errorThreshold = errorThreshold; - this.onLeak = onLeak; - } - - public String getMetricKey() { - return metricKey; - } - - public String getOperator() { - return operator; - } - - public String getErrorThreshold() { - return errorThreshold; - } - - @CheckForNull - public String getWarnThreshold() { - return null; - } - - public boolean isOnLeak() { - return onLeak; - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QPMeasureData.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QPMeasureData.java deleted file mode 100644 index 8c4a40a68b3..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QPMeasureData.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.qualityprofile; - -import com.google.common.collect.ImmutableSortedSet; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import java.io.StringWriter; -import java.util.Comparator; -import java.util.Map; -import java.util.SortedSet; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; -import javax.annotation.concurrent.Immutable; -import org.sonar.api.utils.text.JsonWriter; -import org.sonar.core.util.UtcDateUtils; - -import static java.util.function.Function.identity; -import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex; - -/** - * Represents the array of JSON objects stored in the value of the - * {@link org.sonar.api.measures.CoreMetrics#QUALITY_PROFILES} measures. - */ -@Immutable -public class QPMeasureData { - - private final SortedSet<QualityProfile> profiles; - - public QPMeasureData(Iterable<QualityProfile> qualityProfiles) { - this.profiles = ImmutableSortedSet.copyOf(QualityProfileComparator.INSTANCE, qualityProfiles); - } - - public static QPMeasureData fromJson(String json) { - return new QPMeasureData(StreamSupport.stream(new JsonParser().parse(json).getAsJsonArray().spliterator(), false) - .map(jsonElement -> { - JsonObject jsonProfile = jsonElement.getAsJsonObject(); - return new QualityProfile( - jsonProfile.get("key").getAsString(), - jsonProfile.get("name").getAsString(), - jsonProfile.get("language").getAsString(), - UtcDateUtils.parseDateTime(jsonProfile.get("rulesUpdatedAt").getAsString())); - }).collect(Collectors.toList())); - } - - public static String toJson(QPMeasureData data) { - StringWriter json = new StringWriter(); - try (JsonWriter writer = JsonWriter.of(json)) { - writer.beginArray(); - for (QualityProfile profile : data.getProfiles()) { - writer - .beginObject() - .prop("key", profile.getQpKey()) - .prop("language", profile.getLanguageKey()) - .prop("name", profile.getQpName()) - .prop("rulesUpdatedAt", UtcDateUtils.formatDateTime(profile.getRulesUpdatedAt())) - .endObject(); - } - writer.endArray(); - } - return json.toString(); - } - - public SortedSet<QualityProfile> getProfiles() { - return profiles; - } - - public Map<String, QualityProfile> getProfilesByKey() { - return profiles.stream().collect(uniqueIndex(QualityProfile::getQpKey, identity())); - } - - private enum QualityProfileComparator implements Comparator<QualityProfile> { - INSTANCE; - - @Override - public int compare(QualityProfile o1, QualityProfile o2) { - int c = o1.getLanguageKey().compareTo(o2.getLanguageKey()); - if (c == 0) { - c = o1.getQpName().compareTo(o2.getQpName()); - } - return c; - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QualityProfile.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QualityProfile.java deleted file mode 100644 index 024319ad7f5..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QualityProfile.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.qualityprofile; - -import com.google.common.base.MoreObjects; -import java.util.Date; -import javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; - -import static java.util.Objects.requireNonNull; - -/** - * Represents the JSON object an array of which is stored in the value of the - * {@link org.sonar.api.measures.CoreMetrics#QUALITY_PROFILES} measures. - */ -@Immutable -public class QualityProfile { - private final String qpKey; - private final String qpName; - private final String languageKey; - private final Date rulesUpdatedAt; - - public QualityProfile(String qpKey, String qpName, String languageKey, Date rulesUpdatedAt) { - this.qpKey = requireNonNull(qpKey); - this.qpName = requireNonNull(qpName); - this.languageKey = requireNonNull(languageKey); - this.rulesUpdatedAt = requireNonNull(rulesUpdatedAt); - } - - public String getQpKey() { - return qpKey; - } - - public String getQpName() { - return qpName; - } - - public String getLanguageKey() { - return languageKey; - } - - public Date getRulesUpdatedAt() { - return new Date(rulesUpdatedAt.getTime()); - } - - @Override - public boolean equals(@Nullable Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - QualityProfile qProfile = (QualityProfile) o; - return qpKey.equals(qProfile.qpKey); - } - - @Override - public int hashCode() { - return qpKey.hashCode(); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("key", qpKey) - .add("name", qpName) - .add("language", languageKey) - .add("rulesUpdatedAt", rulesUpdatedAt.getTime()) - .toString(); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/CommonRuleKeys.java b/server/sonar-server/src/main/java/org/sonar/server/rule/CommonRuleKeys.java deleted file mode 100644 index 2c3a7aa2bc0..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/CommonRuleKeys.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.rule; - -public class CommonRuleKeys { - - public static final String REPOSITORY_PREFIX = "common-"; - - public static final String INSUFFICIENT_BRANCH_COVERAGE = "InsufficientBranchCoverage"; - public static final String INSUFFICIENT_BRANCH_COVERAGE_PROPERTY = "minimumBranchCoverageRatio"; - - public static final String INSUFFICIENT_LINE_COVERAGE = "InsufficientLineCoverage"; - public static final String INSUFFICIENT_LINE_COVERAGE_PROPERTY = "minimumLineCoverageRatio"; - - public static final String INSUFFICIENT_COMMENT_DENSITY = "InsufficientCommentDensity"; - public static final String INSUFFICIENT_COMMENT_DENSITY_PROPERTY = "minimumCommentDensity"; - - public static final String DUPLICATED_BLOCKS = "DuplicatedBlocks"; - public static final String FAILED_UNIT_TESTS = "FailedUnitTests"; - public static final String SKIPPED_UNIT_TESTS = "SkippedUnitTests"; - - private CommonRuleKeys() { - // only static methods - } - - public static String commonRepositoryForLang(String language) { - return REPOSITORY_PREFIX + language; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/settings/ChildSettings.java b/server/sonar-server/src/main/java/org/sonar/server/settings/ChildSettings.java deleted file mode 100644 index 386604ce3dd..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/settings/ChildSettings.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.settings; - -import com.google.common.collect.ImmutableMap; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import org.sonar.api.config.Configuration; -import org.sonar.api.config.Settings; -import org.sonar.api.config.internal.ConfigurationBridge; - -import static java.util.Objects.requireNonNull; - -public class ChildSettings extends Settings { - - private final Settings parentSettings; - private final Map<String, String> localProperties = new HashMap<>(); - - public ChildSettings(Settings parentSettings) { - super(parentSettings.getDefinitions(), parentSettings.getEncryption()); - this.parentSettings = parentSettings; - } - - @Override - protected Optional<String> get(String key) { - String value = localProperties.get(key); - if (value != null) { - return Optional.of(value); - } - return parentSettings.getRawString(key); - } - - @Override - protected void set(String key, String value) { - localProperties.put( - requireNonNull(key, "key can't be null"), - requireNonNull(value, "value can't be null").trim()); - } - - @Override - protected void remove(String key) { - localProperties.remove(key); - } - - /** - * Only returns the currently loaded properties. - * - * <p> - * On the Web Server, global properties are loaded lazily when requested by name. Therefor, - * this will return only global properties which have been requested using - * {@link #get(String)} at least once prior to this call. - */ - @Override - public Map<String, String> getProperties() { - // order is important. local properties override parent properties. - ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); - builder.putAll(parentSettings.getProperties()); - builder.putAll(localProperties); - return builder.build(); - } - - public Configuration asConfiguration() { - return new ConfigurationBridge(this); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/settings/ProjectConfigurationLoaderImpl.java b/server/sonar-server/src/main/java/org/sonar/server/settings/ProjectConfigurationLoaderImpl.java index 1b4033f0ded..06905bbcc87 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/settings/ProjectConfigurationLoaderImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/settings/ProjectConfigurationLoaderImpl.java @@ -30,6 +30,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDto; import org.sonar.db.property.PropertyDto; +import org.sonar.server.setting.ChildSettings; import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex; diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/ObjectInputStreamIterator.java b/server/sonar-server/src/main/java/org/sonar/server/util/ObjectInputStreamIterator.java deleted file mode 100644 index 27946857bde..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/util/ObjectInputStreamIterator.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.util; - -import com.google.common.base.Throwables; -import org.apache.commons.io.IOUtils; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import org.sonar.core.util.CloseableIterator; - -public class ObjectInputStreamIterator<E> extends CloseableIterator<E> { - - private ObjectInputStream stream; - - public ObjectInputStreamIterator(InputStream stream) throws IOException { - this.stream = new ObjectInputStream(stream); - } - - @Override - protected E doNext() { - try { - return (E) stream.readObject(); - } catch (EOFException e) { - return null; - } catch (Exception e) { - throw Throwables.propagate(e); - } - } - - @Override - protected void doClose() { - IOUtils.closeQuietly(stream); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/cache/CacheLoader.java b/server/sonar-server/src/main/java/org/sonar/server/util/cache/CacheLoader.java deleted file mode 100644 index 07e0cb43b8a..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/util/cache/CacheLoader.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.util.cache; - -import javax.annotation.CheckForNull; - -import java.util.Collection; -import java.util.Map; - -public interface CacheLoader<K, V> { - - /** - * Value associated with the requested key. Null if key is not found. - */ - @CheckForNull - V load(K key); - - /** - * All the requested keys must be included in the map result. Value in map is null when - * the key is not found. - */ - Map<K, V> loadAll(Collection<? extends K> keys); -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/cache/DiskCache.java b/server/sonar-server/src/main/java/org/sonar/server/util/cache/DiskCache.java deleted file mode 100644 index 905f460dfce..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/util/cache/DiskCache.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.util.cache; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.OutputStream; -import java.io.Serializable; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.sonar.api.utils.System2; -import org.sonar.core.util.CloseableIterator; -import org.sonar.server.util.ObjectInputStreamIterator; - -/** - * Serialize and deserialize objects on disk. No search capabilities, only traversal (full scan). - */ -public class DiskCache<O extends Serializable> { - - private final File file; - private final System2 system2; - - public DiskCache(File file, System2 system2) { - this.system2 = system2; - this.file = file; - OutputStream output = null; - boolean threw = true; - try { - // writes the serialization stream header required when calling "traverse()" - // on empty stream. Moreover it allows to call multiple times "newAppender()" - output = new ObjectOutputStream(new FileOutputStream(file)); - output.flush(); - threw = false; - } catch (IOException e) { - throw new IllegalStateException("Fail to write into file: " + file, e); - } finally { - if (threw) { - // do not hide initial exception - IOUtils.closeQuietly(output); - } else { - // raise an exception if can't close - system2.close(output); - } - } - } - - public DiskAppender newAppender() { - return new DiskAppender(); - } - - public CloseableIterator<O> traverse() { - try { - return new ObjectInputStreamIterator<>(FileUtils.openInputStream(file)); - } catch (IOException e) { - throw new IllegalStateException("Fail to traverse file: " + file, e); - } - } - - public class DiskAppender implements AutoCloseable { - private final ObjectOutputStream output; - - private DiskAppender() { - try { - this.output = new ObjectOutputStream(new FileOutputStream(file, true)) { - @Override - protected void writeStreamHeader() { - // do not write stream headers as it's already done in constructor of DiskCache - } - }; - } catch (IOException e) { - throw new IllegalStateException("Fail to open file " + file, e); - } - } - - public DiskAppender append(O object) { - try { - output.writeObject(object); - output.reset(); - return this; - } catch (IOException e) { - throw new IllegalStateException("Fail to write into file " + file, e); - } - } - - @Override - public void close() { - system2.close(output); - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/cache/MemoryCache.java b/server/sonar-server/src/main/java/org/sonar/server/util/cache/MemoryCache.java deleted file mode 100644 index 246fe863980..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/util/cache/MemoryCache.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.util.cache; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.annotation.CheckForNull; -import org.sonar.server.exceptions.NotFoundException; - -/** - * This in-memory cache relies on {@link org.sonar.server.util.cache.CacheLoader} to - * load missing elements. - * Warning - all searches are kept in memory, even when elements are not found. - */ -public class MemoryCache<K, V> { - - private final CacheLoader<K, V> loader; - private final Map<K, V> map = new HashMap<>(); - - public MemoryCache(CacheLoader<K, V> loader) { - this.loader = loader; - } - - @CheckForNull - public V getNullable(K key) { - V value = map.get(key); - if (value == null && !map.containsKey(key)) { - value = loader.load(key); - map.put(key, value); - } - return value; - } - - public V get(K key) { - V value = getNullable(key); - if (value == null) { - throw new NotFoundException("Not found: " + key); - } - return value; - } - - /** - * Get values associated with keys. All the requested keys are included - * in the Map result. Value is null if the key is not found in cache. - */ - public Map<K, V> getAll(Iterable<K> keys) { - List<K> missingKeys = new ArrayList<>(); - Map<K, V> result = new HashMap<>(); - for (K key : keys) { - V value = map.get(key); - if (value == null && !map.containsKey(key)) { - missingKeys.add(key); - } else { - result.put(key, value); - } - } - if (!missingKeys.isEmpty()) { - Map<K, V> missingValues = loader.loadAll(missingKeys); - map.putAll(missingValues); - result.putAll(missingValues); - for (K missingKey : missingKeys) { - if (!map.containsKey(missingKey)) { - map.put(missingKey, null); - result.put(missingKey, null); - } - } - } - return result; - } - - public void clear() { - map.clear(); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/cache/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/util/cache/package-info.java deleted file mode 100644 index 157d9ef08ca..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/util/cache/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.server.util.cache; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/organization/DefaultOrganizationLoaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/organization/DefaultOrganizationLoaderTest.java deleted file mode 100644 index 1cdd4fa8b57..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/organization/DefaultOrganizationLoaderTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.computation.organization; - -import org.junit.Test; -import org.sonar.server.organization.DefaultOrganizationCache; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; - -public class DefaultOrganizationLoaderTest { - private DefaultOrganizationCache defaultOrganizationCache = mock(DefaultOrganizationCache.class); - private DefaultOrganizationLoader underTest = new DefaultOrganizationLoader(defaultOrganizationCache); - - @Test - public void start_calls_cache_load_method() { - underTest.start(); - - verify(defaultOrganizationCache).load(); - verifyNoMoreInteractions(defaultOrganizationCache); - } - - @Test - public void stop_calls_cache_unload_method() { - underTest.stop(); - - verify(defaultOrganizationCache).unload(); - verifyNoMoreInteractions(defaultOrganizationCache); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/settings/SettingsLoaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/settings/SettingsLoaderTest.java deleted file mode 100644 index f0c5cf58ef9..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/settings/SettingsLoaderTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.computation.settings; - -import org.junit.Test; -import org.sonar.server.setting.ThreadLocalSettings; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; - -public class SettingsLoaderTest { - private ThreadLocalSettings threadLocalSettings = mock(ThreadLocalSettings.class); - private SettingsLoader underTest = new SettingsLoader(threadLocalSettings); - - @Test - public void start_calls_ThreadLocalSettings_load() { - underTest.start(); - - verify(threadLocalSettings).load(); - verifyNoMoreInteractions(threadLocalSettings); - } - - @Test - public void stop_calls_ThreadLocalSettings_remove() { - underTest.stop(); - - verify(threadLocalSettings).unload(); - verifyNoMoreInteractions(threadLocalSettings); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/DebtRatingGridTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/DebtRatingGridTest.java deleted file mode 100644 index 0208ae16f02..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/DebtRatingGridTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.measure; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.server.measure.Rating.A; -import static org.sonar.server.measure.Rating.B; -import static org.sonar.server.measure.Rating.C; -import static org.sonar.server.measure.Rating.D; -import static org.sonar.server.measure.Rating.E; - -public class DebtRatingGridTest { - - private DebtRatingGrid ratingGrid; - - @Rule - public ExpectedException throwable = ExpectedException.none(); - - @Before - public void setUp() { - double[] gridValues = new double[] {0.1, 0.2, 0.5, 1}; - ratingGrid = new DebtRatingGrid(gridValues); - } - - @Test - public void return_rating_matching_density() { - assertThat(ratingGrid.getRatingForDensity(0)).isEqualTo(A); - assertThat(ratingGrid.getRatingForDensity(0.05)).isEqualTo(A); - assertThat(ratingGrid.getRatingForDensity(0.09999999)).isEqualTo(A); - assertThat(ratingGrid.getRatingForDensity(0.1)).isEqualTo(A); - assertThat(ratingGrid.getRatingForDensity(0.15)).isEqualTo(B); - assertThat(ratingGrid.getRatingForDensity(0.2)).isEqualTo(B); - assertThat(ratingGrid.getRatingForDensity(0.25)).isEqualTo(C); - assertThat(ratingGrid.getRatingForDensity(0.5)).isEqualTo(C); - assertThat(ratingGrid.getRatingForDensity(0.65)).isEqualTo(D); - assertThat(ratingGrid.getRatingForDensity(1)).isEqualTo(D); - assertThat(ratingGrid.getRatingForDensity(1.01)).isEqualTo(E); - } - - @Test - public void density_matching_exact_grid_values() { - assertThat(ratingGrid.getRatingForDensity(0.1)).isEqualTo(A); - assertThat(ratingGrid.getRatingForDensity(0.2)).isEqualTo(B); - assertThat(ratingGrid.getRatingForDensity(0.5)).isEqualTo(C); - assertThat(ratingGrid.getRatingForDensity(1)).isEqualTo(D); - } - - @Test - public void convert_int_to_rating() { - assertThat(Rating.valueOf(1)).isEqualTo(A); - assertThat(Rating.valueOf(2)).isEqualTo(B); - assertThat(Rating.valueOf(3)).isEqualTo(C); - assertThat(Rating.valueOf(4)).isEqualTo(D); - assertThat(Rating.valueOf(5)).isEqualTo(E); - } - - @Test - public void fail_on_invalid_density() { - throwable.expect(IllegalArgumentException.class); - throwable.expectMessage("Invalid value '-1.0'"); - - ratingGrid.getRatingForDensity(-1); - } - - @Test - public void fail_to_concert_invalid_value() { - throwable.expect(IllegalArgumentException.class); - Rating.valueOf(10); - } - - @Test - public void fail_on_invalid_grid() { - throwable.expect(IllegalStateException.class); - throwable.expectMessage("Rating grid should contains 4 values"); - - ratingGrid = new DebtRatingGrid(new double[] {0.1, 0.2, 0.5}); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ShortLivingBranchQualityGateTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ShortLivingBranchQualityGateTest.java deleted file mode 100644 index 3f4ad722b67..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ShortLivingBranchQualityGateTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.qualitygate; - -import org.junit.Test; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.server.qualitygate.ShortLivingBranchQualityGate.Condition; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.tuple; - -public class ShortLivingBranchQualityGateTest { - - @Test - public void defines_short_living_branches_hardcoded_quality_gate_conditions() { - assertThat(ShortLivingBranchQualityGate.CONDITIONS) - .extracting(Condition::getMetricKey, Condition::getOperator, Condition::getErrorThreshold, Condition::getWarnThreshold, Condition::isOnLeak) - .containsExactly( - tuple(CoreMetrics.OPEN_ISSUES_KEY, "GT", "0", null, false), - tuple(CoreMetrics.REOPENED_ISSUES_KEY, "GT", "0", null, false)); - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QualityProfileTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QualityProfileTest.java deleted file mode 100644 index 9642502884b..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QualityProfileTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.qualityprofile; - -import java.util.Date; -import org.junit.Test; -import org.sonar.api.utils.DateUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -public class QualityProfileTest { - - private static final String SOME_QP_KEY = "qpKey"; - private static final String SOME_QP_NAME = "qpName"; - private static final String SOME_LANGUAGE_KEY = "languageKey"; - private static final Date SOME_DATE = DateUtils.parseDateTimeQuietly("2010-05-18T15:50:45+0100"); - private static final QualityProfile QUALITY_PROFILE = new QualityProfile(SOME_QP_KEY, SOME_QP_NAME, SOME_LANGUAGE_KEY, SOME_DATE); - - @Test(expected = NullPointerException.class) - public void constructor_throws_NPE_if_qkKey_arg_is_null() { - new QualityProfile(null, SOME_QP_NAME, SOME_LANGUAGE_KEY, SOME_DATE); - } - - @Test(expected = NullPointerException.class) - public void constructor_throws_NPE_if_qpName_arg_is_null() { - new QualityProfile(SOME_QP_KEY, null, SOME_LANGUAGE_KEY, SOME_DATE); - } - - @Test(expected = NullPointerException.class) - public void constructor_throws_NPE_if_languageKey_arg_is_null() { - new QualityProfile(SOME_QP_KEY, SOME_QP_NAME, null, SOME_DATE); - } - - @Test(expected = NullPointerException.class) - public void constructor_throws_NPE_if_rulesUpdatedAt_arg_is_null() { - new QualityProfile(SOME_QP_KEY, SOME_QP_NAME, SOME_LANGUAGE_KEY, null); - } - - @Test - public void verify_properties() { - assertThat(QUALITY_PROFILE.getQpKey()).isEqualTo(SOME_QP_KEY); - assertThat(QUALITY_PROFILE.getQpName()).isEqualTo(SOME_QP_NAME); - assertThat(QUALITY_PROFILE.getLanguageKey()).isEqualTo(SOME_LANGUAGE_KEY); - assertThat(QUALITY_PROFILE.getRulesUpdatedAt()).isEqualTo(SOME_DATE); - } - - @Test - public void verify_getRulesUpdatedAt_keeps_object_immutable() { - assertThat(QUALITY_PROFILE.getRulesUpdatedAt()).isNotSameAs(SOME_DATE); - } - - @Test - public void verify_equals() { - assertThat(QUALITY_PROFILE).isEqualTo(new QualityProfile(SOME_QP_KEY, SOME_QP_NAME, SOME_LANGUAGE_KEY, SOME_DATE)); - assertThat(QUALITY_PROFILE).isEqualTo(QUALITY_PROFILE); - assertThat(QUALITY_PROFILE).isNotEqualTo(null); - } - - @Test - public void verify_toString() { - assertThat(QUALITY_PROFILE.toString()).isEqualTo("QualityProfile{key=qpKey, name=qpName, language=languageKey, rulesUpdatedAt=1274194245000}"); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/CommonRuleKeysTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/CommonRuleKeysTest.java deleted file mode 100644 index 45ab75f9e49..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/CommonRuleKeysTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.rule; - -import org.junit.Test; -import org.sonar.test.TestUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CommonRuleKeysTest { - - @Test - public void wonderful_test_for_commonRepositoryForLang() { - assertThat(CommonRuleKeys.commonRepositoryForLang("java")).isEqualTo("common-java"); - } - - @Test - public void wonderful_test_to_verify_that_this_class_is_an_helper_class() { - assertThat(TestUtils.hasOnlyPrivateConstructors(CommonRuleKeys.class)).isTrue(); - - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/settings/ChildSettingsTest.java b/server/sonar-server/src/test/java/org/sonar/server/settings/ChildSettingsTest.java deleted file mode 100644 index 4f65f2305b2..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/settings/ChildSettingsTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.settings; - -import java.util.Collections; -import java.util.Date; -import java.util.Optional; -import java.util.Random; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.config.PropertyDefinition; -import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.config.internal.MapSettings; - -import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; -import static org.assertj.core.api.Assertions.assertThat; - -public class ChildSettingsTest { - private static final Random RANDOM = new Random(); - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private MapSettings parent = new MapSettings(); - private ChildSettings underTest = new ChildSettings(parent); - - @Test - public void childSettings_should_retrieve_parent_settings() { - String multipleValuesKey = randomAlphanumeric(19); - PropertyDefinition multipleValues = PropertyDefinition.builder(multipleValuesKey).multiValues(true).build(); - MapSettings parent = new MapSettings(new PropertyDefinitions(Collections.singletonList(multipleValues))); - ChildSettings underTest = new ChildSettings(parent); - - parent.setProperty(randomAlphanumeric(10), randomAlphanumeric(20)); - parent.setProperty(randomAlphanumeric(11), RANDOM.nextLong()); - parent.setProperty(randomAlphanumeric(12), RANDOM.nextDouble()); - parent.setProperty(randomAlphanumeric(13), RANDOM.nextFloat()); - parent.setProperty(randomAlphanumeric(14), RANDOM.nextBoolean()); - parent.setProperty(randomAlphanumeric(15), RANDOM.nextInt()); - parent.setProperty(randomAlphanumeric(16), new Date(RANDOM.nextInt())); - parent.setProperty(randomAlphanumeric(17), new Date(RANDOM.nextInt()), true); - parent.setProperty(randomAlphanumeric(18), new Date(RANDOM.nextInt()), false); - parent.setProperty(multipleValuesKey, new String[] { randomAlphanumeric(10), randomAlphanumeric(20) }); - - assertThat(underTest.getProperties()).isEqualTo(parent.getProperties()); - } - - @Test - public void set_will_throw_NPE_if_key_is_null() { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("key can't be null"); - - underTest.set(null, ""); - } - - - @Test - public void set_will_throw_NPE_if_value_is_null() { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("value can't be null"); - - underTest.set(randomAlphanumeric(10), null); - } - - @Test - public void childSettings_override_parent() { - String key = randomAlphanumeric(10); - parent.setProperty(key, randomAlphanumeric(20)); - underTest.setProperty(key, randomAlphanumeric(10)); - - assertThat(underTest.get(key)).isNotEqualTo(parent.getString(key)); - } - - @Test - public void remove_should_not_throw_exception_if_key_is_not_present() { - underTest.remove(randomAlphanumeric(90)); - } - - @Test - public void remove_should_remove_value() { - String key = randomAlphanumeric(10); - String childValue = randomAlphanumeric(10); - - underTest.set(key, childValue); - assertThat(underTest.get(key)).isEqualTo(Optional.of(childValue)); - - underTest.remove(key); - assertThat(underTest.get(key)).isEqualTo(Optional.empty()); - } - - @Test - public void remove_should_retrieve_parent_value() { - String key = randomAlphanumeric(10); - String childValue = randomAlphanumeric(10); - String parentValue = randomAlphanumeric(10); - - parent.setProperty(key, parentValue); - underTest.set(key, childValue); - assertThat(underTest.get(key)).isEqualTo(Optional.of(childValue)); - - underTest.remove(key); - assertThat(underTest.get(key)).isEqualTo(Optional.of(parentValue)); - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/util/ObjectInputStreamIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/util/ObjectInputStreamIteratorTest.java deleted file mode 100644 index 8f0ffea9113..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/util/ObjectInputStreamIteratorTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.util; - -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.NoSuchElementException; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; - -public class ObjectInputStreamIteratorTest { - - @Test - public void read_objects() throws Exception { - ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream(); - ObjectOutputStream objectOutputStream = new ObjectOutputStream(bytesOutput); - objectOutputStream.writeObject(new SimpleSerializable("first")); - objectOutputStream.writeObject(new SimpleSerializable("second")); - objectOutputStream.writeObject(new SimpleSerializable("third")); - objectOutputStream.flush(); - objectOutputStream.close(); - - ObjectInputStreamIterator<SimpleSerializable> it = new ObjectInputStreamIterator<>(new ByteArrayInputStream(bytesOutput.toByteArray())); - assertThat(it.next().value).isEqualTo("first"); - assertThat(it.next().value).isEqualTo("second"); - assertThat(it.next().value).isEqualTo("third"); - try { - it.next(); - fail(); - } catch (NoSuchElementException expected) { - - } - } - - @Test - public void test_error() throws Exception { - ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream(); - ObjectOutputStream objectOutputStream = new ObjectOutputStream(bytesOutput); - objectOutputStream.writeObject(new SimpleSerializable("first")); - objectOutputStream.writeBoolean(false); - objectOutputStream.flush(); - objectOutputStream.close(); - - ObjectInputStreamIterator<SimpleSerializable> it = new ObjectInputStreamIterator<>(new ByteArrayInputStream(bytesOutput.toByteArray())); - assertThat(it.next().value).isEqualTo("first"); - try { - it.next(); - fail(); - } catch (RuntimeException expected) { - - } - } - - static class SimpleSerializable implements Serializable { - String value; - - public SimpleSerializable() { - - } - - public SimpleSerializable(String value) { - this.value = value; - } - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/util/cache/DiskCacheTest.java b/server/sonar-server/src/test/java/org/sonar/server/util/cache/DiskCacheTest.java deleted file mode 100644 index 5180c0e11e3..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/util/cache/DiskCacheTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.util.cache; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.api.utils.System2; -import org.sonar.core.util.CloseableIterator; - -import java.io.ObjectOutputStream; -import java.io.Serializable; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; - -public class DiskCacheTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Test - public void write_and_read() throws Exception { - DiskCache<String> cache = new DiskCache<>(temp.newFile(), System2.INSTANCE); - try (CloseableIterator<String> traverse = cache.traverse()) { - assertThat(traverse).isEmpty(); - } - - cache.newAppender() - .append("foo") - .append("bar") - .close(); - try (CloseableIterator<String> traverse = cache.traverse()) { - assertThat(traverse).containsExactly("foo", "bar"); - } - } - - @Test - public void fail_if_file_is_not_writable() throws Exception { - try { - new DiskCache<>(temp.newFolder(), System2.INSTANCE); - fail(); - } catch (IllegalStateException e) { - assertThat(e).hasMessageContaining("Fail to write into file"); - } - } - - @Test - public void fail_to_serialize() throws Exception { - class Unserializable implements Serializable { - private void writeObject(ObjectOutputStream out) { - throw new UnsupportedOperationException("expected error"); - } - } - DiskCache<Serializable> cache = new DiskCache<>(temp.newFile(), System2.INSTANCE); - try { - cache.newAppender().append(new Unserializable()); - fail(); - } catch (UnsupportedOperationException e) { - assertThat(e).hasMessage("expected error"); - } - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/util/cache/MemoryCacheTest.java b/server/sonar-server/src/test/java/org/sonar/server/util/cache/MemoryCacheTest.java deleted file mode 100644 index 1ad34ad8186..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/util/cache/MemoryCacheTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.util.cache; - -import com.google.common.collect.ImmutableMap; -import org.junit.Test; -import org.sonar.server.exceptions.NotFoundException; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.*; - -public class MemoryCacheTest { - - CacheLoader<String, String> loader = mock(CacheLoader.class); - MemoryCache<String, String> cache = new MemoryCache<>(loader); - - @Test - public void getNullable() { - when(loader.load("foo")).thenReturn("bar"); - assertThat(cache.getNullable("foo")).isEqualTo("bar"); - assertThat(cache.getNullable("foo")).isEqualTo("bar"); - verify(loader, times(1)).load("foo"); - - // return null if key not found - assertThat(cache.getNullable("not_exists")).isNull(); - - // clear cache -> new calls to CacheLoader - cache.clear(); - assertThat(cache.getNullable("foo")).isEqualTo("bar"); - verify(loader, times(2)).load("foo"); - } - - @Test - public void get_throws_exception_if_not_exists() { - when(loader.load("foo")).thenReturn("bar"); - assertThat(cache.get("foo")).isEqualTo("bar"); - assertThat(cache.get("foo")).isEqualTo("bar"); - verify(loader, times(1)).load("foo"); - - try { - cache.get("not_exists"); - fail(); - } catch (NotFoundException e) { - assertThat(e).hasMessage("Not found: not_exists"); - } - } - - @Test - public void getAllNullable() { - // ask for 3 keys but only 2 are available in backed (third key is missing) - List<String> keys = Arrays.asList("one", "two", "three"); - Map<String, String> values = new HashMap<>(); - values.put("one", "un"); - values.put("two", "deux"); - when(loader.loadAll(keys)).thenReturn(values); - assertThat(cache.getAll(keys)) - .hasSize(3) - .containsEntry("one", "un") - .containsEntry("two", "deux") - .containsEntry("three", null); - - // ask for 4 keys. Only a single one was never loaded. The 3 others are kept from cache - when(loader.loadAll(Arrays.asList("four"))).thenReturn(ImmutableMap.of("four", "quatre")); - assertThat(cache.getAll(Arrays.asList("one", "two", "three", "four"))) - .hasSize(4) - .containsEntry("one", "un") - .containsEntry("two", "deux") - .containsEntry("three", null) - .containsEntry("four", "quatre"); - verify(loader, times(2)).loadAll(anyCollection()); - } -} |