import { Dictionary } from 'lodash';
import * as React from 'react';
import { withAppState } from '../../hoc/withAppState';
+import { CompilationInfo } from '../components/CompilationInfo';
import CreateYmlFile from '../components/CreateYmlFile';
import { BuildTools } from '../types';
+import cFamilyExample from './commands/CFamily';
+import dotNetExample from './commands/DotNet';
+import gradleExample from './commands/Gradle';
+import mavenExample from './commands/Maven';
+import othersExample from './commands/Others';
import { PreambuleYaml } from './PreambuleYaml';
export interface AnalysisCommandProps {
}
const YamlTemplate: Dictionary<(branchesEnabled?: boolean, projectKey?: string) => string> = {
- [BuildTools.Gradle]: branchesEnabled => `image: openjdk:8
-
-clone:
- depth: full
-
-pipelines:
- branches:
- '{master}':
- - step:
- name: SonarQube analysis
- caches:
- - gradle
- - sonar
- script:
- - bash ./gradlew sonarqube
-${
- branchesEnabled
- ? `
- pull-requests:
- '**':
- - step:
- name: SonarQube analysis
- caches:
- - gradle
- - sonar
- script:
- - bash ./gradlew sonarqube
-`
- : ''
-}
-definitions:
- caches:
- sonar: ~/.sonar`,
- [BuildTools.Maven]: branchesEnabled => `image: maven:3.3.9
-
-clone:
- depth: full
-
-pipelines:
- branches:
- '{master}':
- - step:
- name: SonarQube analysis
- caches:
- - maven
- - sonar
- script:
- - mvn verify sonar:sonar
-${
- branchesEnabled
- ? `
- pull-requests:
- '**':
- - step:
- name: SonarQube analysis
- caches:
- - maven
- - sonar
- script:
- - mvn verify sonar:sonar
-`
- : ''
-}
-definitions:
- caches:
- sonar: ~/.sonar`,
- [BuildTools.DotNet]: (
- branchesEnabled,
- projectKey
- ) => `image: mcr.microsoft.com/dotnet/core/sdk:latest
-
-pipelines:
- branches:
- '{master}':
- - step:
- name: SonarQube analysis
- caches:
- - dotnetcore
- - sonar
- script:
- - apt-get update
- - apt-get install --yes openjdk-11-jre
- - dotnet tool install --global dotnet-sonarscanner
- - export PATH="$PATH:/root/.dotnet/tools"
- - dotnet sonarscanner begin /k:"${projectKey}" /d:"sonar.login=\${SONAR_TOKEN}" /d:"sonar.host.url=\${SONAR_HOST_URL}"
- - dotnet build
- - dotnet sonarscanner end /d:"sonar.login=\${SONAR_TOKEN}"
- ${
- branchesEnabled
- ? `
- pull-requests:
- '**':
- - step:
- name: SonarQube analysis
- caches:
- - dotnetcore
- - sonar
- script:
- - apt-get update
- - apt-get install --yes openjdk-11-jre
- - dotnet tool install --global dotnet-sonarscanner
- - export PATH="$PATH:/root/.dotnet/tools"
- - dotnet sonarscanner begin /k:"${projectKey}" /d:"sonar.login=\${SONAR_TOKEN}" /d:"sonar.host.url=\${SONAR_HOST_URL}"
- - dotnet build
- - dotnet sonarscanner end /d:"sonar.login=\${SONAR_TOKEN}"
- `
- : ''
- }
-definitions:
- caches:
- sonar: ~/.sonar`,
- [BuildTools.Other]: branchesEnabled => `image: maven:3.3.9
-
-clone:
- depth: full
-
-pipelines:
- branches:
- '{master}':
- - step:
- name: SonarQube analysis
- script:
- - pipe: sonarsource/sonarqube-scan:1.0.0
- variables:
- SONAR_HOST_URL: \${SONAR_HOST_URL} # Get the value from the repository/workspace variable.
- SONAR_TOKEN: \${SONAR_TOKEN} # Get the value from the repository/workspace variable. You shouldn't set secret in clear text here.
-${
- branchesEnabled
- ? `
- pull-requests:
- '**':
- - step:
- name: SonarQube analysis
- script:
- - pipe: sonarsource/sonarqube-scan:1.0.0
- variables:
- SONAR_HOST_URL: \${SONAR_HOST_URL} # Get the value from the repository/workspace variable.
- SONAR_TOKEN: \${SONAR_TOKEN} # Get the value from the repository/workspace variable. You shouldn't set secret in clear text here.
-`
- : ''
-}
-definitions:
- caches:
- sonar: ~/.sonar`
+ [BuildTools.Gradle]: gradleExample,
+ [BuildTools.Maven]: mavenExample,
+ [BuildTools.DotNet]: dotNetExample,
+ [BuildTools.CFamily]: cFamilyExample,
+ [BuildTools.Other]: othersExample
};
export function AnalysisCommand(props: AnalysisCommandProps) {
<>
<PreambuleYaml buildTool={buildTool} component={component} />
<CreateYmlFile yamlFileName="bitbucket-pipelines.yml" yamlTemplate={yamlTemplate} />
+ {buildTool === BuildTools.CFamily && <CompilationInfo className="abs-width-800" />}
</>
);
}
<CodeSnippet snippet={mavenPomSnippet(component.key)} />
</li>
);
+ case BuildTools.CFamily:
case BuildTools.Other:
return <DefaultProjectKey component={component} />;
default:
import { BuildTools } from '../../types';
import { AnalysisCommand, AnalysisCommandProps } from '../AnalysisCommand';
-it.each([[BuildTools.DotNet], [BuildTools.Gradle], [BuildTools.Maven], [BuildTools.Other]])(
- 'should render correctly for %s',
- buildTool => {
- expect(shallowRender({ buildTool })).toMatchSnapshot();
- expect(
- shallowRender({ appState: mockAppState({ branchesEnabled: true }), buildTool })
- ).toMatchSnapshot('with branch enabled');
- }
-);
+it.each([
+ [BuildTools.CFamily],
+ [BuildTools.DotNet],
+ [BuildTools.Gradle],
+ [BuildTools.Maven],
+ [BuildTools.Other]
+])('should render correctly for %s', buildTool => {
+ expect(shallowRender({ buildTool })).toMatchSnapshot();
+ expect(
+ shallowRender({ appState: mockAppState({ branchesEnabled: true }), buildTool })
+ ).toMatchSnapshot('with branch enabled');
+});
function shallowRender(props: Partial<AnalysisCommandProps> = {}) {
return shallow<AnalysisCommandProps>(
import { BuildTools } from '../../types';
import { PreambuleYaml, PreambuleYamlProps } from '../PreambuleYaml';
-it.each([[BuildTools.DotNet], [BuildTools.Gradle], [BuildTools.Maven], [BuildTools.Other]])(
- 'should render correctly for %s',
- buildTool => {
- expect(shallowRender({ buildTool })).toMatchSnapshot();
- }
-);
+it.each([
+ [BuildTools.DotNet],
+ [BuildTools.Gradle],
+ [BuildTools.Maven],
+ [BuildTools.CFamily],
+ [BuildTools.Other]
+])('should render correctly for %s', buildTool => {
+ expect(shallowRender({ buildTool })).toMatchSnapshot();
+});
function shallowRender(props: Partial<PreambuleYamlProps> = {}) {
return shallow<PreambuleYamlProps>(
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`should render correctly for cfamily 1`] = `
+<Fragment>
+ <PreambuleYaml
+ buildTool="cfamily"
+ component={
+ Object {
+ "breadcrumbs": Array [],
+ "key": "my-project",
+ "name": "MyProject",
+ "qualifier": "TRK",
+ "qualityGate": Object {
+ "isDefault": true,
+ "key": "30",
+ "name": "Sonar way",
+ },
+ "qualityProfiles": Array [
+ Object {
+ "deleted": false,
+ "key": "my-qp",
+ "language": "ts",
+ "name": "Sonar way",
+ },
+ ],
+ "tags": Array [],
+ }
+ }
+ />
+ <CreateYmlFile
+ yamlFileName="bitbucket-pipelines.yml"
+ yamlTemplate="image: <image ready for your build toolchain>
+
+clone:
+ depth: full
+
+pipelines:
+ branches:
+ '{master}':
+ - step:
+ name: Download and install the build wrapper, build the project
+ script:
+ - mkdir $HOME/.sonar
+ - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip
+ - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
+ - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
+ - pipe: sonarsource/sonarqube-scan:1.0.0
+ variables:
+ EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output
+ SONAR_HOST_URL: \${SONAR_HOST_URL}
+ SONAR_TOKEN: \${SONAR_TOKEN}
+
+definitions:
+ caches:
+ sonar: ~/.sonar"
+ />
+ <CompilationInfo
+ className="abs-width-800"
+ />
+</Fragment>
+`;
+
+exports[`should render correctly for cfamily: with branch enabled 1`] = `
+<Fragment>
+ <PreambuleYaml
+ buildTool="cfamily"
+ component={
+ Object {
+ "breadcrumbs": Array [],
+ "key": "my-project",
+ "name": "MyProject",
+ "qualifier": "TRK",
+ "qualityGate": Object {
+ "isDefault": true,
+ "key": "30",
+ "name": "Sonar way",
+ },
+ "qualityProfiles": Array [
+ Object {
+ "deleted": false,
+ "key": "my-qp",
+ "language": "ts",
+ "name": "Sonar way",
+ },
+ ],
+ "tags": Array [],
+ }
+ }
+ />
+ <CreateYmlFile
+ yamlFileName="bitbucket-pipelines.yml"
+ yamlTemplate="image: <image ready for your build toolchain>
+
+clone:
+ depth: full
+
+pipelines:
+ branches:
+ '{master}':
+ - step:
+ name: Download and install the build wrapper, build the project
+ script:
+ - mkdir $HOME/.sonar
+ - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip
+ - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
+ - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
+ - pipe: sonarsource/sonarqube-scan:1.0.0
+ variables:
+ EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output
+ SONAR_HOST_URL: \${SONAR_HOST_URL}
+ SONAR_TOKEN: \${SONAR_TOKEN}
+
+ pull-requests:
+ '**':
+ - step:
+ name: Download and install the build wrapper, build the project
+ script:
+ - mkdir $HOME/.sonar
+ - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip
+ - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
+ - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
+ - pipe: sonarsource/sonarqube-scan:1.0.0
+ variables:
+ EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output
+ SONAR_HOST_URL: \${SONAR_HOST_URL}
+ SONAR_TOKEN: \${SONAR_TOKEN}
+definitions:
+ caches:
+ sonar: ~/.sonar"
+ />
+ <CompilationInfo
+ className="abs-width-800"
+ />
+</Fragment>
+`;
+
exports[`should render correctly for dotnet 1`] = `
<Fragment>
<PreambuleYaml
<CreateYmlFile
yamlFileName="bitbucket-pipelines.yml"
yamlTemplate="image: mcr.microsoft.com/dotnet/core/sdk:latest
-
+
pipelines:
branches:
'{master}':
<CreateYmlFile
yamlFileName="bitbucket-pipelines.yml"
yamlTemplate="image: mcr.microsoft.com/dotnet/core/sdk:latest
-
+
pipelines:
branches:
'{master}':
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`should render correctly for cfamily 1`] = `
+<DefaultProjectKey
+ component={
+ Object {
+ "breadcrumbs": Array [],
+ "key": "my-project",
+ "name": "MyProject",
+ "qualifier": "TRK",
+ "qualityGate": Object {
+ "isDefault": true,
+ "key": "30",
+ "name": "Sonar way",
+ },
+ "qualityProfiles": Array [
+ Object {
+ "deleted": false,
+ "key": "my-qp",
+ "language": "ts",
+ "name": "Sonar way",
+ },
+ ],
+ "tags": Array [],
+ }
+ }
+/>
+`;
+
exports[`should render correctly for dotnet 1`] = `""`;
exports[`should render correctly for gradle 1`] = `
--- /dev/null
+/*
+ * 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.
+ */
+
+export default function cFamilyExample(branchesEnabled: boolean) {
+ return `image: <image ready for your build toolchain>
+
+clone:
+ depth: full
+
+pipelines:
+ branches:
+ '{master}':
+ - step:
+ name: Download and install the build wrapper, build the project
+ script:
+ - mkdir $HOME/.sonar
+ - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip
+ - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
+ - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
+ - pipe: sonarsource/sonarqube-scan:1.0.0
+ variables:
+ EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output
+ SONAR_HOST_URL: \${SONAR_HOST_URL}
+ SONAR_TOKEN: \${SONAR_TOKEN}
+${
+ branchesEnabled
+ ? `
+ pull-requests:
+ '**':
+ - step:
+ name: Download and install the build wrapper, build the project
+ script:
+ - mkdir $HOME/.sonar
+ - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip
+ - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
+ - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
+ - pipe: sonarsource/sonarqube-scan:1.0.0
+ variables:
+ EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output
+ SONAR_HOST_URL: \${SONAR_HOST_URL}
+ SONAR_TOKEN: \${SONAR_TOKEN}`
+ : ''
+}
+definitions:
+ caches:
+ sonar: ~/.sonar`;
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+export default function dotNetExample(branchesEnabled: boolean, projectKey: string) {
+ return `image: mcr.microsoft.com/dotnet/core/sdk:latest
+
+pipelines:
+ branches:
+ '{master}':
+ - step:
+ name: SonarQube analysis
+ caches:
+ - dotnetcore
+ - sonar
+ script:
+ - apt-get update
+ - apt-get install --yes openjdk-11-jre
+ - dotnet tool install --global dotnet-sonarscanner
+ - export PATH="$PATH:/root/.dotnet/tools"
+ - dotnet sonarscanner begin /k:"${projectKey}" /d:"sonar.login=\${SONAR_TOKEN}" /d:"sonar.host.url=\${SONAR_HOST_URL}"
+ - dotnet build
+ - dotnet sonarscanner end /d:"sonar.login=\${SONAR_TOKEN}"
+ ${
+ branchesEnabled
+ ? `
+ pull-requests:
+ '**':
+ - step:
+ name: SonarQube analysis
+ caches:
+ - dotnetcore
+ - sonar
+ script:
+ - apt-get update
+ - apt-get install --yes openjdk-11-jre
+ - dotnet tool install --global dotnet-sonarscanner
+ - export PATH="$PATH:/root/.dotnet/tools"
+ - dotnet sonarscanner begin /k:"${projectKey}" /d:"sonar.login=\${SONAR_TOKEN}" /d:"sonar.host.url=\${SONAR_HOST_URL}"
+ - dotnet build
+ - dotnet sonarscanner end /d:"sonar.login=\${SONAR_TOKEN}"
+ `
+ : ''
+ }
+definitions:
+ caches:
+ sonar: ~/.sonar`;
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+export default function gradleExample(branchesEnabled: boolean) {
+ return `image: openjdk:8
+
+clone:
+ depth: full
+
+pipelines:
+ branches:
+ '{master}':
+ - step:
+ name: SonarQube analysis
+ caches:
+ - gradle
+ - sonar
+ script:
+ - bash ./gradlew sonarqube
+${
+ branchesEnabled
+ ? `
+ pull-requests:
+ '**':
+ - step:
+ name: SonarQube analysis
+ caches:
+ - gradle
+ - sonar
+ script:
+ - bash ./gradlew sonarqube
+`
+ : ''
+}
+definitions:
+ caches:
+ sonar: ~/.sonar`;
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+export default function mavenExample(branchesEnabled: boolean) {
+ return `image: maven:3.3.9
+
+clone:
+ depth: full
+
+pipelines:
+ branches:
+ '{master}':
+ - step:
+ name: SonarQube analysis
+ caches:
+ - maven
+ - sonar
+ script:
+ - mvn verify sonar:sonar
+${
+ branchesEnabled
+ ? `
+ pull-requests:
+ '**':
+ - step:
+ name: SonarQube analysis
+ caches:
+ - maven
+ - sonar
+ script:
+ - mvn verify sonar:sonar
+`
+ : ''
+}
+definitions:
+ caches:
+ sonar: ~/.sonar`;
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+export default function othersExample(branchesEnabled: boolean) {
+ return `image: maven:3.3.9
+
+clone:
+ depth: full
+
+pipelines:
+ branches:
+ '{master}':
+ - step:
+ name: SonarQube analysis
+ script:
+ - pipe: sonarsource/sonarqube-scan:1.0.0
+ variables:
+ SONAR_HOST_URL: \${SONAR_HOST_URL} # Get the value from the repository/workspace variable.
+ SONAR_TOKEN: \${SONAR_TOKEN} # Get the value from the repository/workspace variable. You shouldn't set secret in clear text here.
+${
+ branchesEnabled
+ ? `
+ pull-requests:
+ '**':
+ - step:
+ name: SonarQube analysis
+ script:
+ - pipe: sonarsource/sonarqube-scan:1.0.0
+ variables:
+ SONAR_HOST_URL: \${SONAR_HOST_URL} # Get the value from the repository/workspace variable.
+ SONAR_TOKEN: \${SONAR_TOKEN} # Get the value from the repository/workspace variable. You shouldn't set secret in clear text here.
+`
+ : ''
+}
+definitions:
+ caches:
+ sonar: ~/.sonar`;
+}