aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/tutorials/onboarding/AnalysisStep.js
blob: bf535694f94ec05b2a8dadc0236188804ed98977 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * SonarQube
 * Copyright (C) 2009-2017 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.
 */
// @flow
import React from 'react';
import Step from './Step';
import LanguageStep from './LanguageStep';
/*:: import type { Result } from './LanguageStep'; */
import JavaMaven from './commands/JavaMaven';
import JavaGradle from './commands/JavaGradle';
import DotNet from './commands/DotNet';
import Msvc from './commands/Msvc';
import ClangGCC from './commands/ClangGCC';
import Other from './commands/Other';
import { translate } from '../../../helpers/l10n';

/*::
type Props = {|
  onFinish: (projectKey?: string) => void,
  onReset: () => void,
  open: boolean,
  organization?: string,
  sonarCloud: boolean,
  stepNumber: number,
  token: string
|};
*/

/*::
type State = {
  result?: Result
};
*/

export default class AnalysisStep extends React.PureComponent {
  /*:: props: Props; */
  state /*: State */ = {};

  handleLanguageSelect = (result /*: Result | void */) => {
    this.setState({ result });
    const projectKey = result && result.language !== 'java' ? result.projectKey : undefined;
    this.props.onFinish(projectKey);
  };

  handleLanguageReset = () => {
    this.setState({ result: undefined });
    this.props.onReset();
  };

  getHost = () => window.location.origin + window.baseUrl;

  renderForm = () => {
    return (
      <div className="boxed-group-inner">
        <div className="flex-columns">
          <div className="flex-column flex-column-half bordered-right">
            <LanguageStep
              onDone={this.handleLanguageSelect}
              onReset={this.handleLanguageReset}
              organization={this.props.organization}
              sonarCloud={this.props.sonarCloud}
            />
          </div>
          <div className="flex-column flex-column-half">
            {this.renderCommand()}
          </div>
        </div>
      </div>
    );
  };

  renderFormattedCommand = (...lines /*: Array<string> */) =>
    <pre>
      {lines.join(' ' + '\\' + '\n' + '  ')}
    </pre>;

  renderCommand = () => {
    const { result } = this.state;

    if (!result) {
      return null;
    }

    if (result.language === 'java') {
      return result.javaBuild === 'maven'
        ? this.renderCommandForMaven()
        : this.renderCommandForGradle();
    } else if (result.language === 'dotnet') {
      return this.renderCommandForDotNet();
    } else if (result.language === 'c-family') {
      return result.cFamilyCompiler === 'msvc'
        ? this.renderCommandForMSVC()
        : this.renderCommandForClangGCC();
    } else {
      return this.renderCommandForOther();
    }
  };

  renderCommandForMaven = () =>
    <JavaMaven
      host={this.getHost()}
      organization={this.props.organization}
      token={this.props.token}
    />;

  renderCommandForGradle = () =>
    <JavaGradle
      host={this.getHost()}
      organization={this.props.organization}
      token={this.props.token}
    />;

  renderCommandForDotNet = () => {
    return (
      <DotNet
        host={this.getHost()}
        organization={this.props.organization}
        // $FlowFixMe
        projectKey={this.state.result.projectKey}
        token={this.props.token}
      />
    );
  };

  renderCommandForMSVC = () => {
    return (
      <Msvc
        host={this.getHost()}
        organization={this.props.organization}
        // $FlowFixMe
        projectKey={this.state.result.projectKey}
        token={this.props.token}
      />
    );
  };

  renderCommandForClangGCC = () =>
    <ClangGCC
      host={this.getHost()}
      organization={this.props.organization}
      // $FlowFixMe
      os={this.state.result.os}
      // $FlowFixMe
      projectKey={this.state.result.projectKey}
      token={this.props.token}
    />;

  renderCommandForOther = () =>
    <Other
      host={this.getHost()}
      organization={this.props.organization}
      // $FlowFixMe
      os={this.state.result.os}
      // $FlowFixMe
      projectKey={this.state.result.projectKey}
      token={this.props.token}
    />;

  renderResult = () => null;

  render() {
    return (
      <Step
        finished={false}
        onOpen={() => {}}
        open={this.props.open}
        renderForm={this.renderForm}
        renderResult={this.renderResult}
        stepNumber={this.props.stepNumber}
        stepTitle={translate('onboarding.analysis.header')}
      />
    );
  }
}