mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-24 01:51:49 +01: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;
|
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
|
@Override
|
||||||
public void update() throws UpdateException {
|
public void update() throws UpdateException {
|
||||||
try {
|
try {
|
||||||
@@ -65,8 +89,23 @@ public class EngineVersionCheck implements CachedWebDataSource {
|
|||||||
final DatabaseProperties properties = cveDB.getDatabaseProperties();
|
final DatabaseProperties properties = cveDB.getDatabaseProperties();
|
||||||
final long lastChecked = Long.parseLong(properties.getProperty(ENGINE_VERSION_CHECKED_ON, "0"));
|
final long lastChecked = Long.parseLong(properties.getProperty(ENGINE_VERSION_CHECKED_ON, "0"));
|
||||||
final long now = (new Date()).getTime();
|
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");
|
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
|
//check every 30 days if we know there is an update, otherwise check every 7 days
|
||||||
int checkRange = 30;
|
int checkRange = 30;
|
||||||
if (updateToVersion.isEmpty()) {
|
if (updateToVersion.isEmpty()) {
|
||||||
@@ -88,16 +127,9 @@ public class EngineVersionCheck implements CachedWebDataSource {
|
|||||||
DependencyVersion running = new DependencyVersion(currentVersion);
|
DependencyVersion running = new DependencyVersion(currentVersion);
|
||||||
DependencyVersion released = new DependencyVersion(updateToVersion);
|
DependencyVersion released = new DependencyVersion(updateToVersion);
|
||||||
if (running.compareTo(released) < 0) {
|
if (running.compareTo(released) < 0) {
|
||||||
final String msg = String.format("A new version of dependency-check is available. Consider updating to version %s.",
|
return true;
|
||||||
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 false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user