From 083f2d1b0b3dd360ff30f9c74dc8e8d0ca942daf Mon Sep 17 00:00:00 2001 From: Philippe Perrin Date: Thu, 4 Feb 2021 10:09:50 +0100 Subject: [PATCH] SONAR-13657 Deprecate exposed apis --- .../__tests__/exposeLibraries-test.ts | 38 ++++ .../components/extensions/exposeLibraries.ts | 167 ++++++++++-------- 2 files changed, 136 insertions(+), 69 deletions(-) create mode 100644 server/sonar-web/src/main/js/app/components/extensions/__tests__/exposeLibraries-test.ts diff --git a/server/sonar-web/src/main/js/app/components/extensions/__tests__/exposeLibraries-test.ts b/server/sonar-web/src/main/js/app/components/extensions/__tests__/exposeLibraries-test.ts new file mode 100644 index 00000000000..81a92753037 --- /dev/null +++ b/server/sonar-web/src/main/js/app/components/extensions/__tests__/exposeLibraries-test.ts @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import exposeLibraries from '../exposeLibraries'; + +let warnSpy: jest.SpyInstance; + +beforeEach(() => { + warnSpy = jest.spyOn(console, 'warn'); +}); + +it('should run the deprecation notice', () => { + exposeLibraries(); + + const { SonarHelpers, SonarMeasures, SonarComponents } = window as any; + + expect(SonarHelpers).not.toBeNull(); + expect(SonarMeasures).not.toBeNull(); + expect(SonarComponents).not.toBeNull(); + expect(warnSpy).toHaveBeenCalledTimes(3); +}); diff --git a/server/sonar-web/src/main/js/app/components/extensions/exposeLibraries.ts b/server/sonar-web/src/main/js/app/components/extensions/exposeLibraries.ts index a26122e28e8..29c40e9f618 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/exposeLibraries.ts +++ b/server/sonar-web/src/main/js/app/components/extensions/exposeLibraries.ts @@ -107,21 +107,6 @@ import Suggestions from '../embed-docs-modal/Suggestions'; const exposeLibraries = () => { const global = window as any; - global.SonarHelpers = { - getBranchLikeQuery, - isBranch, - isMainBranch, - isPullRequest, - getStandards, - renderCWECategory, - renderOwaspTop10Category, - renderSansTop25Category, - renderSonarSourceSecurityCategory, - getComponentIssuesUrl, - getComponentSecurityHotspotsUrl, - getRulesUrl - }; - global.SonarMeasures = { ...measures, formatMeasure }; global.SonarRequest = { request, get, @@ -133,62 +118,106 @@ const exposeLibraries = () => { throwGlobalError, addGlobalSuccessMessage }; - global.SonarComponents = { - A11ySkipTarget, - ActionsDropdown, - ActionsDropdownItem, - Alert, - AlertErrorIcon, - AlertSuccessIcon, - AlertWarnIcon, - BranchIcon: BranchLikeIcon, - Button, - Checkbox, - CheckIcon, - ClearIcon, - ConfirmButton, - CoverageRating, - DateFormatter, - DateFromNow, - DateTimeFormatter, - DeferredSpinner, - DetachIcon, - Dropdown, - DropdownIcon, - DuplicationsRating, - EditButton, - Favorite, - FormattedMessage, - HelpIcon, - HelpTooltip, - HomePageSelect, - Level, - ListFooter, - LockIcon, - LongLivingBranchIcon: BranchIcon, - Modal, - NotFound, - PlusCircleIcon, - PullRequestIcon, - QualifierIcon, - RadioToggle, - Rating, - ReloadButton, - ResetButtonLink, - SearchBox, - SearchSelect, - SecurityHotspotIcon, - Select, - SelectList, - SimpleModal, - SubmitButton, - Suggestions, - Tooltip, - VulnerabilityIcon - }; - global.t = translate; global.tp = translateWithParameters; + + /** + * @deprecated since SonarQube 8.7 + */ + Object.defineProperty(global, 'SonarHelpers', { + get: () => { + // eslint-disable-next-line no-console + console.warn('SonarHelpers usages are deprecated since SonarQube 8.7'); + return { + getBranchLikeQuery, + isBranch, + isMainBranch, + isPullRequest, + getStandards, + renderCWECategory, + renderOwaspTop10Category, + renderSansTop25Category, + renderSonarSourceSecurityCategory, + getComponentIssuesUrl, + getComponentSecurityHotspotsUrl, + getRulesUrl + }; + } + }); + + /** + * @deprecated since SonarQube 8.7 + */ + Object.defineProperty(global, 'SonarMeasures', { + get: () => { + // eslint-disable-next-line no-console + console.warn('SonarMeasures usages are deprecated since SonarQube 8.7'); + return { ...measures, formatMeasure }; + } + }); + + /** + * @deprecated since SonarQube 8.7 + */ + Object.defineProperty(global, 'SonarComponents', { + get: () => { + // eslint-disable-next-line no-console + console.warn('SonarComponents usages are deprecated since SonarQube 8.7'); + return { + A11ySkipTarget, + ActionsDropdown, + ActionsDropdownItem, + Alert, + AlertErrorIcon, + AlertSuccessIcon, + AlertWarnIcon, + BranchIcon: BranchLikeIcon, + Button, + Checkbox, + CheckIcon, + ClearIcon, + ConfirmButton, + CoverageRating, + DateFormatter, + DateFromNow, + DateTimeFormatter, + DeferredSpinner, + DetachIcon, + Dropdown, + DropdownIcon, + DuplicationsRating, + EditButton, + Favorite, + FormattedMessage, + HelpIcon, + HelpTooltip, + HomePageSelect, + Level, + ListFooter, + LockIcon, + LongLivingBranchIcon: BranchIcon, + Modal, + NotFound, + PlusCircleIcon, + PullRequestIcon, + QualifierIcon, + RadioToggle, + Rating, + ReloadButton, + ResetButtonLink, + SearchBox, + SearchSelect, + SecurityHotspotIcon, + Select, + SelectList, + SimpleModal, + SubmitButton, + Suggestions, + Tooltip, + VulnerabilityIcon + }; + } + }); }; export default exposeLibraries; -- 2.39.5