]> source.dussan.org Git - sonarqube.git/commitdiff
Add MyBatis mapper for DEPENDENCIES
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 19 Jun 2012 15:30:45 +0000 (17:30 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 19 Jun 2012 15:31:01 +0000 (17:31 +0200)
pom.xml
sonar-core/src/main/java/org/sonar/core/dependency/DependencyDto.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/dependency/DependencyMapper.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java
sonar-core/src/main/resources/org/sonar/core/dependency/DependencyMapper.xml [new file with mode: 0644]
sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml
sonar-core/src/test/java/org/sonar/core/dependency/DependencyMapperTest.java [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/dependency/DependencyMapperTest/fixture.xml [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index 701a197bf71bc16963e4bc11a8a7f56c3042e643..975e5a1453a13e6ad534d0b2dd2ad6b8c6424ea5 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
   <packaging>pom</packaging>
   <version>3.2-SNAPSHOT</version>
   <name>Sonar</name>
-  <url>http://www.sonarsource.org</url>
+  <url>http://www.sonarsource.org/</url>
   <description>Open source platform for continuous inspection of code quality</description>
 
   <modules>
diff --git a/sonar-core/src/main/java/org/sonar/core/dependency/DependencyDto.java b/sonar-core/src/main/java/org/sonar/core/dependency/DependencyDto.java
new file mode 100644 (file)
index 0000000..0a61133
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.core.dependency;
+
+public final class DependencyDto {
+  private Long id;
+  private Long fromResourceId;
+  private Long toResourceId;
+  private String usage;
+  private Integer weight;
+
+  public Long getId() {
+    return id;
+  }
+
+  public DependencyDto setId(Long id) {
+    this.id = id;
+    return this;
+  }
+
+  public Long getFromResourceId() {
+    return fromResourceId;
+  }
+
+  public DependencyDto setFromResourceId(Long fromResourceId) {
+    this.fromResourceId = fromResourceId;
+    return this;
+  }
+
+  public Long getToResourceId() {
+    return toResourceId;
+  }
+
+  public DependencyDto setToResourceId(Long toResourceId) {
+    this.toResourceId = toResourceId;
+    return this;
+  }
+
+  public String getUsage() {
+    return usage;
+  }
+
+  public DependencyDto setUsage(String usage) {
+    this.usage = usage;
+    return this;
+  }
+
+  public Integer getWeight() {
+    return weight;
+  }
+
+  public DependencyDto setWeight(Integer weight) {
+    this.weight = weight;
+    return this;
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/dependency/DependencyMapper.java b/sonar-core/src/main/java/org/sonar/core/dependency/DependencyMapper.java
new file mode 100644 (file)
index 0000000..cea1d23
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.core.dependency;
+
+import java.util.List;
+
+public interface DependencyMapper {
+  List<DependencyDto> selectAll();
+}
index 5901695c53e00efecda9b4fd85b9f1088ce86bba..501efd8ed36dee26d4cdf4da63425c47ca58b860 100644 (file)
@@ -41,6 +41,8 @@ import org.sonar.core.dashboard.WidgetDto;
 import org.sonar.core.dashboard.WidgetMapper;
 import org.sonar.core.dashboard.WidgetPropertyDto;
 import org.sonar.core.dashboard.WidgetPropertyMapper;
+import org.sonar.core.dependency.DependencyDto;
+import org.sonar.core.dependency.DependencyMapper;
 import org.sonar.core.duplication.DuplicationMapper;
 import org.sonar.core.duplication.DuplicationUnitDto;
 import org.sonar.core.filter.CriterionDto;
@@ -96,6 +98,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
     loadAlias(conf, "Criterion", CriterionDto.class);
     loadAlias(conf, "FilterColumn", FilterColumnDto.class);
     loadAlias(conf, "Dashboard", DashboardDto.class);
+    loadAlias(conf, "Dependency", DependencyDto.class);
     loadAlias(conf, "DuplicationUnit", DuplicationUnitDto.class);
     loadAlias(conf, "LoadedTemplate", LoadedTemplateDto.class);
     loadAlias(conf, "Property", PropertyDto.class);
@@ -116,6 +119,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
     loadMapper(conf, CriterionMapper.class);
     loadMapper(conf, FilterColumnMapper.class);
     loadMapper(conf, DashboardMapper.class);
+    loadMapper(conf, DependencyMapper.class);
     loadMapper(conf, DuplicationMapper.class);
     loadMapper(conf, LoadedTemplateMapper.class);
     loadMapper(conf, PropertiesMapper.class);
index 4a672113359ff68bde0008fd93310401d1e20f3d..212b954fc88120682460d17217efce0aada5ef05 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.core.resource;
 public final class ResourceDto {
 
   private Long id;
+  private String key;
   private String name;
   private String longName;
   private Integer rootId;
@@ -46,6 +47,15 @@ public final class ResourceDto {
     return this;
   }
 
+  public String getKey() {
+    return key;
+  }
+
+  public ResourceDto setKey(String s) {
+    this.key = s;
+    return this;
+  }
+
   public Integer getRootId() {
     return rootId;
   }
diff --git a/sonar-core/src/main/resources/org/sonar/core/dependency/DependencyMapper.xml b/sonar-core/src/main/resources/org/sonar/core/dependency/DependencyMapper.xml
new file mode 100644 (file)
index 0000000..53ab9f5
--- /dev/null
@@ -0,0 +1,11 @@
+<?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.dependency.DependencyMapper">
+
+  <select id="selectAll" resultType="dependency">
+    select id, from_resource_id as fromResourceId, to_resource_id as toResourceId, dep_usage as usage, dep_weight as weight from dependencies
+  </select>
+
+</mapper>
+
index 6df6d82844ddfcb0b72ea921780cb66b3024e034..c604f28d154e865d0f9506cdb658f5901319af5e 100644 (file)
@@ -23,6 +23,7 @@
 
   <resultMap id="resourceResultMap" type="Resource">
     <id property="id" column="id"/>
+    <result property="key" column="kee"/>
     <result property="name" column="name"/>
     <result property="longName" column="long_name"/>
     <result property="rootId" column="root_id"/>
diff --git a/sonar-core/src/test/java/org/sonar/core/dependency/DependencyMapperTest.java b/sonar-core/src/test/java/org/sonar/core/dependency/DependencyMapperTest.java
new file mode 100644 (file)
index 0000000..11699e5
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.core.dependency;
+
+import org.apache.ibatis.session.SqlSession;
+import org.junit.Test;
+import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.MyBatis;
+
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DependencyMapperTest extends DaoTestCase {
+
+  @Test
+  public void testDescendantProjects_do_not_include_self() {
+    setupData("fixture");
+
+    SqlSession session = getMyBatis().openSession();
+    try {
+      List<DependencyDto> dependencies = session.getMapper(DependencyMapper.class).selectAll();
+
+      assertThat(dependencies).hasSize(2);
+
+      DependencyDto dep = dependencies.get(0);
+      assertThat(dep.getUsage()).isEqualTo("compile");
+      assertThat(dep.getFromResourceId()).isEqualTo(100L);
+      assertThat(dep.getToResourceId()).isEqualTo(101L);
+      assertThat(dep.getId()).isEqualTo(1L);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+
+}
+
diff --git a/sonar-core/src/test/resources/org/sonar/core/dependency/DependencyMapperTest/fixture.xml b/sonar-core/src/test/resources/org/sonar/core/dependency/DependencyMapperTest/fixture.xml
new file mode 100644 (file)
index 0000000..7e8a8e9
--- /dev/null
@@ -0,0 +1,4 @@
+<dataset>
+  <dependencies id="1" from_resource_id="100" to_resource_id="101" from_snapshot_id="1000" to_snapshot_id="1001" dep_usage="compile" dep_weight="1" />
+  <dependencies id="2" from_resource_id="200" to_resource_id="201" from_snapshot_id="2000" to_snapshot_id="2001" dep_usage="provided" dep_weight="1" />
+</dataset>
\ No newline at end of file