2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2020 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2021-02-15 16:20:38 +01:00
|
|
|
|
2021-09-27 22:36:28 +02:00
|
|
|
#pragma once
|
2021-02-15 16:20:38 +01:00
|
|
|
|
2022-02-21 15:24:46 +01:00
|
|
|
#include <utils/filepath.h>
|
2022-06-02 16:13:08 +02:00
|
|
|
#include <QString>
|
2021-02-15 16:20:38 +01:00
|
|
|
|
2022-06-02 16:13:08 +02:00
|
|
|
namespace McuSupport::Internal {
|
2021-02-15 16:20:38 +01:00
|
|
|
|
2022-06-02 16:13:08 +02:00
|
|
|
class McuPackageVersionDetector
|
2021-03-04 17:07:49 +01:00
|
|
|
{
|
2021-02-15 16:20:38 +01:00
|
|
|
public:
|
2022-07-04 22:30:42 +02:00
|
|
|
McuPackageVersionDetector() = default;
|
2021-02-15 16:20:38 +01:00
|
|
|
virtual ~McuPackageVersionDetector() = default;
|
2022-04-21 12:27:51 +02:00
|
|
|
virtual QString parseVersion(const Utils::FilePath &packagePath) const = 0;
|
2021-02-15 16:20:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Get version from the output of an executable
|
2021-03-04 17:07:49 +01:00
|
|
|
class McuPackageExecutableVersionDetector : public McuPackageVersionDetector
|
|
|
|
|
{
|
2021-02-15 16:20:38 +01:00
|
|
|
public:
|
2022-02-21 15:24:46 +01:00
|
|
|
McuPackageExecutableVersionDetector(const Utils::FilePath &detectionPath,
|
2021-02-15 16:20:38 +01:00
|
|
|
const QStringList &detectionArgs,
|
|
|
|
|
const QString &detectionRegExp);
|
2022-04-21 12:27:51 +02:00
|
|
|
QString parseVersion(const Utils::FilePath &packagePath) const final;
|
2022-02-15 11:18:56 +01:00
|
|
|
|
2021-02-15 16:20:38 +01:00
|
|
|
private:
|
2022-02-21 15:24:46 +01:00
|
|
|
const Utils::FilePath m_detectionPath;
|
2021-02-15 16:20:38 +01:00
|
|
|
const QStringList m_detectionArgs;
|
|
|
|
|
const QString m_detectionRegExp;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Get version through parsing an XML file
|
2021-03-04 17:07:49 +01:00
|
|
|
class McuPackageXmlVersionDetector : public McuPackageVersionDetector
|
|
|
|
|
{
|
2021-02-15 16:20:38 +01:00
|
|
|
public:
|
|
|
|
|
McuPackageXmlVersionDetector(const QString &filePattern,
|
|
|
|
|
const QString &elementName,
|
|
|
|
|
const QString &versionAttribute,
|
|
|
|
|
const QString &versionRegExp);
|
2022-04-21 12:27:51 +02:00
|
|
|
QString parseVersion(const Utils::FilePath &packagePath) const final;
|
2022-02-15 11:18:56 +01:00
|
|
|
|
2021-02-15 16:20:38 +01:00
|
|
|
private:
|
|
|
|
|
const QString m_filePattern;
|
|
|
|
|
const QString m_versionElement;
|
|
|
|
|
const QString m_versionAttribute;
|
|
|
|
|
const QString m_versionRegExp;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Get version from the filename of a given file/dir in the package directory
|
2022-10-19 14:24:16 +02:00
|
|
|
class McuPackageDirectoryEntriesVersionDetector : public McuPackageVersionDetector
|
2021-03-04 17:07:49 +01:00
|
|
|
{
|
2021-02-15 16:20:38 +01:00
|
|
|
public:
|
2022-10-19 14:24:16 +02:00
|
|
|
McuPackageDirectoryEntriesVersionDetector(const QString &filePattern,
|
|
|
|
|
const QString &versionRegExp);
|
2022-04-21 12:27:51 +02:00
|
|
|
QString parseVersion(const Utils::FilePath &packagePath) const final;
|
2022-02-15 11:18:56 +01:00
|
|
|
|
2021-02-15 16:20:38 +01:00
|
|
|
private:
|
|
|
|
|
const QString m_filePattern;
|
|
|
|
|
const QString m_versionRegExp;
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-01 11:07:44 +01:00
|
|
|
// Get version from the path of the package itself
|
2021-03-04 17:07:49 +01:00
|
|
|
class McuPackagePathVersionDetector : public McuPackageVersionDetector
|
|
|
|
|
{
|
2021-03-01 11:07:44 +01:00
|
|
|
public:
|
|
|
|
|
McuPackagePathVersionDetector(const QString &versionRegExp);
|
2022-04-21 12:27:51 +02:00
|
|
|
QString parseVersion(const Utils::FilePath &packagePath) const final;
|
2022-02-15 11:18:56 +01:00
|
|
|
|
2021-03-01 11:07:44 +01:00
|
|
|
private:
|
|
|
|
|
const QString m_versionRegExp;
|
|
|
|
|
};
|
|
|
|
|
|
2022-06-02 16:13:08 +02:00
|
|
|
} // namespace McuSupport::Internal
|