<%
technical_debt = measure('sqale_index')
- root_characteristics = Internal.debt.findRootCharacteristics().to_a
+ root_characteristics = Internal.debt.rootCharacteristics().to_a
should_display_diff_measures = dashboard_configuration.selected_period? && technical_debt.variation(dashboard_configuration.period_index)!=nil
if technical_debt.nil? || root_characteristics.empty?
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.core.technicaldebt;
-
-
-import org.sonar.api.rules.Rule;
-import org.sonar.api.technicaldebt.server.Characteristic;
-import org.sonar.api.technicaldebt.server.TechnicalDebtManager;
-import org.sonar.api.technicaldebt.server.internal.DefaultCharacteristic;
-import org.sonar.core.technicaldebt.db.CharacteristicDao;
-import org.sonar.core.technicaldebt.db.CharacteristicDto;
-
-import javax.annotation.CheckForNull;
-
-import java.util.List;
-
-import static com.google.common.collect.Lists.newArrayList;
-
-/**
- * TODO This class should be replaced or created by a TechnicalDebtManagerBuilder
- */
-public class DefaultTechnicalDebtManager implements TechnicalDebtManager {
-
- private final CharacteristicDao dao;
-
- public DefaultTechnicalDebtManager(CharacteristicDao dao) {
- this.dao = dao;
- }
-
- public List<Characteristic> findRootCharacteristics() {
- List<CharacteristicDto> dtos = dao.selectEnabledRootCharacteristics();
- List<Characteristic> characteristics = newArrayList();
- for (CharacteristicDto dto : dtos) {
- characteristics.add(toCharacteristic(dto));
- }
- return characteristics;
- }
-
- @CheckForNull
- public Characteristic findCharacteristicById(Integer id) {
- CharacteristicDto dto = dao.selectById(id);
- if (dto != null) {
- return toCharacteristic(dto);
- }
- return null;
- }
-
- /**
- * @deprecated since 4.3. Always return null
- */
- @Deprecated
- @CheckForNull
- public Characteristic findRequirementByRuleId(int ruleId) {
- return null;
- }
-
- /**
- * @deprecated since 4.3. Always return null
- */
- @Deprecated
- @CheckForNull
- public Characteristic findRequirementByRule(Rule rule) {
- return null;
- }
-
- private static Characteristic toCharacteristic(CharacteristicDto dto) {
- return new DefaultCharacteristic()
- .setId(dto.getId())
- .setKey(dto.getKey())
- .setName(dto.getName())
- .setOrder(dto.getOrder())
- .setParentId(dto.getParentId());
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.core.technicaldebt;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.technicaldebt.server.Characteristic;
-import org.sonar.core.technicaldebt.db.CharacteristicDao;
-import org.sonar.core.technicaldebt.db.CharacteristicDto;
-
-import java.util.List;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class DefaultTechnicalDebtManagerTest {
-
- @Mock
- CharacteristicDao dao;
-
- DefaultTechnicalDebtManager finder;
-
- @Before
- public void setUp() throws Exception {
- finder = new DefaultTechnicalDebtManager(dao);
- }
-
- @Test
- public void find_root_characteristics() throws Exception {
- CharacteristicDto rootCharacteristicDto = new CharacteristicDto()
- .setId(1)
- .setKey("MEMORY_EFFICIENCY")
- .setName("Memory use");
- when(dao.selectEnabledRootCharacteristics()).thenReturn(newArrayList(rootCharacteristicDto));
-
- List<Characteristic> result = finder.findRootCharacteristics();
- assertThat(result).hasSize(1);
-
- Characteristic rootCharacteristic = result.get(0);
- assertThat(rootCharacteristic.key()).isEqualTo("MEMORY_EFFICIENCY");
- assertThat(rootCharacteristic.name()).isEqualTo("Memory use");
- assertThat(rootCharacteristic.parentId()).isNull();
- assertThat(rootCharacteristic.rootId()).isNull();
- }
-
- @Test
- public void find_characteristic() throws Exception {
- Rule rule = Rule.create("repo", "key");
- rule.setId(1);
-
- when(dao.selectById(2)).thenReturn(
- new CharacteristicDto().setId(2).setKey("COMPILER_RELATED_PORTABILITY").setName("Compiler").setParentId(1));
-
- Characteristic result = finder.findCharacteristicById(2);
-
- assertThat(result.id()).isEqualTo(2);
- assertThat(result.parentId()).isEqualTo(1);
- assertThat(result.key()).isEqualTo("COMPILER_RELATED_PORTABILITY");
- assertThat(result.name()).isEqualTo("Compiler");
- }
-
- @Test
- public void not_find_characteristic() throws Exception {
- Rule rule = Rule.create("repo", "key");
- rule.setId(1);
-
- when(dao.selectById(rule.getId())).thenReturn(null);
-
- Characteristic result = finder.findCharacteristicById(2);
- assertThat(result).isNull();
- }
-
- @Test
- public void find_requirement_always_return_null() throws Exception {
- assertThat(finder.findRequirementByRule(Rule.create("repo", "key"))).isNull();
- }
-
- @Test
- public void find_requirement_by_rule_id_always_return_null() throws Exception {
- assertThat(finder.findRequirementByRuleId(1)).isNull();
- }
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.api.server.debt;
+
+import javax.annotation.CheckForNull;
+
+/**
+ * @since 4.3
+ */
+public interface DebtCharacteristic {
+ Integer id();
+
+ String key();
+
+ String name();
+
+ @CheckForNull
+ Integer order();
+
+ @CheckForNull
+ Integer parentId();
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.api.server.debt;
+
+import org.sonar.api.ServerComponent;
+
+import java.util.List;
+
+/**
+ * @since 4.3
+ */
+public interface DebtModel extends ServerComponent {
+
+ List<DebtCharacteristic> characteristics();
+
+ List<DebtCharacteristic> rootCharacteristics();
+
+ DebtCharacteristic characteristicById(int id);
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.api.server.debt.internal;
+
+import org.sonar.api.server.debt.DebtCharacteristic;
+
+/**
+ * @since 4.3
+ */
+public class DefaultDebtCharacteristic implements DebtCharacteristic {
+
+ private Integer id;
+ private String key;
+ private String name;
+ private Integer order;
+ private Integer parentId;
+
+ @Override
+ public Integer id() {
+ return id;
+ }
+
+ public DefaultDebtCharacteristic setId(Integer id) {
+ this.id = id;
+ return this;
+ }
+
+ @Override
+ public String key() {
+ return key;
+ }
+
+ public DefaultDebtCharacteristic setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ public DefaultDebtCharacteristic setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ @Override
+ public Integer order() {
+ return order;
+ }
+
+ public DefaultDebtCharacteristic setOrder(Integer order) {
+ this.order = order;
+ return this;
+ }
+
+ @Override
+ public Integer parentId() {
+ return parentId;
+ }
+
+ public DefaultDebtCharacteristic setParentId(Integer parentId) {
+ this.parentId = parentId;
+ return this;
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.api.server.debt.internal;
+
+import javax.annotation.ParametersAreNonnullByDefault;
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.api.server.debt;
+
+import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.CheckForNull;
/**
- * @since 4.1
+ * @since 4.1 *
+ * @deprecated since 4.3.
*/
+@Deprecated
public interface Characteristic {
Integer id();
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.api.technicaldebt.server;
-
-import org.sonar.api.ServerComponent;
-import org.sonar.api.rules.Rule;
-
-import java.util.List;
-
-/**
- * @since 4.1
- */
-
-public interface TechnicalDebtManager extends ServerComponent {
-
- List<Characteristic> findRootCharacteristics();
-
- /**
- * @deprecated since 4.3. Always return null
- */
- @Deprecated
- Characteristic findRequirementByRule(Rule rule);
-
- Characteristic findCharacteristicById(Integer id);
-}
/**
* @since 4.1
+ * @deprecated since 4.3.
*/
+@Deprecated
public class DefaultCharacteristic implements Characteristic {
private Integer id;
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.debt;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import org.sonar.api.server.debt.DebtCharacteristic;
+import org.sonar.api.server.debt.DebtModel;
+import org.sonar.api.server.debt.internal.DefaultDebtCharacteristic;
+import org.sonar.core.technicaldebt.db.CharacteristicDao;
+import org.sonar.core.technicaldebt.db.CharacteristicDto;
+
+import javax.annotation.CheckForNull;
+
+import java.util.Collection;
+import java.util.List;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+/**
+ * Used through ruby code <pre>Internal.debt</pre>
+ */
+public class DebtModelService implements DebtModel {
+
+ private final CharacteristicDao dao;
+
+ public DebtModelService(CharacteristicDao dao) {
+ this.dao = dao;
+ }
+
+ public List<DebtCharacteristic> rootCharacteristics() {
+ return toCharacteristics(dao.selectEnabledRootCharacteristics());
+ }
+
+ public List<DebtCharacteristic> characteristics() {
+ return toCharacteristics(dao.selectEnabledCharacteristics());
+ }
+
+ @CheckForNull
+ public DebtCharacteristic characteristicById(int id) {
+ CharacteristicDto dto = dao.selectById(id);
+ return dto != null ? toCharacteristic(dto) : null;
+ }
+
+ private static List<DebtCharacteristic> toCharacteristics(Collection<CharacteristicDto> dtos) {
+ return newArrayList(Iterables.transform(dtos, new Function<CharacteristicDto, DebtCharacteristic>() {
+ @Override
+ public DebtCharacteristic apply(CharacteristicDto input) {
+ return toCharacteristic(input);
+ }
+ }));
+ }
+
+ private static DebtCharacteristic toCharacteristic(CharacteristicDto dto) {
+ return new DefaultDebtCharacteristic()
+ .setId(dto.getId())
+ .setKey(dto.getKey())
+ .setName(dto.getName())
+ .setOrder(dto.getOrder())
+ .setParentId(dto.getParentId());
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.debt;
-
-import org.sonar.api.ServerComponent;
-import org.sonar.api.technicaldebt.server.Characteristic;
-import org.sonar.core.technicaldebt.DefaultTechnicalDebtManager;
-
-import javax.annotation.CheckForNull;
-
-import java.util.List;
-
-/**
- * Used through ruby code <pre>Internal.debt</pre>
- */
-public class DebtService implements ServerComponent {
-
- private final DefaultTechnicalDebtManager finder;
-
- public DebtService(DefaultTechnicalDebtManager finder) {
- this.finder = finder;
- }
-
- public List<Characteristic> findRootCharacteristics() {
- return finder.findRootCharacteristics();
- }
-
- @CheckForNull
- public Characteristic findRequirementByRuleId(int ruleId) {
- return finder.findRequirementByRuleId(ruleId);
- }
-
- @CheckForNull
- public Characteristic findCharacteristic(int id) {
- return finder.findCharacteristicById(id);
- }
-
-}
import org.sonar.api.issue.action.Action;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.issue.internal.FieldDiffs;
+import org.sonar.api.server.debt.DebtCharacteristic;
+import org.sonar.api.server.debt.DebtModel;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
-import org.sonar.api.technicaldebt.server.Characteristic;
import org.sonar.api.user.User;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.Duration;
import org.sonar.api.web.UserRole;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.issue.workflow.Transition;
-import org.sonar.core.technicaldebt.DefaultTechnicalDebtManager;
import org.sonar.markdown.Markdown;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.issue.ActionService;
private final IssueService issueService;
private final IssueChangelogService issueChangelogService;
private final ActionService actionService;
- private final DefaultTechnicalDebtManager technicalDebtManager;
+ private final DebtModel debtModel;
private final I18n i18n;
private final Durations durations;
public IssueShowWsHandler(IssueFinder issueFinder, IssueService issueService, IssueChangelogService issueChangelogService, ActionService actionService,
- DefaultTechnicalDebtManager technicalDebtManager, I18n i18n, Durations durations) {
+ DebtModel debtModel, I18n i18n, Durations durations) {
this.issueFinder = issueFinder;
this.issueService = issueService;
this.issueChangelogService = issueChangelogService;
this.actionService = actionService;
- this.technicalDebtManager = technicalDebtManager;
+ this.debtModel = debtModel;
this.i18n = i18n;
this.durations = durations;
}
private void addCharacteristics(IssueQueryResult result, DefaultIssue issue, JsonWriter json) {
Integer subCharacteristicId = result.rule(issue).getCharacteristicId() != null ? result.rule(issue).getCharacteristicId() : result.rule(issue).getDefaultCharacteristicId();
- Characteristic subCharacteristic = findCharacteristicById(subCharacteristicId);
+ DebtCharacteristic subCharacteristic = characteristicById(subCharacteristicId);
if (subCharacteristic != null) {
json.prop("subCharacteristic", subCharacteristic.name());
- Characteristic characteristic = findCharacteristicById(subCharacteristic.parentId());
+ DebtCharacteristic characteristic = characteristicById(subCharacteristic.parentId());
json.prop("characteristic", characteristic != null ? characteristic.name() : null);
}
}
@CheckForNull
- private Characteristic findCharacteristicById(@Nullable Integer id) {
+ private DebtCharacteristic characteristicById(@Nullable Integer id) {
if (id != null) {
- return technicalDebtManager.findCharacteristicById(id);
+ return debtModel.characteristicById(id);
}
return null;
}
import org.sonar.core.metric.DefaultMetricFinder;
import org.sonar.core.notification.DefaultNotificationManager;
import org.sonar.core.permission.PermissionFacade;
-import org.sonar.core.persistence.DaoUtils;
-import org.sonar.core.persistence.DatabaseVersion;
-import org.sonar.core.persistence.DefaultDatabase;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.persistence.PreviewDatabaseFactory;
-import org.sonar.core.persistence.SemaphoreUpdater;
-import org.sonar.core.persistence.SemaphoresImpl;
+import org.sonar.core.persistence.*;
import org.sonar.core.preview.PreviewCache;
import org.sonar.core.profiling.Profiling;
import org.sonar.core.purge.PurgeProfiler;
import org.sonar.core.qualitygate.db.QualityGateDao;
import org.sonar.core.resource.DefaultResourcePermissions;
import org.sonar.core.rule.DefaultRuleFinder;
-import org.sonar.core.technicaldebt.DefaultTechnicalDebtManager;
import org.sonar.core.technicaldebt.TechnicalDebtModelRepository;
import org.sonar.core.technicaldebt.TechnicalDebtModelSynchronizer;
import org.sonar.core.technicaldebt.TechnicalDebtXMLImporter;
import org.sonar.server.db.migrations.DatabaseMigrations;
import org.sonar.server.db.migrations.DatabaseMigrator;
import org.sonar.server.debt.DebtCharacteristicsXMLImporter;
+import org.sonar.server.debt.DebtModelService;
import org.sonar.server.debt.DebtModelSynchronizer;
import org.sonar.server.debt.DebtRulesXMLImporter;
-import org.sonar.server.debt.DebtService;
import org.sonar.server.es.ESIndex;
import org.sonar.server.es.ESNode;
-import org.sonar.server.issue.ActionPlanService;
-import org.sonar.server.issue.ActionService;
-import org.sonar.server.issue.AssignAction;
-import org.sonar.server.issue.CommentAction;
-import org.sonar.server.issue.DefaultIssueFinder;
-import org.sonar.server.issue.InternalRubyIssueService;
-import org.sonar.server.issue.IssueBulkChangeService;
-import org.sonar.server.issue.IssueChangelogFormatter;
-import org.sonar.server.issue.IssueChangelogService;
-import org.sonar.server.issue.IssueCommentService;
-import org.sonar.server.issue.IssueService;
-import org.sonar.server.issue.IssueStatsFinder;
-import org.sonar.server.issue.PlanAction;
-import org.sonar.server.issue.PublicRubyIssueService;
-import org.sonar.server.issue.ServerIssueStorage;
-import org.sonar.server.issue.SetSeverityAction;
-import org.sonar.server.issue.TransitionAction;
+import org.sonar.server.issue.*;
import org.sonar.server.issue.filter.IssueFilterService;
import org.sonar.server.issue.filter.IssueFilterWs;
import org.sonar.server.issue.ws.IssueShowWsHandler;
import org.sonar.server.permission.PermissionFinder;
import org.sonar.server.platform.ws.PlatformWs;
import org.sonar.server.platform.ws.RestartHandler;
-import org.sonar.server.plugins.InstalledPluginReferentialFactory;
-import org.sonar.server.plugins.PluginDownloader;
-import org.sonar.server.plugins.ServerExtensionInstaller;
-import org.sonar.server.plugins.ServerPluginJarInstaller;
-import org.sonar.server.plugins.ServerPluginJarsInstaller;
-import org.sonar.server.plugins.ServerPluginRepository;
-import org.sonar.server.plugins.UpdateCenterClient;
-import org.sonar.server.plugins.UpdateCenterMatrixFactory;
+import org.sonar.server.plugins.*;
import org.sonar.server.qualitygate.QgateProjectFinder;
import org.sonar.server.qualitygate.QualityGates;
import org.sonar.server.qualitygate.ws.QgateAppHandler;
import org.sonar.server.qualitygate.ws.QualityGatesWs;
-import org.sonar.server.qualityprofile.ESActiveRule;
-import org.sonar.server.qualityprofile.ProfilesManager;
-import org.sonar.server.qualityprofile.QProfileActiveRuleOperations;
-import org.sonar.server.qualityprofile.QProfileBackup;
-import org.sonar.server.qualityprofile.QProfileLookup;
-import org.sonar.server.qualityprofile.QProfileOperations;
-import org.sonar.server.qualityprofile.QProfileProjectLookup;
-import org.sonar.server.qualityprofile.QProfileProjectOperations;
-import org.sonar.server.qualityprofile.QProfileRepositoryExporter;
-import org.sonar.server.qualityprofile.QProfileRuleLookup;
-import org.sonar.server.qualityprofile.QProfiles;
-import org.sonar.server.rule.DeprecatedRulesDefinition;
-import org.sonar.server.rule.ESRuleTags;
-import org.sonar.server.rule.RubyRuleService;
-import org.sonar.server.rule.RuleDefinitionsLoader;
-import org.sonar.server.rule.RuleOperations;
-import org.sonar.server.rule.RuleRegistration;
-import org.sonar.server.rule.RuleRegistry;
-import org.sonar.server.rule.RuleRepositories;
-import org.sonar.server.rule.RuleTagLookup;
-import org.sonar.server.rule.RuleTagOperations;
-import org.sonar.server.rule.RuleTags;
-import org.sonar.server.rule.Rules;
-import org.sonar.server.rule.ws.AddTagsWsHandler;
-import org.sonar.server.rule.ws.RemoveTagsWsHandler;
-import org.sonar.server.rule.ws.RuleSearchWsHandler;
-import org.sonar.server.rule.ws.RuleShowWsHandler;
-import org.sonar.server.rule.ws.RuleTagsWs;
-import org.sonar.server.rule.ws.RulesWs;
+import org.sonar.server.qualityprofile.*;
+import org.sonar.server.rule.*;
+import org.sonar.server.rule.ws.*;
import org.sonar.server.source.CodeColorizers;
import org.sonar.server.source.DeprecatedSourceDecorator;
import org.sonar.server.source.HtmlSourceDecorator;
import org.sonar.server.source.SourceService;
import org.sonar.server.source.ws.SourcesShowWsHandler;
import org.sonar.server.source.ws.SourcesWs;
-import org.sonar.server.startup.CleanPreviewAnalysisCache;
-import org.sonar.server.startup.CopyRequirementsFromCharacteristicsToRules;
-import org.sonar.server.startup.GenerateBootstrapIndex;
-import org.sonar.server.startup.GeneratePluginIndex;
-import org.sonar.server.startup.GwtPublisher;
-import org.sonar.server.startup.JdbcDriverDeployer;
-import org.sonar.server.startup.LogServerId;
-import org.sonar.server.startup.RegisterDebtModel;
-import org.sonar.server.startup.RegisterMetrics;
-import org.sonar.server.startup.RegisterNewDashboards;
-import org.sonar.server.startup.RegisterNewMeasureFilters;
-import org.sonar.server.startup.RegisterNewProfiles;
-import org.sonar.server.startup.RegisterPermissionTemplates;
-import org.sonar.server.startup.RegisterServletFilters;
-import org.sonar.server.startup.RenameDeprecatedPropertyKeys;
-import org.sonar.server.startup.ServerMetadataPersister;
+import org.sonar.server.startup.*;
import org.sonar.server.text.MacroInterpreter;
import org.sonar.server.text.RubyTextService;
import org.sonar.server.ui.JRubyI18n;
import org.sonar.server.ui.JRubyProfiling;
import org.sonar.server.ui.PageDecorations;
import org.sonar.server.ui.Views;
-import org.sonar.server.user.DefaultUserService;
-import org.sonar.server.user.GroupMembershipFinder;
-import org.sonar.server.user.GroupMembershipService;
-import org.sonar.server.user.NewUserNotifier;
-import org.sonar.server.user.SecurityRealmFactory;
-import org.sonar.server.util.BooleanTypeValidation;
-import org.sonar.server.util.FloatTypeValidation;
-import org.sonar.server.util.IntegerTypeValidation;
-import org.sonar.server.util.StringListTypeValidation;
-import org.sonar.server.util.StringTypeValidation;
-import org.sonar.server.util.TextTypeValidation;
-import org.sonar.server.util.TypeValidations;
+import org.sonar.server.user.*;
+import org.sonar.server.util.*;
import org.sonar.server.ws.ListingWs;
import org.sonar.server.ws.WebServiceEngine;
pico.addSingleton(TransitionAction.class);
// technical debt
- pico.addSingleton(DebtService.class);
+ pico.addSingleton(DebtModelService.class);
pico.addSingleton(TechnicalDebtModelSynchronizer.class);
pico.addSingleton(DebtModelSynchronizer.class);
pico.addSingleton(TechnicalDebtModelRepository.class);
pico.addSingleton(TechnicalDebtXMLImporter.class);
pico.addSingleton(DebtRulesXMLImporter.class);
pico.addSingleton(DebtCharacteristicsXMLImporter.class);
- pico.addSingleton(DefaultTechnicalDebtManager.class);
// source
pico.addSingleton(HtmlSourceDecorator.class);
@rule = Rule.first(:conditions => ['plugin_name=? and plugin_rule_key=?', rule_key[0], rule_key[1]])
characteristic_id = @rule.characteristic_id || @rule.default_characteristic_id
if characteristic_id
- @characteristic = Internal.debt.findCharacteristic(characteristic_id)
- @root_characteristic = Internal.debt.findCharacteristic(@characteristic.parentId())
+ @characteristic = Internal.debt.characteristicById(characteristic_id)
+ @root_characteristic = Internal.debt.characteristicById(@characteristic.parentId())
end
render :partial => 'issue/rule'
end
end
def self.debt
- component(Java::OrgSonarServerDebt::DebtService.java_class)
+ component(Java::OrgSonarServerDebt::DebtModelService.java_class)
end
def self.profiling
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.debt;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.sonar.api.server.debt.DebtCharacteristic;
+import org.sonar.core.technicaldebt.db.CharacteristicDao;
+import org.sonar.core.technicaldebt.db.CharacteristicDto;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DebtModelServiceTest {
+
+ @Mock
+ CharacteristicDao dao;
+
+ DebtModelService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = new DebtModelService(dao);
+ }
+
+ @Test
+ public void find_root_characteristics() {
+ CharacteristicDto dto = new CharacteristicDto()
+ .setId(1)
+ .setKey("MEMORY_EFFICIENCY")
+ .setName("Memory use");
+ when(dao.selectEnabledRootCharacteristics()).thenReturn(newArrayList(dto));
+ assertThat(service.rootCharacteristics()).hasSize(1);
+ }
+
+ @Test
+ public void find_characteristics() {
+ CharacteristicDto dto = new CharacteristicDto()
+ .setId(1)
+ .setKey("MEMORY_EFFICIENCY")
+ .setName("Memory use");
+ when(dao.selectEnabledCharacteristics()).thenReturn(newArrayList(dto));
+ assertThat(service.characteristics()).hasSize(1);
+ }
+
+ @Test
+ public void find_characteristic_by_id() {
+ CharacteristicDto dto = new CharacteristicDto()
+ .setId(1)
+ .setKey("MEMORY_EFFICIENCY")
+ .setName("Memory use")
+ .setParentId(2)
+ .setOrder(1);
+ when(dao.selectById(1)).thenReturn(dto);
+
+ DebtCharacteristic characteristic = service.characteristicById(1);
+ assertThat(characteristic.id()).isEqualTo(1);
+ assertThat(characteristic.key()).isEqualTo("MEMORY_EFFICIENCY");
+ assertThat(characteristic.name()).isEqualTo("Memory use");
+ assertThat(characteristic.parentId()).isEqualTo(2);
+ assertThat(characteristic.order()).isEqualTo(1);
+
+ assertThat(service.characteristicById(10)).isNull();
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.debt;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.technicaldebt.server.Characteristic;
-import org.sonar.api.technicaldebt.server.internal.DefaultCharacteristic;
-import org.sonar.core.technicaldebt.DefaultTechnicalDebtManager;
-
-import java.util.List;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.*;
-
-public class DebtServiceTest {
-
- DefaultTechnicalDebtManager finder = mock(DefaultTechnicalDebtManager.class);
-
- DebtService service;
-
- @Before
- public void setUp() throws Exception {
- service = new DebtService(finder);
- }
-
- @Test
- public void find_root_characteristics() {
- List<Characteristic> rootCharacteristics = newArrayList();
- when(finder.findRootCharacteristics()).thenReturn(rootCharacteristics);
- assertThat(service.findRootCharacteristics()).isEqualTo(rootCharacteristics);
- }
-
- @Test
- public void find_requirement_by_rule_id() {
- service.findRequirementByRuleId(1);
- verify(finder).findRequirementByRuleId(1);
- }
-
- @Test
- public void find_characteristic() {
- Characteristic characteristic = new DefaultCharacteristic();
- when(finder.findCharacteristicById(1)).thenReturn(characteristic);
- assertThat(service.findCharacteristic(1)).isEqualTo(characteristic);
- }
-
-}
import org.sonar.api.issue.internal.FieldDiffs;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
+import org.sonar.api.server.debt.DebtModel;
+import org.sonar.api.server.debt.internal.DefaultDebtCharacteristic;
import org.sonar.api.server.ws.WsTester;
-import org.sonar.api.technicaldebt.server.internal.DefaultCharacteristic;
import org.sonar.api.user.User;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.Duration;
import org.sonar.core.issue.DefaultActionPlan;
import org.sonar.core.issue.DefaultIssueQueryResult;
import org.sonar.core.issue.workflow.Transition;
-import org.sonar.core.technicaldebt.DefaultTechnicalDebtManager;
import org.sonar.core.user.DefaultUser;
import org.sonar.server.issue.ActionService;
import org.sonar.server.issue.IssueChangelog;
ActionService actionService;
@Mock
- DefaultTechnicalDebtManager technicalDebtManager;
+ DebtModel debtModel;
@Mock
I18n i18n;
when(i18n.message(any(Locale.class), eq("created"), eq((String) null))).thenReturn("Created");
- tester = new WsTester(new IssuesWs(new IssueShowWsHandler(issueFinder, issueService, issueChangelogService, actionService, technicalDebtManager, i18n, durations)));
+ tester = new WsTester(new IssuesWs(new IssueShowWsHandler(issueFinder, issueService, issueChangelogService, actionService, debtModel, i18n, durations)));
}
@Test
issues.add(issue);
result.rule(issue).setCharacteristicId(2);
- when(technicalDebtManager.findCharacteristicById(1)).thenReturn(new DefaultCharacteristic().setId(1).setName("Maintainability"));
- when(technicalDebtManager.findCharacteristicById(2)).thenReturn(new DefaultCharacteristic().setId(2).setName("Readability").setParentId(1));
+ when(debtModel.characteristicById(1)).thenReturn(new DefaultDebtCharacteristic().setId(1).setName("Maintainability"));
+ when(debtModel.characteristicById(2)).thenReturn(new DefaultDebtCharacteristic().setId(2).setName("Readability").setParentId(1));
MockUserSession.set();
WsTester.TestRequest request = tester.newRequest("show").setParam("key", issue.key());
issues.add(issue);
result.rule(issue).setDefaultCharacteristicId(2);
- when(technicalDebtManager.findCharacteristicById(1)).thenReturn(new DefaultCharacteristic().setId(1).setName("Maintainability"));
- when(technicalDebtManager.findCharacteristicById(2)).thenReturn(new DefaultCharacteristic().setId(2).setName("Readability").setParentId(1));
+ when(debtModel.characteristicById(1)).thenReturn(new DefaultDebtCharacteristic().setId(1).setName("Maintainability"));
+ when(debtModel.characteristicById(2)).thenReturn(new DefaultDebtCharacteristic().setId(2).setName("Readability").setParentId(1));
MockUserSession.set();
WsTester.TestRequest request = tester.newRequest("show").setParam("key", issue.key());
issues.add(issue);
result.rule(issue).setCharacteristicId(2);
- when(technicalDebtManager.findCharacteristicById(1)).thenReturn(new DefaultCharacteristic().setId(1).setName("Maintainability"));
- when(technicalDebtManager.findCharacteristicById(2)).thenReturn(new DefaultCharacteristic().setId(2).setName("Readability").setParentId(1));
+ when(debtModel.characteristicById(1)).thenReturn(new DefaultDebtCharacteristic().setId(1).setName("Maintainability"));
+ when(debtModel.characteristicById(2)).thenReturn(new DefaultDebtCharacteristic().setId(2).setName("Readability").setParentId(1));
result.rule(issue).setDefaultCharacteristicId(20);
- when(technicalDebtManager.findCharacteristicById(10)).thenReturn(new DefaultCharacteristic().setId(10).setName("Default Maintainability"));
- when(technicalDebtManager.findCharacteristicById(20)).thenReturn(new DefaultCharacteristic().setId(20).setName("Default Readability").setParentId(10));
+ when(debtModel.characteristicById(10)).thenReturn(new DefaultDebtCharacteristic().setId(10).setName("Default Maintainability"));
+ when(debtModel.characteristicById(20)).thenReturn(new DefaultDebtCharacteristic().setId(20).setName("Default Readability").setParentId(10));
MockUserSession.set();
WsTester.TestRequest request = tester.newRequest("show").setParam("key", issue.key());