8#include "MantidJson/Json.h"
15#include <Poco/DateTimeFormat.h>
16#include <Poco/DateTimeFormatter.h>
17#include <Poco/DateTimeParser.h>
22#include <boost/lexical_cast.hpp>
42 return "Checks if there is a more recent version of Mantid available using "
51 declareProperty(
"IsNewVersionAvailable",
false,
"True if a newer version is available, otherwise false",
60 std::string mostRecentVersion;
63 if (gitHubReleaseUrl.empty()) {
64 gitHubReleaseUrl =
"https://api.github.com/repos/mantidproject/mantid/releases/latest";
67 if (downloadUrl.empty()) {
68 downloadUrl =
"http://download.mantidproject.org";
81 g_log.
debug(
"Cannot get latest version details from " + gitHubReleaseUrl);
82 g_log.
debug(
"The address can be changed using the property "
83 "CheckMantidVersion.GitHubReleaseURL");
89 bool isNewVersionAvailable =
false;
92 std::string jsonErrors;
93 bool parseOK = Mantid::JsonHelpers::parse(json, &root, &jsonErrors);
97 g_log.
warning() <<
"Error found when parsing version information "
98 "retrieved from GitHub as a JSON string. "
99 "Error trying to parse this JSON string: "
100 << json <<
"\n. Parsing error details: " << jsonErrors <<
'\n';
103 std::string gitHubVersionTag;
105 gitHubVersionTag = root[
"tag_name"].asString();
106 }
catch (std::runtime_error &re) {
107 g_log.
error() <<
"Error while trying to get the field 'tag_name' from "
108 "the version information retrieved from GitHub. This "
109 "algorithm cannot continue and will stop now. Error details: "
110 << re.what() <<
'\n';
112 mostRecentVersion =
"Could not get information from GitHub";
113 setProperty(
"MostRecentVersion", mostRecentVersion);
114 setProperty(
"IsNewVersionAvailable", isNewVersionAvailable);
120 if (isNewVersionAvailable) {
122 g_log.
notice(
"A new version of Mantid(" + mostRecentVersion +
") is available for download from " + downloadUrl);
129 setProperty(
"MostRecentVersion", mostRecentVersion);
130 setProperty(
"IsNewVersionAvailable", isNewVersionAvailable);
139 std::string retVal = versionTag;
153 std::vector<int> retVal;
161 auto part = boost::lexical_cast<int>(*h);
162 retVal.emplace_back(part);
163 }
catch (
const boost::bad_lexical_cast &) {
164 g_log.
error(
"Failed to convert the following string to an integer '" + *h +
165 "' as part of CheckMantidVersion::splitVersionString");
166 retVal.emplace_back(0);
181 for (
size_t i = 0; i < gitHubVersionParts.size(); i++) {
183 if (i >= localVersionParts.size()) {
190 if (localVersionParts[i] > 2000) {
196 if (gitHubVersionParts[i] > localVersionParts[i]) {
199 if (gitHubVersionParts[i] < localVersionParts[i]) {
215 std::ostringstream os;
218 inetHelper.
addHeader(
"if-modified-since",
220 Poco::DateTimeFormat::HTTP_FORMAT));
222 std::string retVal = os.str();
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
CheckMantidVersion : Checks if the current version of Mantid is the most recent.
virtual std::string getCurrentVersion() const
Gets the version of this Mantid.
void exec() override
Execute the algorithm.
virtual std::string getVersionsFromGitHub(const std::string &url)
Gets the version json for the most recent release from gitHub.
int version() const override
Algorithm's version for identification.
std::vector< int > splitVersionString(const std::string &versionString) const
splits a .
bool isVersionMoreRecent(const std::string &localVersion, const std::string &gitHubVersion) const
Compare two version strings, tests if the gitHubVersion is more recent.
void init() override
Initialize the algorithm's properties.
std::string cleanVersionTag(const std::string &versionTag) const
Cleans the tag name from github to make it similar to that from MantidVersion.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
const std::string category() const override
Algorithm's category for identification.
Exception thrown when error occurs accessing an internet resource.
const char * what() const noexcept override
Overloaded reporting method.
const int & errorCode() const
Writes out the range and limits.
GitHubApiHelper : A helper class for supporting access to the github api through HTTP and HTTPS,...
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void addHeader(const std::string &key, const std::string &value)
Adds a header.
virtual HTTPStatus sendRequest(const std::string &url, std::ostream &responseStream)
Performs a request using http or https depending on the url.
void debug(const std::string &msg)
Logs at debug level.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
static const char * version()
The full version number.
static const char * releaseDate()
The date of the last commit.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Iterator begin()
Iterator referring to first element in the container.
@ TOK_IGNORE_EMPTY
ignore empty tokens
@ TOK_TRIM
remove leading and trailing whitespace from tokens
Iterator end()
Iterator referring to the past-the-end element in the container.
Mantid::Kernel::StringTokenizer tokenizer
MANTID_KERNEL_DLL std::string strip(const std::string &A)
strip pre/post spaces
MANTID_KERNEL_DLL std::string replaceAll(const std::string &input, const std::string &charStr, const std::string &substitute)
Return a string with all occurrences of the characters in the input replaced by the replace string.
@ Output
An output workspace.