mvn.plugin.zsh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. # Calls ./mvnw if found, otherwise execute the original mvn
  2. mvn-or-mvnw() {
  3. if [ -x ./mvnw ]; then
  4. echo "executing mvnw instead of mvn"
  5. ./mvnw "$@"
  6. else
  7. command mvn "$@"
  8. fi
  9. }
  10. # Wrapper function for Maven's mvn command. Based on https://gist.github.com/1027800
  11. mvn-color() {
  12. local BOLD=$(echoti bold)
  13. local TEXT_RED=$(echoti setaf 1)
  14. local TEXT_GREEN=$(echoti setaf 2)
  15. local TEXT_YELLOW=$(echoti setaf 3)
  16. local TEXT_BLUE=$(echoti setaf 4)
  17. local TEXT_WHITE=$(echoti setaf 7)
  18. local RESET_FORMATTING=$(echoti sgr0)
  19. (
  20. # Filter mvn output using sed. Before filtering set the locale to C, so invalid characters won't break some sed implementations
  21. unset LANG
  22. LC_CTYPE=C mvn "$@" | sed \
  23. -e "s/\(\[INFO\]\)\(.*\)/${TEXT_BLUE}${BOLD}\1${RESET_FORMATTING}\2/g" \
  24. -e "s/\(\[DEBUG\]\)\(.*\)/${TEXT_WHITE}${BOLD}\1${RESET_FORMATTING}\2/g" \
  25. -e "s/\(\[INFO\]\ BUILD SUCCESSFUL\)/${BOLD}${TEXT_GREEN}\1${RESET_FORMATTING}/g" \
  26. -e "s/\(\[WARNING\]\)\(.*\)/${BOLD}${TEXT_YELLOW}\1${RESET_FORMATTING}\2/g" \
  27. -e "s/\(\[ERROR\]\)\(.*\)/${BOLD}${TEXT_RED}\1${RESET_FORMATTING}\2/g" \
  28. -e "s/Tests run: \([^,]*\), Failures: \([^,]*\), Errors: \([^,]*\), Skipped: \([^,]*\)/${BOLD}${TEXT_GREEN}Tests run: \1${RESET_FORMATTING}, Failures: ${BOLD}${TEXT_RED}\2${RESET_FORMATTING}, Errors: ${BOLD}${TEXT_RED}\3${RESET_FORMATTING}, Skipped: ${BOLD}${TEXT_YELLOW}\4${RESET_FORMATTING}/g"
  29. # Make sure formatting is reset
  30. echo -ne "${RESET_FORMATTING}"
  31. )
  32. }
  33. # either use orignal mvn or the mvn wrapper
  34. alias mvn="mvn-or-mvnw"
  35. # Run mvn against the pom found in a project's root directory (assumes a git repo)
  36. alias 'mvn!'='mvn -f $(git rev-parse --show-toplevel 2>/dev/null || echo ".")/pom.xml'
  37. # aliases
  38. alias mvnag='mvn archetype:generate'
  39. alias mvnboot='mvn spring-boot:run'
  40. alias mvnc='mvn clean'
  41. alias mvncd='mvn clean deploy'
  42. alias mvnce='mvn clean eclipse:clean eclipse:eclipse'
  43. alias mvnci='mvn clean install'
  44. alias mvncie='mvn clean install eclipse:eclipse'
  45. alias mvncini='mvn clean initialize'
  46. alias mvncist='mvn clean install -DskipTests'
  47. alias mvncisto='mvn clean install -DskipTests --offline'
  48. alias mvncom='mvn compile'
  49. alias mvncp='mvn clean package'
  50. alias mvnct='mvn clean test'
  51. alias mvncv='mvn clean verify'
  52. alias mvncvst='mvn clean verify -DskipTests'
  53. alias mvnd='mvn deploy'
  54. alias mvndocs='mvn dependency:resolve -Dclassifier=javadoc'
  55. alias mvndt='mvn dependency:tree'
  56. alias mvne='mvn eclipse:eclipse'
  57. alias mvnfmt='mvn fmt:format'
  58. alias mvnjetty='mvn jetty:run'
  59. alias mvnp='mvn package'
  60. alias mvnqdev='mvn quarkus:dev'
  61. alias mvns='mvn site'
  62. alias mvnsrc='mvn dependency:sources'
  63. alias mvnt='mvn test'
  64. alias mvntc='mvn tomcat:run'
  65. alias mvntc7='mvn tomcat7:run'
  66. alias mvn-updates='mvn versions:display-dependency-updates'
  67. function listMavenCompletions {
  68. local file new_file
  69. local -a profiles POM_FILES modules
  70. # Root POM
  71. POM_FILES=(~/.m2/settings.xml)
  72. # POM in the current directory
  73. if [[ -f pom.xml ]]; then
  74. local file=pom.xml
  75. POM_FILES+=("${file:A}")
  76. fi
  77. # Look for POM files in parent directories
  78. while [[ -n "$file" ]] && grep -q "<parent>" "$file"; do
  79. # look for a new relativePath for parent pom.xml
  80. new_file=$(grep -e "<relativePath>.*</relativePath>" "$file" | sed -e 's/.*<relativePath>\(.*\)<\/relativePath>.*/\1/')
  81. # if <parent> is present but not defined, assume ../pom.xml
  82. if [[ -z "$new_file" ]]; then
  83. new_file="../pom.xml"
  84. fi
  85. # if file doesn't exist break
  86. file="${file:h}/${new_file}"
  87. if ! [[ -e "$file" ]]; then
  88. break
  89. fi
  90. POM_FILES+=("${file:A}")
  91. done
  92. # Get profiles from found files
  93. for file in $POM_FILES; do
  94. [[ -e $file ]] || continue
  95. profiles+=($(sed 's/<!--.*-->//' "$file" | sed '/<!--/,/-->/d' | grep -e "<profile>" -A 1 | grep -e "<id>.*</id>" | sed 's?.*<id>\(.*\)<\/id>.*?-P\1?'))
  96. done
  97. # List modules
  98. modules=($(find **/pom.xml -type f | grep -v '/target/classes/META-INF/' | grep '/pom.xml' |sed 's|\(.*\)/pom\.xml|\1|'))
  99. reply=(
  100. # common lifecycle
  101. clean initialize process-resources compile process-test-resources test-compile test package verify install deploy site
  102. # integration testing
  103. pre-integration-test integration-test
  104. # common plugins
  105. deploy failsafe install site surefire checkstyle javadoc jxr pmd ant antrun archetype assembly dependency enforcer gpg help release repository source eclipse idea jetty cargo jboss tomcat tomcat6 tomcat7 exec versions war ear ejb android scm buildnumber nexus repository sonar license hibernate3 liquibase flyway gwt
  106. # deploy
  107. deploy:deploy-file
  108. # failsafe
  109. failsafe:integration-test failsafe:verify
  110. # install
  111. install:install-file install:help
  112. # site
  113. site:site site:deploy site:run site:stage site:stage-deploy site:attach-descriptor site:jar site:effective-site
  114. # surefire
  115. surefire:test
  116. # checkstyle
  117. checkstyle:checkstyle checkstyle:check checkstyle:checkstyle-aggregate
  118. # javadoc
  119. javadoc:javadoc javadoc:test-javadoc javadoc:javadoc-no-fork javadoc:test-javadoc-no-fork javadoc:aggregate javadoc:test-aggregate javadoc:jar javadoc:test-jar javadoc:aggregate-jar javadoc:test-aggregate-jar javadoc:fix javadoc:test-fix javadoc:resource-bundle javadoc:test-resource-bundle
  120. # jxr
  121. jxr:jxr jxr:aggregate jxr:test-jxr jxr:test-aggregate
  122. # pmd
  123. pmd:pmd pmd:cpd pmd:check pmd:cpd-check
  124. # ant
  125. ant:ant ant:clean
  126. # antrun
  127. antrun:run
  128. # archetype
  129. archetype:generate archetype:create-from-project archetype:crawl
  130. # assembly
  131. assembly:single assembly:assembly
  132. # dependency
  133. dependency:analyze dependency:analyze-dep-mgt dependency:analyze-only dependency:analyze-report dependency:analyze-duplicate dependency:build-classpath dependency:copy dependency:copy-dependencies dependency:display-ancestors dependency:get dependency:go-offline dependency:list dependency:list-repositories dependency:properties dependency:purge-local-repository dependency:resolve dependency:resolve-plugins dependency:sources dependency:tree dependency:unpack dependency:unpack-dependencies
  134. # enforcer
  135. enforcer:enforce enforcer:display-info
  136. # gpg
  137. gpg:sign gpg:sign-and-deploy-file
  138. # help
  139. help:active-profiles help:all-profiles help:describe help:effective-pom help:effective-settings help:evaluate help:expressions help:system
  140. # release
  141. release:clean release:prepare release:prepare-with-pom release:rollback release:perform release:stage release:branch release:update-versions
  142. # jgitflow
  143. jgitflow:feature-start jgitflow:feature-finish jgitflow:release-start jgitflow:release-finish jgitflow:hotfix-start jgitflow:hotfix-finish jgitflow:build-number
  144. # repository
  145. repository:bundle-create repository:bundle-pack
  146. # source
  147. source:aggregate source:jar source:jar-no-fork source:test-jar source:test-jar-no-fork
  148. # eclipse
  149. eclipse:clean eclipse:eclipse
  150. # idea
  151. idea:clean idea:idea
  152. # jetty
  153. jetty:run jetty:run-exploded
  154. # cargo
  155. cargo:start cargo:run cargo:stop cargo:deploy cargo:undeploy cargo:help
  156. # jboss
  157. jboss:start jboss:stop jboss:deploy jboss:undeploy jboss:redeploy
  158. # tomcat
  159. tomcat:start tomcat:stop tomcat:deploy tomcat:undeploy tomcat:redeploy
  160. # tomcat6
  161. tomcat6:run tomcat6:run-war tomcat6:run-war-only tomcat6:stop tomcat6:deploy tomcat6:undeploy
  162. # tomcat7
  163. tomcat7:run tomcat7:run-war tomcat7:run-war-only tomcat7:deploy
  164. # tomee
  165. tomee:run tomee:run-war tomee:run-war-only tomee:stop tomee:deploy tomee:undeploy
  166. # spring-boot
  167. spring-boot:run spring-boot:repackage
  168. # quarkus
  169. quarkus:dev quarkus:list-extensions quarkus:add-extension quarkus:add-extensions quarkus:generate-config quarkus:help
  170. # exec
  171. exec:exec exec:java
  172. # versions
  173. versions:display-dependency-updates versions:display-plugin-updates versions:display-property-updates versions:update-parent versions:update-properties versions:update-child-modules versions:lock-snapshots versions:unlock-snapshots versions:resolve-ranges versions:set versions:use-releases versions:use-next-releases versions:use-latest-releases versions:use-next-snapshots versions:use-latest-snapshots versions:use-next-versions versions:use-latest-versions versions:commit versions:revert
  174. # scm
  175. scm:add scm:bootstrap scm:branch scm:changelog scm:check-local-modification scm:checkin scm:checkout scm:diff scm:edit scm:export scm:list scm:remove scm:status scm:tag scm:unedit scm:update scm:update-subprojects scm:validate
  176. # buildnumber
  177. buildnumber:create buildnumber:create-timestamp buildnumber:help buildnumber:hgchangeset
  178. # war
  179. war:war war:exploded war:inplace war:manifest
  180. # ear
  181. ear:ear ear:generate-application-xml
  182. # ejb
  183. ejb:ejb
  184. # android
  185. android:apk android:apklib android:deploy android:deploy-dependencies android:dex android:emulator-start android:emulator-stop android:emulator-stop-all android:generate-sources android:help android:instrument android:manifest-update android:pull android:push android:redeploy android:run android:undeploy android:unpack android:version-update android:zipalign android:devices
  186. # nexus
  187. nexus:staging-list nexus:staging-close nexus:staging-drop nexus:staging-release nexus:staging-build-promotion nexus:staging-profiles-list nexus:settings-download
  188. # repository
  189. repository:bundle-create repository:bundle-pack repository:help
  190. # sonar
  191. sonar:sonar
  192. # license
  193. license:format license:check
  194. # hibernate3
  195. hibernate3:hbm2ddl hibernate3:help
  196. # liquibase
  197. liquibase:changelogSync liquibase:changelogSyncSQL liquibase:clearCheckSums liquibase:dbDoc liquibase:diff liquibase:dropAll liquibase:help liquibase:migrate liquibase:listLocks liquibase:migrateSQL liquibase:releaseLocks liquibase:rollback liquibase:rollbackSQL liquibase:status liquibase:tag liquibase:update liquibase:updateSQL liquibase:updateTestingRollback
  198. # flyway
  199. flyway:clean flyway:history flyway:init flyway:migrate flyway:status flyway:validate
  200. # gwt
  201. gwt:browser gwt:clean gwt:compile gwt:compile-report gwt:css gwt:debug gwt:eclipse gwt:eclipseTest gwt:generateAsync gwt:help gwt:i18n gwt:mergewebxml gwt:resources gwt:run gwt:sdkInstall gwt:source-jar gwt:soyc gwt:test
  202. # asciidoctor
  203. asciidoctor:process-asciidoc asciidoctor:auto-refresh asciidoctor:http asciidoctor:zip
  204. # compiler
  205. compiler:compile compiler:testCompile
  206. # resources
  207. resources:resources resources:testResources resources:copy-resources
  208. # verifier
  209. verifier:verify
  210. # jar
  211. jar:jar jar:test-jar
  212. # rar
  213. rar:rar
  214. # acr
  215. acr:acr
  216. # shade
  217. shade:shade
  218. # changelog
  219. changelog:changelog changelog:dev-activity changelog:file-activity
  220. # changes
  221. changes:announcement-mail changes:announcement-generate changes:changes-check changes:changes-validate changes:changes-report changes:jira-report changes:trac-report changes:github-report
  222. # doap
  223. doap:generate
  224. # docck
  225. docck:check
  226. # jdeps
  227. jdeps:jdkinternals jdeps:test-jdkinternals
  228. # linkcheck
  229. linkcheck:linkcheck
  230. # project-info-reports
  231. project-info-reports:cim project-info-reports:dependencies project-info-reports:dependency-convergence project-info-reports:dependency-info project-info-reports:dependency-management project-info-reports:distribution-management project-info-reports:help project-info-reports:index project-info-reports:issue-tracking project-info-reports:license project-info-reports:mailing-list project-info-reports:modules project-info-reports:plugin-management project-info-reports:plugins project-info-reports:project-team project-info-reports:scm project-info-reports:summary
  232. # surefire-report
  233. surefire-report:failsafe-report-only surefire-report:report surefire-report:report-only
  234. # invoker
  235. invoker:install invoker:integration-test invoker:verify invoker:run
  236. # jarsigner
  237. jarsigner:sign jarsigner:verify
  238. # patch
  239. patch:apply
  240. # pdf
  241. pdf:pdf
  242. # plugin
  243. plugin:descriptor plugin:report plugin:updateRegistry plugin:addPluginArtifactMetadata plugin:helpmojo
  244. # remote-resources
  245. remote-resources:bundle remote-resources:process
  246. # scm-publish
  247. scm-publish:help scm-publish:publish-scm scm-publish:scmpublish
  248. # stage
  249. stage:copy
  250. # toolchain
  251. toolchain:toolchain
  252. #liberty
  253. liberty:clean-server liberty:compile-jsp liberty:configure-arquillian liberty:create-server liberty:debug liberty:debug-server liberty:deploy liberty:dev liberty:display-url liberty:dump-server liberty:install-apps liberty:install-feature liberty:install-server liberty:java-dump-server liberty:package-server liberty:run liberty:run-server liberty:server-status liberty:start liberty:start-server liberty:status liberty:stop liberty:stop-server liberty:test-start-server liberty:test-stop-server liberty:undeploy liberty:uninstall-feature
  254. # options
  255. "-Dmaven.test.skip=true" -DskipTests -DskipITs -Dmaven.surefire.debug -DenableCiProfile "-Dpmd.skip=true" "-Dcheckstyle.skip=true" "-Dtycho.mode=maven" "-Dmaven.test.failure.ignore=true" "-DgroupId=" "-DartifactId=" "-Dversion=" "-Dpackaging=jar" "-Dfile="
  256. # arguments
  257. -am --also-make
  258. -amd --also-make-dependents-am
  259. -B --batch-mode
  260. -b --builder
  261. -C --strict-checksums
  262. -c --lax-checksums
  263. -cpu --check-plugin-updates
  264. -D --define
  265. -e --errors
  266. -emp --encrypt-master-password
  267. -ep --encrypt-password
  268. -f --file
  269. -fae --fail-at-end
  270. -ff --fail-fast
  271. -fn --fail-never
  272. -gs --global-settings
  273. -gt --global-toolchains
  274. -h --help
  275. -l --log-file
  276. -llr --legacy-local-repository
  277. -N --non-recursive
  278. -npr --no-plugin-registry
  279. -npu --no-plugin-updates
  280. -nsu --no-snapshot-updates
  281. -o --offline
  282. -P --activate-profiles
  283. -pl --projects
  284. -q --quiet
  285. -rf --resume-from
  286. -s --settings
  287. -t --toolchains
  288. -T --threads
  289. -U --update-snapshots
  290. -up --update-plugins
  291. -v --version
  292. -V --show-version
  293. -X --debug
  294. cli:execute cli:execute-phase
  295. archetype:generate generate-sources
  296. cobertura:cobertura
  297. -Dtest=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dtest=\1?' ; fi)
  298. -Dit.test=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dit.test=\1?' ; fi)
  299. $profiles
  300. $modules
  301. )
  302. }
  303. compctl -K listMavenCompletions mvn mvnw
  304. compctl -K listMavenCompletions mvn-color
  305. compctl -K listMavenCompletions mvn-or-mvnw