Class EngineVersionCheck

  • All Implemented Interfaces:
    CachedWebDataSource

    @ThreadSafe
    public class EngineVersionCheck
    extends java.lang.Object
    implements CachedWebDataSource
    Checks the gh-pages dependency-check site to determine the current released version number. If the released version number is greater than the running version number a warning is printed recommending that an upgrade be performed.
    Author:
    Jeremy Long
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String CURRENT_ENGINE_RELEASE
      The property key indicating when the last version check occurred.
      static java.lang.String ENGINE_VERSION_CHECKED_ON
      The property key indicating when the last version check occurred.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        EngineVersionCheck()
      Constructs a new engine version check utility.
      protected EngineVersionCheck​(Settings settings)
      Constructs a new engine version check utility for testing.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.String getCurrentReleaseVersion()
      Retrieves the current released version number from the github documentation site.
      protected java.lang.String getUpdateToVersion()
      Getter for updateToVersion - only used for testing.
      boolean purge​(Engine engine)
      Deletes any locally cached data.
      protected void setUpdateToVersion​(java.lang.String version)
      Setter for updateToVersion - only used for testing.
      protected boolean shouldUpdate​(long lastChecked, long now, DatabaseProperties properties, java.lang.String currentVersion)
      Determines if a new version of the dependency-check engine has been released.
      boolean update​(Engine engine)
      Downloads the current released version number and compares it to the running engine's version number.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ENGINE_VERSION_CHECKED_ON

        public static final java.lang.String ENGINE_VERSION_CHECKED_ON
        The property key indicating when the last version check occurred.
        See Also:
        Constant Field Values
      • CURRENT_ENGINE_RELEASE

        public static final java.lang.String CURRENT_ENGINE_RELEASE
        The property key indicating when the last version check occurred.
        See Also:
        Constant Field Values
    • Constructor Detail

      • EngineVersionCheck

        protected EngineVersionCheck​(Settings settings)
        Constructs a new engine version check utility for testing.
        Parameters:
        settings - the configured settings
      • EngineVersionCheck

        public EngineVersionCheck()
        Constructs a new engine version check utility.
    • Method Detail

      • getUpdateToVersion

        protected java.lang.String getUpdateToVersion()
        Getter for updateToVersion - only used for testing. Represents the version retrieved from the database.
        Returns:
        the version to test
      • setUpdateToVersion

        protected void setUpdateToVersion​(java.lang.String version)
        Setter for updateToVersion - only used for testing. Represents the version retrieved from the database.
        Parameters:
        version - the version to test
      • update

        public boolean update​(Engine engine)
                       throws UpdateException
        Downloads the current released version number and compares it to the running engine's version number. If the released version number is newer a warning is printed recommending an upgrade.
        Specified by:
        update in interface CachedWebDataSource
        Parameters:
        engine - a reference to the dependency-check engine
        Returns:
        returns false as no updates are made to the database that would require compaction
        Throws:
        UpdateException - thrown if the local database properties could not be updated
      • shouldUpdate

        protected boolean shouldUpdate​(long lastChecked,
                                       long now,
                                       DatabaseProperties properties,
                                       java.lang.String currentVersion)
                                throws UpdateException
        Determines if a new version of the dependency-check engine has been released.
        Parameters:
        lastChecked - the epoch time of the last version check
        now - the current epoch time
        properties - the database properties object
        currentVersion - the current version of dependency-check
        Returns:
        true if a newer version of the database has been released; otherwise false
        Throws:
        UpdateException - thrown if there is an error connecting to the github documentation site or accessing the local database.
      • getCurrentReleaseVersion

        protected java.lang.String getCurrentReleaseVersion()
        Retrieves the current released version number from the github documentation site.
        Returns:
        the current released version number
      • purge

        public boolean purge​(Engine engine)
        Description copied from interface: CachedWebDataSource
        Deletes any locally cached data.
        Specified by:
        purge in interface CachedWebDataSource
        Parameters:
        engine - a reference to the dependency-check engine
        Returns:
        true if the purge was successful; otherwise false