mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-04-23 08:48:50 +02:00
minor changes to support testing
Former-commit-id: ef1a8934c2a118216a06aeba786be0f732a6060a
This commit is contained in:
@@ -58,6 +58,30 @@ public class EngineVersionCheck implements CachedWebDataSource {
|
||||
*/
|
||||
private CveDB cveDB = null;
|
||||
|
||||
/**
|
||||
* The version retrieved from the database properties or web to check against.
|
||||
*/
|
||||
private String updateToVersion;
|
||||
|
||||
/**
|
||||
* Getter for updateToVersion - only used for testing. Represents the version retrieved from the database.
|
||||
*
|
||||
* @return the version to test
|
||||
*/
|
||||
|
||||
protected String getUpdateToVersion() {
|
||||
return updateToVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for updateToVersion - only used for testing. Represents the version retrieved from the database.
|
||||
*
|
||||
* @param version the version to test
|
||||
*/
|
||||
protected void setUpdateToVersion(String version) {
|
||||
updateToVersion = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() throws UpdateException {
|
||||
try {
|
||||
@@ -65,8 +89,23 @@ public class EngineVersionCheck implements CachedWebDataSource {
|
||||
final DatabaseProperties properties = cveDB.getDatabaseProperties();
|
||||
final long lastChecked = Long.parseLong(properties.getProperty(ENGINE_VERSION_CHECKED_ON, "0"));
|
||||
final long now = (new Date()).getTime();
|
||||
String updateToVersion = properties.getProperty(CURRENT_ENGINE_RELEASE, "");
|
||||
updateToVersion = properties.getProperty(CURRENT_ENGINE_RELEASE, "");
|
||||
String currentVersion = Settings.getString(Settings.KEYS.APPLICATION_VERSION, "0.0.0");
|
||||
boolean updateNeeded = shouldUpdate(lastChecked, now, properties, currentVersion);
|
||||
if (updateNeeded) {
|
||||
final String msg = String.format("A new version of dependency-check is available. Consider updating to version %s.",
|
||||
updateToVersion);
|
||||
LOGGER.warning(msg);
|
||||
}
|
||||
} catch (DatabaseException ex) {
|
||||
LOGGER.log(Level.FINE, "Database Exception opening databases to retrieve properties", ex);
|
||||
throw new UpdateException("Error occured updating database properties.");
|
||||
} finally {
|
||||
closeDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean shouldUpdate(final long lastChecked, final long now, final DatabaseProperties properties, String currentVersion) throws UpdateException {
|
||||
//check every 30 days if we know there is an update, otherwise check every 7 days
|
||||
int checkRange = 30;
|
||||
if (updateToVersion.isEmpty()) {
|
||||
@@ -88,16 +127,9 @@ public class EngineVersionCheck implements CachedWebDataSource {
|
||||
DependencyVersion running = new DependencyVersion(currentVersion);
|
||||
DependencyVersion released = new DependencyVersion(updateToVersion);
|
||||
if (running.compareTo(released) < 0) {
|
||||
final String msg = String.format("A new version of dependency-check is available. Consider updating to version %s.",
|
||||
released.toString());
|
||||
LOGGER.warning(msg);
|
||||
}
|
||||
} catch (DatabaseException ex) {
|
||||
LOGGER.log(Level.FINE, "Database Exception opening databases to retrieve properties", ex);
|
||||
throw new UpdateException("Error occured updating database properties.");
|
||||
} finally {
|
||||
closeDatabase();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user