From dc1ff5ccbf40e2a5360fcc23f4bab843bad52cf7 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 19 Jun 2012 17:30:45 +0200 Subject: [PATCH] Add MyBatis mapper for DEPENDENCIES --- pom.xml | 2 +- .../sonar/core/dependency/DependencyDto.java | 73 +++++++++++++++++++ .../core/dependency/DependencyMapper.java | 26 +++++++ .../org/sonar/core/persistence/MyBatis.java | 4 + .../org/sonar/core/resource/ResourceDto.java | 10 +++ .../core/dependency/DependencyMapper.xml | 11 +++ .../sonar/core/resource/ResourceMapper.xml | 1 + .../core/dependency/DependencyMapperTest.java | 55 ++++++++++++++ .../DependencyMapperTest/fixture.xml | 4 + 9 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 sonar-core/src/main/java/org/sonar/core/dependency/DependencyDto.java create mode 100644 sonar-core/src/main/java/org/sonar/core/dependency/DependencyMapper.java create mode 100644 sonar-core/src/main/resources/org/sonar/core/dependency/DependencyMapper.xml create mode 100644 sonar-core/src/test/java/org/sonar/core/dependency/DependencyMapperTest.java create mode 100644 sonar-core/src/test/resources/org/sonar/core/dependency/DependencyMapperTest/fixture.xml diff --git a/pom.xml b/pom.xml index 701a197bf71..975e5a1453a 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ pom 3.2-SNAPSHOT Sonar - http://www.sonarsource.org + http://www.sonarsource.org/ Open source platform for continuous inspection of code quality 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 index 00000000000..0a61133942b --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/dependency/DependencyDto.java @@ -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 index 00000000000..cea1d23f7c7 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/dependency/DependencyMapper.java @@ -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 selectAll(); +} diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index 5901695c53e..501efd8ed36 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -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); diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java index 4a672113359..212b954fc88 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java @@ -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 index 00000000000..53ab9f500cf --- /dev/null +++ b/sonar-core/src/main/resources/org/sonar/core/dependency/DependencyMapper.xml @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml index 6df6d82844d..c604f28d154 100644 --- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml @@ -23,6 +23,7 @@ + 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 index 00000000000..11699e567db --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/dependency/DependencyMapperTest.java @@ -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 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 index 00000000000..7e8a8e9f677 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/dependency/DependencyMapperTest/fixture.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file -- 2.39.5