]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13657 Deprecate exposed apis
authorPhilippe Perrin <philippe.perrin@sonarsource.com>
Thu, 4 Feb 2021 09:09:50 +0000 (10:09 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 10 Feb 2021 20:07:16 +0000 (20:07 +0000)
server/sonar-web/src/main/js/app/components/extensions/__tests__/exposeLibraries-test.ts [new file with mode: 0644]
server/sonar-web/src/main/js/app/components/extensions/exposeLibraries.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 (file)
index 0000000..81a9275
--- /dev/null
@@ -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);
+});
index a26122e28e808d76f924879d4eab0de17477ae47..29c40e9f618d590858d5504675d683d4852f3900 100644 (file)
@@ -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;