Class JdbcDriverDownloader


  • @Immutable
    public final class JdbcDriverDownloader
    extends Object

    JDBC driver download manager.

    Since:
    2018.1
    Author:
    Andrey Shcheglov <mailto:andrey.shcheglov@jetbrains.com>
    • Field Detail

      • DOWNLOAD_URL_KEY

        @NonNls
        @NotNull
        public static final String DOWNLOAD_URL_KEY

        The name of the internal property holding the URL(s) (comma-separated) to download JDBC driver metadata from. The first URL which returns a valid response will be used.

        See Also:
        Constant Field Values
      • ALLOW_NON_HTTP_URLS_KEY

        @NonNls
        @NotNull
        public static final String ALLOW_NON_HTTP_URLS_KEY

        If "teamcity.maintenance.jdbcDrivers.allowNonHttpUrls" is set to true, other URL schemes (such as ftp:// and file://) will also be supported.

        Note: this will disable the TeamCity-specific HTTP client implementation, resulting in teamcity.http.* and teamcity.https.* family of internal properties being ignored.

        Since:
        2018.1.1
        See Also:
        Constant Field Values
      • LICENSE_FILE_NAME_PATTERN

        @NotNull
        public static final Pattern LICENSE_FILE_NAME_PATTERN

        The regex pattern used to select the license file (DataGrip flavour).

    • Constructor Detail

      • JdbcDriverDownloader

        public JdbcDriverDownloader​(@NotNull
                                    Logger logger,
                                    @NotNull
                                    TeamCityPropertiesProvider propertiesProvider)

        Creates a new JDBC driver download manager using the default URL.

        Parameters:
        logger - the logger to be used (normally, either Loggers.MAINTENANCE or Loggers.STARTUP).
        propertiesProvider - the TeamCity properties provider to use.
      • JdbcDriverDownloader

        public JdbcDriverDownloader​(@NotNull
                                    Logger logger,
                                    @NotNull
                                    JdbcDriverDownloader.UrlConnectionFactory urlConnectionFactory,
                                    @NotNull
                                    TeamCityPropertiesProvider propertiesProvider)

        Creates a new JDBC driver download manager using the default URL and a custom connection factory.

        Parameters:
        logger - the logger to be used (normally, either Loggers.MAINTENANCE or Loggers.STARTUP).
        urlConnectionFactory - the URL connection factory to use.
        propertiesProvider - the TeamCity properties provider to use.
        Since:
        2018.1.1
      • JdbcDriverDownloader

        public JdbcDriverDownloader​(@NotNull
                                    Logger logger,
                                    @NotNull
                                    URL... downloadUrls)

        Creates a new JDBC driver download manager using a custom URL.

        Parameters:
        logger - the logger to be used (normally, either Loggers.MAINTENANCE or Loggers.STARTUP).
        downloadUrls - the URL(s) to download JDBC driver metadata from. The URLs will be attempted in a row, the first one to return a valid response will be used.
        Throws:
        IllegalArgumentException - if downloadUrls are empty.
      • JdbcDriverDownloader

        public JdbcDriverDownloader​(@NotNull
                                    Logger logger,
                                    @NotNull
                                    JdbcDriverDownloader.UrlConnectionFactory urlConnectionFactory,
                                    @NotNull
                                    URL... downloadUrls)

        Creates a new JDBC driver download manager using custom URL and connection factory.

        Parameters:
        logger - the logger to be used (normally, either Loggers.MAINTENANCE or Loggers.STARTUP).
        urlConnectionFactory - the URL connection factory to use.
        downloadUrls - the URL(s) to download JDBC driver metadata from. The URLs will be attempted in a row, the first one to return a valid response will be used.
        Throws:
        IllegalArgumentException - if downloadUrls are empty.
    • Method Detail

      • download

        public void download​(@NotNull
                             DatabaseType type,
                             @NotNull
                             File targetDirectory,
                             boolean cleanupTargetDirectory,
                             @NotNull
                             List<Exception> errors)

        Attempts to download the driver files into the specified directory.

        Parameters:
        type - the database driver to download JDBC drivers for.
        targetDirectory - the directory to download the drivers into (normally, ${TEAMCITY_DATA_PATH}/lib/jdbc).
        cleanupTargetDirectory - whether targetDirectory should be cleaned up before the driver is downloaded (normally, true for maintainDB.sh and false for the start-up UI).
        errors - the download error collector (must be mutable).
        See Also:
        download(DatabaseType, File, boolean, List, Map), download(DatabaseType, File, boolean, List, ProgressListener, Map)
      • isEnabled

        public static boolean isEnabled()

        Feature toggle.

        Returns:
        true if JDBC driver downloader feature is enabled, false otherwise.
      • listLatest

        @NotNull
        public Map<DatabaseType,​JdbcDriver> listLatest()
                                                      throws IOException

        Returns the metadata for the most recent JDBC drivers supported by TeamCity.

        Returns:
        the metadata for the most recent JDBC drivers supported by TeamCity.
        Throws:
        IOException - if there was a failure downloading a valid XML metadata from any of myDownloadUrls (sources didn't contain a well-formed XML, contained XML elements not expected by the deserializer, or an IOException was thrown when opening a connection to the URL (e. g. in response to HTTP 404)).