mvn.plugin.zsh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 mvns='mvn site'
  61. alias mvnsrc='mvn dependency:sources'
  62. alias mvnt='mvn test'
  63. alias mvntc='mvn tomcat:run'
  64. alias mvntc7='mvn tomcat7:run'
  65. alias mvn-updates='mvn versions:display-dependency-updates'
  66. function listMavenCompletions {
  67. local file new_file
  68. local -a profiles POM_FILES
  69. # Root POM
  70. POM_FILES=(~/.m2/settings.xml)
  71. # POM in the current directory
  72. if [[ -f pom.xml ]]; then
  73. local file=pom.xml
  74. POM_FILES+=("${file:A}")
  75. fi
  76. # Look for POM files in parent directories
  77. while [[ -n "$file" ]] && grep -q "<parent>" "$file"; do
  78. # look for a new relativePath for parent pom.xml
  79. new_file=$(grep -e "<relativePath>.*</relativePath>" "$file" | sed -e 's/.*<relativePath>\(.*\)<\/relativePath>.*/\1/')
  80. # if <parent> is present but not defined, assume ../pom.xml
  81. if [[ -z "$new_file" ]]; then
  82. new_file="../pom.xml"
  83. fi
  84. # if file doesn't exist break
  85. file="${file:h}/${new_file}"
  86. if ! [[ -e "$file" ]]; then
  87. break
  88. fi
  89. POM_FILES+=("${file:A}")
  90. done
  91. # Get profiles from found files
  92. for file in $POM_FILES; do
  93. [[ -e $file ]] || continue
  94. profiles+=($(sed 's/<!--.*-->//' "$file" | sed '/<!--/,/-->/d' | grep -e "<profile>" -A 1 | grep -e "<id>.*</id>" | sed 's?.*<id>\(.*\)<\/id>.*?-P\1?'))
  95. done
  96. reply=(
  97. # common lifecycle
  98. clean initialize process-resources compile process-test-resources test-compile test package verify install deploy site
  99. # integration testing
  100. pre-integration-test integration-test
  101. # common plugins
  102. 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
  103. # deploy
  104. deploy:deploy-file
  105. # failsafe
  106. failsafe:integration-test failsafe:verify
  107. # install
  108. install:install-file install:help
  109. # site
  110. site:site site:deploy site:run site:stage site:stage-deploy site:attach-descriptor site:jar site:effective-site
  111. # surefire
  112. surefire:test
  113. # checkstyle
  114. checkstyle:checkstyle checkstyle:check checkstyle:checkstyle-aggregate
  115. # javadoc
  116. 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
  117. # jxr
  118. jxr:jxr jxr:aggregate jxr:test-jxr jxr:test-aggregate
  119. # pmd
  120. pmd:pmd pmd:cpd pmd:check pmd:cpd-check
  121. # ant
  122. ant:ant ant:clean
  123. # antrun
  124. antrun:run
  125. # archetype
  126. archetype:generate archetype:create-from-project archetype:crawl
  127. # assembly
  128. assembly:single assembly:assembly
  129. # dependency
  130. 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
  131. # enforcer
  132. enforcer:enforce enforcer:display-info
  133. # gpg
  134. gpg:sign gpg:sign-and-deploy-file
  135. # help
  136. help:active-profiles help:all-profiles help:describe help:effective-pom help:effective-settings help:evaluate help:expressions help:system
  137. # release
  138. release:clean release:prepare release:prepare-with-pom release:rollback release:perform release:stage release:branch release:update-versions
  139. # jgitflow
  140. jgitflow:feature-start jgitflow:feature-finish jgitflow:release-start jgitflow:release-finish jgitflow:hotfix-start jgitflow:hotfix-finish jgitflow:build-number
  141. # repository
  142. repository:bundle-create repository:bundle-pack
  143. # source
  144. source:aggregate source:jar source:jar-no-fork source:test-jar source:test-jar-no-fork
  145. # eclipse
  146. eclipse:clean eclipse:eclipse
  147. # idea
  148. idea:clean idea:idea
  149. # jetty
  150. jetty:run jetty:run-exploded
  151. # cargo
  152. cargo:start cargo:run cargo:stop cargo:deploy cargo:undeploy cargo:help
  153. # jboss
  154. jboss:start jboss:stop jboss:deploy jboss:undeploy jboss:redeploy
  155. # tomcat
  156. tomcat:start tomcat:stop tomcat:deploy tomcat:undeploy tomcat:redeploy
  157. # tomcat6
  158. tomcat6:run tomcat6:run-war tomcat6:run-war-only tomcat6:stop tomcat6:deploy tomcat6:undeploy
  159. # tomcat7
  160. tomcat7:run tomcat7:run-war tomcat7:run-war-only tomcat7:deploy
  161. # tomee
  162. tomee:run tomee:run-war tomee:run-war-only tomee:stop tomee:deploy tomee:undeploy
  163. # spring-boot
  164. spring-boot:run spring-boot:repackage
  165. # exec
  166. exec:exec exec:java
  167. # versions
  168. 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
  169. # scm
  170. 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
  171. # buildnumber
  172. buildnumber:create buildnumber:create-timestamp buildnumber:help buildnumber:hgchangeset
  173. # war
  174. war:war war:exploded war:inplace war:manifest
  175. # ear
  176. ear:ear ear:generate-application-xml
  177. # ejb
  178. ejb:ejb
  179. # android
  180. 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
  181. # nexus
  182. nexus:staging-list nexus:staging-close nexus:staging-drop nexus:staging-release nexus:staging-build-promotion nexus:staging-profiles-list nexus:settings-download
  183. # repository
  184. repository:bundle-create repository:bundle-pack repository:help
  185. # sonar
  186. sonar:sonar
  187. # license
  188. license:format license:check
  189. # hibernate3
  190. hibernate3:hbm2ddl hibernate3:help
  191. # liquibase
  192. 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
  193. # flyway
  194. flyway:clean flyway:history flyway:init flyway:migrate flyway:status flyway:validate
  195. # gwt
  196. 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
  197. # asciidoctor
  198. asciidoctor:process-asciidoc asciidoctor:auto-refresh asciidoctor:http asciidoctor:zip
  199. # compiler
  200. compiler:compile compiler:testCompile
  201. # resources
  202. resources:resources resources:testResources resources:copy-resources
  203. # verifier
  204. verifier:verify
  205. # jar
  206. jar:jar jar:test-jar
  207. # rar
  208. rar:rar
  209. # acr
  210. acr:acr
  211. # shade
  212. shade:shade
  213. # changelog
  214. changelog:changelog changelog:dev-activity changelog:file-activity
  215. # changes
  216. changes:announcement-mail changes:announcement-generate changes:changes-check changes:changes-validate changes:changes-report changes:jira-report changes:trac-report changes:github-report
  217. # doap
  218. doap:generate
  219. # docck
  220. docck:check
  221. # jdeps
  222. jdeps:jdkinternals jdeps:test-jdkinternals
  223. # linkcheck
  224. linkcheck:linkcheck
  225. # project-info-reports
  226. 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
  227. # surefire-report
  228. surefire-report:failsafe-report-only surefire-report:report surefire-report:report-only
  229. # invoker
  230. invoker:install invoker:integration-test invoker:verify invoker:run
  231. # jarsigner
  232. jarsigner:sign jarsigner:verify
  233. # patch
  234. patch:apply
  235. # pdf
  236. pdf:pdf
  237. # plugin
  238. plugin:descriptor plugin:report plugin:updateRegistry plugin:addPluginArtifactMetadata plugin:helpmojo
  239. # remote-resources
  240. remote-resources:bundle remote-resources:process
  241. # scm-publish
  242. scm-publish:help scm-publish:publish-scm scm-publish:scmpublish
  243. # stage
  244. stage:copy
  245. # toolchain
  246. toolchain:toolchain
  247. #liberty
  248. 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
  249. # options
  250. "-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="
  251. # arguments
  252. -am --also-make
  253. -amd --also-make-dependents-am
  254. -B --batch-mode
  255. -b --builder
  256. -C --strict-checksums
  257. -c --lax-checksums
  258. -cpu --check-plugin-updates
  259. -D --define
  260. -e --errors
  261. -emp --encrypt-master-password
  262. -ep --encrypt-password
  263. -f --file
  264. -fae --fail-at-end
  265. -ff --fail-fast
  266. -fn --fail-never
  267. -gs --global-settings
  268. -gt --global-toolchains
  269. -h --help
  270. -l --log-file
  271. -llr --legacy-local-repository
  272. -N --non-recursive
  273. -npr --no-plugin-registry
  274. -npu --no-plugin-updates
  275. -nsu --no-snapshot-updates
  276. -o --offline
  277. -P --activate-profiles
  278. -pl --projects
  279. -q --quiet
  280. -rf --resume-from
  281. -s --settings
  282. -t --toolchains
  283. -T --threads
  284. -U --update-snapshots
  285. -up --update-plugins
  286. -v --version
  287. -V --show-version
  288. -X --debug
  289. cli:execute cli:execute-phase
  290. archetype:generate generate-sources
  291. cobertura:cobertura
  292. -Dtest=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dtest=\1?' ; fi)
  293. -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)
  294. $profiles
  295. )
  296. }
  297. compctl -K listMavenCompletions mvn mvnw
  298. compctl -K listMavenCompletions mvn-color
  299. compctl -K listMavenCompletions mvn-or-mvnw