/* * SonarQube * Copyright (C) 2009-2024 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 { ClipboardIconButton, CodeSnippet, FlagMessage, NumberedList, NumberedListItem, TutorialStep, } from 'design-system'; import * as React from 'react'; import { FormattedMessage } from 'react-intl'; import withAvailableFeatures, { WithAvailableFeaturesProps, } from '../../../app/components/available-features/withAvailableFeatures'; import { GRADLE_SCANNER_VERSION } from '../../../helpers/constants'; import { translate } from '../../../helpers/l10n'; import { Component } from '../../../types/types'; import { withCLanguageFeature } from '../../hoc/withCLanguageFeature'; import BuildConfigSelection from '../components/BuildConfigSelection'; import GithubCFamilyExampleRepositories from '../components/GithubCFamilyExampleRepositories'; import GradleBuildSelection from '../components/GradleBuildSelection'; import { InlineSnippet } from '../components/InlineSnippet'; import RenderOptions from '../components/RenderOptions'; import { Arch, BuildTools, GradleBuildDSL, OSs, TutorialConfig, TutorialModes } from '../types'; import { shouldShowArchSelector, shouldShowGithubCFamilyExampleRepositories } from '../utils'; import PipeCommand from './commands/PipeCommand'; export interface YmlFileStepProps extends WithAvailableFeaturesProps { component: Component; hasCLanguageFeature: boolean; setDone: (done: boolean) => void; } const mavenSnippet = (key: string, name: string) => ` ${key} ${name} true `; const gradleSnippet = (key: string, name: string, build: GradleBuildDSL) => { const map = { [GradleBuildDSL.Groovy]: `plugins { id "org.sonarqube" version "${GRADLE_SCANNER_VERSION}" } sonar { properties { property "sonar.projectKey", "${key}" property "sonar.projectName", "${name}" property "sonar.qualitygate.wait", true } }`, [GradleBuildDSL.Kotlin]: `plugins { id ("org.sonarqube") version "${GRADLE_SCANNER_VERSION}" } sonar { properties { property("sonar.projectKey", "${key}") property("sonar.projectName", "${name}") property("sonar.qualitygate.wait", true) } }`, }; return map[build]; }; const otherSnippet = (key: string) => `sonar.projectKey=${key} sonar.qualitygate.wait=true `; const snippetForBuildTool = { [BuildTools.Cpp]: otherSnippet, [BuildTools.ObjectiveC]: otherSnippet, [BuildTools.Gradle]: gradleSnippet, [BuildTools.Maven]: mavenSnippet, [BuildTools.Dart]: otherSnippet, [BuildTools.Other]: otherSnippet, }; const filenameForBuildTool = { [BuildTools.Cpp]: 'sonar-project.properties', [BuildTools.ObjectiveC]: 'sonar-project.properties', [BuildTools.Gradle]: GradleBuildDSL.Groovy, [BuildTools.Maven]: 'pom.xml', [BuildTools.Dart]: 'sonar-project.properties', [BuildTools.Other]: 'sonar-project.properties', }; const snippetLanguageForBuildTool = { [BuildTools.Cpp]: undefined, [BuildTools.ObjectiveC]: undefined, [BuildTools.Gradle]: undefined, [BuildTools.Maven]: 'xml', [BuildTools.Dart]: undefined, [BuildTools.Other]: undefined, }; export function YmlFileStep(props: Readonly) { const { component, hasCLanguageFeature, setDone } = props; const [arch, setArch] = React.useState(Arch.X86_64); const [config, setConfig] = React.useState({}); const { buildTool } = config; function onSetConfig(config: TutorialConfig) { setConfig(config); } React.useEffect(() => { setDone(Boolean(config.buildTool)); }, [config.buildTool, setDone]); const renderForm = () => ( {shouldShowArchSelector(OSs.Linux, config) && ( setArch(value)} optionLabelKey="onboarding.build.other.architecture" options={[Arch.X86_64, Arch.Arm64]} titleLabelKey="onboarding.build.other.architecture" /> )} {shouldShowGithubCFamilyExampleRepositories(config) && ( )} {/* Step 2 */} {buildTool !== undefined && buildTool !== BuildTools.DotNet && ( ), }, buildTool === BuildTools.Gradle ? { file2: ( <> ), } : {}, )} /> {buildTool === BuildTools.Gradle ? ( {(build) => ( )} ) : ( )} )} {/* Step 3 */} {buildTool && ( ), }} /> {translate('onboarding.tutorial.with.gitlab_ci.yaml.premium')}

{translate('onboarding.tutorial.with.gitlab_ci.yaml.baseconfig')}

{translate('onboarding.tutorial.with.gitlab_ci.yaml.existing')}

)}
); return ( {renderForm()} ); } export default withCLanguageFeature(withAvailableFeatures(YmlFileStep));