项目作者: marco-nicolini

项目描述 :
A maven plugin to execute shellcheck
高级语言: Java
项目地址: git://github.com/marco-nicolini/shellcheck-maven-plugin.git
创建时间: 2020-09-10T22:35:36Z
项目社区:https://github.com/marco-nicolini/shellcheck-maven-plugin

开源协议:GNU General Public License v3.0

下载


shellcheck-maven-plugin

Maven Central
Multi OS build maven build

A maven plugin to execute shellcheck in a maven build

How it works

The plugin has a single check goal that searches for shell files in standard configurable locations and \
invokes shellcheck on them.

Since shellcheck is a non-java application the plugin provides automatic ways to get hold of the shellcheck binary. This
is controlled by the binaryResolutionMethod plugin configuration:

  • embedded the plugin will use a shellcheck binary embedded in the plugin jar.
    • useful if you’re behind proxy and you want zero-hassles in configuring things
    • you’re bound to the embedded shellcheck version (currently 0.9.0)
  • download the binary will be downloaded at plugin execution time.
    • lets you target a specific shellcheck version different from the embedded one
    • the download is performed under the hood by the maven-download-plugin which provides caching, so you won’t be
      downloading the same binary over and over
  • external the path to a shellcheck binary needs to be provided.
    • you have all control
    • requiring external tools to be installed makes the build less self-contained

For embedded and download resolutions, at plugin execution time, the resolved binary is copied
to ${project.buid.directory}/shellcheck-plugin/shellcheck and then invoked.

Optionally the plugin can be configured to fail the build if warnings are found (i.e. on non-zero shellcheck exit code)
with the failBuildIfWarnings property.

Usage

The plugin is released on maven central, so you can use it in your build like this (just replace
${shellcheck-maven-plugin.version} with the latest version).

Quickstart

The quickest way to get started, using sensible defaults.

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>dev.dimlight</groupId>
  5. <artifactId>shellcheck-maven-plugin</artifactId>
  6. <version>${shellcheck-maven-plugin.version}</version>
  7. <executions>
  8. <execution>
  9. <phase>verify</phase>
  10. <goals>
  11. <goal>check</goal>
  12. </goals>
  13. <configuration>
  14. <sourceDirs>
  15. <sourceDir>
  16. <directory>${project.basedir}/src/main/sh</directory>
  17. <includes>
  18. <include>**/*.sh</include>
  19. </includes>
  20. </sourceDir>
  21. </sourceDirs>
  22. <failBuildIfWarnings>true</failBuildIfWarnings>
  23. <binaryResolutionMethod>embedded</binaryResolutionMethod>
  24. </configuration>
  25. </execution>
  26. </executions>
  27. </plugin>
  28. </plugins>
  29. </build>

A more comprehensive usage example

This is a fairly comprehensive usage example where almost all configuration knobs are used and some defaults are
re-stated in the configuration for transparency and documentation purposes.

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>dev.dimlight</groupId>
  5. <artifactId>shellcheck-maven-plugin</artifactId>
  6. <version>${shellcheck-maven-plugin.version}</version>
  7. <executions>
  8. <execution>
  9. <id>simple-check</id>
  10. <phase>verify</phase>
  11. <goals>
  12. <goal>check</goal>
  13. </goals>
  14. <!-- all configuration keys are included in this example -->
  15. <configuration>
  16. <!-- If set to true plugin execution will be skipped (you can also use the property skip.shellcheck) -->
  17. <skip>false</skip>
  18. <!-- The source dirs where files to check are searched.
  19. This is a FileSet https://maven.apache.org/shared/file-management/fileset.html
  20. however the only things making sense to be specified here are:
  21. directory, includes and excludes.
  22. Includes and Excludes can use ant-style patterns.
  23. This example shows the default configuration -->
  24. <sourceDirs>
  25. <sourceDir>
  26. <directory>${project.basedir}/src/main/sh</directory>
  27. <includes>
  28. <include>**/*.sh</include>
  29. </includes>
  30. </sourceDir>
  31. </sourceDirs>
  32. <!-- the cmdline args to pass to shellcheck
  33. this example maps to the cmdline "shellcheck -a -s bash --format=tty --norc" -->
  34. <args>
  35. <arg>-a</arg>
  36. <arg>-s</arg>
  37. <arg>bash</arg>
  38. <arg>--format=tty</arg>
  39. <arg>--norc</arg>
  40. </args>
  41. <!-- set to true if you want the build to fail when you have warnings -->
  42. <failBuildIfWarnings>false</failBuildIfWarnings>
  43. <!-- chose the binary resolution method "embedded", "download" or "external" -->
  44. <binaryResolutionMethod>download</binaryResolutionMethod>
  45. <!-- if you have chosen "download" as resolution method, you may also provide the url of the shellcheck
  46. release archive (zip or tar.xz) (for all os/arch you're building on) to be used at plugin execution time.
  47. The urls are specified as a configuration map, where the exact key for an architecture
  48. (e.g. "Mac_OS_X-x86_64" in the example below) must match what your jvm returns for the
  49. following expression:
  50. (System.getProperty("os.name") + "-" + System.getProperty("os.arch")).replace(" ", "_")
  51. For your convenience this value is also printed by the plugin almost at start:
  52. e.g. "[INFO] os arch: [Mac_OS_X-x86_64]"
  53. If you don't provide this configuration map at all (or if you don't provide an exact match
  54. to osname-arch as described above) the same url that was used to
  55. fetch the embedded binaries will be used instead. However, at that point
  56. you may as well use the embedded binaries -->
  57. <releaseArchiveUrls>
  58. <Linux-amd64>
  59. https://github.com/koalaman/shellcheck/releases/download/v0.9.0/shellcheck-v0.9.0.linux.x86_64.tar.xz
  60. </Linux-amd64>
  61. <Mac_OS_X-x86_64>
  62. https://github.com/koalaman/shellcheck/releases/download/v0.9.0/shellcheck-v0.9.0.darwin.x86_64.tar.xz
  63. </Mac_OS_X-x86_64>
  64. </releaseArchiveUrls>
  65. <!-- if you chose "external" as resolution method you need also to provide the "externalBinaryPath" -->
  66. <!-- externalBinaryPath>/path/to/shellcheck</externalBinaryPath -->
  67. <!-- Set this to true (along with the filesPerInvocation parameter) to split the check the files
  68. in multiple shellcheck invocations each of which will check at maximum <filesPerInvocation>
  69. files.
  70. This is false by default, which means that all files to check are passed as args
  71. to a single shellcheck invocation. -->
  72. <splitInvocations>false</splitInvocations>
  73. <!-- number of files to pass to a single shellcheck invocation. If not specified (or when 0 or
  74. negative) the behavior is to pass all files to a single shellcheck invocation.
  75. This is useful when you have a big number of files to check and you're hitting the
  76. ARG_MAX limits in you underlying OS: limiting the number of files per invocation can
  77. bring you back below that limit. By default equals to Short.MAX_VALUE, taken into
  78. account only when splitInvocations is true -->
  79. <!-- filesPerInvocation>32767</filesPerInvocation -->
  80. <!-- Name of the file (that will be placed in the plugin output directory) where the shellcheck
  81. stdout/stderr will be redirected.
  82. It can be a simple filename or it can be a "template name" including the placeholders
  83. "@executionId@" and "@runNumber@". This gives you the flexibility to discriminate
  84. captured outputs on different executions on the same plugin definition (or to discriminate
  85. among different runs when <splitInvocations> is true.)
  86. Defaults to "shellcheck.@executionId@.@runNumber@.stderr" -->
  87. <capturedStdoutFileName>shellcheck.@executionId@.stdout</capturedStdoutFileName>
  88. <capturedStderrFileName>shellcheck.@executionId@.stderr</capturedStderrFileName>
  89. </configuration>
  90. </execution>
  91. </executions>
  92. </plugin>
  93. </plugins>
  94. </build>

More examples are available in the it (integration tests) directory in the source tree.

How to build

Requirements

  • jdk >= 8
  • maven >= 3.5.4
  • working internet connection needed to retrieve the shellcheck binaries (configure your proxy in your maven
    settings.xml if you’re behind one)
  1. mvn clean install

shellcheck-maven-plugin is licensed under the GNU General Public License, v3. A copy of this license is included in the
file LICENSE.txt.

Copyright 2022, Marco Nicolini.

ShellCheck is licensed under the GNU General Public License.

Copyright 2012-2022, Vidar ‘koala_man’ Holen and contributors.