]> source.dussan.org Git - sonarqube.git/blob
f9eb7b633dd1926cf81b2107030e46d2595a6bc5
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2024 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 { ClipboardIconButton, CodeSnippet, ListItem, UnorderedList } from 'design-system';
21 import * as React from 'react';
22 import { FormattedMessage } from 'react-intl';
23 import { translate } from '../../../../helpers/l10n';
24 import { InlineSnippet } from '../../components/InlineSnippet';
25 import SentenceWithHighlights from '../../components/SentenceWithHighlights';
26 import { BuildTools } from '../../types';
27
28 export enum PrepareType {
29   JavaMavenGradle,
30   StandAlone,
31   MSBuild,
32 }
33
34 export interface PrepareAnalysisCommandProps {
35   buildTool: BuildTools;
36   kind: PrepareType;
37   projectKey: string;
38   projectName?: string;
39 }
40
41 export default function PrepareAnalysisCommand(props: PrepareAnalysisCommandProps) {
42   const { buildTool, kind, projectKey, projectName } = props;
43
44   const ADDITIONAL_PROPERTY = 'sonar.cfamily.compile-commands=bw-output/compile_commands.json';
45
46   const MAVEN_GRADLE_PROPS_SNIPPET = `# Additional properties that will be passed to the scanner,
47 # Put one key=value per line, example:
48 # sonar.exclusions=**/*.bin
49 sonar.projectKey=${projectKey}
50 sonar.projectName=${projectName}
51 `;
52
53   return (
54     <UnorderedList ticks className="sw-ml-12 sw-my-2">
55       <ListItem>
56         <SentenceWithHighlights
57           translationKey="onboarding.tutorial.with.azure_pipelines.BranchAnalysis.prepare.endpoint"
58           highlightKeys={['endpoint']}
59         />
60       </ListItem>
61       <ListItem>
62         <FormattedMessage
63           id="onboarding.tutorial.with.azure_pipelines.BranchAnalysis.prepare.run_analysis"
64           defaultMessage={translate(
65             'onboarding.tutorial.with.azure_pipelines.BranchAnalysis.prepare.run_analysis',
66           )}
67           values={{
68             section: (
69               <b className="sw-font-semibold">
70                 {translate(
71                   'onboarding.tutorial.with.azure_pipelines.BranchAnalysis.prepare.run_analysis.section',
72                 )}
73               </b>
74             ),
75             run_analysis_value: (
76               <b className="sw-font-semibold">
77                 {translate(
78                   'onboarding.tutorial.with.azure_pipelines.BranchAnalysis.prepare.run_analysis.values',
79                   buildTool,
80                 )}
81               </b>
82             ),
83           }}
84         />
85       </ListItem>
86
87       {kind === PrepareType.StandAlone && (
88         <>
89           <ListItem>
90             <SentenceWithHighlights
91               translationKey="onboarding.tutorial.with.azure_pipelines.BranchAnalysis.manual"
92               highlightKeys={['mode']}
93             />
94           </ListItem>
95
96           <ListItem>
97             <span className="sw-flex sw-items-center">
98               <FormattedMessage
99                 id="onboarding.tutorial.with.azure_pipelines.BranchAnalysis.run.key.sentence"
100                 defaultMessage={translate(
101                   'onboarding.tutorial.with.azure_pipelines.BranchAnalysis.run.key.sentence',
102                 )}
103                 values={{
104                   project_key: (
105                     <b className="sw-font-semibold sw-mx-1">
106                       {translate(
107                         'onboarding.tutorial.with.azure_pipelines.BranchAnalysis.run.key.sentence.project_key',
108                       )}
109                     </b>
110                   ),
111                   key: (
112                     <span className="sw-ml-1">
113                       <InlineSnippet snippet={projectKey} />
114                     </span>
115                   ),
116                   button: <ClipboardIconButton className="sw-ml-2" copyValue={projectKey} />,
117                 }}
118               />
119             </span>
120           </ListItem>
121           {buildTool === BuildTools.CFamily && (
122             <ListItem>
123               <span className="sw-flex sw-items-center sw-flex-wrap">
124                 <FormattedMessage
125                   id="onboarding.tutorial.with.azure_pipelines.BranchAnalysis.prepare_additional.ccpp"
126                   defaultMessage={translate(
127                     'onboarding.tutorial.with.azure_pipelines.BranchAnalysis.prepare_additional.ccpp',
128                   )}
129                   values={{
130                     advanced: (
131                       <b className="sw-font-semibold sw-mx-1">
132                         {translate(
133                           'onboarding.tutorial.with.azure_pipelines.BranchAnalysis.prepare_additional.ccpp.advanced',
134                         )}
135                       </b>
136                     ),
137                     additional: (
138                       <b className="sw-font-semibold sw-mx-1">
139                         {translate(
140                           'onboarding.tutorial.with.azure_pipelines.BranchAnalysis.prepare_additional.ccpp.additional',
141                         )}
142                       </b>
143                     ),
144                     property: (
145                       <span className="sw-ml-1">
146                         <InlineSnippet snippet={ADDITIONAL_PROPERTY} />
147                       </span>
148                     ),
149                     button: (
150                       <ClipboardIconButton className="sw-ml-2" copyValue={ADDITIONAL_PROPERTY} />
151                     ),
152                   }}
153                 />
154               </span>
155             </ListItem>
156           )}
157         </>
158       )}
159
160       {kind === PrepareType.JavaMavenGradle && (
161         <ListItem>
162           <SentenceWithHighlights
163             translationKey="onboarding.tutorial.with.azure_pipelines.BranchAnalysis.advanced_properties"
164             highlightKeys={['section', 'properties']}
165           />
166           :
167           <CodeSnippet
168             className="sw-p-6"
169             language="properties"
170             snippet={MAVEN_GRADLE_PROPS_SNIPPET}
171           />
172         </ListItem>
173       )}
174       {kind === PrepareType.MSBuild && (
175         <ListItem>
176           <span className="sw-flex sw-items-center">
177             <FormattedMessage
178               id="onboarding.tutorial.with.azure_pipelines.BranchAnalysis.run.key.sentence"
179               defaultMessage={translate(
180                 'onboarding.tutorial.with.azure_pipelines.BranchAnalysis.run.key.sentence',
181               )}
182               values={{
183                 project_key: (
184                   <b className="sw-font-semibold sw-mx-1">
185                     {translate(
186                       'onboarding.tutorial.with.azure_pipelines.BranchAnalysis.run.key.sentence.project_key',
187                     )}
188                   </b>
189                 ),
190                 key: (
191                   <span className="sw-ml-1">
192                     <InlineSnippet snippet={projectKey} />
193                   </span>
194                 ),
195                 button: <ClipboardIconButton className="sw-ml-2" copyValue={projectKey} />,
196               }}
197             />
198           </span>
199         </ListItem>
200       )}
201     </UnorderedList>
202   );
203 }