import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.config.Settings;
+import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.db.dialect.Dialect;
import org.sonar.db.dialect.DialectUtils;
+import org.sonar.db.dialect.MySql;
import org.sonar.db.profiling.NullConnectionInterceptor;
import org.sonar.db.profiling.ProfiledConnectionInterceptor;
import org.sonar.db.profiling.ProfiledDataSource;
private static final String DBCP_JDBC_MAX_WAIT = "maxWaitMillis";
private static final Map<String, String> SONAR_JDBC_TO_DBCP_PROPERTY_MAPPINGS = ImmutableMap.of(
SONAR_JDBC_MAX_ACTIVE, DBCP_JDBC_MAX_ACTIVE,
- SONAR_JDBC_MAX_WAIT, DBCP_JDBC_MAX_WAIT
- );
+ SONAR_JDBC_MAX_WAIT, DBCP_JDBC_MAX_WAIT);
private final LogbackHelper logbackHelper;
private final Settings settings;
@Override
public void start() {
+ initSettings();
+ failIfMySql();
try {
- initSettings();
initDataSource();
checkConnection();
properties.setProperty(SONAR_JDBC_DRIVER, dialect.getDefaultDriverClassName());
}
+ private void failIfMySql() {
+ if (!MySql.ID.equals(dialect.getId())) {
+ return;
+ }
+ throw MessageException.of("\n" +
+ "#############################################################################################################\n" +
+ "# End of Life of MySQL Support : SonarQube 7.9 and future versions do not support MySQL. #\n" +
+ "# Please migrate to a supported database. Get more details at #\n" +
+ "# https://community.sonarsource.com/t/end-of-life-of-mysql-support #\n" +
+ "# and https://github.com/SonarSource/mysql-migrator #\n" +
+ "#############################################################################################################\n");
+ }
+
private void initDataSource() throws Exception {
// but it's correctly caught by start()
LOG.info("Create JDBC data source for {}", properties.getProperty(JDBC_URL.getKey()), DEFAULT_URL);
import java.sql.SQLException;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.utils.Version;
-import org.sonar.api.utils.log.Loggers;
public class MySql extends AbstractDialect {
@Override
public void init(DatabaseMetaData metaData) throws SQLException {
checkDbVersion(metaData, MIN_SUPPORTED_VERSION);
-
- String message = "\n" +
- "#############################################################################################################\n" +
- "# End of Life of MySQL Support : SonarQube 7.8 is the last version that will support MySQL. #\n" +
- "# Please consider migrating to a supported database. Get the migration detail on #\n" +
- "# https://community.sonarsource.com/t/end-of-life-of-mysql-support #\n" +
- "# and https://github.com/SonarSource/mysql-migrator #\n" +
- "#############################################################################################################\n";
-
- Loggers.get(getClass()).warn(message);
}
}
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
-import org.sonar.api.config.Settings;
import org.sonar.api.config.internal.MapSettings;
+import org.sonar.api.utils.MessageException;
import org.sonar.db.dialect.PostgreSql;
import org.sonar.process.logging.LogbackHelper;
@RunWith(DataProviderRunner.class)
public class DefaultDatabaseTest {
+
private LogbackHelper logbackHelper = mock(LogbackHelper.class);
private static final String SONAR_JDBC = "sonar.jdbc.";
-
@Rule
public ExpectedException expectedException = none();
@Test
public void shouldCompleteProperties() {
- Settings settings = new MapSettings();
+ MapSettings settings = new MapSettings();
DefaultDatabase db = new DefaultDatabase(logbackHelper, settings) {
@Override
@Test
public void shouldStart() {
- Settings settings = new MapSettings();
+ MapSettings settings = new MapSettings();
settings.setProperty("sonar.jdbc.url", "jdbc:h2:mem:sonar");
settings.setProperty("sonar.jdbc.driverClassName", "org.h2.Driver");
settings.setProperty("sonar.jdbc.username", "sonar");
@Test
public void shouldGuessDialectFromUrl() {
- Settings settings = new MapSettings();
+ MapSettings settings = new MapSettings();
settings.setProperty("sonar.jdbc.url", "jdbc:postgresql://localhost/sonar");
DefaultDatabase database = new DefaultDatabase(logbackHelper, settings);
@Test
public void shouldGuessDefaultDriver() {
- Settings settings = new MapSettings();
+ MapSettings settings = new MapSettings();
settings.setProperty("sonar.jdbc.url", "jdbc:postgresql://localhost/sonar");
DefaultDatabase database = new DefaultDatabase(logbackHelper, settings);
assertThat(database.getProperties().getProperty("sonar.jdbc.driverClassName")).isEqualTo("org.postgresql.Driver");
}
+ @Test
+ public void fail_when_mysql_is_used() {
+ MapSettings settings = new MapSettings();
+ settings.setProperty("sonar.jdbc.url", "jdbc:mysql://localhost/sonar");
+
+ DefaultDatabase database = new DefaultDatabase(logbackHelper, settings);
+
+ expectedException.expect(MessageException.class);
+ expectedException.expectMessage("End of Life of MySQL Support");
+ database.start();
+ }
+
@DataProvider
public static Object[][] sonarJdbcAndDbcpProperties() {
return new Object[][] {
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
-import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.LogTester;
-import org.sonar.api.utils.log.LoggerLevel;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
expectedException.expect(MessageException.class);
expectedException.expectMessage("Unsupported mysql version: 5.5. Minimal supported version is 5.6.");
- DatabaseMetaData metadata = newMetadata( 5, 5);
+ DatabaseMetaData metadata = newMetadata(5, 5);
underTest.init(metadata);
}
@Test
public void init_does_not_fail_if_mysql_5_6() throws Exception {
- DatabaseMetaData metadata = newMetadata( 5, 6);
+ DatabaseMetaData metadata = newMetadata(5, 6);
underTest.init(metadata);
}
- @Test
- public void init_logs_warning() throws SQLException {
- underTest.init(newMetadata(5, 6));
-
- List<String> logs = this.logs.logs(LoggerLevel.WARN);
- assertThat(logs.get(0).contains("End of Life of MySQL Support : SonarQube 7.8 is the last version that will support MySQL.")).isTrue();
- }
-
@Test
public void supportsUpsert_returns_false() {
assertThat(underTest.supportsUpsert()).isFalse();
# H2 embedded database server listening port, defaults to 9092
#sonar.embeddedDatabase.port=9092
-#----- DEPRECATED
-#----- MySQL >=5.6 && <8.0
-# Support of MySQL is dropped in Data Center Editions and deprecated in all other editions
-# Only InnoDB storage engine is supported (not myISAM).
-# Only the bundled driver is supported. It can not be changed.
-#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
-
#----- Oracle 11g/12c
# The Oracle JDBC driver must be copied into the directory extensions/jdbc-driver/oracle/.