import org.sonar.server.db.migrations.debt43.IssueChangelogMigration;
import org.sonar.server.db.migrations.debt43.IssueMigration;
import org.sonar.server.db.migrations.debt43.TechnicalDebtMeasuresMigration;
+import org.sonar.server.db.migrations.packageKeys42.PackageKeysMigration;
import org.sonar.server.db.migrations.violation36.ViolationMigration;
import java.util.List;
IssueMigration.class,
IssueChangelogMigration.class,
TechnicalDebtMeasuresMigration.class,
- DevelopmentCostMeasuresMigration.class
+ DevelopmentCostMeasuresMigration.class,
+ PackageKeysMigration.class
);
}
--- /dev/null
+/*
+ * 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.server.db.migrations.debt43;
+
+import javax.annotation.ParametersAreNonnullByDefault;
--- /dev/null
+/*
+ * 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.server.db.migrations.packageKeys42;
+
+import org.apache.commons.lang.StringUtils;
+import org.sonar.core.persistence.Database;
+import org.sonar.server.db.migrations.DatabaseMigration;
+import org.sonar.server.db.migrations.MassUpdater;
+import org.sonar.server.db.migrations.SqlUtil;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * Used in Rails migration 490
+ *
+ * @since 4.2
+ */
+public class PackageKeysMigration implements DatabaseMigration {
+
+ private final Database db;
+
+ public PackageKeysMigration(Database database) {
+ this.db = database;
+ }
+
+ @Override
+ public void execute() {
+ new MassUpdater(db).execute(
+ new MassUpdater.InputLoader<Row>() {
+ @Override
+ public String selectSql() {
+ return "SELECT id, kee FROM projects WHERE qualifier='PAC'";
+ }
+
+ @Override
+ public Row load(ResultSet rs) throws SQLException {
+ Row row = new Row();
+ row.id = SqlUtil.getLong(rs, 1);
+ row.key = rs.getString(2);
+ return row;
+ }
+ },
+ new MassUpdater.InputConverter<Row>() {
+ @Override
+ public String updateSql() {
+ return "UPDATE projects SET qualifier='DIR', kee=? WHERE id=?";
+ }
+
+ @Override
+ public void convert(Row row, PreparedStatement updateStatement) throws SQLException {
+ updateStatement.setString(1, convertKey(row.key));
+ updateStatement.setLong(2, row.id);
+ }
+ }
+ );
+ }
+
+ String convertKey(String packageKey) {
+ String prefix = StringUtils.substringBeforeLast(packageKey, ":") + ":";
+ String key = StringUtils.substringAfterLast(packageKey, ":");
+ if (key.equals("[default]")) {
+ return prefix + "[root]";
+ }
+ return prefix + StringUtils.replace(key, ".", "/");
+ }
+
+ private static class Row {
+ private Long id;
+ private String key;
+ }
+}
--- /dev/null
+/*
+ * 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.server.db.migrations.packageKeys42;
+
+import javax.annotation.ParametersAreNonnullByDefault;
--- /dev/null
+#
+# 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.
+#
+
+#
+# SonarQube 4.2
+# SONAR-926
+#
+class MigratePackageKeys < ActiveRecord::Migration
+
+ def self.up
+ Java::OrgSonarServerUi::JRubyFacade.getInstance().databaseMigrator().executeMigration('org.sonar.server.db.migrations.packageKeys42.PackageKeysMigration')
+ end
+
+end
+++ /dev/null
-#
-# 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.
-#
-
-#
-# SonarQube 4.2
-# SONAR-926
-#
-class MigratePackageResources < ActiveRecord::Migration
-
- class Project < ActiveRecord::Base
- end
-
- def self.up
- packages = Project.find(:all, :conditions => {:qualifier => 'PAC'})
- packages.each do |package|
- key = package.kee.split(":").last
- prefix = package.kee.chomp(key)
- if key == '[default]'
- package.kee = prefix + '[root]'
- else
- package.kee = prefix + key.gsub('.', '/')
- end
- package.qualifier = 'DIR'
- package.save
- end
- end
-
-end
package org.sonar.server.db.migrations.debt43;
-import org.junit.Before;
import org.junit.Test;
import org.sonar.api.config.Settings;
-import org.sonar.server.db.migrations.debt43.WorkDurationConvertor;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
public class DebtMigrationExecutorTest {
static final int HOURS_IN_DAY = 8;
-
static final Long ONE_MINUTE = 1L;
static final Long ONE_HOUR_IN_MINUTES = ONE_MINUTE * 60;
static final Long ONE_DAY_IN_MINUTES = ONE_HOUR_IN_MINUTES * HOURS_IN_DAY;
Settings settings = new Settings();
-
- WorkDurationConvertor convertor;
-
- @Before
- public void setUp() throws Exception {
- convertor = new WorkDurationConvertor(settings);
- }
+ WorkDurationConvertor convertor = new WorkDurationConvertor(settings);
@Test
public void convert_from_long() throws Exception {
--- /dev/null
+/*
+ * 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.server.db.migrations.packageKeys42;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.core.persistence.TestDatabase;
+import org.sonar.server.db.migrations.DatabaseMigration;
+
+public class PackageKeysMigrationTest {
+
+ @ClassRule
+ public static TestDatabase db = new TestDatabase().schema(PackageKeysMigrationTest.class, "schema.sql");
+
+ DatabaseMigration migration = new PackageKeysMigration(db.database());
+
+ @Test
+ public void execute() throws Exception {
+ db.prepareDbUnit(getClass(), "convert_package_keys.xml");
+
+ migration.execute();
+
+ db.assertDbUnit(getClass(), "convert_package_keys-result.xml", "projects");
+ }
+}
--- /dev/null
+<dataset>
+
+ <!-- do not touch this directory -->
+ <projects id="1" long_name="[null]" scope="DIR" qualifier="DIR" kee="project1:org/foo/Bar"
+ name="org/foo/bar" root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+ created_at="[null]" deprecated_kee="[null]" path="[null]" />
+
+
+ <!-- packages to be changed -->
+ <projects id="2" long_name="[null]" scope="DIR" qualifier="DIR" kee="project2:org/foo/Bar"
+ name="org.foo.Bar" root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+ created_at="[null]" deprecated_kee="[null]" path="[null]"/>
+
+ <projects id="3" long_name="[null]" scope="DIR" qualifier="DIR" kee="project2:branch2:[root]"
+ name="[default]" root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+ created_at="[null]" deprecated_kee="[null]" path="[null]"/>
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- do not touch this directory -->
+ <projects id="1" long_name="[null]" scope="DIR" qualifier="DIR" kee="project1:org/foo/Bar"
+ name="org/foo/bar" root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+ created_at="[null]" deprecated_kee="[null]" path="[null]" />
+
+
+ <!-- packages to be changed -->
+ <projects id="2" long_name="[null]" scope="DIR" qualifier="PAC" kee="project2:org.foo.Bar"
+ name="org.foo.Bar" root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+ created_at="[null]" deprecated_kee="[null]" path="[null]"/>
+
+ <projects id="3" long_name="[null]" scope="DIR" qualifier="PAC" kee="project2:branch2:[default]"
+ name="[default]" root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+ created_at="[null]" deprecated_kee="[null]" path="[null]"/>
+</dataset>
--- /dev/null
+-- 4.3
+CREATE TABLE "PROJECTS" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "NAME" VARCHAR(256),
+ "DESCRIPTION" VARCHAR(2000),
+ "ENABLED" BOOLEAN NOT NULL DEFAULT TRUE,
+ "SCOPE" VARCHAR(3),
+ "QUALIFIER" VARCHAR(10),
+ "KEE" VARCHAR(400),
+ "DEPRECATED_KEE" VARCHAR(400),
+ "PATH" VARCHAR(2000),
+ "ROOT_ID" INTEGER,
+ "LANGUAGE" VARCHAR(20),
+ "COPY_RESOURCE_ID" INTEGER,
+ "LONG_NAME" VARCHAR(256),
+ "PERSON_ID" INTEGER,
+ "CREATED_AT" TIMESTAMP
+);