import com.google.common.collect.Iterables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
import org.sonar.core.persistence.Database;
import org.sonar.server.db.migrations.BaseDataChange;
private static final String COMPLIANCE_NAME = "Compliance";
private static final String COMPLIANCE_KEY_SUFFIX = "_COMPLIANCE";
+ private static final String ERROR_SUFFIX = "Please restore your DB backup, start the previous version of SonarQube " +
+ "and update your SQALE model to fix this issue before trying again to run the migration.";
+
+
private final System2 system;
public AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration(Database db, System2 system) {
}, null);
if (characteristic != null) {
if (characteristic.getParentId() != null) {
- throw new IllegalStateException(String.format("'%s' must be a characteristic", characteristic.getName()));
+ throw MessageException.of(String.format("'%s' must be a characteristic. " + ERROR_SUFFIX, characteristic.getName()));
}
}
return characteristic;
if (characteristic != null) {
Integer parentId = characteristic.getParentId();
if (parentId == null) {
- throw new IllegalStateException(String.format("'%s' must be a sub-characteristic", characteristic.getName()));
+ throw MessageException.of(String.format("'%s' must be a sub-characteristic. " + ERROR_SUFFIX, characteristic.getName()));
} else if (!characteristic.getParentId().equals(parent.getId())) {
- throw new IllegalStateException(String.format("'%s' must be defined under '%s'", characteristic.getName(), parent.getName()));
+ throw MessageException.of(String.format("'%s' must be defined under '%s'. " + ERROR_SUFFIX, characteristic.getName(), parent.getName()));
}
}
return characteristic;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
import org.sonar.core.persistence.TestDatabase;
import org.sonar.server.db.migrations.DatabaseMigration;
public void fail_if_usability_exists_as_sub_characteristic() throws Exception {
db.prepareDbUnit(getClass(), "fail_if_usability_exists_as_sub_characteristic.xml");
- try {
- migration.execute();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("'Usability' must be a characteristic");
+ try {
+ migration.execute();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(MessageException.class).hasMessage(
+ "'Usability' must be a characteristic. Please restore your DB backup, start the previous version of SonarQube " +
+ "and update your SQALE model to fix this issue before trying again to run the migration.");
}
}
migration.execute();
fail();
} catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("'Compliance' must be a sub-characteristic");
+ assertThat(e).isInstanceOf(MessageException.class).hasMessage(
+ "'Compliance' must be a sub-characteristic. Please restore your DB backup, start the previous version of SonarQube " +
+ "and update your SQALE model to fix this issue before trying again to run the migration.");
}
}
migration.execute();
fail();
} catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("'Reusability Compliance' must be defined under 'Reusability'");
+ assertThat(e).isInstanceOf(MessageException.class).hasMessage(
+ "'Reusability Compliance' must be defined under 'Reusability'. Please restore your DB backup, start the previous version of SonarQube " +
+ "and update your SQALE model to fix this issue before trying again to run the migration.");
}
}