Factor out license check.

Change-Id: Ifcaab7252239bde1affa8bc55ab38761c0f6e99f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Christian Kandeler
2015-07-01 17:20:45 +02:00
parent 313724ace9
commit daa478adad
4 changed files with 51 additions and 20 deletions

View File

@@ -28,6 +28,7 @@ HEADERS += \
clangstaticanalyzerdiagnosticmodel.h \ clangstaticanalyzerdiagnosticmodel.h \
clangstaticanalyzerdiagnosticview.h \ clangstaticanalyzerdiagnosticview.h \
clangstaticanalyzer_global.h \ clangstaticanalyzer_global.h \
clangstaticanalyzerlicensecheck.h \
clangstaticanalyzerlogfilereader.h \ clangstaticanalyzerlogfilereader.h \
clangstaticanalyzerplugin.h \ clangstaticanalyzerplugin.h \
clangstaticanalyzerprojectsettings.h \ clangstaticanalyzerprojectsettings.h \

View File

@@ -30,6 +30,7 @@ QtcCommercialPlugin {
"clangstaticanalyzerdiagnosticmodel.h", "clangstaticanalyzerdiagnosticmodel.h",
"clangstaticanalyzerdiagnosticview.cpp", "clangstaticanalyzerdiagnosticview.cpp",
"clangstaticanalyzerdiagnosticview.h", "clangstaticanalyzerdiagnosticview.h",
"clangstaticanalyzerlicensecheck.h",
"clangstaticanalyzerlogfilereader.cpp", "clangstaticanalyzerlogfilereader.cpp",
"clangstaticanalyzerlogfilereader.h", "clangstaticanalyzerlogfilereader.h",
"clangstaticanalyzerplugin.cpp", "clangstaticanalyzerplugin.cpp",

View File

@@ -0,0 +1,45 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd
** All rights reserved.
** For any questions to The Qt Company, please use contact form at http://www.qt.io/contact-us
**
** This file is part of the Qt Enterprise ClangStaticAnalyzer Add-on.
**
** Licensees holding valid Qt Enterprise licenses may use this file in
** accordance with the Qt Enterprise License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company.
**
** If you have questions regarding the use of this file, please use
** contact form at http://www.qt.io/contact-us
**
****************************************************************************/
#ifndef CLANGSTATICANALYZERLICENSECHECK_H
#define CLANGSTATICANALYZERLICENSECHECK_H
#ifdef LICENSECHECKER
#include <extensionsystem/pluginmanager.h>
#include <licensechecker/licensecheckerplugin.h>
#endif
inline bool enterpriseFeaturesAvailable()
{
#ifdef LICENSECHECKER
LicenseChecker::LicenseCheckerPlugin *licenseChecker
= ExtensionSystem::PluginManager::getObject<LicenseChecker::LicenseCheckerPlugin>();
if (licenseChecker && licenseChecker->hasValidLicense()) {
if (licenseChecker->enterpriseFeatures())
return true;
} else {
qWarning() << "Invalid license, disabling Clang Static Analyzer";
}
return false;
#else // LICENSECHECKER
return true;
#endif
}
#endif // Include guard.

View File

@@ -20,6 +20,7 @@
#include "clangstaticanalyzerconfigwidget.h" #include "clangstaticanalyzerconfigwidget.h"
#include "clangstaticanalyzerconstants.h" #include "clangstaticanalyzerconstants.h"
#include "clangstaticanalyzerlicensecheck.h"
#include "clangstaticanalyzerprojectsettingswidget.h" #include "clangstaticanalyzerprojectsettingswidget.h"
#include "clangstaticanalyzerruncontrolfactory.h" #include "clangstaticanalyzerruncontrolfactory.h"
#include "clangstaticanalyzertool.h" #include "clangstaticanalyzertool.h"
@@ -38,12 +39,6 @@
#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/dialogs/ioptionspage.h>
#include <projectexplorer/projectpanelfactory.h> #include <projectexplorer/projectpanelfactory.h>
#ifdef LICENSECHECKER
#include <licensechecker/licensecheckerplugin.h>
#endif
#include <extensionsystem/pluginmanager.h>
#include <QAction> #include <QAction>
#include <QDebug> #include <QDebug>
#include <QMainWindow> #include <QMainWindow>
@@ -117,21 +112,7 @@ bool ClangStaticAnalyzerPlugin::initialize(const QStringList &arguments, QString
panelFactory->setDisplayName(tr("Clang Static Analyzer Settings")); panelFactory->setDisplayName(tr("Clang Static Analyzer Settings"));
panelFactory->setSimpleCreateWidgetFunction<ProjectSettingsWidget>(QIcon()); panelFactory->setSimpleCreateWidgetFunction<ProjectSettingsWidget>(QIcon());
ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory); ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
#ifdef LICENSECHECKER
LicenseChecker::LicenseCheckerPlugin *licenseChecker
= ExtensionSystem::PluginManager::getObject<LicenseChecker::LicenseCheckerPlugin>();
if (licenseChecker && licenseChecker->hasValidLicense()) {
if (licenseChecker->enterpriseFeatures())
return initializeEnterpriseFeatures(arguments, errorString);
} else {
qWarning() << "Invalid license, disabling Clang Static Analyzer";
}
return true;
#else // LICENSECHECKER
return initializeEnterpriseFeatures(arguments, errorString); return initializeEnterpriseFeatures(arguments, errorString);
#endif
} }
bool ClangStaticAnalyzerPlugin::initializeEnterpriseFeatures(const QStringList &arguments, bool ClangStaticAnalyzerPlugin::initializeEnterpriseFeatures(const QStringList &arguments,
@@ -140,6 +121,9 @@ bool ClangStaticAnalyzerPlugin::initializeEnterpriseFeatures(const QStringList &
Q_UNUSED(arguments); Q_UNUSED(arguments);
Q_UNUSED(errorString); Q_UNUSED(errorString);
if (!enterpriseFeaturesAvailable())
return true;
auto tool = m_analyzerTool = new ClangStaticAnalyzerTool(this); auto tool = m_analyzerTool = new ClangStaticAnalyzerTool(this);
addAutoReleasedObject(new ClangStaticAnalyzerRunControlFactory(m_analyzerTool)); addAutoReleasedObject(new ClangStaticAnalyzerRunControlFactory(m_analyzerTool));
addAutoReleasedObject(new ClangStaticAnalyzerOptionsPage); addAutoReleasedObject(new ClangStaticAnalyzerOptionsPage);