You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JavaMaven.tsx 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 * as React from 'react';
  21. import { Component } from '../../../../types/types';
  22. import CreateYmlFile from '../../components/CreateYmlFile';
  23. import { GITHUB_ACTIONS_RUNS_ON_LINUX } from '../constants';
  24. import { generateGitHubActionsYaml } from '../utils';
  25. import MonorepoDocLinkFallback from './MonorepoDocLinkFallback';
  26. export interface JavaMavenProps {
  27. branchesEnabled?: boolean;
  28. mainBranchName: string;
  29. monorepo?: boolean;
  30. component: Component;
  31. }
  32. function mavenYamlSteps(projectKey: string, projectName: string) {
  33. return `
  34. - name: Set up JDK 17
  35. uses: actions/setup-java@v1
  36. with:
  37. java-version: 17
  38. - name: Cache SonarQube packages
  39. uses: actions/cache@v1
  40. with:
  41. path: ~/.sonar/cache
  42. key: \${{ runner.os }}-sonar
  43. restore-keys: \${{ runner.os }}-sonar
  44. - name: Cache Maven packages
  45. uses: actions/cache@v1
  46. with:
  47. path: ~/.m2
  48. key: \${{ runner.os }}-m2-\${{ hashFiles('**/pom.xml') }}
  49. restore-keys: \${{ runner.os }}-m2
  50. - name: Build and analyze
  51. env:
  52. SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
  53. SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}
  54. run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=${projectKey} -Dsonar.projectName='${projectName}'`;
  55. }
  56. export default function JavaMaven(props: JavaMavenProps) {
  57. const { component, branchesEnabled, mainBranchName, monorepo } = props;
  58. if (monorepo) {
  59. return <MonorepoDocLinkFallback />;
  60. }
  61. return (
  62. <CreateYmlFile
  63. yamlFileName=".github/workflows/build.yml"
  64. yamlTemplate={generateGitHubActionsYaml(
  65. mainBranchName,
  66. !!branchesEnabled,
  67. GITHUB_ACTIONS_RUNS_ON_LINUX,
  68. mavenYamlSteps(component.key, component.name),
  69. )}
  70. />
  71. );
  72. }