Skip to content

Commit

Permalink
[JENKINS-46577] Better detection of plugin loading issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrille Le Clerc committed Dec 9, 2017
1 parent ddf7842 commit 98677c4
Showing 1 changed file with 17 additions and 2 deletions.
Expand Up @@ -36,6 +36,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -66,8 +67,13 @@ public PipelineMavenPluginH2Dao(File rootDir) {

File databaseFile = new File(rootDir, "jenkins-jobs");
String jdbcUrl = "jdbc:h2:file:" + databaseFile.getAbsolutePath() + ";AUTO_SERVER=TRUE;MULTI_THREADED=1";
if(LOGGER.isLoggable(Level.FINEST)) {
jdbcUrl += ";TRACE_LEVEL_SYSTEM_OUT=3";
} else if (LOGGER.isLoggable(Level.FINE)) {
jdbcUrl += ";TRACE_LEVEL_SYSTEM_OUT=2";
}
LOGGER.log(Level.INFO, "Open database {0}", jdbcUrl);
jdbcConnectionPool = JdbcConnectionPool.create(jdbcUrl, "sa", "sa");
LOGGER.log(Level.FINE, "Open database {0}", jdbcUrl);

initializeDatabase();
testDatabase();
Expand Down Expand Up @@ -344,7 +350,14 @@ protected synchronized void initializeDatabase() {
}
int newSchemaVersion = getSchemaVersion(cnn);

if (initialSchemaVersion != newSchemaVersion) {
if (newSchemaVersion == 0) {
// https://issues.jenkins-ci.org/browse/JENKINS-46577
throw new IllegalStateException("Failure to load database DDL files. " +
"Files 'sql/h2/xxx_migration.sql' NOT found in the Thread Context Class Loader. " +
" Pipeline Maven Plugin may be installed in an unsupported manner");
} else if (newSchemaVersion == initialSchemaVersion) {
// no migration was needed
} else {
LOGGER.log(Level.INFO, "Database successfully migrated from version {0} to version {1}", new Object[]{initialSchemaVersion, newSchemaVersion});
}
} catch (SQLException e) {
Expand Down Expand Up @@ -388,6 +401,8 @@ protected synchronized void testDatabase() throws RuntimeSqlException {
throw new IllegalStateException("Exception testing table '" + table + "'");
}
}
} catch (SQLException e) {
throw new RuntimeSqlException("Exception testing table '" + table + "' on " + cnn.toString(), e);
}
}
} catch (SQLException e) {
Expand Down

0 comments on commit 98677c4

Please sign in to comment.