diff options
30 files changed, 371 insertions, 23 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationStepModule.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationStepModule.java index a6371738726..3e8334959a3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationStepModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationStepModule.java @@ -66,10 +66,12 @@ import org.sonar.server.db.migrations.v51.RenameComponentRelatedParamsInIssueFil import org.sonar.server.db.migrations.v51.UpdateProjectsModuleUuidPath; import org.sonar.server.db.migrations.v52.AddDependenciesColumns; import org.sonar.server.db.migrations.v52.AddDependenciesComponentUuidColumns; +import org.sonar.server.db.migrations.v52.AddManualMeasuresComponentUuidColumn; import org.sonar.server.db.migrations.v52.DropDependenciesComponentColumns; import org.sonar.server.db.migrations.v52.FeedDependenciesComponentUuids; import org.sonar.server.db.migrations.v52.FeedEventsComponentUuid; import org.sonar.server.db.migrations.v52.FeedFileSourcesDataType; +import org.sonar.server.db.migrations.v52.FeedManualMeasuresComponentUuid; import org.sonar.server.db.migrations.v52.FeedMetricsBooleans; import org.sonar.server.db.migrations.v52.FeedProjectLinksComponentUuid; import org.sonar.server.db.migrations.v52.MoveProjectProfileAssociation; @@ -146,6 +148,8 @@ public class MigrationStepModule extends Module { DropDependenciesComponentColumns.class, FeedFileSourcesDataType.class, FeedMetricsBooleans.class, + AddManualMeasuresComponentUuidColumn.class, + FeedManualMeasuresComponentUuid.class, AddDependenciesColumns.class); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumn.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumn.java new file mode 100644 index 00000000000..df5b945a175 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumn.java @@ -0,0 +1,58 @@ +/* + * 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.db.migrations.v52; + +import java.sql.SQLException; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.AddColumnsBuilder; +import org.sonar.server.db.migrations.DdlChange; + +import static org.sonar.server.db.migrations.AddColumnsBuilder.ColumnDef.Type.STRING; + +/** + * Add the following column to the manual_measures table : + * - component_uuid + */ +public class AddManualMeasuresComponentUuidColumn extends DdlChange { + private final Database db; + + public AddManualMeasuresComponentUuidColumn(Database db) { + super(db); + this.db = db; + } + + @Override + public void execute(DdlChange.Context context) throws SQLException { + context.execute(generateSql()); + } + + private String generateSql() { + return new AddColumnsBuilder(db.getDialect(), "manual_measures") + .addColumn( + new AddColumnsBuilder.ColumnDef() + .setName("component_uuid") + .setType(STRING) + .setLimit(50) + .setNullable(true) + ) + .build(); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuid.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuid.java new file mode 100644 index 00000000000..fe5adaf9e54 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuid.java @@ -0,0 +1,56 @@ +/* + * 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.db.migrations.v52; + +import java.sql.SQLException; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +public class FeedManualMeasuresComponentUuid extends BaseDataChange { + + + public FeedManualMeasuresComponentUuid(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate update = context.prepareMassUpdate().rowPluralName("manual measures"); + update.select( + "SELECT p.uuid, mm.resource_id " + + "FROM manual_measures mm " + + "INNER JOIN projects p ON mm.resource_id = p.id " + + "WHERE mm.component_uuid IS NULL"); + update.update("UPDATE manual_measures SET component_uuid=? WHERE resource_id=?"); + update.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + update.setString(1, row.getString(1)); + update.setLong(2, row.getLong(2)); + return true; + } + }); + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/CustomMeasureDao.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/CustomMeasureDao.java index c18755b1fc0..94c26bca199 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/CustomMeasureDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/CustomMeasureDao.java @@ -25,8 +25,8 @@ import java.util.List; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import org.sonar.api.server.ServerSide; -import org.sonar.core.custommeasure.db.CustomMeasureDto; -import org.sonar.core.custommeasure.db.CustomMeasureMapper; +import org.sonar.core.measure.custom.db.CustomMeasureDto; +import org.sonar.core.measure.custom.db.CustomMeasureMapper; import org.sonar.core.persistence.DaoComponent; import org.sonar.core.persistence.DaoUtils; import org.sonar.core.persistence.DbSession; diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/DeleteAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/DeleteAction.java index 993db3c7f9e..1745aae9f17 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/DeleteAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/DeleteAction.java @@ -25,7 +25,7 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; import org.sonar.api.web.UserRole; import org.sonar.core.component.ComponentDto; -import org.sonar.core.custommeasure.db.CustomMeasureDto; +import org.sonar.core.measure.custom.db.CustomMeasureDto; import org.sonar.core.permission.GlobalPermissions; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.MyBatis; diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/CreateAction.java index e9b253ef47e..9653baf3339 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/CreateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/CreateAction.java @@ -28,7 +28,7 @@ import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.text.JsonWriter; -import org.sonar.core.custommeasure.db.CustomMeasureDto; +import org.sonar.core.measure.custom.db.CustomMeasureDto; import org.sonar.core.metric.db.MetricDto; import org.sonar.core.permission.GlobalPermissions; import org.sonar.core.persistence.DbSession; diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/UpdateAction.java b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/UpdateAction.java index 4b3f8e7852c..07bfeaf66bf 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/UpdateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/UpdateAction.java @@ -28,7 +28,7 @@ import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.text.JsonWriter; -import org.sonar.core.custommeasure.db.CustomMeasureDto; +import org.sonar.core.measure.custom.db.CustomMeasureDto; import org.sonar.core.metric.db.MetricDto; import org.sonar.core.permission.GlobalPermissions; import org.sonar.core.persistence.DbSession; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/MigrationStepModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/MigrationStepModuleTest.java index abc50e78e77..82bb3acb906 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/MigrationStepModuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/MigrationStepModuleTest.java @@ -29,6 +29,6 @@ public class MigrationStepModuleTest { public void verify_count_of_added_MigrationStep_types() throws Exception { ComponentContainer container = new ComponentContainer(); new MigrationStepModule().configure(container); - assertThat(container.size()).isEqualTo(55); + assertThat(container.size()).isEqualTo(57); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumnTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumnTest.java new file mode 100644 index 00000000000..c60f2f3e00f --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumnTest.java @@ -0,0 +1,48 @@ +/* + * 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.db.migrations.v52; + +import java.sql.Types; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonar.core.persistence.DbTester; + +public class AddManualMeasuresComponentUuidColumnTest { + + @ClassRule + public static DbTester db = new DbTester().schema(AddManualMeasuresComponentUuidColumnTest.class, "schema.sql"); + + AddManualMeasuresComponentUuidColumn sut; + + @Before + public void setUp() { + sut = new AddManualMeasuresComponentUuidColumn(db.database()); + } + + @Test + public void update_columns() throws Exception { + sut.execute(); + + db.assertColumnDefinition("manual_measures", "component_uuid", Types.VARCHAR, 50); + } + +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest.java new file mode 100644 index 00000000000..41df873ec9f --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest.java @@ -0,0 +1,54 @@ +/* + * 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.db.migrations.v52; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonar.core.persistence.DbTester; + +public class FeedManualMeasuresComponentUuidTest { + + @ClassRule + public static DbTester db = new DbTester().schema(FeedManualMeasuresComponentUuidTest.class, "schema.sql"); + + FeedManualMeasuresComponentUuid sut; + + @Before + public void setUp() { + db.executeUpdateSql("truncate table manual_measures"); + db.executeUpdateSql("truncate table projects"); + + sut = new FeedManualMeasuresComponentUuid(db.database()); + } + + @Test + public void migrate_empty_db() throws Exception { + sut.execute(); + } + + @Test + public void migrate() throws Exception { + db.prepareDbUnit(this.getClass(), "migrate.xml"); + sut.execute(); + db.assertDbUnit(this.getClass(), "migrate-result.xml", "manual_measures"); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureDaoTest.java index 2d8e7e30add..2fa5021aefa 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureDaoTest.java @@ -27,7 +27,7 @@ import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.sonar.core.custommeasure.db.CustomMeasureDto; +import org.sonar.core.measure.custom.db.CustomMeasureDto; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.DbTester; import org.sonar.server.db.DbClient; @@ -68,6 +68,7 @@ public class CustomMeasureDaoTest { assertThat(result.getId()).isEqualTo(measure.getId()); assertThat(result.getMetricId()).isEqualTo(measure.getMetricId()); assertThat(result.getComponentId()).isEqualTo(measure.getComponentId()); + assertThat(result.getComponentUuid()).isEqualTo(measure.getComponentUuid()); assertThat(result.getDescription()).isEqualTo(measure.getDescription()); assertThat(result.getUserLogin()).isEqualTo(measure.getUserLogin()); assertThat(result.getTextValue()).isEqualTo(measure.getTextValue()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureTesting.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureTesting.java index 20868a91635..72cd665ac52 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureTesting.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureTesting.java @@ -23,7 +23,7 @@ package org.sonar.server.measure.custom.persistence; import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.math.RandomUtils; import org.sonar.api.utils.System2; -import org.sonar.core.custommeasure.db.CustomMeasureDto; +import org.sonar.core.measure.custom.db.CustomMeasureDto; public class CustomMeasureTesting { private CustomMeasureTesting() { @@ -38,8 +38,8 @@ public class CustomMeasureTesting { .setValue(RandomUtils.nextDouble()) .setMetricId(RandomUtils.nextInt()) .setComponentId(RandomUtils.nextInt()) + .setComponentUuid(RandomStringUtils.random(50)) .setCreatedAt(System2.INSTANCE.now()) - .setUpdatedAt(System2.INSTANCE.now()) - ; + .setUpdatedAt(System2.INSTANCE.now()); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java index 67c43d5bd84..612c4514350 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java @@ -28,7 +28,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.web.UserRole; import org.sonar.core.component.ComponentDto; -import org.sonar.core.custommeasure.db.CustomMeasureDto; +import org.sonar.core.measure.custom.db.CustomMeasureDto; import org.sonar.core.permission.GlobalPermissions; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.DbTester; diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java index 2175ff6c594..3853745ce14 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java @@ -29,7 +29,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; -import org.sonar.core.custommeasure.db.CustomMeasureDto; +import org.sonar.core.measure.custom.db.CustomMeasureDto; import org.sonar.core.metric.db.MetricDto; import org.sonar.core.permission.GlobalPermissions; import org.sonar.core.persistence.DbSession; diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumnTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumnTest/schema.sql new file mode 100644 index 00000000000..6fa4c32a970 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumnTest/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE "MANUAL_MEASURES" ( + "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "METRIC_ID" INTEGER NOT NULL, + "RESOURCE_ID" INTEGER, + "VALUE" DOUBLE, + "TEXT_VALUE" VARCHAR(4000), + "USER_LOGIN" VARCHAR(255), + "DESCRIPTION" VARCHAR(4000), + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT +); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest/migrate-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest/migrate-result.xml new file mode 100644 index 00000000000..2dd0252cb3c --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest/migrate-result.xml @@ -0,0 +1,6 @@ +<dataset> + + <manual_measures id="1" resource_id="10" component_uuid="ABCD"/> + <manual_measures id="2" resource_id="20" component_uuid="EFGH"/> + +</dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest/migrate.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest/migrate.xml new file mode 100644 index 00000000000..2a36c383c69 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest/migrate.xml @@ -0,0 +1,9 @@ +<dataset> + + <projects id="10" uuid="ABCD"/> + <projects id="20" uuid="EFGH"/> + + <manual_measures id="1" resource_id="10" component_uuid="[null]"/> + <manual_measures id="2" resource_id="20" component_uuid="EFGH"/> + +</dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest/schema.sql new file mode 100644 index 00000000000..bc2c66dc238 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "MANUAL_MEASURES" ( + "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "RESOURCE_ID" INTEGER, + "COMPONENT_UUID" VARCHAR(50), +); + +CREATE TABLE "PROJECTS" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "UUID" VARCHAR(50), +); diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/manual_measure.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/manual_measure.rb index f69afee49ac..3bc2607c722 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/manual_measure.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/manual_measure.rb @@ -168,6 +168,7 @@ class ManualMeasure < ActiveRecord::Base end def before_create + self.component_uuid=@resource.uuid self.created_at=DateTime.now end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/918_add_manual_measures_component_uuid.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/918_add_manual_measures_component_uuid.rb new file mode 100644 index 00000000000..4d23f59b2fa --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/918_add_manual_measures_component_uuid.rb @@ -0,0 +1,32 @@ +# +# 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.2 +# SONAR-6615 +# +class AddManualMeasuresComponentUuid < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.server.db.migrations.v52.AddManualMeasuresComponentUuidColumn') + add_index 'manual_measures', 'component_uuid', :name => 'manual_measures_component_uuid' + end + +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/919_feed_manual_measures_component_uuid.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/919_feed_manual_measures_component_uuid.rb new file mode 100644 index 00000000000..e96d56159f2 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/919_feed_manual_measures_component_uuid.rb @@ -0,0 +1,31 @@ +# +# 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.2 +# SONAR-6615 +# +class FeedManualMeasuresComponentUuid < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.server.db.migrations.v52.FeedManualMeasuresComponentUuid') + end + +end diff --git a/sonar-batch/src/test/resources/org/sonar/batch/compute/ManualMeasureDecoratorTest/testCopyManualMeasures.xml b/sonar-batch/src/test/resources/org/sonar/batch/compute/ManualMeasureDecoratorTest/testCopyManualMeasures.xml new file mode 100644 index 00000000000..a61777d3ad8 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/compute/ManualMeasureDecoratorTest/testCopyManualMeasures.xml @@ -0,0 +1,11 @@ +<dataset> + <metrics delete_historical_data="[null]" id="1" NAME="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" + enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/> + <metrics delete_historical_data="[null]" id="2" NAME="review_note" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" + enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/> + + + <manual_measures id="1" metric_id="2" resource_id="30" component_uuid="ABCD" value="3.14" text_value="pi" created_at="[null]" updated_at="[null]" description="this is pi" user_login="me"/> + <manual_measures id="2" metric_id="2" resource_id="40" component_uuid="EFGH" value="6" text_value="six" created_at="[null]" updated_at="[null]" description="this is six" user_login="me"/> + +</dataset> diff --git a/sonar-core/src/main/java/org/sonar/core/custommeasure/db/CustomMeasureDto.java b/sonar-core/src/main/java/org/sonar/core/measure/custom/db/CustomMeasureDto.java index 20f139252af..26030e3067e 100644 --- a/sonar-core/src/main/java/org/sonar/core/custommeasure/db/CustomMeasureDto.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/custom/db/CustomMeasureDto.java @@ -18,12 +18,13 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.core.custommeasure.db; +package org.sonar.core.measure.custom.db; public class CustomMeasureDto { private long id; private int metricId; private long componentId; + private String componentUuid; private double value; private String textValue; private String userLogin; @@ -111,4 +112,13 @@ public class CustomMeasureDto { this.createdAt = createdAt; return this; } + + public String getComponentUuid() { + return componentUuid; + } + + public CustomMeasureDto setComponentUuid(String componentUuid) { + this.componentUuid = componentUuid; + return this; + } } diff --git a/sonar-core/src/main/java/org/sonar/core/custommeasure/db/CustomMeasureMapper.java b/sonar-core/src/main/java/org/sonar/core/measure/custom/db/CustomMeasureMapper.java index b2f3d4b9d79..ab0c89beb60 100644 --- a/sonar-core/src/main/java/org/sonar/core/custommeasure/db/CustomMeasureMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/custom/db/CustomMeasureMapper.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.core.custommeasure.db; +package org.sonar.core.measure.custom.db; import java.util.List; import org.apache.ibatis.annotations.Param; diff --git a/sonar-core/src/main/java/org/sonar/core/custommeasure/db/package-info.java b/sonar-core/src/main/java/org/sonar/core/measure/custom/db/package-info.java index 8a19bbe9399..4635db7f1aa 100644 --- a/sonar-core/src/main/java/org/sonar/core/custommeasure/db/package-info.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/custom/db/package-info.java @@ -19,7 +19,7 @@ */ @ParametersAreNonnullByDefault -package org.sonar.core.custommeasure.db; +package org.sonar.core.measure.custom.db; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index 9eb31a6089b..f7d7ee524ed 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -34,7 +34,7 @@ import org.sonar.api.server.ServerSide; @ServerSide public class DatabaseVersion { - public static final int LAST_VERSION = 917; + public static final int LAST_VERSION = 919; /** * List of all the tables.n 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 4e79ef0e850..4c00dfa35f9 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 @@ -53,8 +53,8 @@ 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.custommeasure.db.CustomMeasureDto; -import org.sonar.core.custommeasure.db.CustomMeasureMapper; +import org.sonar.core.measure.custom.db.CustomMeasureDto; +import org.sonar.core.measure.custom.db.CustomMeasureMapper; import org.sonar.core.dashboard.ActiveDashboardDto; import org.sonar.core.dashboard.ActiveDashboardMapper; import org.sonar.core.dashboard.DashboardDto; diff --git a/sonar-core/src/main/resources/org/sonar/core/custommeasure/db/CustomMeasureMapper.xml b/sonar-core/src/main/resources/org/sonar/core/measure/custom/db/CustomMeasureMapper.xml index b796a7ac0bf..a3c935db3dc 100644 --- a/sonar-core/src/main/resources/org/sonar/core/custommeasure/db/CustomMeasureMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/measure/custom/db/CustomMeasureMapper.xml @@ -1,11 +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.custommeasure.db.CustomMeasureMapper"> +<mapper namespace="org.sonar.core.measure.custom.db.CustomMeasureMapper"> <sql id="selectColumns"> m.id, m.metric_id as metricId, m.resource_id as componentId, + m.component_uuid as componentUuid, m.value, m.text_value as textValue, m.user_login as userLogin, @@ -37,12 +38,12 @@ <insert id="insert" parameterType="CustomMeasure" useGeneratedKeys="true" keyColumn="id" keyProperty="id"> INSERT INTO manual_measures ( - metric_id, resource_id, value, text_value, user_login, description, created_at, updated_at + metric_id, resource_id, component_uuid, value, text_value, user_login, description, created_at, updated_at ) VALUES ( - #{metricId, jdbcType=INTEGER}, #{componentId, jdbcType=INTEGER}, #{value, jdbcType=DOUBLE}, - #{textValue, jdbcType=VARCHAR}, #{userLogin, jdbcType=VARCHAR},#{description, jdbcType=VARCHAR}, - #{createdAt, jdbcType=BIGINT}, #{updatedAt, jdbcType=BIGINT} + #{metricId, jdbcType=INTEGER}, #{componentId, jdbcType=INTEGER}, #{componentUuid, jdbcType=VARCHAR}, + #{value, jdbcType=DOUBLE}, #{textValue, jdbcType=VARCHAR}, #{userLogin, jdbcType=VARCHAR}, + #{description, jdbcType=VARCHAR}, #{createdAt, jdbcType=BIGINT}, #{updatedAt, jdbcType=BIGINT} ) </insert> diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index 18b38f9a71d..065ff71ae4c 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -341,6 +341,8 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('914'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('915'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('916'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('917'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('918'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('919'); 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', '1418215735482', '1418215735482', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index c7974769cc9..3670c426c1f 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -282,6 +282,7 @@ CREATE TABLE "MANUAL_MEASURES" ( "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "METRIC_ID" INTEGER NOT NULL, "RESOURCE_ID" INTEGER, + "COMPONENT_UUID" VARCHAR(50), "VALUE" DOUBLE, "TEXT_VALUE" VARCHAR(4000), "USER_LOGIN" VARCHAR(255), @@ -625,6 +626,8 @@ CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES" ("PROP_KEY"); CREATE INDEX "MANUAL_MEASURES_RESOURCE_ID" ON "MANUAL_MEASURES" ("RESOURCE_ID"); +CREATE INDEX "MANUAL_MEASURES_COMPONENT_UUID" ON "MANUAL_MEASURES" ("COMPONENT_UUID"); + CREATE INDEX "PROJECTS_KEE" ON "PROJECTS" ("KEE", "ENABLED"); CREATE INDEX "PROJECTS_ROOT_ID" ON "PROJECTS" ("ROOT_ID"); |