mvn.plugin.zsh 14 KB

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