import org.sonar.api.web.Dashboard;
import org.sonar.api.web.DashboardLayout;
import org.sonar.api.web.DashboardTemplate;
-import org.sonar.core.measure.MeasureFilterDao;
-import org.sonar.core.measure.MeasureFilterDto;
+import org.sonar.core.measure.db.MeasureFilterDao;
+import org.sonar.core.measure.db.MeasureFilterDto;
import org.sonar.plugins.core.measurefilters.MyFavouritesFilter;
import org.sonar.plugins.core.measurefilters.ProjectFilter;
import org.sonar.plugins.core.widgets.MeasureFilterListWidget;
import org.junit.Test;
import org.sonar.api.web.Dashboard;
import org.sonar.api.web.Dashboard.Widget;
-import org.sonar.core.measure.MeasureFilterDao;
-import org.sonar.core.measure.MeasureFilterDto;
+import org.sonar.core.measure.db.MeasureFilterDao;
+import org.sonar.core.measure.db.MeasureFilterDto;
import org.sonar.plugins.core.CorePlugin;
import org.sonar.plugins.core.measurefilters.MyFavouritesFilter;
import org.sonar.plugins.core.measurefilters.ProjectFilter;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.measure;
-
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.BatchComponent;
-import org.sonar.api.ServerComponent;
-import org.sonar.core.persistence.MyBatis;
-
-/**
- * @since 3.4
- */
-public class MeasureFilterDao implements BatchComponent, ServerComponent {
- private MyBatis mybatis;
-
- public MeasureFilterDao(MyBatis mybatis) {
- this.mybatis = mybatis;
- }
-
- public MeasureFilterDto findSystemFilterByName(String name) {
- SqlSession session = mybatis.openSession();
- try {
- MeasureFilterMapper mapper = session.getMapper(MeasureFilterMapper.class);
- return mapper.findSystemFilterByName(name);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public void insert(MeasureFilterDto filter) {
- SqlSession session = mybatis.openSession();
- MeasureFilterMapper mapper = session.getMapper(MeasureFilterMapper.class);
- try {
- mapper.insert(filter);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.measure;
-
-import javax.annotation.Nullable;
-
-import java.util.Date;
-
-/**
- * @since 3.4
- */
-public class MeasureFilterDto {
- private Long id;
- private String name;
- private Long userId;
- private Boolean shared;
- private String description;
- private String data;
- private Date createdAt;
- private Date updatedAt;
-
- public Long getId() {
- return id;
- }
-
- public MeasureFilterDto setId(Long id) {
- this.id = id;
- return this;
- }
-
- public String getName() {
- return name;
- }
-
- public MeasureFilterDto setName(String name) {
- this.name = name;
- return this;
- }
-
- public Long getUserId() {
- return userId;
- }
-
- public MeasureFilterDto setUserId(@Nullable Long userId) {
- this.userId = userId;
- return this;
- }
-
- public Boolean isShared() {
- return shared;
- }
-
- public MeasureFilterDto setShared(@Nullable Boolean shared) {
- this.shared = shared;
- return this;
- }
-
- public String getDescription() {
- return description;
- }
-
- public MeasureFilterDto setDescription(@Nullable String description) {
- this.description = description;
- return this;
- }
-
- public String getData() {
- return data;
- }
-
- public MeasureFilterDto setData(String data) {
- this.data = data;
- return this;
- }
-
- public Date getCreatedAt() {
- return createdAt;
- }
-
- public MeasureFilterDto setCreatedAt(Date createdAt) {
- this.createdAt = createdAt;
- return this;
- }
-
- public Date getUpdatedAt() {
- return updatedAt;
- }
-
- public MeasureFilterDto setUpdatedAt(Date updatedAt) {
- this.updatedAt = updatedAt;
- return this;
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.measure;
-
-/**
- * @since 3.4
- */
-public interface MeasureFilterMapper {
- MeasureFilterDto findSystemFilterByName(String name);
-
- void insert(MeasureFilterDto filter);
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.measure.db;
+
+import org.apache.ibatis.session.SqlSession;
+import org.sonar.api.ServerComponent;
+import org.sonar.core.persistence.MyBatis;
+
+public class MeasureDataDao implements ServerComponent {
+
+ private MyBatis mybatis;
+
+ public MeasureDataDao(MyBatis mybatis) {
+ this.mybatis = mybatis;
+ }
+
+ public MeasureDataDto findByComponentKeyAndMetricKey(String componentKey, String metricKey) {
+ SqlSession session = mybatis.openSession();
+ try {
+ MeasureDataMapper mapper = session.getMapper(MeasureDataMapper.class);
+ return mapper.findByComponentKeyAndMetricKey(componentKey, metricKey);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.measure.db;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Throwables;
+
+import java.io.UnsupportedEncodingException;
+
+public class MeasureDataDto {
+
+ private Integer id;
+
+ private Integer measureId;
+
+ private Integer snapshotId;
+
+ private byte[] data;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public MeasureDataDto setId(Integer id) {
+ this.id = id;
+ return this;
+ }
+
+ public Integer getMeasureId() {
+ return measureId;
+ }
+
+ public MeasureDataDto setMeasureId(Integer measureId) {
+ this.measureId = measureId;
+ return this;
+ }
+
+ public Integer getSnapshotId() {
+ return snapshotId;
+ }
+
+ public MeasureDataDto setSnapshotId(Integer snapshotId) {
+ this.snapshotId = snapshotId;
+ return this;
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ public MeasureDataDto setData(byte[] data) {
+ this.data = data;
+ return this;
+ }
+
+ public String getText() {
+ if (data != null) {
+ try {
+ return new String(data, Charsets.UTF_8.name());
+ } catch (UnsupportedEncodingException e) {
+ // how is it possible to not support UTF-8 ?
+ Throwables.propagate(e);
+ }
+ }
+ return null;
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.measure.db;
+
+import org.apache.ibatis.annotations.Param;
+
+public interface MeasureDataMapper {
+
+ MeasureDataDto findByComponentKeyAndMetricKey(@Param("componentKey") String componentKey, @Param("metricKey") String metricKey);
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.measure.db;
+
+import org.apache.ibatis.session.SqlSession;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.ServerComponent;
+import org.sonar.core.persistence.MyBatis;
+
+/**
+ * @since 3.4
+ */
+public class MeasureFilterDao implements BatchComponent, ServerComponent {
+ private MyBatis mybatis;
+
+ public MeasureFilterDao(MyBatis mybatis) {
+ this.mybatis = mybatis;
+ }
+
+ public MeasureFilterDto findSystemFilterByName(String name) {
+ SqlSession session = mybatis.openSession();
+ try {
+ MeasureFilterMapper mapper = session.getMapper(MeasureFilterMapper.class);
+ return mapper.findSystemFilterByName(name);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void insert(MeasureFilterDto filter) {
+ SqlSession session = mybatis.openSession();
+ MeasureFilterMapper mapper = session.getMapper(MeasureFilterMapper.class);
+ try {
+ mapper.insert(filter);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.measure.db;
+
+import javax.annotation.Nullable;
+
+import java.util.Date;
+
+/**
+ * @since 3.4
+ */
+public class MeasureFilterDto {
+ private Long id;
+ private String name;
+ private Long userId;
+ private Boolean shared;
+ private String description;
+ private String data;
+ private Date createdAt;
+ private Date updatedAt;
+
+ public Long getId() {
+ return id;
+ }
+
+ public MeasureFilterDto setId(Long id) {
+ this.id = id;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public MeasureFilterDto setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public Long getUserId() {
+ return userId;
+ }
+
+ public MeasureFilterDto setUserId(@Nullable Long userId) {
+ this.userId = userId;
+ return this;
+ }
+
+ public Boolean isShared() {
+ return shared;
+ }
+
+ public MeasureFilterDto setShared(@Nullable Boolean shared) {
+ this.shared = shared;
+ return this;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public MeasureFilterDto setDescription(@Nullable String description) {
+ this.description = description;
+ return this;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public MeasureFilterDto setData(String data) {
+ this.data = data;
+ return this;
+ }
+
+ public Date getCreatedAt() {
+ return createdAt;
+ }
+
+ public MeasureFilterDto setCreatedAt(Date createdAt) {
+ this.createdAt = createdAt;
+ return this;
+ }
+
+ public Date getUpdatedAt() {
+ return updatedAt;
+ }
+
+ public MeasureFilterDto setUpdatedAt(Date updatedAt) {
+ this.updatedAt = updatedAt;
+ return this;
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.measure.db;
+
+/**
+ * @since 3.4
+ */
+public interface MeasureFilterMapper {
+ MeasureFilterDto findSystemFilterByName(String name);
+
+ void insert(MeasureFilterDto filter);
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.core.measure.db;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
import org.sonar.core.duplication.DuplicationDao;
import org.sonar.core.graph.jdbc.GraphDao;
import org.sonar.core.issue.db.*;
-import org.sonar.core.measure.MeasureFilterDao;
+import org.sonar.core.measure.db.MeasureDataDao;
+import org.sonar.core.measure.db.MeasureFilterDao;
import org.sonar.core.notification.db.NotificationQueueDao;
import org.sonar.core.permission.PermissionDao;
import org.sonar.core.permission.PermissionTemplateDao;
IssueFilterDao.class,
IssueFilterFavouriteDao.class,
LoadedTemplateDao.class,
+ MeasureDataDao.class,
MeasureFilterDao.class,
NotificationQueueDao.class,
PermissionDao.class,
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
import org.sonar.api.config.Settings;
-import org.sonar.api.database.model.MeasureData;
import org.sonar.api.database.model.MeasureMapper;
import org.sonar.api.database.model.MeasureModel;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.graph.jdbc.GraphDto;
import org.sonar.core.graph.jdbc.GraphDtoMapper;
import org.sonar.core.issue.db.*;
-import org.sonar.core.measure.MeasureFilterDto;
-import org.sonar.core.measure.MeasureFilterMapper;
+import org.sonar.core.measure.db.MeasureDataDto;
+import org.sonar.core.measure.db.MeasureDataMapper;
+import org.sonar.core.measure.db.MeasureFilterDto;
+import org.sonar.core.measure.db.MeasureFilterMapper;
import org.sonar.core.notification.db.NotificationQueueDto;
import org.sonar.core.notification.db.NotificationQueueMapper;
import org.sonar.core.permission.*;
loadAlias(conf, "Widget", WidgetDto.class);
loadAlias(conf, "WidgetProperty", WidgetPropertyDto.class);
loadAlias(conf, "MeasureModel", MeasureModel.class);
- loadAlias(conf, "MeasureData", MeasureData.class);
+ loadAlias(conf, "MeasureData", MeasureDataDto.class);
loadAlias(conf, "Issue", IssueDto.class);
loadAlias(conf, "IssueChange", IssueChangeDto.class);
loadAlias(conf, "IssueFilter", IssueFilterDto.class);
SchemaMigrationMapper.class, SemaphoreMapper.class, UserMapper.class, WidgetMapper.class, WidgetPropertyMapper.class,
MeasureMapper.class, SnapshotDataMapper.class, SnapshotSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class,
NotificationQueueMapper.class, CharacteristicMapper.class, RuleTagMapper.class,
- GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class
+ GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class,
+ MeasureDataMapper.class
};
loadMappers(conf, mappers);
configureLogback(mappers);
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.core.measure.MeasureFilterMapper">
-
- <select id="findSystemFilterByName" parameterType="string" resultType="MeasureFilter">
- select id, name, user_id as "userId", shared, description, data, created_at as "createdAt", updated_at as "updatedAt"
- from measure_filters WHERE user_id is null and name=#{id}
- </select>
-
- <insert id="insert" parameterType="MeasureFilter" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
- INSERT INTO measure_filters (name, user_id, shared, description, data, created_at, updated_at)
- VALUES (#{name}, #{userId}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
- </insert>
-
-</mapper>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.measure.db.MeasureDataMapper">
+
+ <sql id="measureDataColumns">
+ m.id,
+ m.measure_id as measureId,
+ m.snapshot_id as snapshotId,
+ m.measure_id as measureId,
+ m.data as data
+ </sql>
+
+ <select id="findByComponentKeyAndMetricKey" parameterType="map" resultType="MeasureData">
+ SELECT
+ <include refid="measureDataColumns"/>
+ FROM measure_data m
+ INNER JOIN project_measures pm ON pm.id=m.measure_id
+ INNER JOIN snapshots s ON s.id=pm.snapshot_id AND s.islast=${_true}
+ INNER JOIN projects p ON p.id=s.project_id AND p.enabled=${_true}
+ INNER JOIN metrics metric ON metric.id=pm.metric_id
+ <where>
+ AND p.kee = #{componentKey}
+ AND metric.name = #{metricKey}
+ </where>
+ </select>
+
+</mapper>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.measure.db.MeasureFilterMapper">
+
+ <select id="findSystemFilterByName" parameterType="string" resultType="MeasureFilter">
+ select id, name, user_id as "userId", shared, description, data, created_at as "createdAt", updated_at as "updatedAt"
+ from measure_filters WHERE user_id is null and name=#{id}
+ </select>
+
+ <insert id="insert" parameterType="MeasureFilter" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ INSERT INTO measure_filters (name, user_id, shared, description, data, created_at, updated_at)
+ VALUES (#{name}, #{userId}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
+ </insert>
+
+</mapper>
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.measure;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.core.persistence.AbstractDaoTestCase;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class MeasureFilterDaoTest extends AbstractDaoTestCase {
- private MeasureFilterDao dao;
-
- @Before
- public void createDao() {
- dao = new MeasureFilterDao(getMyBatis());
- }
-
- @Test
- public void should_find_filter() {
- setupData("shared");
-
- MeasureFilterDto filter = dao.findSystemFilterByName("Projects");
-
- assertThat(filter.getId()).isEqualTo(1L);
- assertThat(filter.getName()).isEqualTo("Projects");
- }
-
- @Test
- public void should_not_find_filter() {
- setupData("shared");
-
- assertThat(dao.findSystemFilterByName("Unknown")).isNull();
- }
-
- @Test
- public void should_insert() {
- setupData("shared");
-
- MeasureFilterDto filterDto = new MeasureFilterDto();
- filterDto.setName("Project Treemap");
- filterDto.setUserId(123L);
- filterDto.setShared(true);
- filterDto.setDescription("Treemap of projects");
- filterDto.setData("qualifiers=TRK|display=treemap");
-
- dao.insert(filterDto);
-
- checkTables("shouldInsert", new String[]{"created_at", "updated_at"}, "measure_filters");
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.measure.db;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.core.persistence.AbstractDaoTestCase;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class MeasureDataDaoTest extends AbstractDaoTestCase {
+
+ private MeasureDataDao dao;
+
+ @Before
+ public void createDao() {
+ dao = new MeasureDataDao(getMyBatis());
+ }
+
+ @Test
+ public void find_by_component_key_and_metric_key() throws Exception {
+ setupData("shared");
+
+ MeasureDataDto result = dao.findByComponentKeyAndMetricKey("org.sonar.core.measure.db.MeasureData", "authors_by_line");
+ assertThat(result.getId()).isEqualTo(1);
+ assertThat(result.getMeasureId()).isEqualTo(1);
+ assertThat(result.getSnapshotId()).isEqualTo(1);
+ assertThat(result.getText()).isNotNull();
+
+ // FIXME failing because data is returned in wrong format
+// assertThat(result.getText()).isEqualTo("test");
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.measure.db;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.core.persistence.AbstractDaoTestCase;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class MeasureFilterDaoTest extends AbstractDaoTestCase {
+ private MeasureFilterDao dao;
+
+ @Before
+ public void createDao() {
+ dao = new MeasureFilterDao(getMyBatis());
+ }
+
+ @Test
+ public void should_find_filter() {
+ setupData("shared");
+
+ MeasureFilterDto filter = dao.findSystemFilterByName("Projects");
+
+ assertThat(filter.getId()).isEqualTo(1L);
+ assertThat(filter.getName()).isEqualTo("Projects");
+ }
+
+ @Test
+ public void should_not_find_filter() {
+ setupData("shared");
+
+ assertThat(dao.findSystemFilterByName("Unknown")).isNull();
+ }
+
+ @Test
+ public void should_insert() {
+ setupData("shared");
+
+ MeasureFilterDto filterDto = new MeasureFilterDto();
+ filterDto.setName("Project Treemap");
+ filterDto.setUserId(123L);
+ filterDto.setShared(true);
+ filterDto.setDescription("Treemap of projects");
+ filterDto.setData("qualifiers=TRK|display=treemap");
+
+ dao.insert(filterDto);
+
+ checkTables("shouldInsert", new String[]{"created_at", "updated_at"}, "measure_filters");
+ }
+}
+++ /dev/null
-<dataset>
-
- <measure_filters
- id="1"
- name="Projects"
- user_id="[null]"
- shared="[true]"
- description="All projects"
- data="qualifiers=TRK"
- created_at="2012-12-25"
- updated_at="2012-12-25" />
-
- <measure_filters
- id="2"
- name="Files"
- user_id="[null]"
- shared="[true]"
- description="All files"
- data="qualifiers=FIL"
- created_at="2012-01-25"
- updated_at="2012-01-25" />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <measure_filters
- id="1"
- name="Projects"
- user_id="[null]"
- shared="[true]"
- description="All projects"
- data="qualifiers=TRK"
- created_at="2012-12-25"
- updated_at="2012-12-25"/>
-
- <measure_filters
- id="2"
- name="Files"
- user_id="[null]"
- shared="[true]"
- description="All files"
- data="qualifiers=FIL"
- created_at="2012-01-25"
- updated_at="2012-01-25"/>
-
-
- <measure_filters
- id="3"
- name="Project Treemap"
- user_id="123"
- shared="[true]"
- description="Treemap of projects"
- data="qualifiers=TRK|display=treemap"
- created_at="2012-12-25"
- updated_at="2012-12-25"/>
-
-</dataset>
--- /dev/null
+<dataset>
+
+ <snapshots id="1" project_id="1" islast="[true]" />
+ <project_measures id="1" snapshot_id="1" metric_id="1"/>
+ <metrics id="1" name="authors_by_line"/>
+ <projects id="1" kee="org.sonar.core.measure.db.MeasureData" enabled="[true]"/>
+
+ <measure_data id="1" measure_id="1" snapshot_id="1" data="test"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <measure_filters
+ id="1"
+ name="Projects"
+ user_id="[null]"
+ shared="[true]"
+ description="All projects"
+ data="qualifiers=TRK"
+ created_at="2012-12-25"
+ updated_at="2012-12-25" />
+
+ <measure_filters
+ id="2"
+ name="Files"
+ user_id="[null]"
+ shared="[true]"
+ description="All files"
+ data="qualifiers=FIL"
+ created_at="2012-01-25"
+ updated_at="2012-01-25" />
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <measure_filters
+ id="1"
+ name="Projects"
+ user_id="[null]"
+ shared="[true]"
+ description="All projects"
+ data="qualifiers=TRK"
+ created_at="2012-12-25"
+ updated_at="2012-12-25"/>
+
+ <measure_filters
+ id="2"
+ name="Files"
+ user_id="[null]"
+ shared="[true]"
+ description="All files"
+ data="qualifiers=FIL"
+ created_at="2012-01-25"
+ updated_at="2012-01-25"/>
+
+
+ <measure_filters
+ id="3"
+ name="Project Treemap"
+ user_id="123"
+ shared="[true]"
+ description="Treemap of projects"
+ data="qualifiers=TRK|display=treemap"
+ created_at="2012-12-25"
+ updated_at="2012-12-25"/>
+
+</dataset>
import org.sonar.api.ServerComponent;
import org.sonar.api.web.UserRole;
+import org.sonar.core.measure.db.MeasureDataDao;
+import org.sonar.core.measure.db.MeasureDataDto;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
import org.sonar.core.source.HtmlSourceDecorator;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.util.List;
private final HtmlSourceDecorator sourceDecorator;
private final ResourceDao resourceDao;
+ private final MeasureDataDao measureDataDao;
- public SourceService(HtmlSourceDecorator sourceDecorator, ResourceDao resourceDao) {
+ public SourceService(HtmlSourceDecorator sourceDecorator, ResourceDao resourceDao, MeasureDataDao measureDataDao) {
this.sourceDecorator = sourceDecorator;
this.resourceDao = resourceDao;
+ this.measureDataDao = measureDataDao;
}
public List<String> sourcesFromComponent(String componentKey) {
UserSession.get().checkProjectPermission(UserRole.CODEVIEWER, project.getKey());
return sourceDecorator.getDecoratedSourceAsHtml(componentKey, from, to);
}
+
+ // TODO move this in another service
+ @CheckForNull
+ public String findDataFromComponent(String componentKey, String metricKey){
+ MeasureDataDto data = measureDataDao.findByComponentKeyAndMetricKey(componentKey, metricKey);
+ if (data != null) {
+ return data.getText();
+ }
+ return null;
+ }
}
package org.sonar.server.source.ws;
+import com.google.common.base.Splitter;
+import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
import java.util.List;
+import static com.google.common.collect.Lists.newArrayList;
+
public class SourcesShowWsHandler implements RequestHandler {
private final SourceService sourceService;
@Override
public void handle(Request request, Response response) {
String componentKey = request.requiredParam("key");
- Integer from = request.intParam("from");
- Integer to = request.intParam("to");
-
- List<String> sourceHtml = sourceService.sourcesFromComponent(componentKey, from , to);
+ Integer fromParam = request.intParam("from");
+ Integer toParam = request.intParam("to");
+ List<String> sourceHtml = sourceService.sourcesFromComponent(componentKey, fromParam, toParam);
if (sourceHtml == null) {
throw new NotFoundException("Component : " + componentKey + " has no source.");
}
- from = from != null ? from : 1;
+ String scmAuthorData = sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY);
+ String scmDataData = sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY);
+
+ int from = fromParam != null ? fromParam : 1;
+ int to = toParam != null ? toParam : sourceHtml.size() + from;
JsonWriter json = response.newJsonWriter();
- json.beginObject().name("source").beginObject();
- for (int i = 0; i < sourceHtml.size(); i++) {
- String line = sourceHtml.get(i);
+ json.beginObject();
+ writeSource(sourceHtml, from, json);
+ writeScm(scmAuthorData, scmDataData, from, to, json);
+ json.endObject().close();
+ }
+
+ private void writeSource(List<String> source, int from, JsonWriter json) {
+ json.name("source").beginObject();
+ for (int i = 0; i < source.size(); i++) {
+ String line = source.get(i);
json.prop(Integer.toString(i + from), line);
}
- json.endObject().endObject().close();
+ json.endObject();
+ }
+
+ private void writeScm(String authorData, String scmDateData, int from, int to , JsonWriter json) {
+ if (authorData != null) {
+ json.name("scm").beginObject();
+ List<String> authors = splitLine(authorData);
+ for (int i = 0; i < authors.size(); i++) {
+ String[] authorWithLine = splitColumn(authors.get(i));
+ Integer line = Integer.parseInt(authorWithLine[0]);
+ String author = authorWithLine[1];
+ if (line >= from && line <= to) {
+ json.name(Integer.toString(line)).beginArray();
+ json.value(author);
+ json.endArray();
+ }
+ }
+ json.endObject();
+ }
+ }
+
+ private List<String> splitLine(String line){
+ return newArrayList(Splitter.on(";").split(line));
+ }
+
+ private String[] splitColumn(String column){
+ return column.split("=");
}
}
import org.sonar.api.web.Filter;
import org.sonar.api.web.FilterColumn;
import org.sonar.api.web.FilterTemplate;
-import org.sonar.core.measure.MeasureFilterDao;
-import org.sonar.core.measure.MeasureFilterDto;
+import org.sonar.core.measure.db.MeasureFilterDao;
+import org.sonar.core.measure.db.MeasureFilterDto;
import org.sonar.core.template.LoadedTemplateDao;
import org.sonar.core.template.LoadedTemplateDto;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.api.web.UserRole;
+import org.sonar.core.measure.db.MeasureDataDao;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
import org.sonar.core.source.HtmlSourceDecorator;
@Mock
ResourceDao resourceDao;
+ @Mock
+ MeasureDataDao measureDataDao;
+
SourceService service;
@Before
public void setUp() throws Exception {
- service = new SourceService(sourceDecorator, resourceDao);
+ service = new SourceService(sourceDecorator, resourceDao, measureDataDao);
}
@Test
verify(sourceDecorator).getDecoratedSourceAsHtml(componentKey, 1, 2);
}
+
+ @Test
+ public void find_data_from_component() throws Exception {
+ String componentKey = "org.sonar.sample:Sample";
+ service.findDataFromComponent(componentKey, "metric_key");
+ verify(measureDataDao).findByComponentKeyAndMetricKey(componentKey, "metric_key");
+ }
+
+ @Test
+ public void not_find_data_from_component_if_no_data() throws Exception {
+ String componentKey = "org.sonar.sample:Sample";
+ when(measureDataDao.findByComponentKeyAndMetricKey(componentKey, "metric_key")).thenReturn(null);
+ assertThat(service.findDataFromComponent(componentKey, "metric_key")).isNull();
+ }
}
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.server.ws.WsTester;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.source.SourceService;
}
@Test
- public void show_source_with_params_from_and_to() throws Exception {
+ public void show_source_with_from_and_to_params() throws Exception {
String componentKey = "org.apache.struts:struts:Dispatcher";
when(sourceService.sourcesFromComponent(componentKey, 3, 5)).thenReturn(newArrayList(
" */",
WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey).setParam("from", "3").setParam("to", "5");
request.execute().assertJson(getClass(), "show_source_with_params_from_and_to.json");
}
+
+ @Test
+ public void show_source_with_scm() throws Exception {
+ String componentKey = "org.apache.struts:struts:Dispatcher";
+ when(sourceService.sourcesFromComponent(eq(componentKey), anyInt(), anyInt())).thenReturn(newArrayList(
+ "public class <span class=\"sym-31 sym\">HelloWorld</span> {}"
+ ));
+
+ when(sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY)).thenReturn("1=julien;2=simon");
+
+ WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey);
+ request.execute().assertJson(getClass(), "show_source_with_scm.json");
+ }
+
+ @Test
+ public void show_source_with_scm_with_from_and_to_params() throws Exception {
+ String componentKey = "org.apache.struts:struts:Dispatcher";
+ when(sourceService.sourcesFromComponent(componentKey, 3, 5)).thenReturn(newArrayList(
+ " */",
+ "",
+ "public class <span class=\"sym-31 sym\">HelloWorld</span> {"
+ ));
+ when(sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY))
+ .thenReturn("1=julien;2=simon;3=julien;4=simon;5=simon;6=julien");
+
+ WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey).setParam("from", "3").setParam("to", "5");
+ request.execute().assertJson(getClass(), "show_source_with_scm_with_from_and_to_params.json");
+ }
}
import org.sonar.api.web.Filter;
import org.sonar.api.web.FilterColumn;
import org.sonar.api.web.FilterTemplate;
-import org.sonar.core.measure.MeasureFilterDao;
-import org.sonar.core.measure.MeasureFilterDto;
+import org.sonar.core.measure.db.MeasureFilterDao;
+import org.sonar.core.measure.db.MeasureFilterDto;
import org.sonar.core.template.LoadedTemplateDao;
import org.sonar.core.template.LoadedTemplateDto;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
public class RegisterNewMeasureFiltersTest {
private RegisterNewMeasureFilters registration;
--- /dev/null
+{
+ "source": {
+ "1": "public class <span class=\"sym-31 sym\">HelloWorld</span> {}"
+ },
+ "scm": {
+ "1": ["julien"],
+ "2": ["simon"]
+ }
+}
+
+
+
+
+
+
+
+
--- /dev/null
+{
+ "source": {
+ "3": " */",
+ "4": "",
+ "5": "public class <span class=\"sym-31 sym\">HelloWorld</span> {"
+ },
+ "scm": {
+ "3": ["julien"],
+ "4": ["simon"],
+ "5": ["simon"]
+ }
+}
+
+
+
+
+
+
+
+