You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProjectKeyStep.tsx 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import * as React from 'react';
  21. import { FormattedMessage } from 'react-intl';
  22. import { Button } from '../../../components/controls/buttons';
  23. import { ClipboardIconButton } from '../../../components/controls/clipboard';
  24. import { GRADLE_SCANNER_VERSION } from '../../../helpers/constants';
  25. import { translate } from '../../../helpers/l10n';
  26. import { Component } from '../../../types/types';
  27. import CodeSnippet from '../../common/CodeSnippet';
  28. import { withCLanguageFeature } from '../../hoc/withCLanguageFeature';
  29. import RenderOptions from '../components/RenderOptions';
  30. import Step from '../components/Step';
  31. import { BuildTools } from '../types';
  32. export interface ProjectKeyStepProps {
  33. buildTool?: BuildTools;
  34. component: Component;
  35. finished: boolean;
  36. hasCLanguageFeature: boolean;
  37. onDone: () => void;
  38. onOpen: () => void;
  39. open: boolean;
  40. setBuildTool: (tool: BuildTools) => void;
  41. }
  42. const mavenSnippet = () => `<properties>
  43. <sonar.qualitygate.wait>true</sonar.qualitygate.wait>
  44. </properties>`;
  45. const gradleSnippet = (key: string) => `plugins {
  46. id "org.sonarqube" version "${GRADLE_SCANNER_VERSION}"
  47. }
  48. sonar {
  49. properties {
  50. property "sonar.projectKey", "${key}"
  51. property "sonar.qualitygate.wait", true
  52. }
  53. }`;
  54. const otherSnippet = (key: string) => `sonar.projectKey=${key}
  55. sonar.qualitygate.wait=true
  56. `;
  57. const snippetForBuildTool = {
  58. [BuildTools.Maven]: mavenSnippet,
  59. [BuildTools.Gradle]: gradleSnippet,
  60. [BuildTools.CFamily]: otherSnippet,
  61. [BuildTools.Other]: otherSnippet,
  62. };
  63. const filenameForBuildTool = {
  64. [BuildTools.Maven]: 'pom.xml',
  65. [BuildTools.Gradle]: 'build.gradle',
  66. [BuildTools.CFamily]: 'sonar-project.properties',
  67. [BuildTools.Other]: 'sonar-project.properties',
  68. };
  69. export function ProjectKeyStep(props: ProjectKeyStepProps) {
  70. const { buildTool, component, finished, hasCLanguageFeature, open } = props;
  71. const buildToolSelect = (value: BuildTools) => {
  72. props.setBuildTool(value);
  73. if (value === BuildTools.DotNet) {
  74. props.onDone();
  75. }
  76. };
  77. const buildTools = [BuildTools.Maven, BuildTools.Gradle, BuildTools.DotNet];
  78. if (hasCLanguageFeature) {
  79. buildTools.push(BuildTools.CFamily);
  80. }
  81. buildTools.push(BuildTools.Other);
  82. const renderForm = () => (
  83. <div className="boxed-group-inner">
  84. <ol className="list-styled">
  85. <li>
  86. {translate('onboarding.build')}
  87. <RenderOptions
  88. label={translate('onboarding.build')}
  89. checked={buildTool}
  90. onCheck={buildToolSelect}
  91. optionLabelKey="onboarding.build"
  92. options={buildTools}
  93. />
  94. </li>
  95. {buildTool !== undefined && buildTool !== BuildTools.DotNet && (
  96. <li className="abs-width-600">
  97. <FormattedMessage
  98. defaultMessage={translate(
  99. `onboarding.tutorial.with.gitlab_ci.project_key.${buildTool}.step2`
  100. )}
  101. id={`onboarding.tutorial.with.gitlab_ci.project_key.${buildTool}.step2`}
  102. values={{
  103. file: (
  104. <>
  105. <code className="rule">{filenameForBuildTool[buildTool]}</code>
  106. <ClipboardIconButton
  107. className="little-spacer-left"
  108. copyValue={filenameForBuildTool[buildTool]}
  109. />
  110. </>
  111. ),
  112. }}
  113. />
  114. <CodeSnippet snippet={snippetForBuildTool[buildTool](component.key)} />
  115. </li>
  116. )}
  117. </ol>
  118. {buildTool !== undefined && <Button onClick={props.onDone}>{translate('continue')}</Button>}
  119. </div>
  120. );
  121. return (
  122. <Step
  123. finished={finished}
  124. onOpen={props.onOpen}
  125. open={open}
  126. renderForm={renderForm}
  127. stepNumber={1}
  128. stepTitle={translate('onboarding.tutorial.with.gitlab_ci.project_key.title')}
  129. />
  130. );
  131. }
  132. export default withCLanguageFeature(ProjectKeyStep);