From 5032367a49ba54473c2497e3a545426a96ef6fc6 Mon Sep 17 00:00:00 2001
From: stanislavh
Date: Wed, 3 May 2023 10:57:05 +0200
Subject: [PATCH] SONAR-17146 Tutorial for Gradle should Consider Kotlin DSL
---
.../bitbucket-pipelines/PreambuleYaml.tsx | 25 +------
.../BitbucketPipelinesTutorial-it.tsx | 8 +-
.../BitbucketPipelinesTutorial-it.tsx.snap | 15 +++-
.../tutorials/components/GradleBuild.tsx | 63 ++++++++++++++++
.../components/GradleBuildSelection.tsx | 49 ++++++++++++
.../__tests__/GithubActionTutorial-it.tsx | 8 +-
.../GithubActionTutorial-it.tsx.snap | 15 +++-
.../github-action/commands/Gradle.tsx | 23 +-----
.../tutorials/gitlabci/YmlFileStep.tsx | 74 +++++++++++++++----
.../__tests__/GitLabCITutorial-it.tsx | 8 +-
.../GitLabCITutorial-it.tsx.snap | 42 +++++++----
.../jenkins/__tests__/JenkinsTutorial-it.tsx | 8 +-
.../__snapshots__/JenkinsTutorial-it.tsx.snap | 60 ++++++++++++++-
.../jenkins/buildtool-steps/Gradle.tsx | 29 ++++++--
.../tutorials/other/commands/JavaGradle.tsx | 21 ++++--
.../js/components/tutorials/test-utils.ts | 3 +-
.../src/main/js/components/tutorials/types.ts | 5 ++
.../src/main/js/components/tutorials/utils.ts | 20 ++++-
.../resources/org/sonar/l10n/core.properties | 8 +-
19 files changed, 374 insertions(+), 110 deletions(-)
create mode 100644 server/sonar-web/src/main/js/components/tutorials/components/GradleBuild.tsx
create mode 100644 server/sonar-web/src/main/js/components/tutorials/components/GradleBuildSelection.tsx
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 d54087fa9f1..87fec76d2af 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
@@ -18,14 +18,10 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
-import { FormattedMessage } from 'react-intl';
-import { ClipboardIconButton } from '../../../components/controls/clipboard';
-import { translate } from '../../../helpers/l10n';
import { Component } from '../../../types/types';
-import CodeSnippet from '../../common/CodeSnippet';
import DefaultProjectKey from '../components/DefaultProjectKey';
+import GradleBuild from '../components/GradleBuild';
import { BuildTools } from '../types';
-import { buildGradleSnippet } from '../utils';
export interface PreambuleYamlProps {
buildTool: BuildTools;
@@ -36,24 +32,7 @@ export function PreambuleYaml(props: PreambuleYamlProps) {
const { buildTool, component } = props;
switch (buildTool) {
case BuildTools.Gradle:
- return (
-
-
- build.gradle
-
- >
- ),
- sq: org.sonarqube
,
- }}
- />
-
-
- );
+ return ;
case BuildTools.CFamily:
case BuildTools.Other:
return ;
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 7d85f9e2ca5..0a1285123a2 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
@@ -37,7 +37,7 @@ import {
getTutorialActionButtons,
getTutorialBuildButtons,
} from '../../test-utils';
-import { TutorialModes } from '../../types';
+import { GradleBuildDSL, TutorialModes } from '../../types';
import BitbucketPipelinesTutorial, {
BitbucketPipelinesTutorialProps,
} from '../BitbucketPipelinesTutorial';
@@ -79,8 +79,10 @@ it('should follow and complete all steps', async () => {
// Gradle
await user.click(ui.gradleBuildButton.get());
- expect(getCopyToClipboardValue(1)).toMatchSnapshot('Gradle: build.gradle');
- expect(getCopyToClipboardValue(3)).toMatchSnapshot('Gradle: bitbucket-pipelines.yml');
+ expect(getCopyToClipboardValue(2)).toMatchSnapshot('Groovy: build.gradle');
+ await user.click(ui.gradleDSLButton(GradleBuildDSL.Kotlin).get());
+ expect(getCopyToClipboardValue(2)).toMatchSnapshot('Kotlin: build.gradle.kts');
+ expect(getCopyToClipboardValue(4)).toMatchSnapshot('Gradle: bitbucket-pipelines.yml');
// .NET
await user.click(ui.dotnetBuildButton.get());
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 4491112afda..918f9f18ec9 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
@@ -95,7 +95,7 @@ pipelines:
- step: *build-step"
`;
-exports[`should follow and complete all steps: Gradle: build.gradle 1`] = `
+exports[`should follow and complete all steps: Groovy: build.gradle 1`] = `
"plugins {
id "org.sonarqube" version "4.0.0.2929"
}
@@ -108,6 +108,19 @@ sonar {
}"
`;
+exports[`should follow and complete all steps: Kotlin: build.gradle.kts 1`] = `
+"plugins {
+ id("org.sonarqube") version "4.0.0.2929"
+}
+
+sonar {
+ properties {
+ property("sonar.projectKey", "my-project")
+ property("sonar.projectName", "MyProject")
+ }
+}"
+`;
+
exports[`should follow and complete all steps: Maven: bitbucket-pipelines.yml 1`] = `
"image: maven:3-openjdk-11
diff --git a/server/sonar-web/src/main/js/components/tutorials/components/GradleBuild.tsx b/server/sonar-web/src/main/js/components/tutorials/components/GradleBuild.tsx
new file mode 100644
index 00000000000..895aadb09b1
--- /dev/null
+++ b/server/sonar-web/src/main/js/components/tutorials/components/GradleBuild.tsx
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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 React from 'react';
+import { FormattedMessage } from 'react-intl';
+import { translate } from '../../../helpers/l10n';
+import { Component } from '../../../types/types';
+import CodeSnippet from '../../common/CodeSnippet';
+import { ClipboardIconButton } from '../../controls/clipboard';
+import { GradleBuildDSL } from '../types';
+import { buildGradleSnippet } from '../utils';
+import GradleBuildSelection from './GradleBuildSelection';
+
+interface Props {
+ component: Component;
+}
+
+export default function GradleBuild({ component }: Props) {
+ return (
+
+
+ {GradleBuildDSL.Groovy}
+
+ >
+ ),
+ kotlin: (
+ <>
+ {GradleBuildDSL.Kotlin}
+
+ >
+ ),
+ sq: org.sonarqube
,
+ }}
+ />
+
+ {(build) => (
+
+ )}
+
+
+ );
+}
diff --git a/server/sonar-web/src/main/js/components/tutorials/components/GradleBuildSelection.tsx b/server/sonar-web/src/main/js/components/tutorials/components/GradleBuildSelection.tsx
new file mode 100644
index 00000000000..4ed7e7639c1
--- /dev/null
+++ b/server/sonar-web/src/main/js/components/tutorials/components/GradleBuildSelection.tsx
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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 React from 'react';
+import ButtonToggle from '../../controls/ButtonToggle';
+import { GradleBuildDSL } from '../types';
+
+interface Props {
+ className?: string;
+ children: (build: GradleBuildDSL) => React.ReactNode;
+}
+
+export default function GradleBuildSelection({ children, className }: Props) {
+ const [build, setBuild] = React.useState(GradleBuildDSL.Groovy);
+
+ const buildOptions = Object.values(GradleBuildDSL).map((v: GradleBuildDSL) => ({
+ label: v,
+ value: v,
+ }));
+
+ return (
+ <>
+
+ setBuild(value)}
+ />
+
+ {children(build)}
+ >
+ );
+}
diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/GithubActionTutorial-it.tsx b/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/GithubActionTutorial-it.tsx
index 22bd3452109..06ab3f48ec5 100644
--- a/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/GithubActionTutorial-it.tsx
+++ b/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/GithubActionTutorial-it.tsx
@@ -37,7 +37,7 @@ import {
getTutorialActionButtons,
getTutorialBuildButtons,
} from '../../test-utils';
-import { TutorialModes } from '../../types';
+import { GradleBuildDSL, TutorialModes } from '../../types';
import GitHubActionTutorial, { GitHubActionTutorialProps } from '../GitHubActionTutorial';
jest.mock('../../../../api/user-tokens');
@@ -77,8 +77,10 @@ it('should follow and complete all steps', async () => {
// Gradle
await user.click(ui.gradleBuildButton.get());
- expect(getCopyToClipboardValue(1)).toMatchSnapshot('Gradle: build.gradle');
- expect(getCopyToClipboardValue(3)).toMatchSnapshot('Gradle: .github/workflows/build.yml');
+ expect(getCopyToClipboardValue(2)).toMatchSnapshot('Groovy: build.gradle');
+ await user.click(ui.gradleDSLButton(GradleBuildDSL.Kotlin).get());
+ expect(getCopyToClipboardValue(2)).toMatchSnapshot('Kotlin: build.gradle.kts');
+ expect(getCopyToClipboardValue(4)).toMatchSnapshot('Gradle: .github/workflows/build.yml');
// .NET
await user.click(ui.dotnetBuildButton.get());
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 178e17d2273..8d9f3823017 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
@@ -229,7 +229,7 @@ jobs:
run: ./gradlew build sonar --info"
`;
-exports[`should follow and complete all steps: Gradle: build.gradle 1`] = `
+exports[`should follow and complete all steps: Groovy: build.gradle 1`] = `
"plugins {
id "org.sonarqube" version "4.0.0.2929"
}
@@ -242,6 +242,19 @@ sonar {
}"
`;
+exports[`should follow and complete all steps: Kotlin: build.gradle.kts 1`] = `
+"plugins {
+ id("org.sonarqube") version "4.0.0.2929"
+}
+
+sonar {
+ properties {
+ property("sonar.projectKey", "my-project")
+ property("sonar.projectName", "MyProject")
+ }
+}"
+`;
+
exports[`should follow and complete all steps: Maven: .github/workflows/build.yml 1`] = `
"name: Build
diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Gradle.tsx b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Gradle.tsx
index 7d1a8247e21..c0e84c06cd8 100644
--- a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Gradle.tsx
+++ b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Gradle.tsx
@@ -18,14 +18,10 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
-import { FormattedMessage } from 'react-intl';
-import { ClipboardIconButton } from '../../../../components/controls/clipboard';
-import { translate } from '../../../../helpers/l10n';
import { Component } from '../../../../types/types';
-import CodeSnippet from '../../../common/CodeSnippet';
import CreateYmlFile from '../../components/CreateYmlFile';
import FinishButton from '../../components/FinishButton';
-import { buildGradleSnippet } from '../../utils';
+import GradleBuild from '../../components/GradleBuild';
import { GITHUB_ACTIONS_RUNS_ON_LINUX } from '../constants';
import { generateGitHubActionsYaml } from '../utils';
@@ -65,22 +61,7 @@ export default function Gradle(props: GradleProps) {
return (
<>
-
-
- build.gradle
-
- >
- ),
- sq: org.sonarqube
,
- }}
- />
-
-
+
`
true
`;
-const gradleSnippet = (key: string, name: string) => `plugins {
+const gradleSnippet = (key: string, name: string, build: GradleBuildDSL) => {
+ const map = {
+ [GradleBuildDSL.Groovy]: `plugins {
id "org.sonarqube" version "${GRADLE_SCANNER_VERSION}"
}
@@ -60,7 +63,21 @@ sonar {
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
@@ -75,7 +92,7 @@ const snippetForBuildTool = {
const filenameForBuildTool = {
[BuildTools.Maven]: 'pom.xml',
- [BuildTools.Gradle]: 'build.gradle',
+ [BuildTools.Gradle]: GradleBuildDSL.Groovy,
[BuildTools.CFamily]: 'sonar-project.properties',
[BuildTools.Other]: 'sonar-project.properties',
};
@@ -118,19 +135,44 @@ export function YmlFileStep(props: YmlFileStepProps) {
`onboarding.tutorial.with.gitlab_ci.project_key.${buildTool}.step2`
)}
id={`onboarding.tutorial.with.gitlab_ci.project_key.${buildTool}.step2`}
- values={{
- file: (
- <>
- {filenameForBuildTool[buildTool]}
-
- >
- ),
- }}
+ values={Object.assign(
+ {
+ file: (
+ <>
+ {filenameForBuildTool[buildTool]}
+
+ >
+ ),
+ },
+ buildTool === BuildTools.Gradle
+ ? {
+ file2: (
+ <>
+ {GradleBuildDSL.Kotlin}
+
+ >
+ ),
+ }
+ : {}
+ )}
/>
-
+ {buildTool === BuildTools.Gradle ? (
+
+ {(build) => (
+
+ )}
+
+ ) : (
+
+ )}
)}
{buildTool && (
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 d251382f17c..7d76c65e381 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
@@ -31,7 +31,7 @@ import {
getTutorialActionButtons,
getTutorialBuildButtons,
} from '../../test-utils';
-import { TutorialModes } from '../../types';
+import { GradleBuildDSL, TutorialModes } from '../../types';
import GitLabCITutorial, { GitLabCITutorialProps } from '../GitLabCITutorial';
jest.mock('../../../../api/user-tokens');
@@ -72,8 +72,10 @@ it('should follow and complete all steps', async () => {
// Gradle
await user.click(ui.gradleBuildButton.get());
- expect(getCopyToClipboardValue(1)).toMatchSnapshot('Gradle: build.gradle');
- expect(getCopyToClipboardValue(3)).toMatchSnapshot('Gradle: gitlab-ci.yml');
+ expect(getCopyToClipboardValue(2)).toMatchSnapshot('Groovy: build.gradle');
+ await user.click(ui.gradleDSLButton(GradleBuildDSL.Kotlin).get());
+ expect(getCopyToClipboardValue(2)).toMatchSnapshot('Kotlin: build.gradle.kts');
+ expect(getCopyToClipboardValue(4)).toMatchSnapshot('Gradle: gitlab-ci.yml');
// .NET
await user.click(ui.dotnetBuildButton.get());
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 cc7c5e33d3d..d87708cae7b 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
@@ -63,20 +63,6 @@ sonar.qualitygate.wait=true
"
`;
-exports[`should follow and complete all steps: Gradle: build.gradle 1`] = `
-"plugins {
- id "org.sonarqube" version "4.0.0.2929"
-}
-
-sonar {
- properties {
- property "sonar.projectKey", "my-project"
- property "sonar.projectName", "MyProject"
- property "sonar.qualitygate.wait", true
- }
-}"
-`;
-
exports[`should follow and complete all steps: Gradle: gitlab-ci.yml 1`] = `
"sonarqube-check:
image: gradle:jre11-slim
@@ -94,6 +80,34 @@ exports[`should follow and complete all steps: Gradle: gitlab-ci.yml 1`] = `
"
`;
+exports[`should follow and complete all steps: Groovy: build.gradle 1`] = `
+"plugins {
+ id "org.sonarqube" version "4.0.0.2929"
+}
+
+sonar {
+ properties {
+ property "sonar.projectKey", "my-project"
+ property "sonar.projectName", "MyProject"
+ property "sonar.qualitygate.wait", true
+ }
+}"
+`;
+
+exports[`should follow and complete all steps: Kotlin: build.gradle.kts 1`] = `
+"plugins {
+ id ("org.sonarqube") version "4.0.0.2929"
+}
+
+sonar {
+ properties {
+ property("sonar.projectKey", "my-project")
+ property("sonar.projectName", "MyProject")
+ property("sonar.qualitygate.wait", true)
+ }
+}"
+`;
+
exports[`should follow and complete all steps: Maven: gitlab-ci.yml 1`] = `
"sonarqube-check:
image: maven:3.6.3-jdk-11
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 045672dea7a..60c73e54192 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
@@ -32,6 +32,7 @@ import {
getTutorialActionButtons,
getTutorialBuildButtons,
} from '../../test-utils';
+import { GradleBuildDSL } from '../../types';
import JenkinsTutorial, { JenkinsTutorialProps } from '../JenkinsTutorial';
jest.mock('../../../../api/user-tokens');
@@ -117,9 +118,12 @@ it.each([AlmKeys.BitbucketCloud, AlmKeys.BitbucketServer, AlmKeys.GitHub, AlmKey
await user.click(ui.mavenBuildButton.get());
expect(getCopyToClipboardValue()).toMatchSnapshot(`maven jenkinsfile`);
- // Gradle
+ // Gradle (Groovy)
await user.click(ui.gradleBuildButton.get());
- expect(getCopyToClipboardValue()).toMatchSnapshot(`build.gradle file`);
+ expect(getCopyToClipboardValue()).toMatchSnapshot(`Groovy: build.gradle file`);
+ // Gradle(Kotlin)
+ await user.click(ui.gradleDSLButton(GradleBuildDSL.Kotlin).get());
+ expect(getCopyToClipboardValue()).toMatchSnapshot(`Kotlin: build.gradle.kts file`);
expect(getCopyToClipboardValue(1)).toMatchSnapshot(`gradle jenkinsfile`);
// .NET
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 12650e20ff1..5f8c93bd707 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,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`bitbucket: can select devops platform and complete all the steps with copying code snippets: build.gradle file 1`] = `
+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 "4.0.0.2929"
}
@@ -13,6 +13,19 @@ sonar {
}"
`;
+exports[`bitbucket: can select devops platform and complete all the steps with copying code snippets: Kotlin: build.gradle.kts file 1`] = `
+"plugins {
+ id("org.sonarqube") version "4.0.0.2929"
+}
+
+sonar {
+ properties {
+ property("sonar.projectKey", "my-project")
+ property("sonar.projectName", "MyProject")
+ }
+}"
+`;
+
exports[`bitbucket: can select devops platform and complete all the steps with copying code snippets: cfamily linux jenkinsfile 1`] = `
"node {
stage('SCM') {
@@ -194,7 +207,7 @@ 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: build.gradle file 1`] = `
+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 "4.0.0.2929"
}
@@ -207,6 +220,19 @@ sonar {
}"
`;
+exports[`bitbucketcloud: can select devops platform and complete all the steps with copying code snippets: Kotlin: build.gradle.kts file 1`] = `
+"plugins {
+ id("org.sonarqube") version "4.0.0.2929"
+}
+
+sonar {
+ properties {
+ property("sonar.projectKey", "my-project")
+ property("sonar.projectName", "MyProject")
+ }
+}"
+`;
+
exports[`bitbucketcloud: can select devops platform and complete all the steps with copying code snippets: cfamily linux jenkinsfile 1`] = `
"node {
stage('SCM') {
@@ -388,7 +414,7 @@ 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: build.gradle file 1`] = `
+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 "4.0.0.2929"
}
@@ -401,6 +427,19 @@ sonar {
}"
`;
+exports[`github: can select devops platform and complete all the steps with copying code snippets: Kotlin: build.gradle.kts file 1`] = `
+"plugins {
+ id("org.sonarqube") version "4.0.0.2929"
+}
+
+sonar {
+ properties {
+ property("sonar.projectKey", "my-project")
+ property("sonar.projectName", "MyProject")
+ }
+}"
+`;
+
exports[`github: can select devops platform and complete all the steps with copying code snippets: cfamily linux jenkinsfile 1`] = `
"node {
stage('SCM') {
@@ -582,7 +621,7 @@ 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: build.gradle file 1`] = `
+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 "4.0.0.2929"
}
@@ -595,6 +634,19 @@ sonar {
}"
`;
+exports[`gitlab: can select devops platform and complete all the steps with copying code snippets: Kotlin: build.gradle.kts file 1`] = `
+"plugins {
+ id("org.sonarqube") version "4.0.0.2929"
+}
+
+sonar {
+ properties {
+ property("sonar.projectKey", "my-project")
+ property("sonar.projectName", "MyProject")
+ }
+}"
+`;
+
exports[`gitlab: can select devops platform and complete all the steps with copying code snippets: cfamily linux jenkinsfile 1`] = `
"node {
stage('SCM') {
diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/Gradle.tsx b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/Gradle.tsx
index 478ae99d2dd..51c24f8c8ef 100644
--- a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/Gradle.tsx
+++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/Gradle.tsx
@@ -18,9 +18,12 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
+import { FormattedMessage } from 'react-intl';
+import { translate } from '../../../../helpers/l10n';
import CodeSnippet from '../../../common/CodeSnippet';
import FinishButton from '../../components/FinishButton';
-import SentenceWithFilename from '../../components/SentenceWithFilename';
+import GradleBuildSelection from '../../components/GradleBuildSelection';
+import { GradleBuildDSL } from '../../types';
import { buildGradleSnippet } from '../../utils';
import { LanguageProps } from '../JenkinsfileStep';
import CreateJenkinsfileBulletPoint from './CreateJenkinsfileBulletPoint';
@@ -38,14 +41,28 @@ const JENKINSFILE_SNIPPET = `node {
export default function Gradle(props: LanguageProps) {
const { component } = props;
+
return (
<>
-
-
+
+ {GradleBuildDSL.Groovy},
+ kotlin: {GradleBuildDSL.Kotlin}
,
+ }}
+ />
+
+
+ {(build) => (
+
+ )}
+
diff --git a/server/sonar-web/src/main/js/components/tutorials/other/commands/JavaGradle.tsx b/server/sonar-web/src/main/js/components/tutorials/other/commands/JavaGradle.tsx
index 929bb0e0904..d4d21baa62b 100644
--- a/server/sonar-web/src/main/js/components/tutorials/other/commands/JavaGradle.tsx
+++ b/server/sonar-web/src/main/js/components/tutorials/other/commands/JavaGradle.tsx
@@ -25,6 +25,8 @@ import { Component } from '../../../../types/types';
import CodeSnippet from '../../../common/CodeSnippet';
import DocLink from '../../../common/DocLink';
import InstanceMessage from '../../../common/InstanceMessage';
+import GradleBuildSelection from '../../components/GradleBuildSelection';
+import { GradleBuildDSL } from '../../types';
import DoneNextSteps from '../DoneNextSteps';
export interface JavaGradleProps {
@@ -33,11 +35,17 @@ export interface JavaGradleProps {
token: string;
}
+const config = {
+ [GradleBuildDSL.Groovy]: `plugins {
+ id "org.sonarqube" version "${GRADLE_SCANNER_VERSION}"
+}`,
+ [GradleBuildDSL.Kotlin]: `plugins {
+ id("org.sonarqube") version "${GRADLE_SCANNER_VERSION}"
+}`,
+};
+
export default function JavaGradle(props: JavaGradleProps) {
const { baseUrl, component, token } = props;
- const config = `plugins {
- id "org.sonarqube" version "${GRADLE_SCANNER_VERSION}"
-}`;
const command = [
'./gradlew sonar',
@@ -58,13 +66,16 @@ export default function JavaGradle(props: JavaGradleProps) {
id="onboarding.analysis.java.gradle.text.1"
values={{
plugin_code: org.sonarqube
,
- filename: build.gradle
,
+ groovy: {GradleBuildDSL.Groovy}
,
+ kotlin: {GradleBuildDSL.Kotlin}
,
}}
/>
)}
-
+
+ {(build) => }
+
> = {
[TutorialModes.BitbucketPipelines]: 'bitbucket_pipelines',
@@ -70,6 +70,7 @@ export function getTutorialBuildButtons() {
describeBuildTitle: byRole('heading', { name: 'onboarding.build' }),
mavenBuildButton: byRole('button', { name: `onboarding.build.${BuildTools.Maven}` }),
gradleBuildButton: byRole('button', { name: `onboarding.build.${BuildTools.Gradle}` }),
+ gradleDSLButton: (name: GradleBuildDSL) => byRole('button', { name }),
dotnetBuildButton: byRole('button', { name: `onboarding.build.${BuildTools.DotNet}` }),
cFamilyBuildButton: byRole('button', { name: `onboarding.build.${BuildTools.CFamily}` }),
otherBuildButton: byRole('button', { name: `onboarding.build.${BuildTools.Other}` }),
diff --git a/server/sonar-web/src/main/js/components/tutorials/types.ts b/server/sonar-web/src/main/js/components/tutorials/types.ts
index 77fe8964a2d..7364208f171 100644
--- a/server/sonar-web/src/main/js/components/tutorials/types.ts
+++ b/server/sonar-web/src/main/js/components/tutorials/types.ts
@@ -35,6 +35,11 @@ export enum BuildTools {
Other = 'other',
}
+export enum GradleBuildDSL {
+ Groovy = 'build.gradle',
+ Kotlin = 'build.gradle.kts',
+}
+
export enum OSs {
Linux = 'linux',
Windows = 'win',
diff --git a/server/sonar-web/src/main/js/components/tutorials/utils.ts b/server/sonar-web/src/main/js/components/tutorials/utils.ts
index 7d271864828..e35657317d0 100644
--- a/server/sonar-web/src/main/js/components/tutorials/utils.ts
+++ b/server/sonar-web/src/main/js/components/tutorials/utils.ts
@@ -21,13 +21,15 @@ import { GRADLE_SCANNER_VERSION } from '../../helpers/constants';
import { convertGithubApiUrlToLink, stripTrailingSlash } from '../../helpers/urls';
import { AlmSettingsInstance, ProjectAlmBindingResponse } from '../../types/alm-settings';
import { UserToken } from '../../types/token';
+import { GradleBuildDSL } from './types';
export function quote(os: string): (s: string) => string {
return os === 'win' ? (s: string) => `"${s}"` : (s: string) => s;
}
-export function buildGradleSnippet(key: string, name: string) {
- return `plugins {
+export function buildGradleSnippet(key: string, name: string, build: GradleBuildDSL) {
+ const map = {
+ [GradleBuildDSL.Groovy]: `plugins {
id "org.sonarqube" version "${GRADLE_SCANNER_VERSION}"
}
@@ -36,7 +38,19 @@ sonar {
property "sonar.projectKey", "${key}"
property "sonar.projectName", "${name}"
}
-}`;
+}`,
+ [GradleBuildDSL.Kotlin]: `plugins {
+ id("org.sonarqube") version "${GRADLE_SCANNER_VERSION}"
+}
+
+sonar {
+ properties {
+ property("sonar.projectKey", "${key}")
+ property("sonar.projectName", "${name}")
+ }
+}`,
+ };
+ return map[build];
}
export function getUniqueTokenName(tokens: UserToken[], initialTokenName: string) {
diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties
index 30a37db786b..c37a64d1e7b 100644
--- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties
+++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties
@@ -3834,7 +3834,7 @@ onboarding.analysis.java.maven.docs_link=official documentation of the Scanner f
onboarding.analysis.java.maven.text.custom=Run the following command in your project's folder.
onboarding.analysis.java.gradle.header=Execute the Scanner for Gradle
-onboarding.analysis.java.gradle.text.1=Running an analysis with Gradle is straighforward. You just need to declare the {plugin_code} plugin in your {filename} file:
+onboarding.analysis.java.gradle.text.1=Running an analysis with Gradle is straighforward. You just need to declare the {plugin_code} plugin in your {groovy} or {kotlin} file:
onboarding.analysis.java.gradle.text.2=and run the following command:
onboarding.analysis.java.gradle.latest_version=You can find the latest version of the Gradle plugin {link}.
onboarding.analysis.java.gradle.docs_link=official documentation of the Scanner for Gradle
@@ -3898,7 +3898,7 @@ onboarding.tutorial.choose_method.azure-pipelines=With Azure Pipelines
onboarding.tutorial.choose_method.bitbucket-pipelines=With Bitbucket Pipelines
-onboarding.tutorial.with.yaml.gradle=Update your {gradle} file with the {sq} plugin and it's configuration:
+onboarding.tutorial.with.yaml.gradle=Update your {groovy} or {kotlin} file with the {sq} plugin and its configuration:
@@ -3928,7 +3928,7 @@ onboarding.tutorial.with.github_action.yaml.create_yml=Create or update your {fi
onboarding.tutorial.with.gitlab_ci.title=Analyze your project with GitLab CI
onboarding.tutorial.with.gitlab_ci.project_key.title=Set your project key
onboarding.tutorial.with.gitlab_ci.project_key.maven.step2=Add the following to your {file} file:
-onboarding.tutorial.with.gitlab_ci.project_key.gradle.step2=Add the following to your {file} file:
+onboarding.tutorial.with.gitlab_ci.project_key.gradle.step2=Add the following to your {file} or {file2} file:
onboarding.tutorial.with.gitlab_ci.project_key.other.step2=Create a {file} file in your repository and paste the following code:
onboarding.tutorial.with.gitlab_ci.project_key.dotnet.step2=Create a {file} file in your repository and paste the following code:
onboarding.tutorial.with.gitlab_ci.project_key.cfamily.step2=Create a {file} file in your repository and paste the following code:
@@ -4151,7 +4151,7 @@ onboarding.tutorial.with.jenkins.jenkinsfile.maven.step3.help1.sentence.path=Man
onboarding.tutorial.with.jenkins.jenkinsfile.maven.step3.help2.sentence=The name is located under the {path} section, in the {name} field.
onboarding.tutorial.with.jenkins.jenkinsfile.maven.step3.help2.sentence.path=Maven > Maven installations
onboarding.tutorial.with.jenkins.jenkinsfile.maven.step3.help2.sentence.name=Name
-onboarding.tutorial.with.jenkins.jenkinsfile.gradle.step2.sentence=Add the following to your {file} file:
+onboarding.tutorial.with.jenkins.jenkinsfile.gradle.step2.sentence=Add the following to your {groovy} or {kotlin} file:
onboarding.tutorial.with.jenkins.jenkinsfile.dotnet.build_agent=Choose your build agent.
onboarding.tutorial.with.jenkins.dotnet.msbuild.prereqs.title.sentence=Prerequisite: Add a {default_msbuild} tool.
--
2.39.5