1{
2 lib,
3 coreutils,
4 fetchFromGitHub,
5 jre,
6 libarchive,
7 makeWrapper,
8 maven,
9 nix-update-script,
10}:
11
12maven.buildMavenPackage rec {
13 pname = "sonar-scanner-cli";
14 version = "7.1.0.4889";
15
16 src = fetchFromGitHub {
17 owner = "SonarSource";
18 repo = "sonar-scanner-cli";
19 tag = version;
20 hash = "sha256-6TUwk9TyXzGHIEKkzELH+EQppCPLCg192a4ed1ycFrk=";
21 };
22
23 mvnHash = "sha256-uPdnXT/QuhGJ+9Y7TouR+nNm3SUyTxgecuDcMZV/Iq8=";
24
25 mvnParameters = "-Dproject.build.outputTimestamp=1980-01-01T00:00:02Z";
26
27 nativeBuildInputs = [
28 # For bsdtar (name is a misnomer since it handles multiple archive formats) to extract nested directories from .zip files.
29 libarchive
30 makeWrapper
31 ];
32
33 doCheck = false;
34
35 # The .zip file with the programs is placed at "target/sonar-scanner-{project.version}.zip".
36 #
37 # To compute this .zip file path directly, we need to get the project version from the project's pom.xml.
38 #
39 # Parsing pom.xml is unsafe because project versions can be set dynamically. We need to use maven-help-plugin to get the evaluated value instead.
40 #
41 # Network isolation, however, prevents Maven from downloading packages in our shell script so we can't do this:
42 #
43 # MAVEN_PROJECT_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:3.4.1:evaluate \
44 # -Dmaven.repo.local=.m2 \
45 # -Dexpression=project.version \
46 # -DforceStdout \
47 # --quiet)
48 #
49 # We'll use wildcard expansion instead to find (what should be) the only .zip file in the "target" directory.
50 installPhase = ''
51 mkdir $out
52
53 FILES=(target/sonar-scanner-*.zip)
54 bsdtar --extract --file ''${FILES[0]} --strip-components 1 --directory $out
55
56 wrapProgram $out/bin/sonar-scanner \
57 --prefix PATH : ${
58 lib.makeBinPath [
59 coreutils
60 jre
61 ]
62 } \
63 --set JAVA_HOME ${jre}
64
65 wrapProgram $out/bin/sonar-scanner-debug \
66 --prefix PATH : ${lib.makeBinPath [ coreutils ]}
67 '';
68
69 passthru = {
70 updateScript = nix-update-script { };
71 };
72
73 meta = {
74 description = "Scanner CLI for SonarQube and SonarCloud";
75 homepage = "https://github.com/SonarSource/sonar-scanner-cli";
76 license = lib.licenses.lgpl3Only;
77 mainProgram = "sonar-scanner";
78 platforms = lib.platforms.unix;
79 maintainers = with lib.maintainers; [ peterromfeldhk ];
80 };
81}