You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

QModelTester.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. /*
  21. * Copyright (C) 2009-2023 SonarSource SA
  22. * All rights reserved
  23. * mailto:info AT sonarsource DOT com
  24. */
  25. package org.sonarqube.ws.tester;
  26. import com.google.common.base.Joiner;
  27. import com.google.common.base.Preconditions;
  28. public class QModelTester {
  29. private static final String DEV_COST_PROPERTY = "sonar.technicalDebt.developmentCost";
  30. private static final String RATING_GRID_PROPERTY = "sonar.technicalDebt.ratingGrid";
  31. private static final String DEV_COST_LANGUAGE_PROPERTY = "languageSpecificParameters";
  32. private static final String DEV_COST_LANGUAGE_NAME_PROPERTY = DEV_COST_LANGUAGE_PROPERTY + ".0.language";
  33. private static final String DEV_COST_LANGUAGE_COST_PROPERTY = DEV_COST_LANGUAGE_PROPERTY + ".0.man_days";
  34. private static final Joiner COMMA_JOINER = Joiner.on(",");
  35. private final TesterSession session;
  36. QModelTester(TesterSession session) {
  37. this.session = session;
  38. }
  39. public void updateDevelopmentCost(int developmentCost) {
  40. session.settings().setGlobalSettings(DEV_COST_PROPERTY, Integer.toString(developmentCost));
  41. }
  42. public void updateLanguageDevelopmentCost(String language, int developmentCost) {
  43. session.settings().setGlobalSettings(DEV_COST_LANGUAGE_PROPERTY, "0");
  44. session.settings().setGlobalSettings(DEV_COST_LANGUAGE_NAME_PROPERTY, language);
  45. session.settings().setGlobalSettings(DEV_COST_LANGUAGE_COST_PROPERTY, Integer.toString(developmentCost));
  46. }
  47. public void updateRatingGrid(Double... ratingGrid) {
  48. Preconditions.checkState(ratingGrid.length == 4, "Rating grid must contains 4 values");
  49. session.settings().setGlobalSettings(RATING_GRID_PROPERTY, COMMA_JOINER.join(ratingGrid));
  50. }
  51. public void reset() {
  52. session.settings().resetSettings(DEV_COST_LANGUAGE_PROPERTY, DEV_COST_LANGUAGE_NAME_PROPERTY, DEV_COST_LANGUAGE_COST_PROPERTY, RATING_GRID_PROPERTY, DEV_COST_PROPERTY);
  53. }
  54. }