From 8a2e844d04163b8b26cd114d353a38fb8cf9ceee Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov <138671+Godin@users.noreply.github.com> Date: Wed, 25 Sep 2024 21:34:08 +0200 Subject: [PATCH] SONAR-23112 Add tutorials for Dart --- .../__tests__/AzurePipelinesTutorial-it.tsx | 4 + .../commands/AnalysisCommand.tsx | 1 + .../bitbucket-pipelines/AnalysisCommand.tsx | 2 + .../bitbucket-pipelines/PreambuleYaml.tsx | 1 + .../BitbucketPipelinesTutorial-it.tsx | 5 + .../BitbucketPipelinesTutorial-it.tsx.snap | 33 +++++++ .../bitbucket-pipelines/commands/Dart.ts | 60 ++++++++++++ .../github-action/AnalysisCommand.tsx | 10 ++ .../__tests__/GithubActionTutorial-it.tsx | 4 + .../GithubActionTutorial-it.tsx.snap | 30 ++++++ .../tutorials/github-action/commands/Dart.tsx | 92 +++++++++++++++++++ .../tutorials/gitlabci/YmlFileStep.tsx | 3 + .../__tests__/GitLabCITutorial-it.tsx | 5 + .../GitLabCITutorial-it.tsx.snap | 68 ++++++++++++++ .../gitlabci/commands/PipeCommand.tsx | 8 +- .../tutorials/jenkins/JenkinsStep.tsx | 1 + .../jenkins/__tests__/JenkinsTutorial-it.tsx | 5 + .../__snapshots__/JenkinsTutorial-it.tsx.snap | 64 +++++++++++++ .../tutorials/other/BuildToolForm.tsx | 2 + .../other/__tests__/OtherTutorial-it.tsx | 16 ++++ .../__snapshots__/OtherTutorial-it.tsx.snap | 51 ++++++++++ .../other/commands/AnalysisCommand.tsx | 1 + .../js/components/tutorials/test-utils.ts | 1 + .../src/main/js/components/tutorials/types.ts | 1 + .../src/main/js/components/tutorials/utils.ts | 2 + .../resources/org/sonar/l10n/core.properties | 3 + 26 files changed, 472 insertions(+), 1 deletion(-) create mode 100644 server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Dart.ts create mode 100644 server/sonar-web/src/main/js/components/tutorials/github-action/commands/Dart.tsx diff --git a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/__tests__/AzurePipelinesTutorial-it.tsx b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/__tests__/AzurePipelinesTutorial-it.tsx index bdb521f43ec..13b851236a7 100644 --- a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/__tests__/AzurePipelinesTutorial-it.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/__tests__/AzurePipelinesTutorial-it.tsx @@ -117,6 +117,10 @@ it('should render correctly and allow token generation', async () => { await user.click(getTutorialBuildButtons().macosButton.get()); assertObjCStepIsCorrectlyRendered(OSs.MacOS); + // Analysis step: Dart + await user.click(getTutorialBuildButtons().dartBuildButton.get()); + assertOtherStepIsCorrectlyRendered(); + // Analysis step: Other await user.click(getTutorialBuildButtons().otherBuildButton.get()); assertOtherStepIsCorrectlyRendered(); diff --git a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/AnalysisCommand.tsx b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/AnalysisCommand.tsx index 32d77e59a03..b28e92c5cc0 100644 --- a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/AnalysisCommand.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/AnalysisCommand.tsx @@ -53,6 +53,7 @@ export default function AnalysisCommand(props: AnalysisCommandProps) { case BuildTools.ObjectiveC: return ; + case BuildTools.Dart: case BuildTools.Other: return ; diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/AnalysisCommand.tsx b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/AnalysisCommand.tsx index fa956930e0b..bc0bfade9c9 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/AnalysisCommand.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/AnalysisCommand.tsx @@ -30,6 +30,7 @@ import { Arch, BuildTools, TutorialConfig } from '../types'; import { isCFamily } from '../utils'; import { PreambuleYaml } from './PreambuleYaml'; import cFamilyExample from './commands/CFamily'; +import dartExample from './commands/Dart'; import dotNetExample from './commands/DotNet'; import gradleExample from './commands/Gradle'; import mavenExample from './commands/Maven'; @@ -57,6 +58,7 @@ const YamlTemplate: Dictionary = { [BuildTools.DotNet]: dotNetExample, [BuildTools.Cpp]: cFamilyExample, [BuildTools.ObjectiveC]: cFamilyExample, + [BuildTools.Dart]: dartExample, [BuildTools.Other]: othersExample, }; diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/PreambuleYaml.tsx b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/PreambuleYaml.tsx index 83222ccbe61..c8d40198f57 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/PreambuleYaml.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/PreambuleYaml.tsx @@ -35,6 +35,7 @@ export function PreambuleYaml(props: PreambuleYamlProps) { return ; case BuildTools.Cpp: case BuildTools.ObjectiveC: + case BuildTools.Dart: case BuildTools.Other: return ; default: diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/BitbucketPipelinesTutorial-it.tsx b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/BitbucketPipelinesTutorial-it.tsx index 5efadd4646c..54ecf78154a 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/BitbucketPipelinesTutorial-it.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/BitbucketPipelinesTutorial-it.tsx @@ -128,6 +128,11 @@ it('should follow and complete all steps', async () => { 'C++ (manual arm64) and Objective-C: sonar-project.properties', ); + // Dart + await user.click(ui.dartBuildButton.get()); + expect(getCopyToClipboardValue(0, 'Copy')).toMatchSnapshot('Dart: sonar-project.properties'); + expect(getCopyToClipboardValue(1, 'Copy')).toMatchSnapshot('Dart: bitbucket-pipelines.yml'); + // Other await user.click(ui.otherBuildButton.get()); expect(getCopyToClipboardValue(0, 'Copy')).toMatchSnapshot( diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/BitbucketPipelinesTutorial-it.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/BitbucketPipelinesTutorial-it.tsx.snap index 8652ad9cb41..47fabb0cee7 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/BitbucketPipelinesTutorial-it.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/BitbucketPipelinesTutorial-it.tsx.snap @@ -1,5 +1,38 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`should follow and complete all steps: Dart: sonar-project.properties 1`] = `"sonar.projectKey=my-project"`; + +exports[`should follow and complete all steps: Dart: bitbucket-pipelines.yml 1`] = ` +"image: ghcr.io/cirruslabs/flutter:stable + +definitions: + steps: + - step: &build-step + name: Build the project, and run the SonarQube analysis + script: + - + - export SONAR_SCANNER_VERSION=6.1.0.4477 + - mkdir $HOME/.sonar + - curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-\${SONAR_SCANNER_VERSION}-linux-x64.zip + - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ + - export PATH="$PATH:$HOME/.sonar/sonar-scanner-\${SONAR_SCANNER_VERSION}-linux-x64/bin" + - sonar-scanner + caches: + sonar: ~/.sonar + +clone: + depth: full + +pipelines: + branches: + '{main}': + - step: *build-step + + pull-requests: + '**': + - step: *build-step" +`; + exports[`should follow and complete all steps: .NET: bitbucket-pipelines.yml 1`] = ` "image: mcr.microsoft.com/dotnet/sdk:7.0 diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Dart.ts b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Dart.ts new file mode 100644 index 00000000000..3bb69f1b23f --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Dart.ts @@ -0,0 +1,60 @@ +/* + * 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 { Arch, OSs } from '../../types'; +import { SONAR_SCANNER_CLI_LATEST_VERSION, getScannerUrlSuffix } from '../../utils'; +import { BuildToolExampleBuilder } from '../AnalysisCommand'; + +const dartExample: BuildToolExampleBuilder = ({ branchesEnabled, mainBranchName }) => { + const scannerSuffix = getScannerUrlSuffix(OSs.Linux, Arch.X86_64); + return `image: ghcr.io/cirruslabs/flutter:stable + +definitions: + steps: + - step: &build-step + name: Build the project, and run the SonarQube analysis + script: + - + - export SONAR_SCANNER_VERSION=${SONAR_SCANNER_CLI_LATEST_VERSION} + - mkdir $HOME/.sonar + - curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-\${SONAR_SCANNER_VERSION}${scannerSuffix}.zip + - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ + - export PATH="$PATH:$HOME/.sonar/sonar-scanner-\${SONAR_SCANNER_VERSION}${scannerSuffix}/bin" + - sonar-scanner + caches: + sonar: ~/.sonar + +clone: + depth: full + +pipelines: + branches: + '{${mainBranchName}}': + - step: *build-step +${ + branchesEnabled + ? ` + pull-requests: + '**': + - step: *build-step` + : '' +}`; +}; + +export default dartExample; diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/AnalysisCommand.tsx b/server/sonar-web/src/main/js/components/tutorials/github-action/AnalysisCommand.tsx index f58f9d0bae9..ddcfe597564 100644 --- a/server/sonar-web/src/main/js/components/tutorials/github-action/AnalysisCommand.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/github-action/AnalysisCommand.tsx @@ -25,6 +25,7 @@ import { Feature } from '../../../types/features'; import { Component } from '../../../types/types'; import { BuildTools, TutorialConfig } from '../types'; import CFamily from './commands/CFamily'; +import Dart from './commands/Dart'; import DotNet from './commands/DotNet'; import Gradle from './commands/Gradle'; import JavaMaven from './commands/JavaMaven'; @@ -80,6 +81,15 @@ export function AnalysisCommand(props: Readonly) { component={component} /> ); + case BuildTools.Dart: + return ( + + ); case BuildTools.Other: return ( { 'Objective-C MacOS: .github/workflows/build.yml', ); + // Dart + await user.click(ui.dartBuildButton.get()); + expect(getCopyToClipboardValue(0, 'Copy')).toMatchSnapshot('Dart: .github/workflows/build.yml'); + // Other await user.click(ui.otherBuildButton.get()); expect(getCopyToClipboardValue(0, 'Copy')).toMatchSnapshot( diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/__snapshots__/GithubActionTutorial-it.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/__snapshots__/GithubActionTutorial-it.tsx.snap index 98d789f4c4a..90daec9363a 100644 --- a/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/__snapshots__/GithubActionTutorial-it.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/__snapshots__/GithubActionTutorial-it.tsx.snap @@ -1,5 +1,35 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`should follow and complete all steps: Dart: .github/workflows/build.yml 1`] = ` +" +name: Build + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build: + name: Build and analyze + runs-on: ubuntu-latest + steps: + - + - name: Download sonar-scanner + run: | + curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.1.0.4477-linux-x64.zip + unzip $HOME/.sonar/sonar-scanner.zip -o -d $HOME/.sonar/ + - name: Run sonar-scanner + env: + SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }} + run: | + sonar-scanner-6.1.0.4477-linux-x64/bin/sonar-scanner \\ + -Dsonar.projectKey=my-project" +`; + exports[`should follow and complete all steps: .NET: .github/workflows/build.yml 1`] = ` "name: Build diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Dart.tsx b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Dart.tsx new file mode 100644 index 00000000000..44c989c4e6d --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Dart.tsx @@ -0,0 +1,92 @@ +/* + * 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 { CodeSnippet, Link, NumberedListItem } from 'design-system'; +import * as React from 'react'; +import { FormattedMessage } from 'react-intl'; +import { DocLink } from '../../../../helpers/doc-links'; +import { useDocUrl } from '../../../../helpers/docs'; +import { translate } from '../../../../helpers/l10n'; +import { Component } from '../../../../types/types'; +import MonorepoDocLinkFallback from './MonorepoDocLinkFallback'; + +export interface DartProps { + branchesEnabled?: boolean; + component: Component; + mainBranchName: string; + monorepo?: boolean; +} + +export default function Dart(props: Readonly) { + const { component, branchesEnabled, mainBranchName, monorepo } = props; + const docUrl = useDocUrl(DocLink.SonarScanner); + + if (monorepo) { + return ; + } + + return ( + + + + - name: Download sonar-scanner + run: | + curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.1.0.4477-linux-x64.zip + unzip $HOME/.sonar/sonar-scanner.zip -o -d $HOME/.sonar/ + - name: Run sonar-scanner + env: + SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }} + run: | + sonar-scanner-6.1.0.4477-linux-x64/bin/sonar-scanner \\ + -Dsonar.projectKey=${component.key}`} + language="yml" + /> + +

+ {translate('onboarding.analysis.sq_scanner.docs_link')}, + }} + /> +

+
+ ); +} diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx index 992c09c3ca7..6ca29e6a793 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx @@ -92,6 +92,7 @@ const snippetForBuildTool = { [BuildTools.ObjectiveC]: otherSnippet, [BuildTools.Gradle]: gradleSnippet, [BuildTools.Maven]: mavenSnippet, + [BuildTools.Dart]: otherSnippet, [BuildTools.Other]: otherSnippet, }; @@ -100,6 +101,7 @@ const filenameForBuildTool = { [BuildTools.ObjectiveC]: 'sonar-project.properties', [BuildTools.Gradle]: GradleBuildDSL.Groovy, [BuildTools.Maven]: 'pom.xml', + [BuildTools.Dart]: 'sonar-project.properties', [BuildTools.Other]: 'sonar-project.properties', }; @@ -108,6 +110,7 @@ const snippetLanguageForBuildTool = { [BuildTools.ObjectiveC]: undefined, [BuildTools.Gradle]: undefined, [BuildTools.Maven]: 'xml', + [BuildTools.Dart]: undefined, [BuildTools.Other]: undefined, }; diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/GitLabCITutorial-it.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/GitLabCITutorial-it.tsx index 6ac323f6d0c..26fec42cb08 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/GitLabCITutorial-it.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/GitLabCITutorial-it.tsx @@ -88,6 +88,11 @@ it('should follow and complete all steps', async () => { await user.click(ui.autoConfigManual.get()); expect(getCopyToClipboardValue(1, 'Copy')).toMatchSnapshot('CPP - manual: gitlab-ci.yml'); + // Dart + await user.click(ui.dartBuildButton.get()); + expect(getCopyToClipboardValue(0, 'Copy')).toMatchSnapshot('Dart: sonar-project.properties'); + expect(getCopyToClipboardValue(1, 'Copy')).toMatchSnapshot('Dart: gitlab-ci.yml'); + // Other await user.click(ui.otherBuildButton.get()); expect(getCopyToClipboardValue(0, 'Copy')).toMatchSnapshot('Other: sonar-project.properties'); diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-it.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-it.tsx.snap index c2e41a10cbc..0dcb01b15f3 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-it.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-it.tsx.snap @@ -186,6 +186,74 @@ sonar.qualitygate.wait=true " `; +exports[`should follow and complete all steps: Dart: gitlab-ci.yml 1`] = ` +"image: ghcr.io/cirruslabs/flutter:stable + +variables: + SONAR_USER_HOME: "\${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache + GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task + +stages: + - get-binaries + - sonarqube-check + - sonarqube-vulnerability-report + +get-binaries: + stage: get-binaries + cache: + policy: push + key: "\${CI_COMMIT_SHORT_SHA}" + paths: + - sonar-scanner/ + + script: + # Download sonar-scanner + - curl -sSLo ./sonar-scanner.zip 'https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.1.0.4477-linux-x64.zip' + - unzip -o sonar-scanner.zip + - mv sonar-scanner-6.1.0.4477-linux-x64 sonar-scanner + + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + - if: $CI_COMMIT_BRANCH == 'master' + - if: $CI_COMMIT_BRANCH == 'main' + - if: $CI_COMMIT_BRANCH == 'develop' + +sonarqube-check: + stage: sonarqube-check + + script: + - + - sonar-scanner/bin/sonar-scanner --define sonar.host.url="\${SONAR_HOST_URL}" + allow_failure: true + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + - if: $CI_COMMIT_BRANCH == 'master' + - if: $CI_COMMIT_BRANCH == 'main' + - if: $CI_COMMIT_BRANCH == 'develop' + +sonarqube-vulnerability-report: + stage: sonarqube-vulnerability-report + script: + - 'curl -u "\${SONAR_TOKEN}:" "\${SONAR_HOST_URL}/api/issues/gitlab_sast_export?projectKey=my-project&branch=\${CI_COMMIT_BRANCH}&pullRequest=\${CI_MERGE_REQUEST_IID}" -o gl-sast-sonar-report.json' + allow_failure: true + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + - if: $CI_COMMIT_BRANCH == 'master' + - if: $CI_COMMIT_BRANCH == 'main' + - if: $CI_COMMIT_BRANCH == 'develop' + artifacts: + expire_in: 1 day + reports: + sast: gl-sast-sonar-report.json +" +`; + +exports[`should follow and complete all steps: Dart: sonar-project.properties 1`] = ` +"sonar.projectKey=my-project +sonar.qualitygate.wait=true +" +`; + exports[`should follow and complete all steps: Gradle: gitlab-ci.yml 1`] = ` "image: gradle:8.2.0-jdk17-jammy diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommand.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommand.tsx index 0e819d263f7..2276988966c 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommand.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommand.tsx @@ -79,6 +79,12 @@ const BUILD_TOOL_SPECIFIC: { `sonar-scanner/bin/sonar-scanner --define sonar.host.url="\${SONAR_HOST_URL}" ` + `--define sonar.cfamily.compile-commands="\${BUILD_WRAPPER_OUT_DIR}/compile_commands.json"`, }, + [BuildTools.Dart]: { + image: 'ghcr.io/cirruslabs/flutter:stable', + script: () => ` + - + - sonar-scanner/bin/sonar-scanner --define sonar.host.url="\${SONAR_HOST_URL}"`, + }, [BuildTools.Other]: { image: ` name: sonarsource/sonar-scanner-cli:latest @@ -187,7 +193,7 @@ export default function PipeCommand(props: Readonly) { stageDeclaration = ['sonarqube-check', ...stageDeclaration]; } - if (isCFamily(buildTool)) { + if (isCFamily(buildTool) || buildTool === BuildTools.Dart) { stages = [getBinaries, ...stages]; stageDeclaration = ['get-binaries', ...stageDeclaration]; } diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/JenkinsStep.tsx b/server/sonar-web/src/main/js/components/tutorials/jenkins/JenkinsStep.tsx index 87ca0994688..079af4ae849 100644 --- a/server/sonar-web/src/main/js/components/tutorials/jenkins/JenkinsStep.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/JenkinsStep.tsx @@ -38,6 +38,7 @@ const BUILDTOOL_COMPONENT_MAP: { [BuildTools.DotNet]: DotNet, [BuildTools.Cpp]: CFamily, [BuildTools.ObjectiveC]: CFamily, + [BuildTools.Dart]: Other, [BuildTools.Other]: Other, }; diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/JenkinsTutorial-it.tsx b/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/JenkinsTutorial-it.tsx index 98dcb166e66..61ccedae4bd 100644 --- a/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/JenkinsTutorial-it.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/JenkinsTutorial-it.tsx @@ -183,6 +183,11 @@ it.each([AlmKeys.BitbucketCloud, AlmKeys.BitbucketServer, AlmKeys.GitHub, AlmKey await user.click(ui.macosButton.get()); expect(getCopyToClipboardValue(3, 'Copy')).toMatchSnapshot(`objectivec: macos jenkinsfile`); + // Dart + await user.click(ui.dartBuildButton.get()); + expect(getCopyToClipboardValue(2, 'Copy')).toMatchSnapshot(`Dart: sonar-project.properties`); + expect(getCopyToClipboardValue(3, 'Copy')).toMatchSnapshot(`Dart: jenkinsfile`); + // Other await user.click(ui.otherBuildButton.get()); expect(getCopyToClipboardValue(2, 'Copy')).toMatchSnapshot( diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/JenkinsTutorial-it.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/JenkinsTutorial-it.tsx.snap index cb6312f809a..a0688444fe3 100644 --- a/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/JenkinsTutorial-it.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/JenkinsTutorial-it.tsx.snap @@ -1,5 +1,21 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`bitbucket: can select devops platform and complete all the steps with copying code snippets: Dart: jenkinsfile 1`] = ` +"node { + stage('SCM') { + checkout scm + } + stage('SonarQube Analysis') { + def scannerHome = tool 'SonarScanner'; + withSonarQubeEnv() { + sh "\${scannerHome}/bin/sonar-scanner" + } + } +}" +`; + +exports[`bitbucket: can select devops platform and complete all the steps with copying code snippets: Dart: sonar-project.properties 1`] = `"sonar.projectKey=my-project"`; + exports[`bitbucket: can select devops platform and complete all the steps with copying code snippets: Groovy: build.gradle file 1`] = ` "plugins { id "org.sonarqube" version "5.0.0.4638" @@ -349,6 +365,22 @@ exports[`bitbucket: can select devops platform and complete all the steps with c " `; +exports[`bitbucketcloud: can select devops platform and complete all the steps with copying code snippets: Dart: jenkinsfile 1`] = ` +"node { + stage('SCM') { + checkout scm + } + stage('SonarQube Analysis') { + def scannerHome = tool 'SonarScanner'; + withSonarQubeEnv() { + sh "\${scannerHome}/bin/sonar-scanner" + } + } +}" +`; + +exports[`bitbucketcloud: can select devops platform and complete all the steps with copying code snippets: Dart: sonar-project.properties 1`] = `"sonar.projectKey=my-project"`; + exports[`bitbucketcloud: can select devops platform and complete all the steps with copying code snippets: Groovy: build.gradle file 1`] = ` "plugins { id "org.sonarqube" version "5.0.0.4638" @@ -698,6 +730,22 @@ exports[`bitbucketcloud: can select devops platform and complete all the steps w " `; +exports[`github: can select devops platform and complete all the steps with copying code snippets: Dart: jenkinsfile 1`] = ` +"node { + stage('SCM') { + checkout scm + } + stage('SonarQube Analysis') { + def scannerHome = tool 'SonarScanner'; + withSonarQubeEnv() { + sh "\${scannerHome}/bin/sonar-scanner" + } + } +}" +`; + +exports[`github: can select devops platform and complete all the steps with copying code snippets: Dart: sonar-project.properties 1`] = `"sonar.projectKey=my-project"`; + exports[`github: can select devops platform and complete all the steps with copying code snippets: Groovy: build.gradle file 1`] = ` "plugins { id "org.sonarqube" version "5.0.0.4638" @@ -1047,6 +1095,22 @@ exports[`github: can select devops platform and complete all the steps with copy " `; +exports[`gitlab: can select devops platform and complete all the steps with copying code snippets: Dart: jenkinsfile 1`] = ` +"node { + stage('SCM') { + checkout scm + } + stage('SonarQube Analysis') { + def scannerHome = tool 'SonarScanner'; + withSonarQubeEnv() { + sh "\${scannerHome}/bin/sonar-scanner" + } + } +}" +`; + +exports[`gitlab: can select devops platform and complete all the steps with copying code snippets: Dart: sonar-project.properties 1`] = `"sonar.projectKey=my-project"`; + exports[`gitlab: can select devops platform and complete all the steps with copying code snippets: Groovy: build.gradle file 1`] = ` "plugins { id "org.sonarqube" version "5.0.0.4638" diff --git a/server/sonar-web/src/main/js/components/tutorials/other/BuildToolForm.tsx b/server/sonar-web/src/main/js/components/tutorials/other/BuildToolForm.tsx index 78d5bbf5531..3cc9278e818 100644 --- a/server/sonar-web/src/main/js/components/tutorials/other/BuildToolForm.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/other/BuildToolForm.tsx @@ -43,6 +43,7 @@ export function BuildToolForm(props: Readonly) { function handleConfigChange(newConfig: TutorialConfig) { const selectOsByDefault = (newConfig.buildTool === BuildTools.Cpp || newConfig.buildTool === BuildTools.ObjectiveC || + newConfig.buildTool === BuildTools.Dart || newConfig.buildTool === BuildTools.Other) && { os: OSs.Linux, }; @@ -65,6 +66,7 @@ export function BuildToolForm(props: Readonly) { /> )} {(config.buildTool === BuildTools.Other || + config.buildTool === BuildTools.Dart || config.buildTool === BuildTools.Cpp || config.buildTool === BuildTools.ObjectiveC) && ( { ); expect(getCopyToClipboardValue(3, 'Copy')).toMatchSnapshot('objective-c macos: execute scanner'); + // Dart - Linux + await user.click(ui.dartBuildButton.get()); + await user.click(ui.linuxButton.get()); + expect(getCopyToClipboardValue(0, 'Copy')).toMatchSnapshot('Dart linux: download scanner'); + expect(getCopyToClipboardValue(1, 'Copy')).toMatchSnapshot('Dart linux: execute scanner'); + + // Dart - Windows + await user.click(ui.windowsButton.get()); + expect(getCopyToClipboardValue(0, 'Copy')).toMatchSnapshot('Dart windows: download scanner'); + expect(getCopyToClipboardValue(1, 'Copy')).toMatchSnapshot('Dart windows: execute scanner'); + + // Dart - MacOS + await user.click(ui.macosButton.get()); + expect(getCopyToClipboardValue(0, 'Copy')).toMatchSnapshot('Dart macos: download scanner'); + expect(getCopyToClipboardValue(1, 'Copy')).toMatchSnapshot('Dart macos: execute scanner'); + // Other - Linux await user.click(ui.otherBuildButton.get()); await user.click(ui.linuxButton.get()); diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/OtherTutorial-it.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/OtherTutorial-it.tsx.snap index fce78d03bc7..c82a688c22c 100644 --- a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/OtherTutorial-it.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/OtherTutorial-it.tsx.snap @@ -1,5 +1,56 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`can choose build tools and copy provided settings: Dart linux: download scanner 1`] = ` +"export SONAR_SCANNER_VERSION=6.1.0.4477 +export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux-x64 +curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux-x64.zip +unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ +export PATH=$SONAR_SCANNER_HOME/bin:$PATH +export SONAR_SCANNER_OPTS="-server" +" +`; + +exports[`can choose build tools and copy provided settings: Dart linux: execute scanner 1`] = ` +"sonar-scanner \\ + -Dsonar.projectKey=my-project \\ + -Dsonar.sources=. \\ + -Dsonar.host.url=http://localhost:9000" +`; + +exports[`can choose build tools and copy provided settings: Dart windows: download scanner 1`] = ` +"$env:SONAR_SCANNER_VERSION = "6.1.0.4477" +$env:SONAR_DIRECTORY = [System.IO.Path]::Combine($(get-location).Path,".sonar") +$env:SONAR_SCANNER_HOME = "$env:SONAR_DIRECTORY/sonar-scanner-$env:SONAR_SCANNER_VERSION-windows-x64" +rm $env:SONAR_SCANNER_HOME -Force -Recurse -ErrorAction SilentlyContinue +New-Item -path $env:SONAR_SCANNER_HOME -type directory +(New-Object System.Net.WebClient).DownloadFile("https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$env:SONAR_SCANNER_VERSION-windows-x64.zip", "$env:SONAR_DIRECTORY/sonar-scanner.zip") +Add-Type -AssemblyName System.IO.Compression.FileSystem +[System.IO.Compression.ZipFile]::ExtractToDirectory("$env:SONAR_DIRECTORY/sonar-scanner.zip", "$env:SONAR_DIRECTORY") +rm ./.sonar/sonar-scanner.zip -Force -ErrorAction SilentlyContinue +$env:Path += ";$env:SONAR_SCANNER_HOME/bin" +$env:SONAR_SCANNER_OPTS="-server" +" +`; + +exports[`can choose build tools and copy provided settings: Dart windows: execute scanner 1`] = `"sonar-scanner.bat -D"sonar.projectKey=my-project" -D"sonar.sources=." -D"sonar.host.url=http://localhost:9000""`; + +exports[`can choose build tools and copy provided settings: Dart macos: download scanner 1`] = ` +"export SONAR_SCANNER_VERSION=6.1.0.4477 +export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-macosx-x64 +curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-macosx-x64.zip +unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ +export PATH=$SONAR_SCANNER_HOME/bin:$PATH +export SONAR_SCANNER_OPTS="-server" +" +`; + +exports[`can choose build tools and copy provided settings: Dart macos: execute scanner 1`] = ` +"sonar-scanner \\ + -Dsonar.projectKey=my-project \\ + -Dsonar.sources=. \\ + -Dsonar.host.url=http://localhost:9000" +`; + exports[`can choose build tools and copy provided settings: c++ (automatic) and other linux arm64: download scanner 1`] = ` "export SONAR_SCANNER_VERSION=6.1.0.4477 export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux-aarch64 diff --git a/server/sonar-web/src/main/js/components/tutorials/other/commands/AnalysisCommand.tsx b/server/sonar-web/src/main/js/components/tutorials/other/commands/AnalysisCommand.tsx index 846fdb0f14c..2ad95448d8f 100644 --- a/server/sonar-web/src/main/js/components/tutorials/other/commands/AnalysisCommand.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/other/commands/AnalysisCommand.tsx @@ -53,6 +53,7 @@ export default function AnalysisCommand(props: Readonly) { case BuildTools.DotNet: return ; + case BuildTools.Dart: case BuildTools.Other: return (