]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5623 - datamodel and dto creation for the analysis report
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 19 Sep 2014 16:58:38 +0000 (18:58 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 24 Sep 2014 15:48:23 +0000 (17:48 +0200)
13 files changed:
server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/db/package-info.java [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/computation/db/package-info.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/computation/package-info.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml [new file with mode: 0644]
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl

diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java b/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java
new file mode 100644 (file)
index 0000000..f22b172
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.computation.db;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import org.sonar.api.utils.System2;
+import org.sonar.core.computation.db.AnalysisReportDto;
+import org.sonar.core.computation.db.AnalysisReportMapper;
+import org.sonar.core.issue.db.IssueDto;
+import org.sonar.core.issue.db.IssueMapper;
+import org.sonar.core.persistence.DaoComponent;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.server.db.BaseDao;
+import org.sonar.server.search.IndexDefinition;
+
+import java.util.Date;
+import java.util.Map;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public class AnalysisReportDao extends BaseDao<AnalysisReportMapper, AnalysisReportDto, String> implements DaoComponent {
+
+  public AnalysisReportDao() {
+    this(System2.INSTANCE);
+  }
+
+  @VisibleForTesting
+  public AnalysisReportDao(System2 system) {
+    super(AnalysisReportMapper.class, system);
+  }
+
+  @Override
+  protected AnalysisReportDto doGetNullableByKey(DbSession session, String key) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  protected AnalysisReportDto doUpdate(DbSession session, AnalysisReportDto issue) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  protected AnalysisReportDto doInsert(DbSession session, AnalysisReportDto report) {
+    checkNotNull(report.getProjectKey(), "Cannot insert Report with no project key!");
+    mapper(session).insert(report);
+    return report;
+  }
+
+  @Override
+  protected String getSynchronizationStatementName() {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  protected Map getSynchronizationParams(Date date, Map<String, String> params) {
+    throw new UnsupportedOperationException();
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/db/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/computation/db/package-info.java
new file mode 100644 (file)
index 0000000..d34d492
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.server.computation.db;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml
new file mode 100644 (file)
index 0000000..40a6535
--- /dev/null
@@ -0,0 +1,29 @@
+<!--
+  ~ SonarQube, open source software quality management tool.
+  ~ Copyright (C) 2008-2014 SonarSource
+  ~ mailto:contact AT sonarsource DOT com
+  ~
+  ~ SonarQube is free software; you can redistribute it and/or
+  ~ modify it under the terms of the GNU Lesser General Public
+  ~ License as published by the Free Software Foundation; either
+  ~ version 3 of the License, or (at your option) any later version.
+  ~
+  ~ SonarQube is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  ~ Lesser General Public License for more details.
+  ~
+  ~ You should have received a copy of the GNU Lesser General Public License
+  ~ along with this program; if not, write to the Free Software Foundation,
+  ~ Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+  -->
+
+<dataset>
+  <issues
+      id="100"
+      project_key="sonarqube"
+      created_at="2013-05-21"
+      updated_at="2013-05-22"
+      version="123456789"
+      />
+</dataset>
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb
new file mode 100644 (file)
index 0000000..4240957
--- /dev/null
@@ -0,0 +1,38 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+#
+# SonarQube 5.0
+# SONAR-5624
+#
+class CreateAnalysisReports < ActiveRecord::Migration
+
+  def self.up
+    create_table :analysis_reports do |t|
+      t.column :project_key, :string, :limit => 400, :null => false
+      t.column :report_status, :string, :limit => 20, :null => false
+      t.column :report_data, :text, :null => true
+      t.column :created_at,   :datetime, :null => false
+      t.column :updated_at,   :datetime, :null => false
+    end
+    add_index :analysis_reports, ['project_key'], :name => 'analysis_reports_project_key', :unique => true
+  end
+
+end
+
diff --git a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java
new file mode 100644 (file)
index 0000000..7af44d4
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.core.computation.db;
+
+import org.sonar.core.persistence.Dto;
+
+import javax.annotation.Nullable;
+
+/**
+ * since 5.0
+ */
+public class AnalysisReportDto extends Dto<String> {
+
+    private Long id;
+    private String projectKey;
+    private String status;
+    private String data;
+
+    public String getProjectKey() {
+        return projectKey;
+    }
+
+    public AnalysisReportDto setProjectKey(String projectKey) {
+      this.projectKey = projectKey;
+      return this;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public AnalysisReportDto setStatus(String status) {
+      this.status = status;
+      return this;
+    }
+
+    public String getData() {
+        return data;
+    }
+
+    public AnalysisReportDto setData(@Nullable String data) {
+      this.data = data;
+      return this;
+    }
+
+
+    @Override
+    public String getKey() {
+        return getProjectKey();
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public AnalysisReportDto setId(Long id) {
+      this.id = id;
+      return this;
+    }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java
new file mode 100644 (file)
index 0000000..8f59836
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.core.computation.db;
+
+/**
+ * since 5.0
+ */
+public interface AnalysisReportMapper {
+    void insert(AnalysisReportDto report);
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/computation/db/package-info.java b/sonar-core/src/main/java/org/sonar/core/computation/db/package-info.java
new file mode 100644 (file)
index 0000000..d10519e
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.core.computation.db;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-core/src/main/java/org/sonar/core/computation/package-info.java b/sonar-core/src/main/java/org/sonar/core/computation/package-info.java
new file mode 100644 (file)
index 0000000..70ca84c
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.core.computation;
+
+import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
index 639bbc835eb041861c52c92569f24a013cd4bf71..694c2f2e182b7ac62519d9fe0aad5f6a1755fc89 100644 (file)
@@ -33,7 +33,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 701;
+  public static final int LAST_VERSION = 702;
 
   public static enum Status {
     UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
@@ -50,6 +50,7 @@ public class DatabaseVersion implements BatchComponent, ServerComponent {
     "active_rules",
     "active_rule_parameters",
     "activities",
+    "analysis_reports",
     "authors",
     "characteristics",
     "dashboards",
index 768edb20cb69f13016edc1db22eaacad3cf73cd3..051892c4cc908b7b6d839e4b6b34e872e65f9f82 100644 (file)
@@ -39,6 +39,8 @@ import org.sonar.core.component.ComponentDto;
 import org.sonar.core.component.SnapshotDto;
 import org.sonar.core.component.db.ComponentMapper;
 import org.sonar.core.component.db.SnapshotMapper;
+import org.sonar.core.computation.db.AnalysisReportDto;
+import org.sonar.core.computation.db.AnalysisReportMapper;
 import org.sonar.core.config.Logback;
 import org.sonar.core.dashboard.*;
 import org.sonar.core.dependency.DependencyDto;
@@ -157,6 +159,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
     loadAlias(conf, "ActiveRuleParam", ActiveRuleParamDto.class);
     loadAlias(conf, "RequirementMigration", RequirementMigrationDto.class);
     loadAlias(conf, "Activity", ActivityDto.class);
+    loadAlias(conf, "AnalysisReport", AnalysisReportDto.class);
 
     // AuthorizationMapper has to be loaded before IssueMapper because this last one used it
     loadMapper(conf, "org.sonar.core.user.AuthorizationMapper");
@@ -174,7 +177,8 @@ public class MyBatis implements BatchComponent, ServerComponent {
       NotificationQueueMapper.class, CharacteristicMapper.class,
       GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class,
       MeasureMapper.class, MetricMapper.class, QualityGateMapper.class, QualityGateConditionMapper.class, ComponentMapper.class, SnapshotMapper.class,
-      ProjectQgateAssociationMapper.class
+      ProjectQgateAssociationMapper.class,
+      AnalysisReportMapper.class
     };
     loadMappers(conf, mappers);
     configureLogback(mappers);
diff --git a/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml b/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml
new file mode 100644 (file)
index 0000000..8183df1
--- /dev/null
@@ -0,0 +1,12 @@
+<?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.computation.db.AnalysisReportMapper">
+
+  <insert id="insert" parameterType="AnalysisReport" useGeneratedKeys="true" >
+    insert into activities
+    (project_key, report_status, report_data, created_at, updated_at)
+    values (#{projectKey}, #{status}, #{data}, #{createdAt}, #{updatedAt})
+  </insert>
+</mapper>
+
index 78c9e4ceb491f854c6d4c34cadd6aa5b4b9db5d3..1c8151296231b251d5dfd54ebf7b1056be6f270e 100644 (file)
@@ -256,6 +256,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('583');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('584');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('700');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('701');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('702');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 013bbc2ad7258980d7d6554eab3ae8714fd3ed6a..253cdc7a5f05d290f50f30c69c6399b4264fb42b 100644 (file)
@@ -547,6 +547,15 @@ CREATE TABLE "ACTIVITIES" (
   "DATA_FIELD" CLOB(2147483647)
 );
 
+CREATE TABLE "ANALYSIS_REPORTS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "PROJECT_KEY" VARCHAR(400) NOT NULL,
+  "REPORT_STATUS" VARCHAR(20) NOT NULL,
+  "REPORT_DATA" CLOB(2147483647),
+  "CREATED_AT" TIMESTAMP NOT NULL,
+  "UPDATED_AT" TIMESTAMP
+);
+
 -- ----------------------------------------------
 -- DDL Statements for indexes
 -- ----------------------------------------------
@@ -681,4 +690,6 @@ CREATE UNIQUE INDEX "ACTIVE_RULES_UNIQUE" ON "ACTIVE_RULES" ("PROFILE_ID","RULE_
 
 CREATE INDEX "SNAPSHOT_DATA_RESOURCE_IDS" ON "SNAPSHOT_DATA" ("RESOURCE_ID");
 
-CREATE UNIQUE INDEX "QPROFILE_UNIQUE_KEY" ON "RULES_PROFILES" ("KEE");
+CREATE UNIQUE INDEX "PROFILE_UNIQUE_KEY" ON "RULES_PROFILES" ("KEE");
+
+CREATE UNIQUE INDEX "ANALYSIS_REPORTS_PROJECT_KEY" ON "ANALYSIS_REPORTS" ("PROJECT_KEY");