]> source.dussan.org Git - sonarqube.git/commitdiff
SourcesShowWS : Add scm author
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 27 Jan 2014 16:08:46 +0000 (17:08 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 27 Jan 2014 16:08:58 +0000 (17:08 +0100)
33 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/GlobalDefaultDashboard.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/GlobalDefaultDashboardTest.java
sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterDao.java [deleted file]
sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterDto.java [deleted file]
sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterMapper.java [deleted file]
sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDataDao.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDataDto.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDataMapper.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/measure/db/MeasureFilterDao.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/measure/db/MeasureFilterDto.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/measure/db/MeasureFilterMapper.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/measure/db/package-info.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-core/src/main/resources/org/sonar/core/measure/MeasureFilterMapper.xml [deleted file]
sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureDataMapper.xml [new file with mode: 0644]
sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureFilterMapper.xml [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterDaoTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/measure/db/MeasureDataDaoTest.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/measure/db/MeasureFilterDaoTest.java [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterDaoTest/shared.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterDaoTest/shouldInsert-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureDataDaoTest/shared.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shared.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shouldInsert-result.xml [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/source/SourceService.java
sonar-server/src/main/java/org/sonar/server/source/ws/SourcesShowWsHandler.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterNewMeasureFilters.java
sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java
sonar-server/src/test/java/org/sonar/server/source/ws/SourcesShowWsHandlerTest.java
sonar-server/src/test/java/org/sonar/server/startup/RegisterNewMeasureFiltersTest.java
sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm.json [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_with_from_and_to_params.json [new file with mode: 0644]

index 60c207ad9e9b4638d7698d4f0a36bba6d8da243b..7315913c878c11422b77cebdd4e7576930fe1f58 100644 (file)
@@ -22,8 +22,8 @@ package org.sonar.plugins.core.dashboards;
 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;
index 521aa51fdc66cfcc2340532893721b71167e6bc2..e74bc8bedec660b7bd435e5e0b4cebff67242ace 100644 (file)
@@ -23,8 +23,8 @@ import org.junit.Before;
 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;
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterDao.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterDao.java
deleted file mode 100644 (file)
index d1f355c..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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);
-    }
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterDto.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterDto.java
deleted file mode 100644 (file)
index 5efb7e7..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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;
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterMapper.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterMapper.java
deleted file mode 100644 (file)
index 492df2f..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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);
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDataDao.java b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDataDao.java
new file mode 100644 (file)
index 0000000..68619c4
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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);
+    }
+  }
+
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDataDto.java b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDataDto.java
new file mode 100644 (file)
index 0000000..0e27679
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * 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;
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDataMapper.java b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDataMapper.java
new file mode 100644 (file)
index 0000000..5be8ab5
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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);
+
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureFilterDao.java b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureFilterDao.java
new file mode 100644 (file)
index 0000000..a45d3c3
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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);
+    }
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureFilterDto.java b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureFilterDto.java
new file mode 100644 (file)
index 0000000..bd942f8
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * 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;
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureFilterMapper.java b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureFilterMapper.java
new file mode 100644 (file)
index 0000000..25e3eaa
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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);
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/package-info.java b/sonar-core/src/main/java/org/sonar/core/measure/db/package-info.java
new file mode 100644 (file)
index 0000000..340b045
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
index f2e8d6f77b21f058ef901168d98f27230deddd25..99ed13b1bc900bd6ca5a7c505594b82ef009fa80 100644 (file)
@@ -25,7 +25,8 @@ import org.sonar.core.dashboard.DashboardDao;
 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;
@@ -70,6 +71,7 @@ public final class DaoUtils {
       IssueFilterDao.class,
       IssueFilterFavouriteDao.class,
       LoadedTemplateDao.class,
+      MeasureDataDao.class,
       MeasureFilterDao.class,
       NotificationQueueDao.class,
       PermissionDao.class,
index 09c38625390a7ee544b83b61d57a95c576ea8fdc..ab2b3472488883d33fea89e4709d7040606ffdd9 100644 (file)
@@ -31,7 +31,6 @@ import org.slf4j.LoggerFactory;
 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;
@@ -46,8 +45,10 @@ import org.sonar.core.duplication.DuplicationUnitDto;
 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.*;
@@ -125,7 +126,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
     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);
@@ -157,7 +158,8 @@ public class MyBatis implements BatchComponent, ServerComponent {
       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);
diff --git a/sonar-core/src/main/resources/org/sonar/core/measure/MeasureFilterMapper.xml b/sonar-core/src/main/resources/org/sonar/core/measure/MeasureFilterMapper.xml
deleted file mode 100644 (file)
index 425b8cc..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<?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>
diff --git a/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureDataMapper.xml b/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureDataMapper.xml
new file mode 100644 (file)
index 0000000..bcefc34
--- /dev/null
@@ -0,0 +1,28 @@
+<?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>
diff --git a/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureFilterMapper.xml b/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureFilterMapper.xml
new file mode 100644 (file)
index 0000000..b2803b6
--- /dev/null
@@ -0,0 +1,16 @@
+<?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>
diff --git a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterDaoTest.java b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterDaoTest.java
deleted file mode 100644 (file)
index 87445a5..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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");
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/measure/db/MeasureDataDaoTest.java b/sonar-core/src/test/java/org/sonar/core/measure/db/MeasureDataDaoTest.java
new file mode 100644 (file)
index 0000000..bec6ebd
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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");
+  }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/measure/db/MeasureFilterDaoTest.java b/sonar-core/src/test/java/org/sonar/core/measure/db/MeasureFilterDaoTest.java
new file mode 100644 (file)
index 0000000..289a0cf
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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");
+  }
+}
diff --git a/sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterDaoTest/shared.xml
deleted file mode 100644 (file)
index 94d2292..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<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>
diff --git a/sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterDaoTest/shouldInsert-result.xml b/sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterDaoTest/shouldInsert-result.xml
deleted file mode 100644 (file)
index 1100b16..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<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>
diff --git a/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureDataDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureDataDaoTest/shared.xml
new file mode 100644 (file)
index 0000000..941c098
--- /dev/null
@@ -0,0 +1,10 @@
+<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>
diff --git a/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shared.xml
new file mode 100644 (file)
index 0000000..94d2292
--- /dev/null
@@ -0,0 +1,23 @@
+<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>
diff --git a/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shouldInsert-result.xml b/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shouldInsert-result.xml
new file mode 100644 (file)
index 0000000..1100b16
--- /dev/null
@@ -0,0 +1,34 @@
+<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>
index da550c98e07fd2e785b927006165734070a9ab60..f2472b273df6e023f07cf59e569e424785c0a9ff 100644 (file)
@@ -22,12 +22,15 @@ package org.sonar.server.source;
 
 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;
@@ -36,10 +39,12 @@ public class SourceService implements ServerComponent {
 
   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) {
@@ -54,4 +59,14 @@ public class SourceService implements ServerComponent {
     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;
+  }
 }
index 0e7fdedfe9d2b3b0714928123473a10e7b2ce523..eda1fc926c401e670f84c57344d75da9dbb262ed 100644 (file)
@@ -20,6 +20,8 @@
 
 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;
@@ -29,6 +31,8 @@ import org.sonar.server.source.SourceService;
 
 import java.util.List;
 
+import static com.google.common.collect.Lists.newArrayList;
+
 public class SourcesShowWsHandler implements RequestHandler {
 
   private final SourceService sourceService;
@@ -40,22 +44,58 @@ public class SourcesShowWsHandler implements RequestHandler {
   @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("=");
   }
 
 }
index 27e59daac27df9112f9cd511d3b4d32caad96ff5..7994219fc598e30b24c59e9212319d064914d69b 100644 (file)
@@ -30,8 +30,8 @@ import org.sonar.api.web.Criterion;
 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;
 
index 35d69afb2d1564a3214a6bb6871f9bda6f83ad3d..91cb480f5d9704e77a96ae1547a80e0bdd391745 100644 (file)
@@ -26,6 +26,7 @@ import org.junit.runner.RunWith;
 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;
@@ -45,11 +46,14 @@ public class SourceServiceTest {
   @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
@@ -92,4 +96,18 @@ public class SourceServiceTest {
 
     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();
+  }
 }
index 6909a818b1e5f5b2b3b5859c653eeefd879b15d9..f02b4c25cd13439aca9ea3f40b25adae257e0d5d 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.Test;
 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;
@@ -79,7 +80,7 @@ public class SourcesShowWsHandlerTest {
   }
 
   @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(
       " */",
@@ -89,4 +90,32 @@ public class SourcesShowWsHandlerTest {
     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");
+  }
 }
index bd300f57c8e8797c926e981da908284fe9aeef12..6decdaf348f3fc9ea891445c9132a30f514a2dae 100644 (file)
@@ -25,8 +25,8 @@ import org.sonar.api.web.Criterion;
 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;
 
@@ -34,10 +34,7 @@ import static org.fest.assertions.Assertions.assertThat;
 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;
diff --git a/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm.json b/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm.json
new file mode 100644 (file)
index 0000000..c9e2ac9
--- /dev/null
@@ -0,0 +1,17 @@
+{
+  "source": {
+    "1": "public class <span class=\"sym-31 sym\">HelloWorld</span> {}"
+  },
+  "scm": {
+    "1": ["julien"],
+    "2": ["simon"]
+  }
+}
+
+
+
+
+
+
+
+
diff --git a/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_with_from_and_to_params.json b/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_with_from_and_to_params.json
new file mode 100644 (file)
index 0000000..6990b66
--- /dev/null
@@ -0,0 +1,20 @@
+{
+  "source": {
+    "3": " */",
+    "4": "",
+    "5": "public class <span class=\"sym-31 sym\">HelloWorld</span> {"
+  },
+  "scm": {
+    "3": ["julien"],
+    "4": ["simon"],
+    "5": ["simon"]
+  }
+}
+
+
+
+
+
+
+
+